@@ -170,7 +170,7 @@ |
||
| 170 | 170 | * |
| 171 | 171 | * @param string $fileName The path to the file |
| 172 | 172 | * @param int $preferred_format The preferred format - 0 to automatically determine, 1 for gif, 2 for jpg, 3 for png, 6 for bmp and 15 for wbmp |
| 173 | - * @return boolean Whether the reencoding was successful |
|
| 173 | + * @return false|null Whether the reencoding was successful |
|
| 174 | 174 | */ |
| 175 | 175 | function reencodeImage($fileName, $preferred_format = 0) |
| 176 | 176 | { |
@@ -523,7 +523,6 @@ discard block |
||
| 523 | 523 | /** |
| 524 | 524 | * Copy image. |
| 525 | 525 | * Used when imagecopyresample() is not available. |
| 526 | - |
|
| 527 | 526 | * @param resource $dst_img The destination image - a GD image resource |
| 528 | 527 | * @param resource $src_img The source image - a GD image resource |
| 529 | 528 | * @param int $dst_x The "x" coordinate of the destination image |
@@ -754,7 +753,6 @@ discard block |
||
| 754 | 753 | |
| 755 | 754 | /** |
| 756 | 755 | * Writes a gif file to disk as a png file. |
| 757 | - |
|
| 758 | 756 | * @param resource $gif A gif image resource |
| 759 | 757 | * @param string $lpszFileName The name of the file |
| 760 | 758 | * @param int $background_color The background color |
@@ -18,8 +18,9 @@ discard block |
||
| 18 | 18 | * @version 2.1 Beta 3 |
| 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', |
@@ -343,38 +351,39 @@ discard block |
||
| 343 | 351 | fclose($fp_destination); |
| 344 | 352 | |
| 345 | 353 | $sizes = @getimagesize($destination); |
| 346 | - } |
|
| 347 | - elseif ($fp_destination) |
|
| 354 | + } elseif ($fp_destination) |
|
| 348 | 355 | { |
| 349 | 356 | $sizes = @getimagesize($source); |
| 350 | 357 | |
| 351 | 358 | $fp_source = fopen($source, 'rb'); |
| 352 | 359 | if ($fp_source !== false) |
| 353 | 360 | { |
| 354 | - while (!feof($fp_source)) |
|
| 355 | - fwrite($fp_destination, fread($fp_source, 8192)); |
|
| 361 | + while (!feof($fp_source)) { |
|
| 362 | + fwrite($fp_destination, fread($fp_source, 8192)); |
|
| 363 | + } |
|
| 356 | 364 | fclose($fp_source); |
| 365 | + } else { |
|
| 366 | + $sizes = array(-1, -1, -1); |
|
| 357 | 367 | } |
| 358 | - else |
|
| 359 | - $sizes = array(-1, -1, -1); |
|
| 360 | 368 | fclose($fp_destination); |
| 361 | 369 | } |
| 362 | 370 | // We can't get to the file. |
| 363 | - else |
|
| 364 | - $sizes = array(-1, -1, -1); |
|
| 371 | + else { |
|
| 372 | + $sizes = array(-1, -1, -1); |
|
| 373 | + } |
|
| 365 | 374 | |
| 366 | 375 | // See if we have -or- can get the needed memory for this operation |
| 367 | 376 | // ImageMagick isn't subject to PHP's memory limits :) |
| 368 | - if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) |
|
| 369 | - return false; |
|
| 377 | + if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) { |
|
| 378 | + return false; |
|
| 379 | + } |
|
| 370 | 380 | |
| 371 | 381 | // A known and supported format? |
| 372 | 382 | // @todo test PSD and gif. |
| 373 | 383 | if ((checkImagick() || checkMagickWand()) && isset($default_formats[$sizes[2]])) |
| 374 | 384 | { |
| 375 | 385 | return resizeImage(null, $destination, null, null, $max_width, $max_height, true, $preferred_format); |
| 376 | - } |
|
| 377 | - elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) |
|
| 386 | + } elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) |
|
| 378 | 387 | { |
| 379 | 388 | $imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]]; |
| 380 | 389 | if ($src_img = @$imagecreatefrom($destination)) |
@@ -427,14 +436,14 @@ discard block |
||
| 427 | 436 | $dest_width = empty($max_width) ? $src_width : $max_width; |
| 428 | 437 | $dest_height = empty($max_height) ? $src_height : $max_height; |
| 429 | 438 | |
| 430 | - if ($default_formats[$preferred_format] == 'jpeg') |
|
| 431 | - $imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 439 | + if ($default_formats[$preferred_format] == 'jpeg') { |
|
| 440 | + $imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 441 | + } |
|
| 432 | 442 | |
| 433 | 443 | $imagick->setImageFormat($default_formats[$preferred_format]); |
| 434 | 444 | $imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true); |
| 435 | 445 | $success = $imagick->writeImage($destName); |
| 436 | - } |
|
| 437 | - else |
|
| 446 | + } else |
|
| 438 | 447 | { |
| 439 | 448 | $magick_wand = newMagickWand(); |
| 440 | 449 | MagickReadImage($magick_wand, $destName); |
@@ -443,8 +452,9 @@ discard block |
||
| 443 | 452 | $dest_width = empty($max_width) ? $src_width : $max_width; |
| 444 | 453 | $dest_height = empty($max_height) ? $src_height : $max_height; |
| 445 | 454 | |
| 446 | - if ($default_formats[$preferred_format] == 'jpeg') |
|
| 447 | - MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 455 | + if ($default_formats[$preferred_format] == 'jpeg') { |
|
| 456 | + MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 457 | + } |
|
| 448 | 458 | |
| 449 | 459 | MagickSetImageFormat($magick_wand, $default_formats[$preferred_format]); |
| 450 | 460 | MagickResizeImage($magick_wand, $dest_width, $dest_height, MW_LanczosFilter, 1, true); |
@@ -452,8 +462,7 @@ discard block |
||
| 452 | 462 | } |
| 453 | 463 | |
| 454 | 464 | return !empty($success); |
| 455 | - } |
|
| 456 | - elseif (checkGD()) |
|
| 465 | + } elseif (checkGD()) |
|
| 457 | 466 | { |
| 458 | 467 | $success = false; |
| 459 | 468 | |
@@ -464,8 +473,7 @@ discard block |
||
| 464 | 473 | { |
| 465 | 474 | $dst_width = $max_width; |
| 466 | 475 | $dst_height = round($src_height * $max_width / $src_width); |
| 467 | - } |
|
| 468 | - elseif (!empty($max_height)) |
|
| 476 | + } elseif (!empty($max_height)) |
|
| 469 | 477 | { |
| 470 | 478 | $dst_width = round($src_width * $max_height / $src_height); |
| 471 | 479 | $dst_height = $max_height; |
@@ -483,44 +491,48 @@ discard block |
||
| 483 | 491 | if ((!empty($preferred_format)) && ($preferred_format == 3)) |
| 484 | 492 | { |
| 485 | 493 | imagealphablending($dst_img, false); |
| 486 | - if (function_exists('imagesavealpha')) |
|
| 487 | - imagesavealpha($dst_img, true); |
|
| 494 | + if (function_exists('imagesavealpha')) { |
|
| 495 | + imagesavealpha($dst_img, true); |
|
| 496 | + } |
|
| 488 | 497 | } |
| 498 | + } else { |
|
| 499 | + $dst_img = imagecreate($dst_width, $dst_height); |
|
| 489 | 500 | } |
| 490 | - else |
|
| 491 | - $dst_img = imagecreate($dst_width, $dst_height); |
|
| 492 | 501 | |
| 493 | 502 | // Resize it! |
| 494 | - if ($gd2) |
|
| 495 | - imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 496 | - else |
|
| 497 | - imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 503 | + if ($gd2) { |
|
| 504 | + imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 505 | + } else { |
|
| 506 | + imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 507 | + } |
|
| 508 | + } else { |
|
| 509 | + $dst_img = $src_img; |
|
| 498 | 510 | } |
| 499 | - else |
|
| 500 | - $dst_img = $src_img; |
|
| 511 | + } else { |
|
| 512 | + $dst_img = $src_img; |
|
| 501 | 513 | } |
| 502 | - else |
|
| 503 | - $dst_img = $src_img; |
|
| 504 | 514 | |
| 505 | 515 | // Save the image as ... |
| 506 | - if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) |
|
| 507 | - $success = imagepng($dst_img, $destName); |
|
| 508 | - elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) |
|
| 509 | - $success = imagegif($dst_img, $destName); |
|
| 510 | - elseif (function_exists('imagejpeg')) |
|
| 511 | - $success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 516 | + if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) { |
|
| 517 | + $success = imagepng($dst_img, $destName); |
|
| 518 | + } elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) { |
|
| 519 | + $success = imagegif($dst_img, $destName); |
|
| 520 | + } elseif (function_exists('imagejpeg')) { |
|
| 521 | + $success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 522 | + } |
|
| 512 | 523 | |
| 513 | 524 | // Free the memory. |
| 514 | 525 | imagedestroy($src_img); |
| 515 | - if ($dst_img != $src_img) |
|
| 516 | - imagedestroy($dst_img); |
|
| 526 | + if ($dst_img != $src_img) { |
|
| 527 | + imagedestroy($dst_img); |
|
| 528 | + } |
|
| 517 | 529 | |
| 518 | 530 | return $success; |
| 519 | - } |
|
| 520 | - else |
|
| 521 | - // Without GD, no image resizing at all. |
|
| 531 | + } else { |
|
| 532 | + // Without GD, no image resizing at all. |
|
| 522 | 533 | return false; |
| 523 | -} |
|
| 534 | + } |
|
| 535 | + } |
|
| 524 | 536 | |
| 525 | 537 | /** |
| 526 | 538 | * Copy image. |
@@ -574,8 +586,9 @@ discard block |
||
| 574 | 586 | $color = imagecolorresolve($dst_img, $red, $green, $blue); |
| 575 | 587 | if ($color == -1) |
| 576 | 588 | { |
| 577 | - if ($palsize++ < 256) |
|
| 578 | - imagecolorallocate($dst_img, $red, $green, $blue); |
|
| 589 | + if ($palsize++ < 256) { |
|
| 590 | + imagecolorallocate($dst_img, $red, $green, $blue); |
|
| 591 | + } |
|
| 579 | 592 | $color = imagecolorclosest($dst_img, $red, $green, $blue); |
| 580 | 593 | } |
| 581 | 594 | |
@@ -605,13 +618,15 @@ discard block |
||
| 605 | 618 | $header = unpack('vtype/Vsize/Vreserved/Voffset', fread($fp, 14)); |
| 606 | 619 | $info = unpack('Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vcolorimportant', fread($fp, 40)); |
| 607 | 620 | |
| 608 | - if ($header['type'] != 0x4D42) |
|
| 609 | - return false; |
|
| 621 | + if ($header['type'] != 0x4D42) { |
|
| 622 | + return false; |
|
| 623 | + } |
|
| 610 | 624 | |
| 611 | - if ($gd2) |
|
| 612 | - $dst_img = imagecreatetruecolor($info['width'], $info['height']); |
|
| 613 | - else |
|
| 614 | - $dst_img = imagecreate($info['width'], $info['height']); |
|
| 625 | + if ($gd2) { |
|
| 626 | + $dst_img = imagecreatetruecolor($info['width'], $info['height']); |
|
| 627 | + } else { |
|
| 628 | + $dst_img = imagecreate($info['width'], $info['height']); |
|
| 629 | + } |
|
| 615 | 630 | |
| 616 | 631 | $palette_size = $header['offset'] - 54; |
| 617 | 632 | $info['ncolor'] = $palette_size / 4; |
@@ -637,8 +652,9 @@ discard block |
||
| 637 | 652 | fseek($fp, $header['offset'] + ($scan_line_size + $scan_line_align) * $l); |
| 638 | 653 | $scan_line = fread($fp, $scan_line_size); |
| 639 | 654 | |
| 640 | - if (strlen($scan_line) < $scan_line_size) |
|
| 641 | - continue; |
|
| 655 | + if (strlen($scan_line) < $scan_line_size) { |
|
| 656 | + continue; |
|
| 657 | + } |
|
| 642 | 658 | |
| 643 | 659 | if ($info['bits'] == 32) |
| 644 | 660 | { |
@@ -656,14 +672,14 @@ discard block |
||
| 656 | 672 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
| 657 | 673 | |
| 658 | 674 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
| 659 | - if ($color == -1) |
|
| 660 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 675 | + if ($color == -1) { |
|
| 676 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 677 | + } |
|
| 661 | 678 | } |
| 662 | 679 | |
| 663 | 680 | imagesetpixel($dst_img, $x, $y, $color); |
| 664 | 681 | } |
| 665 | - } |
|
| 666 | - elseif ($info['bits'] == 24) |
|
| 682 | + } elseif ($info['bits'] == 24) |
|
| 667 | 683 | { |
| 668 | 684 | $x = 0; |
| 669 | 685 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -678,14 +694,14 @@ discard block |
||
| 678 | 694 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
| 679 | 695 | |
| 680 | 696 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
| 681 | - if ($color == -1) |
|
| 682 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 697 | + if ($color == -1) { |
|
| 698 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 699 | + } |
|
| 683 | 700 | } |
| 684 | 701 | |
| 685 | 702 | imagesetpixel($dst_img, $x, $y, $color); |
| 686 | 703 | } |
| 687 | - } |
|
| 688 | - elseif ($info['bits'] == 16) |
|
| 704 | + } elseif ($info['bits'] == 16) |
|
| 689 | 705 | { |
| 690 | 706 | $x = 0; |
| 691 | 707 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -706,20 +722,20 @@ discard block |
||
| 706 | 722 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
| 707 | 723 | |
| 708 | 724 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
| 709 | - if ($color == -1) |
|
| 710 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 725 | + if ($color == -1) { |
|
| 726 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 727 | + } |
|
| 711 | 728 | } |
| 712 | 729 | |
| 713 | 730 | imagesetpixel($dst_img, $x, $y, $color); |
| 714 | 731 | } |
| 715 | - } |
|
| 716 | - elseif ($info['bits'] == 8) |
|
| 732 | + } elseif ($info['bits'] == 8) |
|
| 717 | 733 | { |
| 718 | 734 | $x = 0; |
| 719 | - for ($j = 0; $j < $scan_line_size; $x++) |
|
| 720 | - imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]); |
|
| 721 | - } |
|
| 722 | - elseif ($info['bits'] == 4) |
|
| 735 | + for ($j = 0; $j < $scan_line_size; $x++) { |
|
| 736 | + imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]); |
|
| 737 | + } |
|
| 738 | + } elseif ($info['bits'] == 4) |
|
| 723 | 739 | { |
| 724 | 740 | $x = 0; |
| 725 | 741 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -727,11 +743,11 @@ discard block |
||
| 727 | 743 | $byte = ord($scan_line{$j++}); |
| 728 | 744 | |
| 729 | 745 | imagesetpixel($dst_img, $x, $y, $palette[(int) ($byte / 16)]); |
| 730 | - if (++$x < $info['width']) |
|
| 731 | - imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]); |
|
| 746 | + if (++$x < $info['width']) { |
|
| 747 | + imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]); |
|
| 748 | + } |
|
| 732 | 749 | } |
| 733 | - } |
|
| 734 | - elseif ($info['bits'] == 1) |
|
| 750 | + } elseif ($info['bits'] == 1) |
|
| 735 | 751 | { |
| 736 | 752 | $x = 0; |
| 737 | 753 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -740,7 +756,9 @@ discard block |
||
| 740 | 756 | |
| 741 | 757 | imagesetpixel($dst_img, $x, $y, $palette[(($byte) & 128) != 0]); |
| 742 | 758 | for ($shift = 1; $shift < 8; $shift++) { |
| 743 | - if (++$x < $info['width']) imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]); |
|
| 759 | + if (++$x < $info['width']) { |
|
| 760 | + imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]); |
|
| 761 | + } |
|
| 744 | 762 | } |
| 745 | 763 | } |
| 746 | 764 | } |
@@ -764,15 +782,18 @@ discard block |
||
| 764 | 782 | */ |
| 765 | 783 | function gif_outputAsPng($gif, $lpszFileName, $background_color = -1) |
| 766 | 784 | { |
| 767 | - if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') |
|
| 768 | - return false; |
|
| 785 | + if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') { |
|
| 786 | + return false; |
|
| 787 | + } |
|
| 769 | 788 | |
| 770 | 789 | $fd = $gif->get_png_data($background_color); |
| 771 | - if (strlen($fd) <= 0) |
|
| 772 | - return false; |
|
| 790 | + if (strlen($fd) <= 0) { |
|
| 791 | + return false; |
|
| 792 | + } |
|
| 773 | 793 | |
| 774 | - if (!($fh = @fopen($lpszFileName, 'wb'))) |
|
| 775 | - return false; |
|
| 794 | + if (!($fh = @fopen($lpszFileName, 'wb'))) { |
|
| 795 | + return false; |
|
| 796 | + } |
|
| 776 | 797 | |
| 777 | 798 | @fwrite($fh, $fd, strlen($fd)); |
| 778 | 799 | @fflush($fh); |
@@ -799,8 +820,9 @@ discard block |
||
| 799 | 820 | // What type are we going to be doing? |
| 800 | 821 | $imageType = $modSettings['visual_verification_type']; |
| 801 | 822 | // Special case to allow the admin center to show samples. |
| 802 | - if ($user_info['is_admin'] && isset($_GET['type'])) |
|
| 803 | - $imageType = (int) $_GET['type']; |
|
| 823 | + if ($user_info['is_admin'] && isset($_GET['type'])) { |
|
| 824 | + $imageType = (int) $_GET['type']; |
|
| 825 | + } |
|
| 804 | 826 | |
| 805 | 827 | // Some quick references for what we do. |
| 806 | 828 | // Do we show no, low or high noise? |
@@ -834,25 +856,28 @@ discard block |
||
| 834 | 856 | $character_spacing = 1; |
| 835 | 857 | |
| 836 | 858 | // What color is the background - generally white unless we're on "hard". |
| 837 | - if ($simpleBGColor) |
|
| 838 | - $background_color = array(255, 255, 255); |
|
| 839 | - else |
|
| 840 | - $background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243); |
|
| 859 | + if ($simpleBGColor) { |
|
| 860 | + $background_color = array(255, 255, 255); |
|
| 861 | + } else { |
|
| 862 | + $background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243); |
|
| 863 | + } |
|
| 841 | 864 | |
| 842 | 865 | // The color of the characters shown (red, green, blue). |
| 843 | - if ($simpleFGColor) |
|
| 844 | - $foreground_color = array(0, 0, 0); |
|
| 845 | - else |
|
| 866 | + if ($simpleFGColor) { |
|
| 867 | + $foreground_color = array(0, 0, 0); |
|
| 868 | + } else |
|
| 846 | 869 | { |
| 847 | 870 | $foreground_color = array(64, 101, 136); |
| 848 | 871 | |
| 849 | 872 | // Has the theme author requested a custom color? |
| 850 | - if (isset($settings['verification_foreground'])) |
|
| 851 | - $foreground_color = $settings['verification_foreground']; |
|
| 873 | + if (isset($settings['verification_foreground'])) { |
|
| 874 | + $foreground_color = $settings['verification_foreground']; |
|
| 875 | + } |
|
| 852 | 876 | } |
| 853 | 877 | |
| 854 | - if (!is_dir($settings['default_theme_dir'] . '/fonts')) |
|
| 855 | - return false; |
|
| 878 | + if (!is_dir($settings['default_theme_dir'] . '/fonts')) { |
|
| 879 | + return false; |
|
| 880 | + } |
|
| 856 | 881 | |
| 857 | 882 | // Get a list of the available fonts. |
| 858 | 883 | $font_dir = dir($settings['default_theme_dir'] . '/fonts'); |
@@ -863,25 +888,28 @@ discard block |
||
| 863 | 888 | { |
| 864 | 889 | if (preg_match('~^(.+)\.gdf$~', $entry, $matches) === 1) |
| 865 | 890 | { |
| 866 | - if ($endian ^ (strpos($entry, '_end.gdf') === false)) |
|
| 867 | - $font_list[] = $entry; |
|
| 891 | + if ($endian ^ (strpos($entry, '_end.gdf') === false)) { |
|
| 892 | + $font_list[] = $entry; |
|
| 893 | + } |
|
| 894 | + } elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) { |
|
| 895 | + $ttfont_list[] = $entry; |
|
| 868 | 896 | } |
| 869 | - elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) |
|
| 870 | - $ttfont_list[] = $entry; |
|
| 871 | 897 | } |
| 872 | 898 | |
| 873 | - if (empty($font_list)) |
|
| 874 | - return false; |
|
| 899 | + if (empty($font_list)) { |
|
| 900 | + return false; |
|
| 901 | + } |
|
| 875 | 902 | |
| 876 | 903 | // For non-hard things don't even change fonts. |
| 877 | 904 | if (!$varyFonts) |
| 878 | 905 | { |
| 879 | 906 | $font_list = array($font_list[0]); |
| 880 | 907 | // Try use Screenge if we can - it looks good! |
| 881 | - if (in_array('AnonymousPro.ttf', $ttfont_list)) |
|
| 882 | - $ttfont_list = array('AnonymousPro.ttf'); |
|
| 883 | - else |
|
| 884 | - $ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]); |
|
| 908 | + if (in_array('AnonymousPro.ttf', $ttfont_list)) { |
|
| 909 | + $ttfont_list = array('AnonymousPro.ttf'); |
|
| 910 | + } else { |
|
| 911 | + $ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]); |
|
| 912 | + } |
|
| 885 | 913 | |
| 886 | 914 | } |
| 887 | 915 | |
@@ -899,14 +927,16 @@ discard block |
||
| 899 | 927 | } |
| 900 | 928 | |
| 901 | 929 | // Load all fonts and determine the maximum font height. |
| 902 | - foreach ($loaded_fonts as $font_index => $dummy) |
|
| 903 | - $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 | + } |
|
| 904 | 933 | |
| 905 | 934 | // Determine the dimensions of each character. |
| 906 | - if ($imageType == 4 || $imageType == 5) |
|
| 907 | - $extra = 80; |
|
| 908 | - else |
|
| 909 | - $extra = 45; |
|
| 935 | + if ($imageType == 4 || $imageType == 5) { |
|
| 936 | + $extra = 80; |
|
| 937 | + } else { |
|
| 938 | + $extra = 45; |
|
| 939 | + } |
|
| 910 | 940 | |
| 911 | 941 | $total_width = $character_spacing * strlen($code) + $extra; |
| 912 | 942 | $max_height = 0; |
@@ -927,13 +957,15 @@ discard block |
||
| 927 | 957 | imagefilledrectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $bg_color); |
| 928 | 958 | |
| 929 | 959 | // Randomize the foreground color a little. |
| 930 | - for ($i = 0; $i < 3; $i++) |
|
| 931 | - $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 | + } |
|
| 932 | 963 | $fg_color = imagecolorallocate($code_image, $foreground_color[0], $foreground_color[1], $foreground_color[2]); |
| 933 | 964 | |
| 934 | 965 | // Color for the dots. |
| 935 | - for ($i = 0; $i < 3; $i++) |
|
| 936 | - $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 | + } |
|
| 937 | 969 | $randomness_color = imagecolorallocate($code_image, $dotbgcolor[0], $dotbgcolor[1], $dotbgcolor[2]); |
| 938 | 970 | |
| 939 | 971 | // Some squares/rectanges for new extreme level |
@@ -959,10 +991,11 @@ discard block |
||
| 959 | 991 | $can_do_ttf = function_exists('imagettftext'); |
| 960 | 992 | |
| 961 | 993 | // How much rotation will we give? |
| 962 | - if ($rotationType == 'none') |
|
| 963 | - $angle = 0; |
|
| 964 | - else |
|
| 965 | - $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 | + } |
|
| 966 | 999 | |
| 967 | 1000 | // What color shall we do it? |
| 968 | 1001 | if ($fontColorType == 'cyclic') |
@@ -976,51 +1009,56 @@ discard block |
||
| 976 | 1009 | array(0, 0, 0), |
| 977 | 1010 | array(143, 39, 31), |
| 978 | 1011 | ); |
| 979 | - if (!isset($last_index)) |
|
| 980 | - $last_index = -1; |
|
| 1012 | + if (!isset($last_index)) { |
|
| 1013 | + $last_index = -1; |
|
| 1014 | + } |
|
| 981 | 1015 | $new_index = $last_index; |
| 982 | - while ($last_index == $new_index) |
|
| 983 | - $new_index = mt_rand(0, count($colors) - 1); |
|
| 1016 | + while ($last_index == $new_index) { |
|
| 1017 | + $new_index = mt_rand(0, count($colors) - 1); |
|
| 1018 | + } |
|
| 984 | 1019 | $char_fg_color = $colors[$new_index]; |
| 985 | 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]); |
|
| 986 | 1025 | } |
| 987 | - elseif ($fontColorType == 'random') |
|
| 988 | - $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])); |
|
| 989 | - else |
|
| 990 | - $char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]); |
|
| 991 | 1026 | |
| 992 | 1027 | if (!empty($can_do_ttf)) |
| 993 | 1028 | { |
| 994 | 1029 | // GD2 handles font size differently. |
| 995 | - if ($fontSizeRandom) |
|
| 996 | - $font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25); |
|
| 997 | - else |
|
| 998 | - $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 | + } |
|
| 999 | 1035 | |
| 1000 | 1036 | // Work out the sizes - also fix the character width cause TTF not quite so wide! |
| 1001 | 1037 | $font_x = $fontHorSpace == 'minus' && $cur_x > 0 ? $cur_x - 3 : $cur_x + 5; |
| 1002 | 1038 | $font_y = $max_height - ($fontVerPos == 'vrandom' ? mt_rand(2, 8) : ($fontVerPos == 'random' ? mt_rand(3, 5) : 5)); |
| 1003 | 1039 | |
| 1004 | 1040 | // What font face? |
| 1005 | - if (!empty($ttfont_list)) |
|
| 1006 | - $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 | + } |
|
| 1007 | 1044 | |
| 1008 | 1045 | // What color are we to do it in? |
| 1009 | 1046 | $is_reverse = $showReverseChars ? mt_rand(0, 1) : false; |
| 1010 | 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]); |
| 1011 | 1048 | |
| 1012 | 1049 | $fontcord = @imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $char_color, $fontface, $character['id']); |
| 1013 | - if (empty($fontcord)) |
|
| 1014 | - $can_do_ttf = false; |
|
| 1015 | - elseif ($is_reverse) |
|
| 1050 | + if (empty($fontcord)) { |
|
| 1051 | + $can_do_ttf = false; |
|
| 1052 | + } elseif ($is_reverse) |
|
| 1016 | 1053 | { |
| 1017 | 1054 | imagefilledpolygon($code_image, $fontcord, 4, $fg_color); |
| 1018 | 1055 | // Put the character back! |
| 1019 | 1056 | imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $randomness_color, $fontface, $character['id']); |
| 1020 | 1057 | } |
| 1021 | 1058 | |
| 1022 | - if ($can_do_ttf) |
|
| 1023 | - $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 | + } |
|
| 1024 | 1062 | } |
| 1025 | 1063 | |
| 1026 | 1064 | if (!$can_do_ttf) |
@@ -1039,8 +1077,9 @@ discard block |
||
| 1039 | 1077 | } |
| 1040 | 1078 | |
| 1041 | 1079 | // Sorry, no rotation available. |
| 1042 | - else |
|
| 1043 | - 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 | + } |
|
| 1044 | 1083 | $cur_x += $character['width'] + $character_spacing; |
| 1045 | 1084 | } |
| 1046 | 1085 | } |
@@ -1053,17 +1092,22 @@ discard block |
||
| 1053 | 1092 | } |
| 1054 | 1093 | |
| 1055 | 1094 | // Make the background color transparent on the hard image. |
| 1056 | - if (!$simpleBGColor) |
|
| 1057 | - imagecolortransparent($code_image, $bg_color); |
|
| 1058 | - if ($hasBorder) |
|
| 1059 | - 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 | + } |
|
| 1060 | 1101 | |
| 1061 | 1102 | // Add some noise to the background? |
| 1062 | 1103 | if ($noiseType != 'none') |
| 1063 | 1104 | { |
| 1064 | - for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2)) |
|
| 1065 | - for ($j = mt_rand(0, 10); $j < $total_width; $j += mt_rand(1, 10)) |
|
| 1066 | - 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 | + } |
|
| 1067 | 1111 | |
| 1068 | 1112 | // Put in some lines too? |
| 1069 | 1113 | if ($noiseType != 'extreme') |
@@ -1076,8 +1120,7 @@ discard block |
||
| 1076 | 1120 | $x1 = mt_rand(0, $total_width); |
| 1077 | 1121 | $x2 = mt_rand(0, $total_width); |
| 1078 | 1122 | $y1 = 0; $y2 = $max_height; |
| 1079 | - } |
|
| 1080 | - else |
|
| 1123 | + } else |
|
| 1081 | 1124 | { |
| 1082 | 1125 | $y1 = mt_rand(0, $max_height); |
| 1083 | 1126 | $y2 = mt_rand(0, $max_height); |
@@ -1086,8 +1129,7 @@ discard block |
||
| 1086 | 1129 | imagesetthickness($code_image, mt_rand(1, 2)); |
| 1087 | 1130 | imageline($code_image, $x1, $y1, $x2, $y2, mt_rand(0, 1) ? $fg_color : $randomness_color); |
| 1088 | 1131 | } |
| 1089 | - } |
|
| 1090 | - else |
|
| 1132 | + } else |
|
| 1091 | 1133 | { |
| 1092 | 1134 | // Put in some ellipse |
| 1093 | 1135 | $num_ellipse = $noiseType == 'extreme' ? mt_rand(6, 12) : mt_rand(2, 6); |
@@ -1107,8 +1149,7 @@ discard block |
||
| 1107 | 1149 | { |
| 1108 | 1150 | header('Content-type: image/gif'); |
| 1109 | 1151 | imagegif($code_image); |
| 1110 | - } |
|
| 1111 | - else |
|
| 1152 | + } else |
|
| 1112 | 1153 | { |
| 1113 | 1154 | header('Content-type: image/png'); |
| 1114 | 1155 | imagepng($code_image); |
@@ -1131,25 +1172,29 @@ discard block |
||
| 1131 | 1172 | { |
| 1132 | 1173 | global $settings; |
| 1133 | 1174 | |
| 1134 | - if (!is_dir($settings['default_theme_dir'] . '/fonts')) |
|
| 1135 | - return false; |
|
| 1175 | + if (!is_dir($settings['default_theme_dir'] . '/fonts')) { |
|
| 1176 | + return false; |
|
| 1177 | + } |
|
| 1136 | 1178 | |
| 1137 | 1179 | // Get a list of the available font directories. |
| 1138 | 1180 | $font_dir = dir($settings['default_theme_dir'] . '/fonts'); |
| 1139 | 1181 | $font_list = array(); |
| 1140 | - while ($entry = $font_dir->read()) |
|
| 1141 | - 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')) |
|
| 1142 | 1184 | $font_list[] = $entry; |
| 1185 | + } |
|
| 1143 | 1186 | |
| 1144 | - if (empty($font_list)) |
|
| 1145 | - return false; |
|
| 1187 | + if (empty($font_list)) { |
|
| 1188 | + return false; |
|
| 1189 | + } |
|
| 1146 | 1190 | |
| 1147 | 1191 | // Pick a random font. |
| 1148 | 1192 | $random_font = $font_list[array_rand($font_list)]; |
| 1149 | 1193 | |
| 1150 | 1194 | // Check if the given letter exists. |
| 1151 | - if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) |
|
| 1152 | - return false; |
|
| 1195 | + if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) { |
|
| 1196 | + return false; |
|
| 1197 | + } |
|
| 1153 | 1198 | |
| 1154 | 1199 | // Include it! |
| 1155 | 1200 | header('Content-type: image/png'); |
@@ -243,6 +243,7 @@ |
||
| 243 | 243 | * @param null|array The groups to remove the member(s) from. If null, the specified members are stripped from all their membergroups. |
| 244 | 244 | * @param bool $permissionCheckDone Whether we've already checked permissions prior to calling this function |
| 245 | 245 | * @param bool $ignoreProtected Whether to ignore protected groups |
| 246 | + * @param integer $groups |
|
| 246 | 247 | * @return bool Whether the operation was successful |
| 247 | 248 | */ |
| 248 | 249 | function removeMembersFromGroups($members, $groups = null, $permissionCheckDone = false, $ignoreProtected = false) |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 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 | * Delete one of more membergroups. |
@@ -31,15 +32,16 @@ discard block |
||
| 31 | 32 | global $smcFunc, $modSettings, $txt; |
| 32 | 33 | |
| 33 | 34 | // Make sure it's an array. |
| 34 | - if (!is_array($groups)) |
|
| 35 | - $groups = array((int) $groups); |
|
| 36 | - else |
|
| 35 | + if (!is_array($groups)) { |
|
| 36 | + $groups = array((int) $groups); |
|
| 37 | + } else |
|
| 37 | 38 | { |
| 38 | 39 | $groups = array_unique($groups); |
| 39 | 40 | |
| 40 | 41 | // Make sure all groups are integer. |
| 41 | - foreach ($groups as $key => $value) |
|
| 42 | - $groups[$key] = (int) $value; |
|
| 42 | + foreach ($groups as $key => $value) { |
|
| 43 | + $groups[$key] = (int) $value; |
|
| 44 | + } |
|
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | // Some groups are protected (guests, administrators, moderators, newbies). |
@@ -56,15 +58,17 @@ discard block |
||
| 56 | 58 | 'is_protected' => 1, |
| 57 | 59 | ) |
| 58 | 60 | ); |
| 59 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 60 | - $protected_groups[] = $row['id_group']; |
|
| 61 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 62 | + $protected_groups[] = $row['id_group']; |
|
| 63 | + } |
|
| 61 | 64 | $smcFunc['db_free_result']($request); |
| 62 | 65 | } |
| 63 | 66 | |
| 64 | 67 | // Make sure they don't delete protected groups! |
| 65 | 68 | $groups = array_diff($groups, array_unique($protected_groups)); |
| 66 | - if (empty($groups)) |
|
| 67 | - return 'no_group_found'; |
|
| 69 | + if (empty($groups)) { |
|
| 70 | + return 'no_group_found'; |
|
| 71 | + } |
|
| 68 | 72 | |
| 69 | 73 | // Make sure they don't try to delete a group attached to a paid subscription. |
| 70 | 74 | $subscriptions = array(); |
@@ -74,13 +78,14 @@ discard block |
||
| 74 | 78 | ORDER BY name'); |
| 75 | 79 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 76 | 80 | { |
| 77 | - if (in_array($row['id_group'], $groups)) |
|
| 78 | - $subscriptions[] = $row['name']; |
|
| 79 | - else |
|
| 81 | + if (in_array($row['id_group'], $groups)) { |
|
| 82 | + $subscriptions[] = $row['name']; |
|
| 83 | + } else |
|
| 80 | 84 | { |
| 81 | 85 | $add_groups = explode(',', $row['add_groups']); |
| 82 | - if (count(array_intersect($add_groups, $groups)) != 0) |
|
| 83 | - $subscriptions[] = $row['name']; |
|
| 86 | + if (count(array_intersect($add_groups, $groups)) != 0) { |
|
| 87 | + $subscriptions[] = $row['name']; |
|
| 88 | + } |
|
| 84 | 89 | } |
| 85 | 90 | } |
| 86 | 91 | $smcFunc['db_free_result']($request); |
@@ -101,8 +106,9 @@ discard block |
||
| 101 | 106 | 'group_list' => $groups, |
| 102 | 107 | ) |
| 103 | 108 | ); |
| 104 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 105 | - logAction('delete_group', array('group' => $row['group_name']), 'admin'); |
|
| 109 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 110 | + logAction('delete_group', array('group' => $row['group_name']), 'admin'); |
|
| 111 | + } |
|
| 106 | 112 | $smcFunc['db_free_result']($request); |
| 107 | 113 | |
| 108 | 114 | call_integration_hook('integrate_delete_membergroups', array($groups)); |
@@ -187,12 +193,14 @@ discard block |
||
| 187 | 193 | ) |
| 188 | 194 | ); |
| 189 | 195 | $updates = array(); |
| 190 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 191 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 196 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 197 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 198 | + } |
|
| 192 | 199 | $smcFunc['db_free_result']($request); |
| 193 | 200 | |
| 194 | - foreach ($updates as $additional_groups => $memberArray) |
|
| 195 | - updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)))); |
|
| 201 | + foreach ($updates as $additional_groups => $memberArray) { |
|
| 202 | + updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)))); |
|
| 203 | + } |
|
| 196 | 204 | |
| 197 | 205 | // No boards can provide access to these membergroups anymore. |
| 198 | 206 | $request = $smcFunc['db_query']('', ' |
@@ -204,12 +212,13 @@ discard block |
||
| 204 | 212 | ) |
| 205 | 213 | ); |
| 206 | 214 | $updates = array(); |
| 207 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 208 | - $updates[$row['member_groups']][] = $row['id_board']; |
|
| 215 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 216 | + $updates[$row['member_groups']][] = $row['id_board']; |
|
| 217 | + } |
|
| 209 | 218 | $smcFunc['db_free_result']($request); |
| 210 | 219 | |
| 211 | - foreach ($updates as $member_groups => $boardArray) |
|
| 212 | - $smcFunc['db_query']('', ' |
|
| 220 | + foreach ($updates as $member_groups => $boardArray) { |
|
| 221 | + $smcFunc['db_query']('', ' |
|
| 213 | 222 | UPDATE {db_prefix}boards |
| 214 | 223 | SET member_groups = {string:member_groups} |
| 215 | 224 | WHERE id_board IN ({array_int:board_lists})', |
@@ -218,6 +227,7 @@ discard block |
||
| 218 | 227 | 'member_groups' => implode(',', array_diff(explode(',', $member_groups), $groups)), |
| 219 | 228 | ) |
| 220 | 229 | ); |
| 230 | + } |
|
| 221 | 231 | |
| 222 | 232 | // Recalculate the post groups, as they likely changed. |
| 223 | 233 | updateStats('postgroups'); |
@@ -225,8 +235,9 @@ discard block |
||
| 225 | 235 | // Make a note of the fact that the cache may be wrong. |
| 226 | 236 | $settings_update = array('settings_updated' => time()); |
| 227 | 237 | // Have we deleted the spider group? |
| 228 | - if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups)) |
|
| 229 | - $settings_update['spider_group'] = 0; |
|
| 238 | + if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups)) { |
|
| 239 | + $settings_update['spider_group'] = 0; |
|
| 240 | + } |
|
| 230 | 241 | |
| 231 | 242 | updateSettings($settings_update); |
| 232 | 243 | |
@@ -250,22 +261,24 @@ discard block |
||
| 250 | 261 | global $smcFunc, $modSettings, $sourcedir; |
| 251 | 262 | |
| 252 | 263 | // You're getting nowhere without this permission, unless of course you are the group's moderator. |
| 253 | - if (!$permissionCheckDone) |
|
| 254 | - isAllowedTo('manage_membergroups'); |
|
| 264 | + if (!$permissionCheckDone) { |
|
| 265 | + isAllowedTo('manage_membergroups'); |
|
| 266 | + } |
|
| 255 | 267 | |
| 256 | 268 | // Assume something will happen. |
| 257 | 269 | updateSettings(array('settings_updated' => time())); |
| 258 | 270 | |
| 259 | 271 | // Cleaning the input. |
| 260 | - if (!is_array($members)) |
|
| 261 | - $members = array((int) $members); |
|
| 262 | - else |
|
| 272 | + if (!is_array($members)) { |
|
| 273 | + $members = array((int) $members); |
|
| 274 | + } else |
|
| 263 | 275 | { |
| 264 | 276 | $members = array_unique($members); |
| 265 | 277 | |
| 266 | 278 | // Cast the members to integer. |
| 267 | - foreach ($members as $key => $value) |
|
| 268 | - $members[$key] = (int) $value; |
|
| 279 | + foreach ($members as $key => $value) { |
|
| 280 | + $members[$key] = (int) $value; |
|
| 281 | + } |
|
| 269 | 282 | } |
| 270 | 283 | |
| 271 | 284 | // Before we get started, let's check we won't leave the admin group empty! |
@@ -277,14 +290,15 @@ discard block |
||
| 277 | 290 | // Remove any admins if there are too many. |
| 278 | 291 | $non_changing_admins = array_diff(array_keys($admins), $members); |
| 279 | 292 | |
| 280 | - if (empty($non_changing_admins)) |
|
| 281 | - $members = array_diff($members, array_keys($admins)); |
|
| 293 | + if (empty($non_changing_admins)) { |
|
| 294 | + $members = array_diff($members, array_keys($admins)); |
|
| 295 | + } |
|
| 282 | 296 | } |
| 283 | 297 | |
| 284 | 298 | // Just in case. |
| 285 | - if (empty($members)) |
|
| 286 | - return false; |
|
| 287 | - elseif ($groups === null) |
|
| 299 | + if (empty($members)) { |
|
| 300 | + return false; |
|
| 301 | + } elseif ($groups === null) |
|
| 288 | 302 | { |
| 289 | 303 | // Wanna remove all groups from these members? That's easy. |
| 290 | 304 | $smcFunc['db_query']('', ' |
@@ -306,20 +320,21 @@ discard block |
||
| 306 | 320 | updateStats('postgroups', $members); |
| 307 | 321 | |
| 308 | 322 | // Log what just happened. |
| 309 | - foreach ($members as $member) |
|
| 310 | - logAction('removed_all_groups', array('member' => $member), 'admin'); |
|
| 323 | + foreach ($members as $member) { |
|
| 324 | + logAction('removed_all_groups', array('member' => $member), 'admin'); |
|
| 325 | + } |
|
| 311 | 326 | |
| 312 | 327 | return true; |
| 313 | - } |
|
| 314 | - elseif (!is_array($groups)) |
|
| 315 | - $groups = array((int) $groups); |
|
| 316 | - else |
|
| 328 | + } elseif (!is_array($groups)) { |
|
| 329 | + $groups = array((int) $groups); |
|
| 330 | + } else |
|
| 317 | 331 | { |
| 318 | 332 | $groups = array_unique($groups); |
| 319 | 333 | |
| 320 | 334 | // Make sure all groups are integer. |
| 321 | - foreach ($groups as $key => $value) |
|
| 322 | - $groups[$key] = (int) $value; |
|
| 335 | + foreach ($groups as $key => $value) { |
|
| 336 | + $groups[$key] = (int) $value; |
|
| 337 | + } |
|
| 323 | 338 | } |
| 324 | 339 | |
| 325 | 340 | // Fetch a list of groups members cannot be assigned to explicitly, and the group names of the ones we want. |
@@ -335,10 +350,11 @@ discard block |
||
| 335 | 350 | $group_names = array(); |
| 336 | 351 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 337 | 352 | { |
| 338 | - if ($row['min_posts'] != -1) |
|
| 339 | - $implicitGroups[] = $row['id_group']; |
|
| 340 | - else |
|
| 341 | - $group_names[$row['id_group']] = $row['group_name']; |
|
| 353 | + if ($row['min_posts'] != -1) { |
|
| 354 | + $implicitGroups[] = $row['id_group']; |
|
| 355 | + } else { |
|
| 356 | + $group_names[$row['id_group']] = $row['group_name']; |
|
| 357 | + } |
|
| 342 | 358 | } |
| 343 | 359 | $smcFunc['db_free_result']($request); |
| 344 | 360 | |
@@ -357,8 +373,9 @@ discard block |
||
| 357 | 373 | ) |
| 358 | 374 | ); |
| 359 | 375 | $protected_groups = array(1); |
| 360 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 361 | - $protected_groups[] = $row['id_group']; |
|
| 376 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 377 | + $protected_groups[] = $row['id_group']; |
|
| 378 | + } |
|
| 362 | 379 | $smcFunc['db_free_result']($request); |
| 363 | 380 | |
| 364 | 381 | // If you're not an admin yourself, you can't touch protected groups! |
@@ -366,8 +383,9 @@ discard block |
||
| 366 | 383 | } |
| 367 | 384 | |
| 368 | 385 | // Only continue if there are still groups and members left. |
| 369 | - if (empty($groups) || empty($members)) |
|
| 370 | - return false; |
|
| 386 | + if (empty($groups) || empty($members)) { |
|
| 387 | + return false; |
|
| 388 | + } |
|
| 371 | 389 | |
| 372 | 390 | // First, reset those who have this as their primary group - this is the easy one. |
| 373 | 391 | $log_inserts = array(); |
@@ -381,8 +399,9 @@ discard block |
||
| 381 | 399 | 'member_list' => $members, |
| 382 | 400 | ) |
| 383 | 401 | ); |
| 384 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 385 | - $log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']); |
|
| 402 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 403 | + $log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']); |
|
| 404 | + } |
|
| 386 | 405 | $smcFunc['db_free_result']($request); |
| 387 | 406 | |
| 388 | 407 | $smcFunc['db_query']('', ' |
@@ -414,16 +433,17 @@ discard block |
||
| 414 | 433 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 415 | 434 | { |
| 416 | 435 | // What log entries must we make for this one, eh? |
| 417 | - foreach (explode(',', $row['additional_groups']) as $group) |
|
| 418 | - if (in_array($group, $groups)) |
|
| 436 | + foreach (explode(',', $row['additional_groups']) as $group) { |
|
| 437 | + if (in_array($group, $groups)) |
|
| 419 | 438 | $log_inserts[] = array('group' => $group_names[$group], 'member' => $row['id_member']); |
| 439 | + } |
|
| 420 | 440 | |
| 421 | 441 | $updates[$row['additional_groups']][] = $row['id_member']; |
| 422 | 442 | } |
| 423 | 443 | $smcFunc['db_free_result']($request); |
| 424 | 444 | |
| 425 | - foreach ($updates as $additional_groups => $memberArray) |
|
| 426 | - $smcFunc['db_query']('', ' |
|
| 445 | + foreach ($updates as $additional_groups => $memberArray) { |
|
| 446 | + $smcFunc['db_query']('', ' |
|
| 427 | 447 | UPDATE {db_prefix}members |
| 428 | 448 | SET additional_groups = {string:additional_groups} |
| 429 | 449 | WHERE id_member IN ({array_int:member_list})', |
@@ -432,6 +452,7 @@ discard block |
||
| 432 | 452 | 'additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)), |
| 433 | 453 | ) |
| 434 | 454 | ); |
| 455 | + } |
|
| 435 | 456 | |
| 436 | 457 | // Their post groups may have changed now... |
| 437 | 458 | updateStats('postgroups', $members); |
@@ -440,8 +461,9 @@ discard block |
||
| 440 | 461 | if (!empty($log_inserts) && !empty($modSettings['modlog_enabled'])) |
| 441 | 462 | { |
| 442 | 463 | require_once($sourcedir . '/Logging.php'); |
| 443 | - foreach ($log_inserts as $extra) |
|
| 444 | - logAction('removed_from_group', $extra, 'admin'); |
|
| 464 | + foreach ($log_inserts as $extra) { |
|
| 465 | + logAction('removed_from_group', $extra, 'admin'); |
|
| 466 | + } |
|
| 445 | 467 | } |
| 446 | 468 | |
| 447 | 469 | // Mission successful. |
@@ -477,21 +499,23 @@ discard block |
||
| 477 | 499 | global $smcFunc, $sourcedir; |
| 478 | 500 | |
| 479 | 501 | // Show your licence, but only if it hasn't been done yet. |
| 480 | - if (!$permissionCheckDone) |
|
| 481 | - isAllowedTo('manage_membergroups'); |
|
| 502 | + if (!$permissionCheckDone) { |
|
| 503 | + isAllowedTo('manage_membergroups'); |
|
| 504 | + } |
|
| 482 | 505 | |
| 483 | 506 | // Make sure we don't keep old stuff cached. |
| 484 | 507 | updateSettings(array('settings_updated' => time())); |
| 485 | 508 | |
| 486 | - if (!is_array($members)) |
|
| 487 | - $members = array((int) $members); |
|
| 488 | - else |
|
| 509 | + if (!is_array($members)) { |
|
| 510 | + $members = array((int) $members); |
|
| 511 | + } else |
|
| 489 | 512 | { |
| 490 | 513 | $members = array_unique($members); |
| 491 | 514 | |
| 492 | 515 | // Make sure all members are integer. |
| 493 | - foreach ($members as $key => $value) |
|
| 494 | - $members[$key] = (int) $value; |
|
| 516 | + foreach ($members as $key => $value) { |
|
| 517 | + $members[$key] = (int) $value; |
|
| 518 | + } |
|
| 495 | 519 | } |
| 496 | 520 | $group = (int) $group; |
| 497 | 521 | |
@@ -508,20 +532,23 @@ discard block |
||
| 508 | 532 | $group_names = array(); |
| 509 | 533 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 510 | 534 | { |
| 511 | - if ($row['min_posts'] != -1) |
|
| 512 | - $implicitGroups[] = $row['id_group']; |
|
| 513 | - else |
|
| 514 | - $group_names[$row['id_group']] = $row['group_name']; |
|
| 535 | + if ($row['min_posts'] != -1) { |
|
| 536 | + $implicitGroups[] = $row['id_group']; |
|
| 537 | + } else { |
|
| 538 | + $group_names[$row['id_group']] = $row['group_name']; |
|
| 539 | + } |
|
| 515 | 540 | } |
| 516 | 541 | $smcFunc['db_free_result']($request); |
| 517 | 542 | |
| 518 | 543 | // Sorry, you can't join an implicit group. |
| 519 | - if (in_array($group, $implicitGroups) || empty($members)) |
|
| 520 | - return false; |
|
| 544 | + if (in_array($group, $implicitGroups) || empty($members)) { |
|
| 545 | + return false; |
|
| 546 | + } |
|
| 521 | 547 | |
| 522 | 548 | // Only admins can add admins... |
| 523 | - if (!allowedTo('admin_forum') && $group == 1) |
|
| 524 | - return false; |
|
| 549 | + if (!allowedTo('admin_forum') && $group == 1) { |
|
| 550 | + return false; |
|
| 551 | + } |
|
| 525 | 552 | // ... and assign protected groups! |
| 526 | 553 | elseif (!allowedTo('admin_forum') && !$ignoreProtected) |
| 527 | 554 | { |
@@ -539,13 +566,14 @@ discard block |
||
| 539 | 566 | $smcFunc['db_free_result']($request); |
| 540 | 567 | |
| 541 | 568 | // Is it protected? |
| 542 | - if ($is_protected == 1) |
|
| 543 | - return false; |
|
| 569 | + if ($is_protected == 1) { |
|
| 570 | + return false; |
|
| 571 | + } |
|
| 544 | 572 | } |
| 545 | 573 | |
| 546 | 574 | // Do the actual updates. |
| 547 | - if ($type == 'only_additional') |
|
| 548 | - $smcFunc['db_query']('', ' |
|
| 575 | + if ($type == 'only_additional') { |
|
| 576 | + $smcFunc['db_query']('', ' |
|
| 549 | 577 | UPDATE {db_prefix}members |
| 550 | 578 | SET additional_groups = CASE WHEN additional_groups = {string:blank_string} THEN {string:id_group_string} ELSE CONCAT(additional_groups, {string:id_group_string_extend}) END |
| 551 | 579 | WHERE id_member IN ({array_int:member_list}) |
@@ -559,8 +587,8 @@ discard block |
||
| 559 | 587 | 'blank_string' => '', |
| 560 | 588 | ) |
| 561 | 589 | ); |
| 562 | - elseif ($type == 'only_primary' || $type == 'force_primary') |
|
| 563 | - $smcFunc['db_query']('', ' |
|
| 590 | + } elseif ($type == 'only_primary' || $type == 'force_primary') { |
|
| 591 | + $smcFunc['db_query']('', ' |
|
| 564 | 592 | UPDATE {db_prefix}members |
| 565 | 593 | SET id_group = {int:id_group} |
| 566 | 594 | WHERE id_member IN ({array_int:member_list})' . ($type == 'force_primary' ? '' : ' |
@@ -572,8 +600,8 @@ discard block |
||
| 572 | 600 | 'regular_group' => 0, |
| 573 | 601 | ) |
| 574 | 602 | ); |
| 575 | - elseif ($type == 'auto') |
|
| 576 | - $smcFunc['db_query']('', ' |
|
| 603 | + } elseif ($type == 'auto') { |
|
| 604 | + $smcFunc['db_query']('', ' |
|
| 577 | 605 | UPDATE {db_prefix}members |
| 578 | 606 | SET |
| 579 | 607 | id_group = CASE WHEN id_group = {int:regular_group} THEN {int:id_group} ELSE id_group END, |
@@ -592,9 +620,11 @@ discard block |
||
| 592 | 620 | 'id_group_string_extend' => ',' . $group, |
| 593 | 621 | ) |
| 594 | 622 | ); |
| 623 | + } |
|
| 595 | 624 | // Ack!!? What happened? |
| 596 | - else |
|
| 597 | - trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING); |
|
| 625 | + else { |
|
| 626 | + trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING); |
|
| 627 | + } |
|
| 598 | 628 | |
| 599 | 629 | call_integration_hook('integrate_add_members_to_group', array($members, $group, &$group_names)); |
| 600 | 630 | |
@@ -603,8 +633,9 @@ discard block |
||
| 603 | 633 | |
| 604 | 634 | // Log the data. |
| 605 | 635 | require_once($sourcedir . '/Logging.php'); |
| 606 | - foreach ($members as $member) |
|
| 607 | - logAction('added_to_group', array('group' => $group_names[$group], 'member' => $member), 'admin'); |
|
| 636 | + foreach ($members as $member) { |
|
| 637 | + logAction('added_to_group', array('group' => $group_names[$group], 'member' => $member), 'admin'); |
|
| 638 | + } |
|
| 608 | 639 | |
| 609 | 640 | return true; |
| 610 | 641 | } |
@@ -632,8 +663,9 @@ discard block |
||
| 632 | 663 | ) |
| 633 | 664 | ); |
| 634 | 665 | $members = array(); |
| 635 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 636 | - $members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 666 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 667 | + $members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 668 | + } |
|
| 637 | 669 | $smcFunc['db_free_result']($request); |
| 638 | 670 | |
| 639 | 671 | // If there are more than $limit members, add a 'more' link. |
@@ -641,10 +673,10 @@ discard block |
||
| 641 | 673 | { |
| 642 | 674 | array_pop($members); |
| 643 | 675 | return true; |
| 676 | + } else { |
|
| 677 | + return false; |
|
| 678 | + } |
|
| 644 | 679 | } |
| 645 | - else |
|
| 646 | - return false; |
|
| 647 | -} |
|
| 648 | 680 | |
| 649 | 681 | /** |
| 650 | 682 | * Retrieve a list of (visible) membergroups used by the cache. |
@@ -669,8 +701,9 @@ discard block |
||
| 669 | 701 | ) |
| 670 | 702 | ); |
| 671 | 703 | $groupCache = array(); |
| 672 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 673 | - $groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>'; |
|
| 704 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 705 | + $groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>'; |
|
| 706 | + } |
|
| 674 | 707 | $smcFunc['db_free_result']($request); |
| 675 | 708 | |
| 676 | 709 | return array( |
@@ -718,8 +751,9 @@ discard block |
||
| 718 | 751 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 719 | 752 | { |
| 720 | 753 | // We only list the groups they can see. |
| 721 | - if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) |
|
| 722 | - continue; |
|
| 754 | + if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) { |
|
| 755 | + continue; |
|
| 756 | + } |
|
| 723 | 757 | |
| 724 | 758 | $row['icons'] = explode('#', $row['icons']); |
| 725 | 759 | |
@@ -754,12 +788,11 @@ discard block |
||
| 754 | 788 | 'group_list' => $group_ids, |
| 755 | 789 | ) |
| 756 | 790 | ); |
| 757 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 758 | - $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 791 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 792 | + $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 793 | + } |
|
| 759 | 794 | $smcFunc['db_free_result']($query); |
| 760 | - } |
|
| 761 | - |
|
| 762 | - else |
|
| 795 | + } else |
|
| 763 | 796 | { |
| 764 | 797 | $query = $smcFunc['db_query']('', ' |
| 765 | 798 | SELECT id_group, COUNT(*) AS num_members |
@@ -770,8 +803,9 @@ discard block |
||
| 770 | 803 | 'group_list' => $group_ids, |
| 771 | 804 | ) |
| 772 | 805 | ); |
| 773 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 774 | - $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 806 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 807 | + $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 808 | + } |
|
| 775 | 809 | $smcFunc['db_free_result']($query); |
| 776 | 810 | |
| 777 | 811 | // Only do additional groups if we can moderate... |
@@ -790,8 +824,9 @@ discard block |
||
| 790 | 824 | 'blank_string' => '', |
| 791 | 825 | ) |
| 792 | 826 | ); |
| 793 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 794 | - $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 827 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 828 | + $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 829 | + } |
|
| 795 | 830 | $smcFunc['db_free_result']($query); |
| 796 | 831 | } |
| 797 | 832 | } |
@@ -805,8 +840,9 @@ discard block |
||
| 805 | 840 | 'group_list' => $group_ids, |
| 806 | 841 | ) |
| 807 | 842 | ); |
| 808 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 809 | - $groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 843 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 844 | + $groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 845 | + } |
|
| 810 | 846 | $smcFunc['db_free_result']($query); |
| 811 | 847 | } |
| 812 | 848 | |
@@ -815,8 +851,9 @@ discard block |
||
| 815 | 851 | { |
| 816 | 852 | $sort_ascending = strpos($sort, 'DESC') === false; |
| 817 | 853 | |
| 818 | - foreach ($groups as $group) |
|
| 819 | - $sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1; |
|
| 854 | + foreach ($groups as $group) { |
|
| 855 | + $sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1; |
|
| 856 | + } |
|
| 820 | 857 | |
| 821 | 858 | array_multisort($sort_array, $sort_ascending ? SORT_ASC : SORT_DESC, SORT_REGULAR, $groups); |
| 822 | 859 | } |
@@ -286,7 +286,7 @@ |
||
| 286 | 286 | /** |
| 287 | 287 | * Delete a menu. |
| 288 | 288 | * @param string $menu_id The ID of the menu to destroy or 'last' for the most recent one |
| 289 | - * @return bool|void False if the menu doesn't exist, nothing otherwise |
|
| 289 | + * @return false|null False if the menu doesn't exist, nothing otherwise |
|
| 290 | 290 | */ |
| 291 | 291 | function destroyMenu($menu_id = 'last') |
| 292 | 292 | { |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Create a menu. |
@@ -64,22 +65,26 @@ discard block |
||
| 64 | 65 | $menu_context['current_action'] = isset($menuOptions['action']) ? $menuOptions['action'] : $context['current_action']; |
| 65 | 66 | |
| 66 | 67 | // Allow extend *any* menu with a single hook |
| 67 | - if (!empty($menu_context['current_action'])) |
|
| 68 | - call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData)); |
|
| 68 | + if (!empty($menu_context['current_action'])) { |
|
| 69 | + call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData)); |
|
| 70 | + } |
|
| 69 | 71 | |
| 70 | 72 | // What is the current area selected? |
| 71 | - if (isset($menuOptions['current_area']) || isset($_GET['area'])) |
|
| 72 | - $menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area']; |
|
| 73 | + if (isset($menuOptions['current_area']) || isset($_GET['area'])) { |
|
| 74 | + $menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area']; |
|
| 75 | + } |
|
| 73 | 76 | |
| 74 | 77 | // Build a list of additional parameters that should go in the URL. |
| 75 | 78 | $menu_context['extra_parameters'] = ''; |
| 76 | - if (!empty($menuOptions['extra_url_parameters'])) |
|
| 77 | - foreach ($menuOptions['extra_url_parameters'] as $key => $value) |
|
| 79 | + if (!empty($menuOptions['extra_url_parameters'])) { |
|
| 80 | + foreach ($menuOptions['extra_url_parameters'] as $key => $value) |
|
| 78 | 81 | $menu_context['extra_parameters'] .= ';' . $key . '=' . $value; |
| 82 | + } |
|
| 79 | 83 | |
| 80 | 84 | // Only include the session ID in the URL if it's strictly necessary. |
| 81 | - if (empty($menuOptions['disable_url_session_check'])) |
|
| 82 | - $menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id']; |
|
| 85 | + if (empty($menuOptions['disable_url_session_check'])) { |
|
| 86 | + $menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id']; |
|
| 87 | + } |
|
| 83 | 88 | |
| 84 | 89 | $include_data = array(); |
| 85 | 90 | |
@@ -87,8 +92,9 @@ discard block |
||
| 87 | 92 | foreach ($menuData as $section_id => $section) |
| 88 | 93 | { |
| 89 | 94 | // Is this enabled - or has as permission check - which fails? |
| 90 | - if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) |
|
| 91 | - continue; |
|
| 95 | + if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) { |
|
| 96 | + continue; |
|
| 97 | + } |
|
| 92 | 98 | |
| 93 | 99 | // Now we cycle through the sections to pick the right area. |
| 94 | 100 | foreach ($section['areas'] as $area_id => $area) |
@@ -110,41 +116,45 @@ discard block |
||
| 110 | 116 | if (empty($area['hidden'])) |
| 111 | 117 | { |
| 112 | 118 | // First time this section? |
| 113 | - if (!isset($menu_context['sections'][$section_id])) |
|
| 114 | - $menu_context['sections'][$section_id]['title'] = $section['title']; |
|
| 119 | + if (!isset($menu_context['sections'][$section_id])) { |
|
| 120 | + $menu_context['sections'][$section_id]['title'] = $section['title']; |
|
| 121 | + } |
|
| 115 | 122 | |
| 116 | 123 | $menu_context['sections'][$section_id]['areas'][$area_id] = array('label' => isset($area['label']) ? $area['label'] : $txt[$area_id]); |
| 117 | 124 | // We'll need the ID as well... |
| 118 | 125 | $menu_context['sections'][$section_id]['id'] = $section_id; |
| 119 | 126 | // Does it have a custom URL? |
| 120 | - if (isset($area['custom_url'])) |
|
| 121 | - $menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url']; |
|
| 127 | + if (isset($area['custom_url'])) { |
|
| 128 | + $menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url']; |
|
| 129 | + } |
|
| 122 | 130 | |
| 123 | 131 | // Does this area have its own icon? |
| 124 | - if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa') |
|
| 125 | - $menu_context['sections'][$section_id]['areas'][$area_id] = safe_unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9')); |
|
| 126 | - elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon'])) |
|
| 127 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
| 128 | - elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon'])) |
|
| 129 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
| 130 | - elseif (isset($area['icon'])) |
|
| 131 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>'; |
|
| 132 | - else |
|
| 133 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>'; |
|
| 134 | - |
|
| 135 | - if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon'])) |
|
| 136 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class']; |
|
| 137 | - elseif (isset($area['icon'])) |
|
| 132 | + if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa') { |
|
| 133 | + $menu_context['sections'][$section_id]['areas'][$area_id] = safe_unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9')); |
|
| 134 | + } elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon'])) { |
|
| 135 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
| 136 | + } elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon'])) { |
|
| 137 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
| 138 | + } elseif (isset($area['icon'])) { |
|
| 139 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>'; |
|
| 140 | + } else { |
|
| 141 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>'; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon'])) { |
|
| 145 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class']; |
|
| 146 | + } elseif (isset($area['icon'])) |
|
| 138 | 147 | { |
| 139 | - if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon'])) |
|
| 140 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon']; |
|
| 141 | - elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon'])) |
|
| 142 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon']; |
|
| 148 | + if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon'])) { |
|
| 149 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon']; |
|
| 150 | + } elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon'])) { |
|
| 151 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon']; |
|
| 152 | + } |
|
| 143 | 153 | |
| 144 | 154 | $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area['icon']); |
| 155 | + } else { |
|
| 156 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id); |
|
| 145 | 157 | } |
| 146 | - else |
|
| 147 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id); |
|
| 148 | 158 | |
| 149 | 159 | // Some areas may be listed but not active, which we show as greyed out. |
| 150 | 160 | $menu_context['sections'][$section_id]['areas'][$area_id]['inactive'] = !empty($area['inactive']); |
@@ -158,35 +168,41 @@ discard block |
||
| 158 | 168 | { |
| 159 | 169 | if ((empty($sub[1]) || allowedTo($sub[1])) && (!isset($sub['enabled']) || !empty($sub['enabled']))) |
| 160 | 170 | { |
| 161 | - if ($first_sa == null) |
|
| 162 | - $first_sa = $sa; |
|
| 171 | + if ($first_sa == null) { |
|
| 172 | + $first_sa = $sa; |
|
| 173 | + } |
|
| 163 | 174 | |
| 164 | 175 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa] = array('label' => $sub[0]); |
| 165 | 176 | // Custom URL? |
| 166 | - if (isset($sub['url'])) |
|
| 167 | - $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url']; |
|
| 177 | + if (isset($sub['url'])) { |
|
| 178 | + $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url']; |
|
| 179 | + } |
|
| 168 | 180 | |
| 169 | 181 | // A bit complicated - but is this set? |
| 170 | 182 | if ($menu_context['current_area'] == $area_id) |
| 171 | 183 | { |
| 172 | 184 | // Save which is the first... |
| 173 | - if (empty($first_sa)) |
|
| 174 | - $first_sa = $sa; |
|
| 185 | + if (empty($first_sa)) { |
|
| 186 | + $first_sa = $sa; |
|
| 187 | + } |
|
| 175 | 188 | |
| 176 | 189 | // Is this the current subsection? |
| 177 | - if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) |
|
| 178 | - $menu_context['current_subsection'] = $sa; |
|
| 190 | + if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) { |
|
| 191 | + $menu_context['current_subsection'] = $sa; |
|
| 192 | + } |
|
| 179 | 193 | // Otherwise is it the default? |
| 180 | - elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) |
|
| 181 | - $menu_context['current_subsection'] = $sa; |
|
| 194 | + elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) { |
|
| 195 | + $menu_context['current_subsection'] = $sa; |
|
| 196 | + } |
|
| 182 | 197 | } |
| 183 | 198 | |
| 184 | 199 | // Let's assume this is the last, for now. |
| 185 | 200 | $last_sa = $sa; |
| 186 | 201 | } |
| 187 | 202 | // Mark it as disabled... |
| 188 | - else |
|
| 189 | - $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true; |
|
| 203 | + else { |
|
| 204 | + $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true; |
|
| 205 | + } |
|
| 190 | 206 | } |
| 191 | 207 | |
| 192 | 208 | // Set which one is first, last and selected in the group. |
@@ -195,8 +211,9 @@ discard block |
||
| 195 | 211 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $last_sa : $first_sa]['is_first'] = true; |
| 196 | 212 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $first_sa : $last_sa]['is_last'] = true; |
| 197 | 213 | |
| 198 | - if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) |
|
| 199 | - $menu_context['current_subsection'] = $first_sa; |
|
| 214 | + if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) { |
|
| 215 | + $menu_context['current_subsection'] = $first_sa; |
|
| 216 | + } |
|
| 200 | 217 | } |
| 201 | 218 | } |
| 202 | 219 | } |
@@ -230,23 +247,26 @@ discard block |
||
| 230 | 247 | $menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action']; |
| 231 | 248 | |
| 232 | 249 | // If we didn't find the area we were looking for go to a default one. |
| 233 | - if (isset($backup_area) && empty($found_section)) |
|
| 234 | - $menu_context['current_area'] = $backup_area; |
|
| 250 | + if (isset($backup_area) && empty($found_section)) { |
|
| 251 | + $menu_context['current_area'] = $backup_area; |
|
| 252 | + } |
|
| 235 | 253 | |
| 236 | 254 | // If there are sections quickly goes through all the sections to check if the base menu has an url |
| 237 | 255 | if (!empty($menu_context['current_section'])) |
| 238 | 256 | { |
| 239 | 257 | $menu_context['sections'][$menu_context['current_section']]['selected'] = true; |
| 240 | 258 | $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['selected'] = true; |
| 241 | - if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) |
|
| 242 | - $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true; |
|
| 259 | + if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) { |
|
| 260 | + $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true; |
|
| 261 | + } |
|
| 243 | 262 | |
| 244 | - foreach ($menu_context['sections'] as $section_id => $section) |
|
| 245 | - foreach ($section['areas'] as $area_id => $area) |
|
| 263 | + foreach ($menu_context['sections'] as $section_id => $section) { |
|
| 264 | + foreach ($section['areas'] as $area_id => $area) |
|
| 246 | 265 | { |
| 247 | 266 | if (!isset($menu_context['sections'][$section_id]['url'])) |
| 248 | 267 | { |
| 249 | 268 | $menu_context['sections'][$section_id]['url'] = isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $area_id; |
| 269 | + } |
|
| 250 | 270 | break; |
| 251 | 271 | } |
| 252 | 272 | } |
@@ -257,8 +277,9 @@ discard block |
||
| 257 | 277 | { |
| 258 | 278 | // Never happened! |
| 259 | 279 | $context['max_menu_id']--; |
| 260 | - if ($context['max_menu_id'] == 0) |
|
| 261 | - unset($context['max_menu_id']); |
|
| 280 | + if ($context['max_menu_id'] == 0) { |
|
| 281 | + unset($context['max_menu_id']); |
|
| 282 | + } |
|
| 262 | 283 | |
| 263 | 284 | return false; |
| 264 | 285 | } |
@@ -269,8 +290,9 @@ discard block |
||
| 269 | 290 | $context['template_layers'][] = $menu_context['layer_name']; |
| 270 | 291 | |
| 271 | 292 | // Check we had something - for sanity sake. |
| 272 | - if (empty($include_data)) |
|
| 273 | - return false; |
|
| 293 | + if (empty($include_data)) { |
|
| 294 | + return false; |
|
| 295 | + } |
|
| 274 | 296 | |
| 275 | 297 | // Finally - return information on the selected item. |
| 276 | 298 | $include_data += array( |
@@ -293,12 +315,14 @@ discard block |
||
| 293 | 315 | global $context; |
| 294 | 316 | |
| 295 | 317 | $menu_name = $menu_id == 'last' && isset($context['max_menu_id']) && isset($context['menu_data_' . $context['max_menu_id']]) ? 'menu_data_' . $context['max_menu_id'] : 'menu_data_' . $menu_id; |
| 296 | - if (!isset($context[$menu_name])) |
|
| 297 | - return false; |
|
| 318 | + if (!isset($context[$menu_name])) { |
|
| 319 | + return false; |
|
| 320 | + } |
|
| 298 | 321 | |
| 299 | 322 | $layer_index = array_search($context[$menu_name]['layer_name'], $context['template_layers']); |
| 300 | - if ($layer_index !== false) |
|
| 301 | - unset($context['template_layers'][$layer_index]); |
|
| 323 | + if ($layer_index !== false) { |
|
| 324 | + unset($context['template_layers'][$layer_index]); |
|
| 325 | + } |
|
| 302 | 326 | |
| 303 | 327 | unset($context[$menu_name]); |
| 304 | 328 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param bool $single_file If true returns the contents of the file specified by destination if it exists |
| 29 | 29 | * @param bool $overwrite Whether to overwrite existing files |
| 30 | 30 | * @param null|array $files_to_extract Specific files to extract |
| 31 | - * @return array|false An array of information about extracted files or false on failure |
|
| 31 | + * @return string An array of information about extracted files or false on failure |
|
| 32 | 32 | */ |
| 33 | 33 | function read_tgz_file($gzfilename, $destination, $single_file = false, $overwrite = false, $files_to_extract = null) |
| 34 | 34 | { |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @param bool $single_file Whether to only extract a single file |
| 60 | 60 | * @param bool $overwrite Whether to overwrite existing data |
| 61 | 61 | * @param null|array $files_to_extract If set, only extracts the specified files |
| 62 | - * @return array|false An array of information about the extracted files or false on failure |
|
| 62 | + * @return string An array of information about the extracted files or false on failure |
|
| 63 | 63 | */ |
| 64 | 64 | function read_tgz_data($gzfilename, $destination, $single_file = false, $overwrite = false, $files_to_extract = null) |
| 65 | 65 | { |
@@ -3251,7 +3251,7 @@ discard block |
||
| 3251 | 3251 | * http://www.php.net/crc32#79567 |
| 3252 | 3252 | * |
| 3253 | 3253 | * @param string $number |
| 3254 | - * @return string The crc32 |
|
| 3254 | + * @return integer The crc32 |
|
| 3255 | 3255 | */ |
| 3256 | 3256 | function smf_crc32($number) |
| 3257 | 3257 | { |
@@ -16,8 +16,9 @@ discard block |
||
| 16 | 16 | * @version 2.1 Beta 3 |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | -if (!defined('SMF')) |
|
| 19 | +if (!defined('SMF')) { |
|
| 20 | 20 | die('No direct access...'); |
| 21 | +} |
|
| 21 | 22 | |
| 22 | 23 | /** |
| 23 | 24 | * Reads a .tar.gz file, filename, in and extracts file(s) from it. |
@@ -67,47 +68,53 @@ discard block |
||
| 67 | 68 | loadLanguage('Packages'); |
| 68 | 69 | |
| 69 | 70 | // This function sorta needs gzinflate! |
| 70 | - if (!function_exists('gzinflate')) |
|
| 71 | - fatal_lang_error('package_no_zlib', 'critical'); |
|
| 71 | + if (!function_exists('gzinflate')) { |
|
| 72 | + fatal_lang_error('package_no_zlib', 'critical'); |
|
| 73 | + } |
|
| 72 | 74 | |
| 73 | 75 | if (substr($gzfilename, 0, 7) == 'http://' || substr($gzfilename, 0, 8) == 'https://') |
| 74 | 76 | { |
| 75 | 77 | $data = fetch_web_data($gzfilename); |
| 76 | 78 | |
| 77 | - if ($data === false) |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - else |
|
| 79 | + if ($data === false) { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | + } else |
|
| 81 | 83 | { |
| 82 | 84 | $data = @file_get_contents($gzfilename); |
| 83 | 85 | |
| 84 | - if ($data === false) |
|
| 85 | - return false; |
|
| 86 | + if ($data === false) { |
|
| 87 | + return false; |
|
| 88 | + } |
|
| 86 | 89 | } |
| 87 | 90 | |
| 88 | 91 | umask(0); |
| 89 | - if (!$single_file && $destination !== null && !file_exists($destination)) |
|
| 90 | - mktree($destination, 0777); |
|
| 92 | + if (!$single_file && $destination !== null && !file_exists($destination)) { |
|
| 93 | + mktree($destination, 0777); |
|
| 94 | + } |
|
| 91 | 95 | |
| 92 | 96 | // No signature? |
| 93 | - if (strlen($data) < 2) |
|
| 94 | - return false; |
|
| 97 | + if (strlen($data) < 2) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 95 | 100 | |
| 96 | 101 | $id = unpack('H2a/H2b', substr($data, 0, 2)); |
| 97 | 102 | if (strtolower($id['a'] . $id['b']) != '1f8b') |
| 98 | 103 | { |
| 99 | 104 | // Okay, this ain't no tar.gz, but maybe it's a zip file. |
| 100 | - if (substr($data, 0, 2) == 'PK') |
|
| 101 | - return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract); |
|
| 102 | - else |
|
| 103 | - return false; |
|
| 105 | + if (substr($data, 0, 2) == 'PK') { |
|
| 106 | + return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract); |
|
| 107 | + } else { |
|
| 108 | + return false; |
|
| 109 | + } |
|
| 104 | 110 | } |
| 105 | 111 | |
| 106 | 112 | $flags = unpack('Ct/Cf', substr($data, 2, 2)); |
| 107 | 113 | |
| 108 | 114 | // Not deflate! |
| 109 | - if ($flags['t'] != 8) |
|
| 110 | - return false; |
|
| 115 | + if ($flags['t'] != 8) { |
|
| 116 | + return false; |
|
| 117 | + } |
|
| 111 | 118 | $flags = $flags['f']; |
| 112 | 119 | |
| 113 | 120 | $offset = 10; |
@@ -117,18 +124,21 @@ discard block |
||
| 117 | 124 | // @todo Might be mussed. |
| 118 | 125 | if ($flags & 12) |
| 119 | 126 | { |
| 120 | - while ($flags & 8 && $data{$offset++} != "\0") |
|
| 121 | - continue; |
|
| 122 | - while ($flags & 4 && $data{$offset++} != "\0") |
|
| 123 | - continue; |
|
| 127 | + while ($flags & 8 && $data{$offset++} != "\0") { |
|
| 128 | + continue; |
|
| 129 | + } |
|
| 130 | + while ($flags & 4 && $data{$offset++} != "\0") { |
|
| 131 | + continue; |
|
| 132 | + } |
|
| 124 | 133 | } |
| 125 | 134 | |
| 126 | 135 | $crc = unpack('Vcrc32/Visize', substr($data, strlen($data) - 8, 8)); |
| 127 | 136 | $data = @gzinflate(substr($data, $offset, strlen($data) - 8 - $offset)); |
| 128 | 137 | |
| 129 | 138 | // smf_crc32 and crc32 may not return the same results, so we accept either. |
| 130 | - if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) |
|
| 131 | - return false; |
|
| 139 | + if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) { |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 132 | 142 | |
| 133 | 143 | $blocks = strlen($data) / 512 - 1; |
| 134 | 144 | $offset = 0; |
@@ -149,83 +159,98 @@ discard block |
||
| 149 | 159 | |
| 150 | 160 | foreach ($current as $k => $v) |
| 151 | 161 | { |
| 152 | - if (in_array($k, $octdec)) |
|
| 153 | - $current[$k] = octdec(trim($v)); |
|
| 154 | - else |
|
| 155 | - $current[$k] = trim($v); |
|
| 162 | + if (in_array($k, $octdec)) { |
|
| 163 | + $current[$k] = octdec(trim($v)); |
|
| 164 | + } else { |
|
| 165 | + $current[$k] = trim($v); |
|
| 166 | + } |
|
| 156 | 167 | } |
| 157 | 168 | |
| 158 | - if ($current['type'] == 5 && substr($current['filename'], -1) != '/') |
|
| 159 | - $current['filename'] .= '/'; |
|
| 169 | + if ($current['type'] == 5 && substr($current['filename'], -1) != '/') { |
|
| 170 | + $current['filename'] .= '/'; |
|
| 171 | + } |
|
| 160 | 172 | |
| 161 | 173 | $checksum = 256; |
| 162 | - for ($i = 0; $i < 148; $i++) |
|
| 163 | - $checksum += ord($header{$i}); |
|
| 164 | - for ($i = 156; $i < 512; $i++) |
|
| 165 | - $checksum += ord($header{$i}); |
|
| 174 | + for ($i = 0; $i < 148; $i++) { |
|
| 175 | + $checksum += ord($header{$i}); |
|
| 176 | + } |
|
| 177 | + for ($i = 156; $i < 512; $i++) { |
|
| 178 | + $checksum += ord($header{$i}); |
|
| 179 | + } |
|
| 166 | 180 | |
| 167 | - if ($current['checksum'] != $checksum) |
|
| 168 | - break; |
|
| 181 | + if ($current['checksum'] != $checksum) { |
|
| 182 | + break; |
|
| 183 | + } |
|
| 169 | 184 | |
| 170 | 185 | $size = ceil($current['size'] / 512); |
| 171 | 186 | $current['data'] = substr($data, ++$offset << 9, $current['size']); |
| 172 | 187 | $offset += $size; |
| 173 | 188 | |
| 174 | 189 | // Not a directory and doesn't exist already... |
| 175 | - if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) |
|
| 176 | - $write_this = true; |
|
| 190 | + if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) { |
|
| 191 | + $write_this = true; |
|
| 192 | + } |
|
| 177 | 193 | // File exists... check if it is newer. |
| 178 | - elseif (substr($current['filename'], -1, 1) != '/') |
|
| 179 | - $write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime']; |
|
| 194 | + elseif (substr($current['filename'], -1, 1) != '/') { |
|
| 195 | + $write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime']; |
|
| 196 | + } |
|
| 180 | 197 | // Folder... create. |
| 181 | 198 | elseif ($destination !== null && !$single_file) |
| 182 | 199 | { |
| 183 | 200 | // Protect from accidental parent directory writing... |
| 184 | 201 | $current['filename'] = strtr($current['filename'], array('../' => '', '/..' => '')); |
| 185 | 202 | |
| 186 | - if (!file_exists($destination . '/' . $current['filename'])) |
|
| 187 | - mktree($destination . '/' . $current['filename'], 0777); |
|
| 203 | + if (!file_exists($destination . '/' . $current['filename'])) { |
|
| 204 | + mktree($destination . '/' . $current['filename'], 0777); |
|
| 205 | + } |
|
| 188 | 206 | $write_this = false; |
| 207 | + } else { |
|
| 208 | + $write_this = false; |
|
| 189 | 209 | } |
| 190 | - else |
|
| 191 | - $write_this = false; |
|
| 192 | 210 | |
| 193 | 211 | if ($write_this && $destination !== null) |
| 194 | 212 | { |
| 195 | - if (strpos($current['filename'], '/') !== false && !$single_file) |
|
| 196 | - mktree($destination . '/' . dirname($current['filename']), 0777); |
|
| 213 | + if (strpos($current['filename'], '/') !== false && !$single_file) { |
|
| 214 | + mktree($destination . '/' . dirname($current['filename']), 0777); |
|
| 215 | + } |
|
| 197 | 216 | |
| 198 | 217 | // Is this the file we're looking for? |
| 199 | - if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) |
|
| 200 | - return $current['data']; |
|
| 218 | + if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) { |
|
| 219 | + return $current['data']; |
|
| 220 | + } |
|
| 201 | 221 | // If we're looking for another file, keep going. |
| 202 | - elseif ($single_file) |
|
| 203 | - continue; |
|
| 222 | + elseif ($single_file) { |
|
| 223 | + continue; |
|
| 224 | + } |
|
| 204 | 225 | // Looking for restricted files? |
| 205 | - elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) |
|
| 206 | - continue; |
|
| 226 | + elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) { |
|
| 227 | + continue; |
|
| 228 | + } |
|
| 207 | 229 | |
| 208 | 230 | package_put_contents($destination . '/' . $current['filename'], $current['data']); |
| 209 | 231 | } |
| 210 | 232 | |
| 211 | - if (substr($current['filename'], -1, 1) != '/') |
|
| 212 | - $return[] = array( |
|
| 233 | + if (substr($current['filename'], -1, 1) != '/') { |
|
| 234 | + $return[] = array( |
|
| 213 | 235 | 'filename' => $current['filename'], |
| 214 | 236 | 'md5' => md5($current['data']), |
| 215 | 237 | 'preview' => substr($current['data'], 0, 100), |
| 216 | 238 | 'size' => $current['size'], |
| 217 | 239 | 'skipped' => false |
| 218 | 240 | ); |
| 241 | + } |
|
| 219 | 242 | } |
| 220 | 243 | |
| 221 | - if ($destination !== null && !$single_file) |
|
| 222 | - package_flush_cache(); |
|
| 244 | + if ($destination !== null && !$single_file) { |
|
| 245 | + package_flush_cache(); |
|
| 246 | + } |
|
| 223 | 247 | |
| 224 | - if ($single_file) |
|
| 225 | - return false; |
|
| 226 | - else |
|
| 227 | - return $return; |
|
| 228 | -} |
|
| 248 | + if ($single_file) { |
|
| 249 | + return false; |
|
| 250 | + } else { |
|
| 251 | + return $return; |
|
| 252 | + } |
|
| 253 | + } |
|
| 229 | 254 | |
| 230 | 255 | /** |
| 231 | 256 | * Extract zip data. A functional copy of {@list read_zip_data()}. |
@@ -254,65 +279,74 @@ discard block |
||
| 254 | 279 | { |
| 255 | 280 | $i = $iterator->getSubPathname(); |
| 256 | 281 | // If this is a file, and it doesn't exist.... happy days! |
| 257 | - if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) |
|
| 258 | - $write_this = true; |
|
| 282 | + if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) { |
|
| 283 | + $write_this = true; |
|
| 284 | + } |
|
| 259 | 285 | // If the file exists, we may not want to overwrite it. |
| 260 | - elseif (substr($i, -1) != '/') |
|
| 261 | - $write_this = $overwrite; |
|
| 262 | - else |
|
| 263 | - $write_this = false; |
|
| 286 | + elseif (substr($i, -1) != '/') { |
|
| 287 | + $write_this = $overwrite; |
|
| 288 | + } else { |
|
| 289 | + $write_this = false; |
|
| 290 | + } |
|
| 264 | 291 | |
| 265 | 292 | // Get the actual compressed data. |
| 266 | - if (!$file_info->isDir()) |
|
| 267 | - $file_data = file_get_contents($file_info); |
|
| 268 | - elseif ($destination !== null && !$single_file) |
|
| 293 | + if (!$file_info->isDir()) { |
|
| 294 | + $file_data = file_get_contents($file_info); |
|
| 295 | + } elseif ($destination !== null && !$single_file) |
|
| 269 | 296 | { |
| 270 | 297 | // Folder... create. |
| 271 | - if (!file_exists($destination . '/' . $i)) |
|
| 272 | - mktree($destination . '/' . $i, 0777); |
|
| 298 | + if (!file_exists($destination . '/' . $i)) { |
|
| 299 | + mktree($destination . '/' . $i, 0777); |
|
| 300 | + } |
|
| 273 | 301 | $file_data = null; |
| 302 | + } else { |
|
| 303 | + $file_data = null; |
|
| 274 | 304 | } |
| 275 | - else |
|
| 276 | - $file_data = null; |
|
| 277 | 305 | |
| 278 | 306 | // Okay! We can write this file, looks good from here... |
| 279 | 307 | if ($write_this && $destination !== null) |
| 280 | 308 | { |
| 281 | - if (!$single_file && !is_dir($destination . '/' . dirname($i))) |
|
| 282 | - mktree($destination . '/' . dirname($i), 0777); |
|
| 309 | + if (!$single_file && !is_dir($destination . '/' . dirname($i))) { |
|
| 310 | + mktree($destination . '/' . dirname($i), 0777); |
|
| 311 | + } |
|
| 283 | 312 | |
| 284 | 313 | // If we're looking for a specific file, and this is it... ka-bam, baby. |
| 285 | - if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) |
|
| 286 | - return $file_data; |
|
| 314 | + if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) { |
|
| 315 | + return $file_data; |
|
| 316 | + } |
|
| 287 | 317 | // Oh? Another file. Fine. You don't like this file, do you? I know how it is. Yeah... just go away. No, don't apologize. I know this file's just not *good enough* for you. |
| 288 | - elseif ($single_file) |
|
| 289 | - continue; |
|
| 318 | + elseif ($single_file) { |
|
| 319 | + continue; |
|
| 320 | + } |
|
| 290 | 321 | // Don't really want this? |
| 291 | - elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) |
|
| 292 | - continue; |
|
| 322 | + elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) { |
|
| 323 | + continue; |
|
| 324 | + } |
|
| 293 | 325 | |
| 294 | 326 | package_put_contents($destination . '/' . $i, $file_data); |
| 295 | 327 | } |
| 296 | 328 | |
| 297 | - if (substr($i, -1, 1) != '/') |
|
| 298 | - $return[] = array( |
|
| 329 | + if (substr($i, -1, 1) != '/') { |
|
| 330 | + $return[] = array( |
|
| 299 | 331 | 'filename' => $i, |
| 300 | 332 | 'md5' => md5($file_data), |
| 301 | 333 | 'preview' => substr($file_data, 0, 100), |
| 302 | 334 | 'size' => strlen($file_data), |
| 303 | 335 | 'skipped' => false |
| 304 | 336 | ); |
| 337 | + } |
|
| 305 | 338 | } |
| 306 | 339 | |
| 307 | - if ($destination !== null && !$single_file) |
|
| 308 | - package_flush_cache(); |
|
| 340 | + if ($destination !== null && !$single_file) { |
|
| 341 | + package_flush_cache(); |
|
| 342 | + } |
|
| 309 | 343 | |
| 310 | - if ($single_file) |
|
| 311 | - return false; |
|
| 312 | - else |
|
| 313 | - return $return; |
|
| 314 | - } |
|
| 315 | - catch (Exception $e) |
|
| 344 | + if ($single_file) { |
|
| 345 | + return false; |
|
| 346 | + } else { |
|
| 347 | + return $return; |
|
| 348 | + } |
|
| 349 | + } catch (Exception $e) |
|
| 316 | 350 | { |
| 317 | 351 | return false; |
| 318 | 352 | } |
@@ -334,13 +368,15 @@ discard block |
||
| 334 | 368 | function read_zip_data($data, $destination, $single_file = false, $overwrite = false, $files_to_extract = null) |
| 335 | 369 | { |
| 336 | 370 | umask(0); |
| 337 | - if ($destination !== null && !file_exists($destination) && !$single_file) |
|
| 338 | - mktree($destination, 0777); |
|
| 371 | + if ($destination !== null && !file_exists($destination) && !$single_file) { |
|
| 372 | + mktree($destination, 0777); |
|
| 373 | + } |
|
| 339 | 374 | |
| 340 | 375 | // Look for the end of directory signature 0x06054b50 |
| 341 | 376 | $data_ecr = explode("\x50\x4b\x05\x06", $data); |
| 342 | - if (!isset($data_ecr[1])) |
|
| 343 | - return false; |
|
| 377 | + if (!isset($data_ecr[1])) { |
|
| 378 | + return false; |
|
| 379 | + } |
|
| 344 | 380 | |
| 345 | 381 | $return = array(); |
| 346 | 382 | |
@@ -355,8 +391,9 @@ discard block |
||
| 355 | 391 | array_shift($file_sections); |
| 356 | 392 | |
| 357 | 393 | // sections and count from the signature must match or the zip file is bad |
| 358 | - if (count($file_sections) != $zip_info['files']) |
|
| 359 | - return false; |
|
| 394 | + if (count($file_sections) != $zip_info['files']) { |
|
| 395 | + return false; |
|
| 396 | + } |
|
| 360 | 397 | |
| 361 | 398 | // go though each file in the archive |
| 362 | 399 | foreach ($file_sections as $data) |
@@ -378,68 +415,79 @@ discard block |
||
| 378 | 415 | } |
| 379 | 416 | |
| 380 | 417 | // If this is a file, and it doesn't exist.... happy days! |
| 381 | - if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) |
|
| 382 | - $write_this = true; |
|
| 418 | + if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) { |
|
| 419 | + $write_this = true; |
|
| 420 | + } |
|
| 383 | 421 | // If the file exists, we may not want to overwrite it. |
| 384 | - elseif (substr($file_info['filename'], -1) != '/') |
|
| 385 | - $write_this = $overwrite; |
|
| 422 | + elseif (substr($file_info['filename'], -1) != '/') { |
|
| 423 | + $write_this = $overwrite; |
|
| 424 | + } |
|
| 386 | 425 | // This is a directory, so we're gonna want to create it. (probably...) |
| 387 | 426 | elseif ($destination !== null && !$single_file) |
| 388 | 427 | { |
| 389 | 428 | // Just a little accident prevention, don't mind me. |
| 390 | 429 | $file_info['filename'] = strtr($file_info['filename'], array('../' => '', '/..' => '')); |
| 391 | 430 | |
| 392 | - if (!file_exists($destination . '/' . $file_info['filename'])) |
|
| 393 | - mktree($destination . '/' . $file_info['filename'], 0777); |
|
| 431 | + if (!file_exists($destination . '/' . $file_info['filename'])) { |
|
| 432 | + mktree($destination . '/' . $file_info['filename'], 0777); |
|
| 433 | + } |
|
| 394 | 434 | $write_this = false; |
| 435 | + } else { |
|
| 436 | + $write_this = false; |
|
| 395 | 437 | } |
| 396 | - else |
|
| 397 | - $write_this = false; |
|
| 398 | 438 | |
| 399 | 439 | // Get the actual compressed data. |
| 400 | 440 | $file_info['data'] = substr($data, 26 + $file_info['filename_length'] + $file_info['extrafield_length']); |
| 401 | 441 | |
| 402 | 442 | // Only inflate it if we need to ;) |
| 403 | - if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) |
|
| 404 | - $file_info['data'] = gzinflate($file_info['data']); |
|
| 443 | + if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) { |
|
| 444 | + $file_info['data'] = gzinflate($file_info['data']); |
|
| 445 | + } |
|
| 405 | 446 | |
| 406 | 447 | // Okay! We can write this file, looks good from here... |
| 407 | 448 | if ($write_this && $destination !== null) |
| 408 | 449 | { |
| 409 | - if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) |
|
| 410 | - mktree($file_info['dir'], 0777); |
|
| 450 | + if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) { |
|
| 451 | + mktree($file_info['dir'], 0777); |
|
| 452 | + } |
|
| 411 | 453 | |
| 412 | 454 | // If we're looking for a specific file, and this is it... ka-bam, baby. |
| 413 | - if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) |
|
| 414 | - return $file_info['data']; |
|
| 455 | + if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) { |
|
| 456 | + return $file_info['data']; |
|
| 457 | + } |
|
| 415 | 458 | // Oh? Another file. Fine. You don't like this file, do you? I know how it is. Yeah... just go away. No, don't apologize. I know this file's just not *good enough* for you. |
| 416 | - elseif ($single_file) |
|
| 417 | - continue; |
|
| 459 | + elseif ($single_file) { |
|
| 460 | + continue; |
|
| 461 | + } |
|
| 418 | 462 | // Don't really want this? |
| 419 | - elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) |
|
| 420 | - continue; |
|
| 463 | + elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) { |
|
| 464 | + continue; |
|
| 465 | + } |
|
| 421 | 466 | |
| 422 | 467 | package_put_contents($destination . '/' . $file_info['filename'], $file_info['data']); |
| 423 | 468 | } |
| 424 | 469 | |
| 425 | - if (substr($file_info['filename'], -1, 1) != '/') |
|
| 426 | - $return[] = array( |
|
| 470 | + if (substr($file_info['filename'], -1, 1) != '/') { |
|
| 471 | + $return[] = array( |
|
| 427 | 472 | 'filename' => $file_info['filename'], |
| 428 | 473 | 'md5' => md5($file_info['data']), |
| 429 | 474 | 'preview' => substr($file_info['data'], 0, 100), |
| 430 | 475 | 'size' => $file_info['size'], |
| 431 | 476 | 'skipped' => false |
| 432 | 477 | ); |
| 478 | + } |
|
| 433 | 479 | } |
| 434 | 480 | |
| 435 | - if ($destination !== null && !$single_file) |
|
| 436 | - package_flush_cache(); |
|
| 481 | + if ($destination !== null && !$single_file) { |
|
| 482 | + package_flush_cache(); |
|
| 483 | + } |
|
| 437 | 484 | |
| 438 | - if ($single_file) |
|
| 439 | - return false; |
|
| 440 | - else |
|
| 441 | - return $return; |
|
| 442 | -} |
|
| 485 | + if ($single_file) { |
|
| 486 | + return false; |
|
| 487 | + } else { |
|
| 488 | + return $return; |
|
| 489 | + } |
|
| 490 | + } |
|
| 443 | 491 | |
| 444 | 492 | /** |
| 445 | 493 | * Checks the existence of a remote file since file_exists() does not do remote. |
@@ -451,14 +499,16 @@ discard block |
||
| 451 | 499 | { |
| 452 | 500 | $a_url = parse_url($url); |
| 453 | 501 | |
| 454 | - if (!isset($a_url['scheme'])) |
|
| 455 | - return false; |
|
| 502 | + if (!isset($a_url['scheme'])) { |
|
| 503 | + return false; |
|
| 504 | + } |
|
| 456 | 505 | |
| 457 | 506 | // Attempt to connect... |
| 458 | 507 | $temp = ''; |
| 459 | 508 | $fid = fsockopen($a_url['host'], !isset($a_url['port']) ? 80 : $a_url['port'], $temp, $temp, 8); |
| 460 | - if (!$fid) |
|
| 461 | - return false; |
|
| 509 | + if (!$fid) { |
|
| 510 | + return false; |
|
| 511 | + } |
|
| 462 | 512 | |
| 463 | 513 | fputs($fid, 'HEAD ' . $a_url['path'] . ' HTTP/1.0' . "\r\n" . 'Host: ' . $a_url['host'] . "\r\n\r\n"); |
| 464 | 514 | $head = fread($fid, 1024); |
@@ -493,8 +543,9 @@ discard block |
||
| 493 | 543 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 494 | 544 | { |
| 495 | 545 | // Already found this? If so don't add it twice! |
| 496 | - if (in_array($row['package_id'], $found)) |
|
| 497 | - continue; |
|
| 546 | + if (in_array($row['package_id'], $found)) { |
|
| 547 | + continue; |
|
| 548 | + } |
|
| 498 | 549 | |
| 499 | 550 | $found[] = $row['package_id']; |
| 500 | 551 | |
@@ -529,19 +580,21 @@ discard block |
||
| 529 | 580 | global $sourcedir, $packagesdir, $smcFunc; |
| 530 | 581 | |
| 531 | 582 | // Extract package-info.xml from downloaded file. (*/ is used because it could be in any directory.) |
| 532 | - if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) |
|
| 533 | - $packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true); |
|
| 534 | - else |
|
| 583 | + if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) { |
|
| 584 | + $packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true); |
|
| 585 | + } else |
|
| 535 | 586 | { |
| 536 | - if (!file_exists($packagesdir . '/' . $gzfilename)) |
|
| 537 | - return 'package_get_error_not_found'; |
|
| 587 | + if (!file_exists($packagesdir . '/' . $gzfilename)) { |
|
| 588 | + return 'package_get_error_not_found'; |
|
| 589 | + } |
|
| 538 | 590 | |
| 539 | - if (is_file($packagesdir . '/' . $gzfilename)) |
|
| 540 | - $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true); |
|
| 541 | - elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) |
|
| 542 | - $packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml'); |
|
| 543 | - else |
|
| 544 | - return 'package_get_error_missing_xml'; |
|
| 591 | + if (is_file($packagesdir . '/' . $gzfilename)) { |
|
| 592 | + $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true); |
|
| 593 | + } elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) { |
|
| 594 | + $packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml'); |
|
| 595 | + } else { |
|
| 596 | + return 'package_get_error_missing_xml'; |
|
| 597 | + } |
|
| 545 | 598 | } |
| 546 | 599 | |
| 547 | 600 | // Nothing? |
@@ -549,10 +602,11 @@ discard block |
||
| 549 | 602 | { |
| 550 | 603 | // Perhaps they are trying to install a theme, lets tell them nicely this is the wrong function |
| 551 | 604 | $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/theme_info.xml', true); |
| 552 | - if (!empty($packageInfo)) |
|
| 553 | - return 'package_get_error_is_theme'; |
|
| 554 | - else |
|
| 555 | - return 'package_get_error_is_zero'; |
|
| 605 | + if (!empty($packageInfo)) { |
|
| 606 | + return 'package_get_error_is_theme'; |
|
| 607 | + } else { |
|
| 608 | + return 'package_get_error_is_zero'; |
|
| 609 | + } |
|
| 556 | 610 | } |
| 557 | 611 | |
| 558 | 612 | // Parse package-info.xml into an xmlArray. |
@@ -560,8 +614,9 @@ discard block |
||
| 560 | 614 | $packageInfo = new xmlArray($packageInfo); |
| 561 | 615 | |
| 562 | 616 | // @todo Error message of some sort? |
| 563 | - if (!$packageInfo->exists('package-info[0]')) |
|
| 564 | - return 'package_get_error_packageinfo_corrupt'; |
|
| 617 | + if (!$packageInfo->exists('package-info[0]')) { |
|
| 618 | + return 'package_get_error_packageinfo_corrupt'; |
|
| 619 | + } |
|
| 565 | 620 | |
| 566 | 621 | $packageInfo = $packageInfo->path('package-info[0]'); |
| 567 | 622 | |
@@ -580,8 +635,9 @@ discard block |
||
| 580 | 635 | } |
| 581 | 636 | } |
| 582 | 637 | |
| 583 | - if (!isset($package['type'])) |
|
| 584 | - $package['type'] = 'modification'; |
|
| 638 | + if (!isset($package['type'])) { |
|
| 639 | + $package['type'] = 'modification'; |
|
| 640 | + } |
|
| 585 | 641 | |
| 586 | 642 | return $package; |
| 587 | 643 | } |
@@ -634,15 +690,14 @@ discard block |
||
| 634 | 690 | { |
| 635 | 691 | $ftp_file = strtr($file, array($_SESSION['pack_ftp']['root'] => '')); |
| 636 | 692 | $package_ftp->chmod($ftp_file, $perms); |
| 693 | + } else { |
|
| 694 | + smf_chmod($file, $perms); |
|
| 637 | 695 | } |
| 638 | - else |
|
| 639 | - smf_chmod($file, $perms); |
|
| 640 | 696 | |
| 641 | 697 | $new_permissions = @fileperms($file); |
| 642 | 698 | $result = $new_permissions == $perms ? 'success' : 'failure'; |
| 643 | 699 | unset($_SESSION['pack_ftp']['original_perms'][$file]); |
| 644 | - } |
|
| 645 | - elseif ($do_change) |
|
| 700 | + } elseif ($do_change) |
|
| 646 | 701 | { |
| 647 | 702 | $new_permissions = ''; |
| 648 | 703 | $result = 'skipped'; |
@@ -758,8 +813,7 @@ discard block |
||
| 758 | 813 | |
| 759 | 814 | $context['sub_template'] = 'show_list'; |
| 760 | 815 | $context['default_list'] = 'restore_file_permissions'; |
| 761 | - } |
|
| 762 | - else |
|
| 816 | + } else |
|
| 763 | 817 | { |
| 764 | 818 | unset($listOptions['columns']['result']); |
| 765 | 819 | } |
@@ -769,12 +823,14 @@ discard block |
||
| 769 | 823 | createList($listOptions); |
| 770 | 824 | |
| 771 | 825 | // If we just restored permissions then whereever we are, we are now done and dusted. |
| 772 | - if (!empty($_POST['restore_perms'])) |
|
| 773 | - obExit(); |
|
| 826 | + if (!empty($_POST['restore_perms'])) { |
|
| 827 | + obExit(); |
|
| 828 | + } |
|
| 774 | 829 | } |
| 775 | 830 | // Otherwise, it's entirely irrelevant? |
| 776 | - elseif ($restore_write_status) |
|
| 777 | - return true; |
|
| 831 | + elseif ($restore_write_status) { |
|
| 832 | + return true; |
|
| 833 | + } |
|
| 778 | 834 | |
| 779 | 835 | // This is where we report what we got up to. |
| 780 | 836 | $return_data = array( |
@@ -812,11 +868,12 @@ discard block |
||
| 812 | 868 | if (!in_array($_POST['ftp_path'], array('', '/'))) |
| 813 | 869 | { |
| 814 | 870 | $ftp_root = strtr($boarddir, array($_POST['ftp_path'] => '')); |
| 815 | - if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) |
|
| 816 | - $ftp_root = substr($ftp_root, 0, -1); |
|
| 871 | + if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) { |
|
| 872 | + $ftp_root = substr($ftp_root, 0, -1); |
|
| 873 | + } |
|
| 874 | + } else { |
|
| 875 | + $ftp_root = $boarddir; |
|
| 817 | 876 | } |
| 818 | - else |
|
| 819 | - $ftp_root = $boarddir; |
|
| 820 | 877 | |
| 821 | 878 | $_SESSION['pack_ftp'] = array( |
| 822 | 879 | 'server' => $_POST['ftp_server'], |
@@ -828,8 +885,9 @@ discard block |
||
| 828 | 885 | 'connected' => true, |
| 829 | 886 | ); |
| 830 | 887 | |
| 831 | - if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) |
|
| 832 | - updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 888 | + if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) { |
|
| 889 | + updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 890 | + } |
|
| 833 | 891 | |
| 834 | 892 | // This is now the primary connection. |
| 835 | 893 | $package_ftp = $ftp; |
@@ -842,12 +900,13 @@ discard block |
||
| 842 | 900 | foreach ($chmodFiles as $k => $file) |
| 843 | 901 | { |
| 844 | 902 | // Sometimes this can somehow happen maybe? |
| 845 | - if (empty($file)) |
|
| 846 | - unset($chmodFiles[$k]); |
|
| 903 | + if (empty($file)) { |
|
| 904 | + unset($chmodFiles[$k]); |
|
| 905 | + } |
|
| 847 | 906 | // Already writable? |
| 848 | - elseif (@is_writable($file)) |
|
| 849 | - $return_data['files']['writable'][] = $file; |
|
| 850 | - else |
|
| 907 | + elseif (@is_writable($file)) { |
|
| 908 | + $return_data['files']['writable'][] = $file; |
|
| 909 | + } else |
|
| 851 | 910 | { |
| 852 | 911 | // Now try to change that. |
| 853 | 912 | $return_data['files'][package_chmod($file, 'writable', true) ? 'writable' : 'notwritable'][] = $file; |
@@ -864,19 +923,21 @@ discard block |
||
| 864 | 923 | { |
| 865 | 924 | require_once($sourcedir . '/Class-Package.php'); |
| 866 | 925 | $ftp = new ftp_connection(null); |
| 926 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
| 927 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 867 | 928 | } |
| 868 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
| 869 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 870 | 929 | |
| 871 | 930 | list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir); |
| 872 | 931 | |
| 873 | - if ($found_path) |
|
| 874 | - $_POST['ftp_path'] = $detect_path; |
|
| 875 | - elseif (!isset($_POST['ftp_path'])) |
|
| 876 | - $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 932 | + if ($found_path) { |
|
| 933 | + $_POST['ftp_path'] = $detect_path; |
|
| 934 | + } elseif (!isset($_POST['ftp_path'])) { |
|
| 935 | + $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 936 | + } |
|
| 877 | 937 | |
| 878 | - if (!isset($_POST['ftp_username'])) |
|
| 879 | - $_POST['ftp_username'] = $username; |
|
| 938 | + if (!isset($_POST['ftp_username'])) { |
|
| 939 | + $_POST['ftp_username'] = $username; |
|
| 940 | + } |
|
| 880 | 941 | } |
| 881 | 942 | |
| 882 | 943 | $context['package_ftp'] = array( |
@@ -889,8 +950,9 @@ discard block |
||
| 889 | 950 | ); |
| 890 | 951 | |
| 891 | 952 | // Which files failed? |
| 892 | - if (!isset($context['notwritable_files'])) |
|
| 893 | - $context['notwritable_files'] = array(); |
|
| 953 | + if (!isset($context['notwritable_files'])) { |
|
| 954 | + $context['notwritable_files'] = array(); |
|
| 955 | + } |
|
| 894 | 956 | $context['notwritable_files'] = array_merge($context['notwritable_files'], $return_data['files']['notwritable']); |
| 895 | 957 | |
| 896 | 958 | // Sent here to die? |
@@ -923,40 +985,48 @@ discard block |
||
| 923 | 985 | foreach ($files as $k => $file) |
| 924 | 986 | { |
| 925 | 987 | // If this file doesn't exist, then we actually want to look at the directory, no? |
| 926 | - if (!file_exists($file)) |
|
| 927 | - $file = dirname($file); |
|
| 988 | + if (!file_exists($file)) { |
|
| 989 | + $file = dirname($file); |
|
| 990 | + } |
|
| 928 | 991 | |
| 929 | 992 | // This looks odd, but it's an attempt to work around PHP suExec. |
| 930 | - if (!@is_writable($file)) |
|
| 931 | - smf_chmod($file, 0755); |
|
| 932 | - if (!@is_writable($file)) |
|
| 933 | - smf_chmod($file, 0777); |
|
| 934 | - if (!@is_writable(dirname($file))) |
|
| 935 | - smf_chmod($file, 0755); |
|
| 936 | - if (!@is_writable(dirname($file))) |
|
| 937 | - smf_chmod($file, 0777); |
|
| 993 | + if (!@is_writable($file)) { |
|
| 994 | + smf_chmod($file, 0755); |
|
| 995 | + } |
|
| 996 | + if (!@is_writable($file)) { |
|
| 997 | + smf_chmod($file, 0777); |
|
| 998 | + } |
|
| 999 | + if (!@is_writable(dirname($file))) { |
|
| 1000 | + smf_chmod($file, 0755); |
|
| 1001 | + } |
|
| 1002 | + if (!@is_writable(dirname($file))) { |
|
| 1003 | + smf_chmod($file, 0777); |
|
| 1004 | + } |
|
| 938 | 1005 | |
| 939 | 1006 | $fp = is_dir($file) ? @opendir($file) : @fopen($file, 'rb'); |
| 940 | 1007 | if (@is_writable($file) && $fp) |
| 941 | 1008 | { |
| 942 | 1009 | unset($files[$k]); |
| 943 | - if (!is_dir($file)) |
|
| 944 | - fclose($fp); |
|
| 945 | - else |
|
| 946 | - closedir($fp); |
|
| 1010 | + if (!is_dir($file)) { |
|
| 1011 | + fclose($fp); |
|
| 1012 | + } else { |
|
| 1013 | + closedir($fp); |
|
| 1014 | + } |
|
| 947 | 1015 | } |
| 948 | 1016 | } |
| 949 | 1017 | |
| 950 | 1018 | // No FTP required! |
| 951 | - if (empty($files)) |
|
| 952 | - return array(); |
|
| 1019 | + if (empty($files)) { |
|
| 1020 | + return array(); |
|
| 1021 | + } |
|
| 953 | 1022 | } |
| 954 | 1023 | |
| 955 | 1024 | // They've opted to not use FTP, and try anyway. |
| 956 | 1025 | if (isset($_SESSION['pack_ftp']) && $_SESSION['pack_ftp'] == false) |
| 957 | 1026 | { |
| 958 | - if ($files === null) |
|
| 959 | - return array(); |
|
| 1027 | + if ($files === null) { |
|
| 1028 | + return array(); |
|
| 1029 | + } |
|
| 960 | 1030 | |
| 961 | 1031 | foreach ($files as $k => $file) |
| 962 | 1032 | { |
@@ -968,26 +1038,29 @@ discard block |
||
| 968 | 1038 | smf_chmod($file, 0755); |
| 969 | 1039 | } |
| 970 | 1040 | |
| 971 | - if (!@is_writable($file)) |
|
| 972 | - smf_chmod($file, 0777); |
|
| 973 | - if (!@is_writable(dirname($file))) |
|
| 974 | - smf_chmod(dirname($file), 0777); |
|
| 1041 | + if (!@is_writable($file)) { |
|
| 1042 | + smf_chmod($file, 0777); |
|
| 1043 | + } |
|
| 1044 | + if (!@is_writable(dirname($file))) { |
|
| 1045 | + smf_chmod(dirname($file), 0777); |
|
| 1046 | + } |
|
| 975 | 1047 | |
| 976 | - if (@is_writable($file)) |
|
| 977 | - unset($files[$k]); |
|
| 1048 | + if (@is_writable($file)) { |
|
| 1049 | + unset($files[$k]); |
|
| 1050 | + } |
|
| 978 | 1051 | } |
| 979 | 1052 | |
| 980 | 1053 | return $files; |
| 981 | - } |
|
| 982 | - elseif (isset($_SESSION['pack_ftp'])) |
|
| 1054 | + } elseif (isset($_SESSION['pack_ftp'])) |
|
| 983 | 1055 | { |
| 984 | 1056 | // Load the file containing the ftp_connection class. |
| 985 | 1057 | require_once($sourcedir . '/Class-Package.php'); |
| 986 | 1058 | |
| 987 | 1059 | $package_ftp = new ftp_connection($_SESSION['pack_ftp']['server'], $_SESSION['pack_ftp']['port'], $_SESSION['pack_ftp']['username'], package_crypt($_SESSION['pack_ftp']['password'])); |
| 988 | 1060 | |
| 989 | - if ($files === null) |
|
| 990 | - return array(); |
|
| 1061 | + if ($files === null) { |
|
| 1062 | + return array(); |
|
| 1063 | + } |
|
| 991 | 1064 | |
| 992 | 1065 | foreach ($files as $k => $file) |
| 993 | 1066 | { |
@@ -1001,13 +1074,16 @@ discard block |
||
| 1001 | 1074 | $package_ftp->chmod($ftp_file, 0755); |
| 1002 | 1075 | } |
| 1003 | 1076 | |
| 1004 | - if (!@is_writable($file)) |
|
| 1005 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1006 | - if (!@is_writable(dirname($file))) |
|
| 1007 | - $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 1077 | + if (!@is_writable($file)) { |
|
| 1078 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1079 | + } |
|
| 1080 | + if (!@is_writable(dirname($file))) { |
|
| 1081 | + $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 1082 | + } |
|
| 1008 | 1083 | |
| 1009 | - if (@is_writable($file)) |
|
| 1010 | - unset($files[$k]); |
|
| 1084 | + if (@is_writable($file)) { |
|
| 1085 | + unset($files[$k]); |
|
| 1086 | + } |
|
| 1011 | 1087 | } |
| 1012 | 1088 | |
| 1013 | 1089 | return $files; |
@@ -1019,8 +1095,7 @@ discard block |
||
| 1019 | 1095 | |
| 1020 | 1096 | $files = packageRequireFTP($destination_url, $files, $return); |
| 1021 | 1097 | return $files; |
| 1022 | - } |
|
| 1023 | - elseif (isset($_POST['ftp_username'])) |
|
| 1098 | + } elseif (isset($_POST['ftp_username'])) |
|
| 1024 | 1099 | { |
| 1025 | 1100 | require_once($sourcedir . '/Class-Package.php'); |
| 1026 | 1101 | $ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']); |
@@ -1042,19 +1117,21 @@ discard block |
||
| 1042 | 1117 | { |
| 1043 | 1118 | require_once($sourcedir . '/Class-Package.php'); |
| 1044 | 1119 | $ftp = new ftp_connection(null); |
| 1120 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
| 1121 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 1045 | 1122 | } |
| 1046 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
| 1047 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 1048 | 1123 | |
| 1049 | 1124 | list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir); |
| 1050 | 1125 | |
| 1051 | - if ($found_path) |
|
| 1052 | - $_POST['ftp_path'] = $detect_path; |
|
| 1053 | - elseif (!isset($_POST['ftp_path'])) |
|
| 1054 | - $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 1126 | + if ($found_path) { |
|
| 1127 | + $_POST['ftp_path'] = $detect_path; |
|
| 1128 | + } elseif (!isset($_POST['ftp_path'])) { |
|
| 1129 | + $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 1130 | + } |
|
| 1055 | 1131 | |
| 1056 | - if (!isset($_POST['ftp_username'])) |
|
| 1057 | - $_POST['ftp_username'] = $username; |
|
| 1132 | + if (!isset($_POST['ftp_username'])) { |
|
| 1133 | + $_POST['ftp_username'] = $username; |
|
| 1134 | + } |
|
| 1058 | 1135 | |
| 1059 | 1136 | $context['package_ftp'] = array( |
| 1060 | 1137 | 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), |
@@ -1066,23 +1143,24 @@ discard block |
||
| 1066 | 1143 | ); |
| 1067 | 1144 | |
| 1068 | 1145 | // If we're returning dump out here. |
| 1069 | - if ($return) |
|
| 1070 | - return $files; |
|
| 1146 | + if ($return) { |
|
| 1147 | + return $files; |
|
| 1148 | + } |
|
| 1071 | 1149 | |
| 1072 | 1150 | $context['page_title'] = $txt['package_ftp_necessary']; |
| 1073 | 1151 | $context['sub_template'] = 'ftp_required'; |
| 1074 | 1152 | obExit(); |
| 1075 | - } |
|
| 1076 | - else |
|
| 1153 | + } else |
|
| 1077 | 1154 | { |
| 1078 | 1155 | if (!in_array($_POST['ftp_path'], array('', '/'))) |
| 1079 | 1156 | { |
| 1080 | 1157 | $ftp_root = strtr($boarddir, array($_POST['ftp_path'] => '')); |
| 1081 | - if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) |
|
| 1082 | - $ftp_root = substr($ftp_root, 0, -1); |
|
| 1158 | + if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) { |
|
| 1159 | + $ftp_root = substr($ftp_root, 0, -1); |
|
| 1160 | + } |
|
| 1161 | + } else { |
|
| 1162 | + $ftp_root = $boarddir; |
|
| 1083 | 1163 | } |
| 1084 | - else |
|
| 1085 | - $ftp_root = $boarddir; |
|
| 1086 | 1164 | |
| 1087 | 1165 | $_SESSION['pack_ftp'] = array( |
| 1088 | 1166 | 'server' => $_POST['ftp_server'], |
@@ -1093,8 +1171,9 @@ discard block |
||
| 1093 | 1171 | 'root' => $ftp_root, |
| 1094 | 1172 | ); |
| 1095 | 1173 | |
| 1096 | - if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) |
|
| 1097 | - updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 1174 | + if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) { |
|
| 1175 | + updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 1176 | + } |
|
| 1098 | 1177 | |
| 1099 | 1178 | $files = packageRequireFTP($destination_url, $files, $return); |
| 1100 | 1179 | } |
@@ -1122,16 +1201,18 @@ discard block |
||
| 1122 | 1201 | global $packagesdir, $forum_version, $context, $temp_path, $language, $smcFunc; |
| 1123 | 1202 | |
| 1124 | 1203 | // Mayday! That action doesn't exist!! |
| 1125 | - if (empty($packageXML) || !$packageXML->exists($method)) |
|
| 1126 | - return array(); |
|
| 1204 | + if (empty($packageXML) || !$packageXML->exists($method)) { |
|
| 1205 | + return array(); |
|
| 1206 | + } |
|
| 1127 | 1207 | |
| 1128 | 1208 | // We haven't found the package script yet... |
| 1129 | 1209 | $script = false; |
| 1130 | 1210 | $the_version = strtr($forum_version, array('SMF ' => '')); |
| 1131 | 1211 | |
| 1132 | 1212 | // Emulation support... |
| 1133 | - if (!empty($_SESSION['version_emulate'])) |
|
| 1134 | - $the_version = $_SESSION['version_emulate']; |
|
| 1213 | + if (!empty($_SESSION['version_emulate'])) { |
|
| 1214 | + $the_version = $_SESSION['version_emulate']; |
|
| 1215 | + } |
|
| 1135 | 1216 | |
| 1136 | 1217 | // Single package emulation |
| 1137 | 1218 | if (!empty($_REQUEST['ve']) && !empty($_REQUEST['package'])) |
@@ -1139,8 +1220,9 @@ discard block |
||
| 1139 | 1220 | $the_version = $_REQUEST['ve']; |
| 1140 | 1221 | $_SESSION['single_version_emulate'][$_REQUEST['package']] = $the_version; |
| 1141 | 1222 | } |
| 1142 | - if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) |
|
| 1143 | - $the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']]; |
|
| 1223 | + if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) { |
|
| 1224 | + $the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']]; |
|
| 1225 | + } |
|
| 1144 | 1226 | |
| 1145 | 1227 | // Get all the versions of this method and find the right one. |
| 1146 | 1228 | $these_methods = $packageXML->set($method); |
@@ -1150,16 +1232,18 @@ discard block |
||
| 1150 | 1232 | if ($this_method->exists('@for')) |
| 1151 | 1233 | { |
| 1152 | 1234 | // Don't keep going if this won't work for this version of SMF. |
| 1153 | - if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) |
|
| 1154 | - continue; |
|
| 1235 | + if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) { |
|
| 1236 | + continue; |
|
| 1237 | + } |
|
| 1155 | 1238 | } |
| 1156 | 1239 | |
| 1157 | 1240 | // Upgrades may go from a certain old version of the mod. |
| 1158 | 1241 | if ($method == 'upgrade' && $this_method->exists('@from')) |
| 1159 | 1242 | { |
| 1160 | 1243 | // Well, this is for the wrong old version... |
| 1161 | - if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) |
|
| 1162 | - continue; |
|
| 1244 | + if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) { |
|
| 1245 | + continue; |
|
| 1246 | + } |
|
| 1163 | 1247 | } |
| 1164 | 1248 | |
| 1165 | 1249 | // We've found it! |
@@ -1168,8 +1252,9 @@ discard block |
||
| 1168 | 1252 | } |
| 1169 | 1253 | |
| 1170 | 1254 | // Bad news, a matching script wasn't found! |
| 1171 | - if ($script === false) |
|
| 1172 | - return array(); |
|
| 1255 | + if ($script === false) { |
|
| 1256 | + return array(); |
|
| 1257 | + } |
|
| 1173 | 1258 | |
| 1174 | 1259 | // Find all the actions in this method - in theory, these should only be allowed actions. (* means all.) |
| 1175 | 1260 | $actions = $script->set('*'); |
@@ -1198,12 +1283,12 @@ discard block |
||
| 1198 | 1283 | if ((isset($_REQUEST['readme']) && $action->fetch('@lang') == $_REQUEST['readme']) || (isset($_REQUEST['license']) && $action->fetch('@lang') == $_REQUEST['license']) || (!isset($_REQUEST['readme']) && $action->fetch('@lang') == $language) || (!isset($_REQUEST['license']) && $action->fetch('@lang') == $language)) |
| 1199 | 1284 | { |
| 1200 | 1285 | // In case the user put the blocks in the wrong order. |
| 1201 | - if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') |
|
| 1202 | - $context[$type][] = 'default'; |
|
| 1286 | + if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') { |
|
| 1287 | + $context[$type][] = 'default'; |
|
| 1288 | + } |
|
| 1203 | 1289 | |
| 1204 | 1290 | $context[$type]['selected'] = $smcFunc['htmlspecialchars']($action->fetch('@lang')); |
| 1205 | - } |
|
| 1206 | - else |
|
| 1291 | + } else |
|
| 1207 | 1292 | { |
| 1208 | 1293 | // We don't want this now, but we'll allow the user to select to read it. |
| 1209 | 1294 | $context[$type][] = $smcFunc['htmlspecialchars']($action->fetch('@lang')); |
@@ -1218,9 +1303,9 @@ discard block |
||
| 1218 | 1303 | { |
| 1219 | 1304 | $context[$type][] = 'default'; |
| 1220 | 1305 | continue; |
| 1306 | + } else { |
|
| 1307 | + $context[$type]['selected'] = 'default'; |
|
| 1221 | 1308 | } |
| 1222 | - else |
|
| 1223 | - $context[$type]['selected'] = 'default'; |
|
| 1224 | 1309 | } |
| 1225 | 1310 | } |
| 1226 | 1311 | |
@@ -1230,9 +1315,9 @@ discard block |
||
| 1230 | 1315 | $filename = $temp_path . '$auto_' . $temp_auto++ . (in_array($actionType, array('readme', 'redirect', 'license')) ? '.txt' : ($actionType == 'code' || $actionType == 'database' ? '.php' : '.mod')); |
| 1231 | 1316 | package_put_contents($filename, $action->fetch('.')); |
| 1232 | 1317 | $filename = strtr($filename, array($temp_path => '')); |
| 1318 | + } else { |
|
| 1319 | + $filename = $action->fetch('.'); |
|
| 1233 | 1320 | } |
| 1234 | - else |
|
| 1235 | - $filename = $action->fetch('.'); |
|
| 1236 | 1321 | |
| 1237 | 1322 | $return[] = array( |
| 1238 | 1323 | 'type' => $actionType, |
@@ -1247,8 +1332,7 @@ discard block |
||
| 1247 | 1332 | ); |
| 1248 | 1333 | |
| 1249 | 1334 | continue; |
| 1250 | - } |
|
| 1251 | - elseif ($actionType == 'hook') |
|
| 1335 | + } elseif ($actionType == 'hook') |
|
| 1252 | 1336 | { |
| 1253 | 1337 | $return[] = array( |
| 1254 | 1338 | 'type' => $actionType, |
@@ -1260,16 +1344,16 @@ discard block |
||
| 1260 | 1344 | 'description' => '', |
| 1261 | 1345 | ); |
| 1262 | 1346 | continue; |
| 1263 | - } |
|
| 1264 | - elseif ($actionType == 'credits') |
|
| 1347 | + } elseif ($actionType == 'credits') |
|
| 1265 | 1348 | { |
| 1266 | 1349 | // quick check of any supplied url |
| 1267 | 1350 | $url = $action->exists('@url') ? $action->fetch('@url') : ''; |
| 1268 | 1351 | if (strlen(trim($url)) > 0 && substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://') |
| 1269 | 1352 | { |
| 1270 | 1353 | $url = 'http://' . $url; |
| 1271 | - if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) |
|
| 1272 | - $url = ''; |
|
| 1354 | + if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) { |
|
| 1355 | + $url = ''; |
|
| 1356 | + } |
|
| 1273 | 1357 | } |
| 1274 | 1358 | |
| 1275 | 1359 | $return[] = array( |
@@ -1281,8 +1365,7 @@ discard block |
||
| 1281 | 1365 | 'title' => $action->fetch('.'), |
| 1282 | 1366 | ); |
| 1283 | 1367 | continue; |
| 1284 | - } |
|
| 1285 | - elseif ($actionType == 'requires') |
|
| 1368 | + } elseif ($actionType == 'requires') |
|
| 1286 | 1369 | { |
| 1287 | 1370 | $return[] = array( |
| 1288 | 1371 | 'type' => $actionType, |
@@ -1291,14 +1374,12 @@ discard block |
||
| 1291 | 1374 | 'description' => '', |
| 1292 | 1375 | ); |
| 1293 | 1376 | continue; |
| 1294 | - } |
|
| 1295 | - elseif ($actionType == 'error') |
|
| 1377 | + } elseif ($actionType == 'error') |
|
| 1296 | 1378 | { |
| 1297 | 1379 | $return[] = array( |
| 1298 | 1380 | 'type' => 'error', |
| 1299 | 1381 | ); |
| 1300 | - } |
|
| 1301 | - elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir'))) |
|
| 1382 | + } elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir'))) |
|
| 1302 | 1383 | { |
| 1303 | 1384 | $this_action = &$return[]; |
| 1304 | 1385 | $this_action = array( |
@@ -1312,8 +1393,7 @@ discard block |
||
| 1312 | 1393 | { |
| 1313 | 1394 | $this_action['unparsed_destination'] = $action->fetch('@destination'); |
| 1314 | 1395 | $this_action['destination'] = parse_path($action->fetch('@destination')) . '/' . basename($this_action['filename']); |
| 1315 | - } |
|
| 1316 | - else |
|
| 1396 | + } else |
|
| 1317 | 1397 | { |
| 1318 | 1398 | $this_action['unparsed_filename'] = $this_action['filename']; |
| 1319 | 1399 | $this_action['filename'] = parse_path($this_action['filename']); |
@@ -1322,10 +1402,11 @@ discard block |
||
| 1322 | 1402 | // If we're moving or requiring (copying) a file. |
| 1323 | 1403 | if (substr($actionType, 0, 4) == 'move' || substr($actionType, 0, 7) == 'require') |
| 1324 | 1404 | { |
| 1325 | - if ($action->exists('@from')) |
|
| 1326 | - $this_action['source'] = parse_path($action->fetch('@from')); |
|
| 1327 | - else |
|
| 1328 | - $this_action['source'] = $temp_path . $this_action['filename']; |
|
| 1405 | + if ($action->exists('@from')) { |
|
| 1406 | + $this_action['source'] = parse_path($action->fetch('@from')); |
|
| 1407 | + } else { |
|
| 1408 | + $this_action['source'] = $temp_path . $this_action['filename']; |
|
| 1409 | + } |
|
| 1329 | 1410 | } |
| 1330 | 1411 | |
| 1331 | 1412 | // Check if these things can be done. (chmod's etc.) |
@@ -1334,22 +1415,23 @@ discard block |
||
| 1334 | 1415 | if (!mktree($this_action['destination'], false)) |
| 1335 | 1416 | { |
| 1336 | 1417 | $temp = $this_action['destination']; |
| 1337 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1338 | - $temp = dirname($temp); |
|
| 1418 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1419 | + $temp = dirname($temp); |
|
| 1420 | + } |
|
| 1339 | 1421 | |
| 1340 | 1422 | $return[] = array( |
| 1341 | 1423 | 'type' => 'chmod', |
| 1342 | 1424 | 'filename' => $temp |
| 1343 | 1425 | ); |
| 1344 | 1426 | } |
| 1345 | - } |
|
| 1346 | - elseif ($actionType == 'create-file') |
|
| 1427 | + } elseif ($actionType == 'create-file') |
|
| 1347 | 1428 | { |
| 1348 | 1429 | if (!mktree(dirname($this_action['destination']), false)) |
| 1349 | 1430 | { |
| 1350 | 1431 | $temp = dirname($this_action['destination']); |
| 1351 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1352 | - $temp = dirname($temp); |
|
| 1432 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1433 | + $temp = dirname($temp); |
|
| 1434 | + } |
|
| 1353 | 1435 | |
| 1354 | 1436 | $return[] = array( |
| 1355 | 1437 | 'type' => 'chmod', |
@@ -1357,36 +1439,38 @@ discard block |
||
| 1357 | 1439 | ); |
| 1358 | 1440 | } |
| 1359 | 1441 | |
| 1360 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
| 1361 | - $return[] = array( |
|
| 1442 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
| 1443 | + $return[] = array( |
|
| 1362 | 1444 | 'type' => 'chmod', |
| 1363 | 1445 | 'filename' => $this_action['destination'] |
| 1364 | 1446 | ); |
| 1365 | - } |
|
| 1366 | - elseif ($actionType == 'require-dir') |
|
| 1447 | + } |
|
| 1448 | + } elseif ($actionType == 'require-dir') |
|
| 1367 | 1449 | { |
| 1368 | 1450 | if (!mktree($this_action['destination'], false)) |
| 1369 | 1451 | { |
| 1370 | 1452 | $temp = $this_action['destination']; |
| 1371 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1372 | - $temp = dirname($temp); |
|
| 1453 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1454 | + $temp = dirname($temp); |
|
| 1455 | + } |
|
| 1373 | 1456 | |
| 1374 | 1457 | $return[] = array( |
| 1375 | 1458 | 'type' => 'chmod', |
| 1376 | 1459 | 'filename' => $temp |
| 1377 | 1460 | ); |
| 1378 | 1461 | } |
| 1379 | - } |
|
| 1380 | - elseif ($actionType == 'require-file') |
|
| 1462 | + } elseif ($actionType == 'require-file') |
|
| 1381 | 1463 | { |
| 1382 | - if ($action->exists('@theme')) |
|
| 1383 | - $this_action['theme_action'] = $action->fetch('@theme'); |
|
| 1464 | + if ($action->exists('@theme')) { |
|
| 1465 | + $this_action['theme_action'] = $action->fetch('@theme'); |
|
| 1466 | + } |
|
| 1384 | 1467 | |
| 1385 | 1468 | if (!mktree(dirname($this_action['destination']), false)) |
| 1386 | 1469 | { |
| 1387 | 1470 | $temp = dirname($this_action['destination']); |
| 1388 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1389 | - $temp = dirname($temp); |
|
| 1471 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1472 | + $temp = dirname($temp); |
|
| 1473 | + } |
|
| 1390 | 1474 | |
| 1391 | 1475 | $return[] = array( |
| 1392 | 1476 | 'type' => 'chmod', |
@@ -1394,19 +1478,20 @@ discard block |
||
| 1394 | 1478 | ); |
| 1395 | 1479 | } |
| 1396 | 1480 | |
| 1397 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
| 1398 | - $return[] = array( |
|
| 1481 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
| 1482 | + $return[] = array( |
|
| 1399 | 1483 | 'type' => 'chmod', |
| 1400 | 1484 | 'filename' => $this_action['destination'] |
| 1401 | 1485 | ); |
| 1402 | - } |
|
| 1403 | - elseif ($actionType == 'move-dir' || $actionType == 'move-file') |
|
| 1486 | + } |
|
| 1487 | + } elseif ($actionType == 'move-dir' || $actionType == 'move-file') |
|
| 1404 | 1488 | { |
| 1405 | 1489 | if (!mktree(dirname($this_action['destination']), false)) |
| 1406 | 1490 | { |
| 1407 | 1491 | $temp = dirname($this_action['destination']); |
| 1408 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1409 | - $temp = dirname($temp); |
|
| 1492 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1493 | + $temp = dirname($temp); |
|
| 1494 | + } |
|
| 1410 | 1495 | |
| 1411 | 1496 | $return[] = array( |
| 1412 | 1497 | 'type' => 'chmod', |
@@ -1414,30 +1499,30 @@ discard block |
||
| 1414 | 1499 | ); |
| 1415 | 1500 | } |
| 1416 | 1501 | |
| 1417 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
| 1418 | - $return[] = array( |
|
| 1502 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
| 1503 | + $return[] = array( |
|
| 1419 | 1504 | 'type' => 'chmod', |
| 1420 | 1505 | 'filename' => $this_action['destination'] |
| 1421 | 1506 | ); |
| 1422 | - } |
|
| 1423 | - elseif ($actionType == 'remove-dir') |
|
| 1507 | + } |
|
| 1508 | + } elseif ($actionType == 'remove-dir') |
|
| 1424 | 1509 | { |
| 1425 | - if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) |
|
| 1426 | - $return[] = array( |
|
| 1510 | + if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) { |
|
| 1511 | + $return[] = array( |
|
| 1427 | 1512 | 'type' => 'chmod', |
| 1428 | 1513 | 'filename' => $this_action['filename'] |
| 1429 | 1514 | ); |
| 1430 | - } |
|
| 1431 | - elseif ($actionType == 'remove-file') |
|
| 1515 | + } |
|
| 1516 | + } elseif ($actionType == 'remove-file') |
|
| 1432 | 1517 | { |
| 1433 | - if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) |
|
| 1434 | - $return[] = array( |
|
| 1518 | + if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) { |
|
| 1519 | + $return[] = array( |
|
| 1435 | 1520 | 'type' => 'chmod', |
| 1436 | 1521 | 'filename' => $this_action['filename'] |
| 1437 | 1522 | ); |
| 1523 | + } |
|
| 1438 | 1524 | } |
| 1439 | - } |
|
| 1440 | - else |
|
| 1525 | + } else |
|
| 1441 | 1526 | { |
| 1442 | 1527 | $return[] = array( |
| 1443 | 1528 | 'type' => 'error', |
@@ -1448,8 +1533,9 @@ discard block |
||
| 1448 | 1533 | } |
| 1449 | 1534 | |
| 1450 | 1535 | // Only testing - just return a list of things to be done. |
| 1451 | - if ($testing_only) |
|
| 1452 | - return $return; |
|
| 1536 | + if ($testing_only) { |
|
| 1537 | + return $return; |
|
| 1538 | + } |
|
| 1453 | 1539 | |
| 1454 | 1540 | umask(0); |
| 1455 | 1541 | |
@@ -1457,78 +1543,81 @@ discard block |
||
| 1457 | 1543 | $not_done = array(array('type' => '!')); |
| 1458 | 1544 | foreach ($return as $action) |
| 1459 | 1545 | { |
| 1460 | - if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) |
|
| 1461 | - $not_done[] = $action; |
|
| 1546 | + if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) { |
|
| 1547 | + $not_done[] = $action; |
|
| 1548 | + } |
|
| 1462 | 1549 | |
| 1463 | 1550 | if ($action['type'] == 'create-dir') |
| 1464 | 1551 | { |
| 1465 | - if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) |
|
| 1466 | - $failure |= !mktree($action['destination'], 0777); |
|
| 1467 | - } |
|
| 1468 | - elseif ($action['type'] == 'create-file') |
|
| 1552 | + if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) { |
|
| 1553 | + $failure |= !mktree($action['destination'], 0777); |
|
| 1554 | + } |
|
| 1555 | + } elseif ($action['type'] == 'create-file') |
|
| 1469 | 1556 | { |
| 1470 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
| 1471 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1557 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
| 1558 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1559 | + } |
|
| 1472 | 1560 | |
| 1473 | 1561 | // Create an empty file. |
| 1474 | 1562 | package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only); |
| 1475 | 1563 | |
| 1476 | - if (!file_exists($action['destination'])) |
|
| 1477 | - $failure = true; |
|
| 1478 | - } |
|
| 1479 | - elseif ($action['type'] == 'require-dir') |
|
| 1564 | + if (!file_exists($action['destination'])) { |
|
| 1565 | + $failure = true; |
|
| 1566 | + } |
|
| 1567 | + } elseif ($action['type'] == 'require-dir') |
|
| 1480 | 1568 | { |
| 1481 | 1569 | copytree($action['source'], $action['destination']); |
| 1482 | 1570 | // Any other theme folders? |
| 1483 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) |
|
| 1484 | - foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1571 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) { |
|
| 1572 | + foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1485 | 1573 | copytree($action['source'], $theme_destination); |
| 1486 | - } |
|
| 1487 | - elseif ($action['type'] == 'require-file') |
|
| 1574 | + } |
|
| 1575 | + } elseif ($action['type'] == 'require-file') |
|
| 1488 | 1576 | { |
| 1489 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
| 1490 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1577 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
| 1578 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1579 | + } |
|
| 1491 | 1580 | |
| 1492 | 1581 | package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only); |
| 1493 | 1582 | |
| 1494 | 1583 | $failure |= !copy($action['source'], $action['destination']); |
| 1495 | 1584 | |
| 1496 | 1585 | // Any other theme files? |
| 1497 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) |
|
| 1498 | - foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1586 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) { |
|
| 1587 | + foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1499 | 1588 | { |
| 1500 | 1589 | if (!mktree(dirname($theme_destination), 0755) || !is_writable(dirname($theme_destination))) |
| 1501 | 1590 | $failure |= !mktree(dirname($theme_destination), 0777); |
| 1591 | + } |
|
| 1502 | 1592 | |
| 1503 | 1593 | package_put_contents($theme_destination, package_get_contents($action['source']), $testing_only); |
| 1504 | 1594 | |
| 1505 | 1595 | $failure |= !copy($action['source'], $theme_destination); |
| 1506 | 1596 | } |
| 1507 | - } |
|
| 1508 | - elseif ($action['type'] == 'move-file') |
|
| 1597 | + } elseif ($action['type'] == 'move-file') |
|
| 1509 | 1598 | { |
| 1510 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
| 1511 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1599 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
| 1600 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1601 | + } |
|
| 1512 | 1602 | |
| 1513 | 1603 | $failure |= !rename($action['source'], $action['destination']); |
| 1514 | - } |
|
| 1515 | - elseif ($action['type'] == 'move-dir') |
|
| 1604 | + } elseif ($action['type'] == 'move-dir') |
|
| 1516 | 1605 | { |
| 1517 | - if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) |
|
| 1518 | - $failure |= !mktree($action['destination'], 0777); |
|
| 1606 | + if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) { |
|
| 1607 | + $failure |= !mktree($action['destination'], 0777); |
|
| 1608 | + } |
|
| 1519 | 1609 | |
| 1520 | 1610 | $failure |= !rename($action['source'], $action['destination']); |
| 1521 | - } |
|
| 1522 | - elseif ($action['type'] == 'remove-dir') |
|
| 1611 | + } elseif ($action['type'] == 'remove-dir') |
|
| 1523 | 1612 | { |
| 1524 | 1613 | deltree($action['filename']); |
| 1525 | 1614 | |
| 1526 | 1615 | // Any other theme folders? |
| 1527 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) |
|
| 1528 | - foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1616 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) { |
|
| 1617 | + foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1529 | 1618 | deltree($theme_destination); |
| 1530 | - } |
|
| 1531 | - elseif ($action['type'] == 'remove-file') |
|
| 1619 | + } |
|
| 1620 | + } elseif ($action['type'] == 'remove-file') |
|
| 1532 | 1621 | { |
| 1533 | 1622 | // Make sure the file exists before deleting it. |
| 1534 | 1623 | if (file_exists($action['filename'])) |
@@ -1537,16 +1626,18 @@ discard block |
||
| 1537 | 1626 | $failure |= !unlink($action['filename']); |
| 1538 | 1627 | } |
| 1539 | 1628 | // The file that was supposed to be deleted couldn't be found. |
| 1540 | - else |
|
| 1541 | - $failure = true; |
|
| 1629 | + else { |
|
| 1630 | + $failure = true; |
|
| 1631 | + } |
|
| 1542 | 1632 | |
| 1543 | 1633 | // Any other theme folders? |
| 1544 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) |
|
| 1545 | - foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1634 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) { |
|
| 1635 | + foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1546 | 1636 | if (file_exists($theme_destination)) |
| 1547 | 1637 | $failure |= !unlink($theme_destination); |
| 1548 | - else |
|
| 1549 | - $failure = true; |
|
| 1638 | + } else { |
|
| 1639 | + $failure = true; |
|
| 1640 | + } |
|
| 1550 | 1641 | } |
| 1551 | 1642 | } |
| 1552 | 1643 | |
@@ -1568,8 +1659,9 @@ discard block |
||
| 1568 | 1659 | { |
| 1569 | 1660 | static $near_version = 0; |
| 1570 | 1661 | |
| 1571 | - if ($reset) |
|
| 1572 | - $near_version = 0; |
|
| 1662 | + if ($reset) { |
|
| 1663 | + $near_version = 0; |
|
| 1664 | + } |
|
| 1573 | 1665 | |
| 1574 | 1666 | // Normalize the $versions while we remove our previous Doh! |
| 1575 | 1667 | $versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions))); |
@@ -1578,16 +1670,19 @@ discard block |
||
| 1578 | 1670 | foreach ($versions as $for) |
| 1579 | 1671 | { |
| 1580 | 1672 | // Adjust for those wild cards |
| 1581 | - if (strpos($for, '*') !== false) |
|
| 1582 | - $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1673 | + if (strpos($for, '*') !== false) { |
|
| 1674 | + $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1675 | + } |
|
| 1583 | 1676 | |
| 1584 | 1677 | // If we have a range, grab the lower value, done this way so it looks normal-er to the user e.g. 2.0 vs 2.0.99 |
| 1585 | - if (strpos($for, '-') !== false) |
|
| 1586 | - list ($for, $higher) = explode('-', $for); |
|
| 1678 | + if (strpos($for, '-') !== false) { |
|
| 1679 | + list ($for, $higher) = explode('-', $for); |
|
| 1680 | + } |
|
| 1587 | 1681 | |
| 1588 | 1682 | // Do the compare, if the for is greater, than what we have but not greater than what we are running ..... |
| 1589 | - if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) |
|
| 1590 | - $near_version = $for; |
|
| 1683 | + if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) { |
|
| 1684 | + $near_version = $for; |
|
| 1685 | + } |
|
| 1591 | 1686 | } |
| 1592 | 1687 | |
| 1593 | 1688 | return !empty($near_version) ? $near_version : false; |
@@ -1610,15 +1705,17 @@ discard block |
||
| 1610 | 1705 | $versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions))); |
| 1611 | 1706 | |
| 1612 | 1707 | // Perhaps we do accept anything? |
| 1613 | - if (in_array('all', $versions)) |
|
| 1614 | - return true; |
|
| 1708 | + if (in_array('all', $versions)) { |
|
| 1709 | + return true; |
|
| 1710 | + } |
|
| 1615 | 1711 | |
| 1616 | 1712 | // Loop through each version. |
| 1617 | 1713 | foreach ($versions as $for) |
| 1618 | 1714 | { |
| 1619 | 1715 | // Wild card spotted? |
| 1620 | - if (strpos($for, '*') !== false) |
|
| 1621 | - $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1716 | + if (strpos($for, '*') !== false) { |
|
| 1717 | + $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1718 | + } |
|
| 1622 | 1719 | |
| 1623 | 1720 | // Do we have a range? |
| 1624 | 1721 | if (strpos($for, '-') !== false) |
@@ -1626,12 +1723,14 @@ discard block |
||
| 1626 | 1723 | list ($lower, $upper) = explode('-', $for); |
| 1627 | 1724 | |
| 1628 | 1725 | // Compare the version against lower and upper bounds. |
| 1629 | - if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) |
|
| 1630 | - return true; |
|
| 1726 | + if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) { |
|
| 1727 | + return true; |
|
| 1728 | + } |
|
| 1631 | 1729 | } |
| 1632 | 1730 | // Otherwise check if they are equal... |
| 1633 | - elseif (compareVersions($version, $for) === 0) |
|
| 1634 | - return true; |
|
| 1731 | + elseif (compareVersions($version, $for) === 0) { |
|
| 1732 | + return true; |
|
| 1733 | + } |
|
| 1635 | 1734 | } |
| 1636 | 1735 | |
| 1637 | 1736 | return false; |
@@ -1671,12 +1770,14 @@ discard block |
||
| 1671 | 1770 | } |
| 1672 | 1771 | |
| 1673 | 1772 | // Are they the same, perhaps? |
| 1674 | - if ($versions[1] === $versions[2]) |
|
| 1675 | - return 0; |
|
| 1773 | + if ($versions[1] === $versions[2]) { |
|
| 1774 | + return 0; |
|
| 1775 | + } |
|
| 1676 | 1776 | |
| 1677 | 1777 | // Get version numbering categories... |
| 1678 | - if (!isset($categories)) |
|
| 1679 | - $categories = array_keys($versions[1]); |
|
| 1778 | + if (!isset($categories)) { |
|
| 1779 | + $categories = array_keys($versions[1]); |
|
| 1780 | + } |
|
| 1680 | 1781 | |
| 1681 | 1782 | // Loop through each category. |
| 1682 | 1783 | foreach ($categories as $category) |
@@ -1686,13 +1787,15 @@ discard block |
||
| 1686 | 1787 | { |
| 1687 | 1788 | // Dev builds are a problematic exception. |
| 1688 | 1789 | // (stable) dev < (stable) but (unstable) dev = (unstable) |
| 1689 | - if ($category == 'type') |
|
| 1690 | - return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1); |
|
| 1691 | - elseif ($category == 'dev') |
|
| 1692 | - return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0); |
|
| 1790 | + if ($category == 'type') { |
|
| 1791 | + return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1); |
|
| 1792 | + } elseif ($category == 'dev') { |
|
| 1793 | + return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0); |
|
| 1794 | + } |
|
| 1693 | 1795 | // Otherwise a simple comparison. |
| 1694 | - else |
|
| 1695 | - return $versions[1][$category] > $versions[2][$category] ? 1 : -1; |
|
| 1796 | + else { |
|
| 1797 | + return $versions[1][$category] > $versions[2][$category] ? 1 : -1; |
|
| 1798 | + } |
|
| 1696 | 1799 | } |
| 1697 | 1800 | } |
| 1698 | 1801 | |
@@ -1726,11 +1829,13 @@ discard block |
||
| 1726 | 1829 | ); |
| 1727 | 1830 | |
| 1728 | 1831 | // do we parse in a package directory? |
| 1729 | - if (!empty($temp_path)) |
|
| 1730 | - $dirs['$package'] = $temp_path; |
|
| 1832 | + if (!empty($temp_path)) { |
|
| 1833 | + $dirs['$package'] = $temp_path; |
|
| 1834 | + } |
|
| 1731 | 1835 | |
| 1732 | - if (strlen($path) == 0) |
|
| 1733 | - trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR); |
|
| 1836 | + if (strlen($path) == 0) { |
|
| 1837 | + trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR); |
|
| 1838 | + } |
|
| 1734 | 1839 | |
| 1735 | 1840 | return strtr($path, $dirs); |
| 1736 | 1841 | } |
@@ -1746,8 +1851,9 @@ discard block |
||
| 1746 | 1851 | { |
| 1747 | 1852 | global $package_ftp; |
| 1748 | 1853 | |
| 1749 | - if (!file_exists($dir)) |
|
| 1750 | - return; |
|
| 1854 | + if (!file_exists($dir)) { |
|
| 1855 | + return; |
|
| 1856 | + } |
|
| 1751 | 1857 | |
| 1752 | 1858 | $current_dir = @opendir($dir); |
| 1753 | 1859 | if ($current_dir == false) |
@@ -1755,8 +1861,9 @@ discard block |
||
| 1755 | 1861 | if ($delete_dir && isset($package_ftp)) |
| 1756 | 1862 | { |
| 1757 | 1863 | $ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => '')); |
| 1758 | - if (!is_dir($dir)) |
|
| 1759 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1864 | + if (!is_dir($dir)) { |
|
| 1865 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1866 | + } |
|
| 1760 | 1867 | $package_ftp->unlink($ftp_file); |
| 1761 | 1868 | } |
| 1762 | 1869 | |
@@ -1765,26 +1872,28 @@ discard block |
||
| 1765 | 1872 | |
| 1766 | 1873 | while ($entryname = readdir($current_dir)) |
| 1767 | 1874 | { |
| 1768 | - if (in_array($entryname, array('.', '..'))) |
|
| 1769 | - continue; |
|
| 1875 | + if (in_array($entryname, array('.', '..'))) { |
|
| 1876 | + continue; |
|
| 1877 | + } |
|
| 1770 | 1878 | |
| 1771 | - if (is_dir($dir . '/' . $entryname)) |
|
| 1772 | - deltree($dir . '/' . $entryname); |
|
| 1773 | - else |
|
| 1879 | + if (is_dir($dir . '/' . $entryname)) { |
|
| 1880 | + deltree($dir . '/' . $entryname); |
|
| 1881 | + } else |
|
| 1774 | 1882 | { |
| 1775 | 1883 | // Here, 755 doesn't really matter since we're deleting it anyway. |
| 1776 | 1884 | if (isset($package_ftp)) |
| 1777 | 1885 | { |
| 1778 | 1886 | $ftp_file = strtr($dir . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
| 1779 | 1887 | |
| 1780 | - if (!is_writable($dir . '/' . $entryname)) |
|
| 1781 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1888 | + if (!is_writable($dir . '/' . $entryname)) { |
|
| 1889 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1890 | + } |
|
| 1782 | 1891 | $package_ftp->unlink($ftp_file); |
| 1783 | - } |
|
| 1784 | - else |
|
| 1892 | + } else |
|
| 1785 | 1893 | { |
| 1786 | - if (!is_writable($dir . '/' . $entryname)) |
|
| 1787 | - smf_chmod($dir . '/' . $entryname, 0777); |
|
| 1894 | + if (!is_writable($dir . '/' . $entryname)) { |
|
| 1895 | + smf_chmod($dir . '/' . $entryname, 0777); |
|
| 1896 | + } |
|
| 1788 | 1897 | unlink($dir . '/' . $entryname); |
| 1789 | 1898 | } |
| 1790 | 1899 | } |
@@ -1797,14 +1906,15 @@ discard block |
||
| 1797 | 1906 | if (isset($package_ftp)) |
| 1798 | 1907 | { |
| 1799 | 1908 | $ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => '')); |
| 1800 | - if (!is_writable($dir . '/' . $entryname)) |
|
| 1801 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1909 | + if (!is_writable($dir . '/' . $entryname)) { |
|
| 1910 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1911 | + } |
|
| 1802 | 1912 | $package_ftp->unlink($ftp_file); |
| 1803 | - } |
|
| 1804 | - else |
|
| 1913 | + } else |
|
| 1805 | 1914 | { |
| 1806 | - if (!is_writable($dir)) |
|
| 1807 | - smf_chmod($dir, 0777); |
|
| 1915 | + if (!is_writable($dir)) { |
|
| 1916 | + smf_chmod($dir, 0777); |
|
| 1917 | + } |
|
| 1808 | 1918 | @rmdir($dir); |
| 1809 | 1919 | } |
| 1810 | 1920 | } |
@@ -1826,10 +1936,11 @@ discard block |
||
| 1826 | 1936 | { |
| 1827 | 1937 | if (!is_writable($strPath) && $mode !== false) |
| 1828 | 1938 | { |
| 1829 | - if (isset($package_ftp)) |
|
| 1830 | - $package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode); |
|
| 1831 | - else |
|
| 1832 | - smf_chmod($strPath, $mode); |
|
| 1939 | + if (isset($package_ftp)) { |
|
| 1940 | + $package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode); |
|
| 1941 | + } else { |
|
| 1942 | + smf_chmod($strPath, $mode); |
|
| 1943 | + } |
|
| 1833 | 1944 | } |
| 1834 | 1945 | |
| 1835 | 1946 | $test = @opendir($strPath); |
@@ -1837,36 +1948,37 @@ discard block |
||
| 1837 | 1948 | { |
| 1838 | 1949 | closedir($test); |
| 1839 | 1950 | return is_writable($strPath); |
| 1951 | + } else { |
|
| 1952 | + return false; |
|
| 1840 | 1953 | } |
| 1841 | - else |
|
| 1842 | - return false; |
|
| 1843 | 1954 | } |
| 1844 | 1955 | // Is this an invalid path and/or we can't make the directory? |
| 1845 | - if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) |
|
| 1846 | - return false; |
|
| 1956 | + if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) { |
|
| 1957 | + return false; |
|
| 1958 | + } |
|
| 1847 | 1959 | |
| 1848 | 1960 | if (!is_writable(dirname($strPath)) && $mode !== false) |
| 1849 | 1961 | { |
| 1850 | - if (isset($package_ftp)) |
|
| 1851 | - $package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode); |
|
| 1852 | - else |
|
| 1853 | - smf_chmod(dirname($strPath), $mode); |
|
| 1962 | + if (isset($package_ftp)) { |
|
| 1963 | + $package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode); |
|
| 1964 | + } else { |
|
| 1965 | + smf_chmod(dirname($strPath), $mode); |
|
| 1966 | + } |
|
| 1854 | 1967 | } |
| 1855 | 1968 | |
| 1856 | - if ($mode !== false && isset($package_ftp)) |
|
| 1857 | - return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))); |
|
| 1858 | - elseif ($mode === false) |
|
| 1969 | + if ($mode !== false && isset($package_ftp)) { |
|
| 1970 | + return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))); |
|
| 1971 | + } elseif ($mode === false) |
|
| 1859 | 1972 | { |
| 1860 | 1973 | $test = @opendir(dirname($strPath)); |
| 1861 | 1974 | if ($test) |
| 1862 | 1975 | { |
| 1863 | 1976 | closedir($test); |
| 1864 | 1977 | return true; |
| 1978 | + } else { |
|
| 1979 | + return false; |
|
| 1865 | 1980 | } |
| 1866 | - else |
|
| 1867 | - return false; |
|
| 1868 | - } |
|
| 1869 | - else |
|
| 1981 | + } else |
|
| 1870 | 1982 | { |
| 1871 | 1983 | @mkdir($strPath, $mode); |
| 1872 | 1984 | $test = @opendir($strPath); |
@@ -1874,9 +1986,9 @@ discard block |
||
| 1874 | 1986 | { |
| 1875 | 1987 | closedir($test); |
| 1876 | 1988 | return true; |
| 1989 | + } else { |
|
| 1990 | + return false; |
|
| 1877 | 1991 | } |
| 1878 | - else |
|
| 1879 | - return false; |
|
| 1880 | 1992 | } |
| 1881 | 1993 | } |
| 1882 | 1994 | |
@@ -1891,39 +2003,46 @@ discard block |
||
| 1891 | 2003 | { |
| 1892 | 2004 | global $package_ftp; |
| 1893 | 2005 | |
| 1894 | - if (!file_exists($destination) || !is_writable($destination)) |
|
| 1895 | - mktree($destination, 0755); |
|
| 1896 | - if (!is_writable($destination)) |
|
| 1897 | - mktree($destination, 0777); |
|
| 2006 | + if (!file_exists($destination) || !is_writable($destination)) { |
|
| 2007 | + mktree($destination, 0755); |
|
| 2008 | + } |
|
| 2009 | + if (!is_writable($destination)) { |
|
| 2010 | + mktree($destination, 0777); |
|
| 2011 | + } |
|
| 1898 | 2012 | |
| 1899 | 2013 | $current_dir = opendir($source); |
| 1900 | - if ($current_dir == false) |
|
| 1901 | - return; |
|
| 2014 | + if ($current_dir == false) { |
|
| 2015 | + return; |
|
| 2016 | + } |
|
| 1902 | 2017 | |
| 1903 | 2018 | while ($entryname = readdir($current_dir)) |
| 1904 | 2019 | { |
| 1905 | - if (in_array($entryname, array('.', '..'))) |
|
| 1906 | - continue; |
|
| 2020 | + if (in_array($entryname, array('.', '..'))) { |
|
| 2021 | + continue; |
|
| 2022 | + } |
|
| 1907 | 2023 | |
| 1908 | - if (isset($package_ftp)) |
|
| 1909 | - $ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2024 | + if (isset($package_ftp)) { |
|
| 2025 | + $ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2026 | + } |
|
| 1910 | 2027 | |
| 1911 | 2028 | if (is_file($source . '/' . $entryname)) |
| 1912 | 2029 | { |
| 1913 | - if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) |
|
| 1914 | - $package_ftp->create_file($ftp_file); |
|
| 1915 | - elseif (!file_exists($destination . '/' . $entryname)) |
|
| 1916 | - @touch($destination . '/' . $entryname); |
|
| 2030 | + if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) { |
|
| 2031 | + $package_ftp->create_file($ftp_file); |
|
| 2032 | + } elseif (!file_exists($destination . '/' . $entryname)) { |
|
| 2033 | + @touch($destination . '/' . $entryname); |
|
| 2034 | + } |
|
| 1917 | 2035 | } |
| 1918 | 2036 | |
| 1919 | 2037 | package_chmod($destination . '/' . $entryname); |
| 1920 | 2038 | |
| 1921 | - if (is_dir($source . '/' . $entryname)) |
|
| 1922 | - copytree($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 1923 | - elseif (file_exists($destination . '/' . $entryname)) |
|
| 1924 | - package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname)); |
|
| 1925 | - else |
|
| 1926 | - copy($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 2039 | + if (is_dir($source . '/' . $entryname)) { |
|
| 2040 | + copytree($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 2041 | + } elseif (file_exists($destination . '/' . $entryname)) { |
|
| 2042 | + package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname)); |
|
| 2043 | + } else { |
|
| 2044 | + copy($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 2045 | + } |
|
| 1927 | 2046 | } |
| 1928 | 2047 | |
| 1929 | 2048 | closedir($current_dir); |
@@ -1941,21 +2060,24 @@ discard block |
||
| 1941 | 2060 | $data = array(); |
| 1942 | 2061 | |
| 1943 | 2062 | $dir = @dir($path . $sub_path); |
| 1944 | - if (!$dir) |
|
| 1945 | - return array(); |
|
| 2063 | + if (!$dir) { |
|
| 2064 | + return array(); |
|
| 2065 | + } |
|
| 1946 | 2066 | while ($entry = $dir->read()) |
| 1947 | 2067 | { |
| 1948 | - if ($entry == '.' || $entry == '..') |
|
| 1949 | - continue; |
|
| 2068 | + if ($entry == '.' || $entry == '..') { |
|
| 2069 | + continue; |
|
| 2070 | + } |
|
| 1950 | 2071 | |
| 1951 | - if (is_dir($path . $sub_path . '/' . $entry)) |
|
| 1952 | - $data = array_merge($data, listtree($path, $sub_path . '/' . $entry)); |
|
| 1953 | - else |
|
| 1954 | - $data[] = array( |
|
| 2072 | + if (is_dir($path . $sub_path . '/' . $entry)) { |
|
| 2073 | + $data = array_merge($data, listtree($path, $sub_path . '/' . $entry)); |
|
| 2074 | + } else { |
|
| 2075 | + $data[] = array( |
|
| 1955 | 2076 | 'filename' => $sub_path == '' ? $entry : $sub_path . '/' . $entry, |
| 1956 | 2077 | 'size' => filesize($path . $sub_path . '/' . $entry), |
| 1957 | 2078 | 'skipped' => false, |
| 1958 | 2079 | ); |
| 2080 | + } |
|
| 1959 | 2081 | } |
| 1960 | 2082 | $dir->close(); |
| 1961 | 2083 | |
@@ -2010,8 +2132,9 @@ discard block |
||
| 2010 | 2132 | { |
| 2011 | 2133 | // If this filename is relative, if so take a guess at what it should be. |
| 2012 | 2134 | $real_filename = $filename; |
| 2013 | - if (strpos($filename, 'Themes') === 0) |
|
| 2014 | - $real_filename = $boarddir . '/' . $filename; |
|
| 2135 | + if (strpos($filename, 'Themes') === 0) { |
|
| 2136 | + $real_filename = $boarddir . '/' . $filename; |
|
| 2137 | + } |
|
| 2015 | 2138 | |
| 2016 | 2139 | if (strpos($real_filename, $theme['theme_dir']) === 0) |
| 2017 | 2140 | { |
@@ -2030,8 +2153,9 @@ discard block |
||
| 2030 | 2153 | foreach ($theme_paths as $id => $theme) |
| 2031 | 2154 | { |
| 2032 | 2155 | // Default is getting done anyway, so no need for involvement here. |
| 2033 | - if ($id == 1) |
|
| 2034 | - continue; |
|
| 2156 | + if ($id == 1) { |
|
| 2157 | + continue; |
|
| 2158 | + } |
|
| 2035 | 2159 | |
| 2036 | 2160 | // For every template, do we want it? Yea, no, maybe? |
| 2037 | 2161 | foreach ($template_changes[1] as $index => $template_file) |
@@ -2054,8 +2178,9 @@ discard block |
||
| 2054 | 2178 | ); |
| 2055 | 2179 | |
| 2056 | 2180 | // Sometimes though, we have some additional files for other themes, if we have add them to the mix. |
| 2057 | - if (isset($custom_themes_add[$files_to_change[1]])) |
|
| 2058 | - $files_to_change += $custom_themes_add[$files_to_change[1]]; |
|
| 2181 | + if (isset($custom_themes_add[$files_to_change[1]])) { |
|
| 2182 | + $files_to_change += $custom_themes_add[$files_to_change[1]]; |
|
| 2183 | + } |
|
| 2059 | 2184 | |
| 2060 | 2185 | // Now, loop through all the files we're changing, and, well, change them ;) |
| 2061 | 2186 | foreach ($files_to_change as $theme => $working_file) |
@@ -2089,11 +2214,13 @@ discard block |
||
| 2089 | 2214 | continue; |
| 2090 | 2215 | } |
| 2091 | 2216 | // Okay, we're creating this file then...? |
| 2092 | - elseif (!file_exists($working_file)) |
|
| 2093 | - $working_data = ''; |
|
| 2217 | + elseif (!file_exists($working_file)) { |
|
| 2218 | + $working_data = ''; |
|
| 2219 | + } |
|
| 2094 | 2220 | // Phew, it exists! Load 'er up! |
| 2095 | - else |
|
| 2096 | - $working_data = str_replace("\r", '', package_get_contents($working_file)); |
|
| 2221 | + else { |
|
| 2222 | + $working_data = str_replace("\r", '', package_get_contents($working_file)); |
|
| 2223 | + } |
|
| 2097 | 2224 | |
| 2098 | 2225 | $actions[] = array( |
| 2099 | 2226 | 'type' => 'opened', |
@@ -2114,8 +2241,8 @@ discard block |
||
| 2114 | 2241 | |
| 2115 | 2242 | // Grab all search items of this operation (in most cases just 1). |
| 2116 | 2243 | $searches = $operation->set('search'); |
| 2117 | - foreach ($searches as $i => $search) |
|
| 2118 | - $actual_operation['searches'][] = array( |
|
| 2244 | + foreach ($searches as $i => $search) { |
|
| 2245 | + $actual_operation['searches'][] = array( |
|
| 2119 | 2246 | 'position' => $search->exists('@position') && in_array(trim($search->fetch('@position')), array('before', 'after', 'replace', 'end')) ? trim($search->fetch('@position')) : 'replace', |
| 2120 | 2247 | 'is_reg_exp' => $search->exists('@regexp') && trim($search->fetch('@regexp')) === 'true', |
| 2121 | 2248 | 'loose_whitespace' => $search->exists('@whitespace') && trim($search->fetch('@whitespace')) === 'loose', |
@@ -2124,6 +2251,7 @@ discard block |
||
| 2124 | 2251 | 'preg_search' => '', |
| 2125 | 2252 | 'preg_replace' => '', |
| 2126 | 2253 | ); |
| 2254 | + } |
|
| 2127 | 2255 | |
| 2128 | 2256 | // At least one search should be defined. |
| 2129 | 2257 | if (empty($actual_operation['searches'])) |
@@ -2148,30 +2276,32 @@ discard block |
||
| 2148 | 2276 | // Reverse modification of regular expressions are not allowed. |
| 2149 | 2277 | if ($search['is_reg_exp']) |
| 2150 | 2278 | { |
| 2151 | - if ($actual_operation['error'] === 'fatal') |
|
| 2152 | - $actions[] = array( |
|
| 2279 | + if ($actual_operation['error'] === 'fatal') { |
|
| 2280 | + $actions[] = array( |
|
| 2153 | 2281 | 'type' => 'failure', |
| 2154 | 2282 | 'filename' => $working_file, |
| 2155 | 2283 | 'search' => $search['search'], |
| 2156 | 2284 | 'is_custom' => $theme > 1 ? $theme : 0, |
| 2157 | 2285 | ); |
| 2286 | + } |
|
| 2158 | 2287 | |
| 2159 | 2288 | // Continue to the next operation. |
| 2160 | 2289 | continue 2; |
| 2161 | 2290 | } |
| 2162 | 2291 | |
| 2163 | 2292 | // The replacement is now the search subject... |
| 2164 | - if ($search['position'] === 'replace' || $search['position'] === 'end') |
|
| 2165 | - $actual_operation['searches'][$i]['search'] = $search['add']; |
|
| 2166 | - else |
|
| 2293 | + if ($search['position'] === 'replace' || $search['position'] === 'end') { |
|
| 2294 | + $actual_operation['searches'][$i]['search'] = $search['add']; |
|
| 2295 | + } else |
|
| 2167 | 2296 | { |
| 2168 | 2297 | // Reversing a before/after modification becomes a replacement. |
| 2169 | 2298 | $actual_operation['searches'][$i]['position'] = 'replace'; |
| 2170 | 2299 | |
| 2171 | - if ($search['position'] === 'before') |
|
| 2172 | - $actual_operation['searches'][$i]['search'] .= $search['add']; |
|
| 2173 | - elseif ($search['position'] === 'after') |
|
| 2174 | - $actual_operation['searches'][$i]['search'] = $search['add'] . $search['search']; |
|
| 2300 | + if ($search['position'] === 'before') { |
|
| 2301 | + $actual_operation['searches'][$i]['search'] .= $search['add']; |
|
| 2302 | + } elseif ($search['position'] === 'after') { |
|
| 2303 | + $actual_operation['searches'][$i]['search'] = $search['add'] . $search['search']; |
|
| 2304 | + } |
|
| 2175 | 2305 | } |
| 2176 | 2306 | |
| 2177 | 2307 | // ...and the search subject is now the replacement. |
@@ -2199,16 +2329,17 @@ discard block |
||
| 2199 | 2329 | foreach ($actual_operation['searches'] as $i => $search) |
| 2200 | 2330 | { |
| 2201 | 2331 | // Not much needed if the search subject is already a regexp. |
| 2202 | - if ($search['is_reg_exp']) |
|
| 2203 | - $actual_operation['searches'][$i]['preg_search'] = $search['search']; |
|
| 2204 | - else |
|
| 2332 | + if ($search['is_reg_exp']) { |
|
| 2333 | + $actual_operation['searches'][$i]['preg_search'] = $search['search']; |
|
| 2334 | + } else |
|
| 2205 | 2335 | { |
| 2206 | 2336 | // Make the search subject fit into a regular expression. |
| 2207 | 2337 | $actual_operation['searches'][$i]['preg_search'] = preg_quote($search['search'], '~'); |
| 2208 | 2338 | |
| 2209 | 2339 | // Using 'loose', a random amount of tabs and spaces may be used. |
| 2210 | - if ($search['loose_whitespace']) |
|
| 2211 | - $actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']); |
|
| 2340 | + if ($search['loose_whitespace']) { |
|
| 2341 | + $actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']); |
|
| 2342 | + } |
|
| 2212 | 2343 | } |
| 2213 | 2344 | |
| 2214 | 2345 | // Shuzzup. This is done so we can safely use a regular expression. ($0 is bad!!) |
@@ -2234,8 +2365,7 @@ discard block |
||
| 2234 | 2365 | if ($undo) |
| 2235 | 2366 | { |
| 2236 | 2367 | $actual_operation['searches'][$i]['preg_replace'] = ''; |
| 2237 | - } |
|
| 2238 | - else |
|
| 2368 | + } else |
|
| 2239 | 2369 | { |
| 2240 | 2370 | $actual_operation['searches'][$i]['preg_search'] = '(\\n\\?\\>)?$'; |
| 2241 | 2371 | $actual_operation['searches'][$i]['preg_replace'] .= '$1'; |
@@ -2282,8 +2412,9 @@ discard block |
||
| 2282 | 2412 | } |
| 2283 | 2413 | |
| 2284 | 2414 | // Replace it into nothing? That's not an option...unless it's an undoing end. |
| 2285 | - if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) |
|
| 2286 | - continue; |
|
| 2415 | + if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) { |
|
| 2416 | + continue; |
|
| 2417 | + } |
|
| 2287 | 2418 | |
| 2288 | 2419 | // Finally, we're doing some replacements. |
| 2289 | 2420 | $working_data = preg_replace('~' . $actual_operation['searches'][$i]['preg_search'] . '~s', $actual_operation['searches'][$i]['preg_replace'], $working_data, 1); |
@@ -2308,22 +2439,25 @@ discard block |
||
| 2308 | 2439 | |
| 2309 | 2440 | package_chmod($working_file); |
| 2310 | 2441 | |
| 2311 | - if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) |
|
| 2312 | - $actions[] = array( |
|
| 2442 | + if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) { |
|
| 2443 | + $actions[] = array( |
|
| 2313 | 2444 | 'type' => 'chmod', |
| 2314 | 2445 | 'filename' => $working_file |
| 2315 | 2446 | ); |
| 2447 | + } |
|
| 2316 | 2448 | |
| 2317 | - if (basename($working_file) == 'Settings_bak.php') |
|
| 2318 | - continue; |
|
| 2449 | + if (basename($working_file) == 'Settings_bak.php') { |
|
| 2450 | + continue; |
|
| 2451 | + } |
|
| 2319 | 2452 | |
| 2320 | 2453 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
| 2321 | 2454 | { |
| 2322 | 2455 | // No, no, not Settings.php! |
| 2323 | - if (basename($working_file) == 'Settings.php') |
|
| 2324 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2325 | - else |
|
| 2326 | - @copy($working_file, $working_file . '~'); |
|
| 2456 | + if (basename($working_file) == 'Settings.php') { |
|
| 2457 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2458 | + } else { |
|
| 2459 | + @copy($working_file, $working_file . '~'); |
|
| 2460 | + } |
|
| 2327 | 2461 | } |
| 2328 | 2462 | |
| 2329 | 2463 | // Always call this, even if in testing, because it won't really be written in testing mode. |
@@ -2390,8 +2524,9 @@ discard block |
||
| 2390 | 2524 | if ($code_match[1] != 'edit file' && $code_match[1] != 'file') |
| 2391 | 2525 | { |
| 2392 | 2526 | // It's a step, let's add that to the current steps. |
| 2393 | - if (isset($temp_changes[$step_counter])) |
|
| 2394 | - $temp_changes[$step_counter]['changes'][] = $code_match[0]; |
|
| 2527 | + if (isset($temp_changes[$step_counter])) { |
|
| 2528 | + $temp_changes[$step_counter]['changes'][] = $code_match[0]; |
|
| 2529 | + } |
|
| 2395 | 2530 | continue; |
| 2396 | 2531 | } |
| 2397 | 2532 | |
@@ -2408,11 +2543,13 @@ discard block |
||
| 2408 | 2543 | foreach ($theme_paths as $id => $theme) |
| 2409 | 2544 | { |
| 2410 | 2545 | // If this filename is relative, if so take a guess at what it should be. |
| 2411 | - if (strpos($filename, 'Themes') === 0) |
|
| 2412 | - $filename = $boarddir . '/' . $filename; |
|
| 2546 | + if (strpos($filename, 'Themes') === 0) { |
|
| 2547 | + $filename = $boarddir . '/' . $filename; |
|
| 2548 | + } |
|
| 2413 | 2549 | |
| 2414 | - if (strpos($filename, $theme['theme_dir']) === 0) |
|
| 2415 | - $template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1); |
|
| 2550 | + if (strpos($filename, $theme['theme_dir']) === 0) { |
|
| 2551 | + $template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1); |
|
| 2552 | + } |
|
| 2416 | 2553 | } |
| 2417 | 2554 | } |
| 2418 | 2555 | |
@@ -2425,8 +2562,9 @@ discard block |
||
| 2425 | 2562 | foreach ($theme_paths as $id => $theme) |
| 2426 | 2563 | { |
| 2427 | 2564 | // Don't do default, it means nothing to me. |
| 2428 | - if ($id == 1) |
|
| 2429 | - continue; |
|
| 2565 | + if ($id == 1) { |
|
| 2566 | + continue; |
|
| 2567 | + } |
|
| 2430 | 2568 | |
| 2431 | 2569 | // Now, for each file do we need to edit it? |
| 2432 | 2570 | foreach ($template_changes[1] as $pos => $template_file) |
@@ -2462,32 +2600,36 @@ discard block |
||
| 2462 | 2600 | package_chmod($working_file); |
| 2463 | 2601 | |
| 2464 | 2602 | // Don't even dare. |
| 2465 | - if (basename($working_file) == 'Settings_bak.php') |
|
| 2466 | - continue; |
|
| 2603 | + if (basename($working_file) == 'Settings_bak.php') { |
|
| 2604 | + continue; |
|
| 2605 | + } |
|
| 2467 | 2606 | |
| 2468 | - if (!is_writable($working_file)) |
|
| 2469 | - $actions[] = array( |
|
| 2607 | + if (!is_writable($working_file)) { |
|
| 2608 | + $actions[] = array( |
|
| 2470 | 2609 | 'type' => 'chmod', |
| 2471 | 2610 | 'filename' => $working_file |
| 2472 | 2611 | ); |
| 2612 | + } |
|
| 2473 | 2613 | |
| 2474 | 2614 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
| 2475 | 2615 | { |
| 2476 | - if (basename($working_file) == 'Settings.php') |
|
| 2477 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2478 | - else |
|
| 2479 | - @copy($working_file, $working_file . '~'); |
|
| 2616 | + if (basename($working_file) == 'Settings.php') { |
|
| 2617 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2618 | + } else { |
|
| 2619 | + @copy($working_file, $working_file . '~'); |
|
| 2620 | + } |
|
| 2480 | 2621 | } |
| 2481 | 2622 | |
| 2482 | 2623 | package_put_contents($working_file, $working_data, $testing); |
| 2483 | 2624 | } |
| 2484 | 2625 | |
| 2485 | - if ($working_file !== null) |
|
| 2486 | - $actions[] = array( |
|
| 2626 | + if ($working_file !== null) { |
|
| 2627 | + $actions[] = array( |
|
| 2487 | 2628 | 'type' => 'saved', |
| 2488 | 2629 | 'filename' => $working_file, |
| 2489 | 2630 | 'is_custom' => $is_custom, |
| 2490 | 2631 | ); |
| 2632 | + } |
|
| 2491 | 2633 | |
| 2492 | 2634 | // Is this "now working on" file a theme specific one? |
| 2493 | 2635 | $is_custom = isset($theme_id_ref[$counter - 1]) ? $theme_id_ref[$counter - 1] : 0; |
@@ -2506,10 +2648,11 @@ discard block |
||
| 2506 | 2648 | { |
| 2507 | 2649 | $places_to_check = array($boarddir, $sourcedir, $settings['default_theme_dir'], $settings['default_theme_dir'] . '/languages'); |
| 2508 | 2650 | |
| 2509 | - foreach ($places_to_check as $place) |
|
| 2510 | - if (file_exists($place . '/' . $working_file)) |
|
| 2651 | + foreach ($places_to_check as $place) { |
|
| 2652 | + if (file_exists($place . '/' . $working_file)) |
|
| 2511 | 2653 | { |
| 2512 | 2654 | $working_file = $place . '/' . $working_file; |
| 2655 | + } |
|
| 2513 | 2656 | break; |
| 2514 | 2657 | } |
| 2515 | 2658 | } |
@@ -2523,8 +2666,7 @@ discard block |
||
| 2523 | 2666 | 'type' => 'opened', |
| 2524 | 2667 | 'filename' => $working_file |
| 2525 | 2668 | ); |
| 2526 | - } |
|
| 2527 | - else |
|
| 2669 | + } else |
|
| 2528 | 2670 | { |
| 2529 | 2671 | $actions[] = array( |
| 2530 | 2672 | 'type' => 'missing', |
@@ -2560,11 +2702,13 @@ discard block |
||
| 2560 | 2702 | $replace_with = $code_match[2]; |
| 2561 | 2703 | |
| 2562 | 2704 | // Add this afterward... |
| 2563 | - if ($code_match[1] == 'add' || $code_match[1] == 'add after') |
|
| 2564 | - $replace_with = $working_search . "\n" . $replace_with; |
|
| 2705 | + if ($code_match[1] == 'add' || $code_match[1] == 'add after') { |
|
| 2706 | + $replace_with = $working_search . "\n" . $replace_with; |
|
| 2707 | + } |
|
| 2565 | 2708 | // Add this beforehand. |
| 2566 | - elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') |
|
| 2567 | - $replace_with .= "\n" . $working_search; |
|
| 2709 | + elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') { |
|
| 2710 | + $replace_with .= "\n" . $working_search; |
|
| 2711 | + } |
|
| 2568 | 2712 | // Otherwise.. replace with $replace_with ;). |
| 2569 | 2713 | } |
| 2570 | 2714 | |
@@ -2627,29 +2771,32 @@ discard block |
||
| 2627 | 2771 | { |
| 2628 | 2772 | package_chmod($working_file); |
| 2629 | 2773 | |
| 2630 | - if (!is_writable($working_file)) |
|
| 2631 | - $actions[] = array( |
|
| 2774 | + if (!is_writable($working_file)) { |
|
| 2775 | + $actions[] = array( |
|
| 2632 | 2776 | 'type' => 'chmod', |
| 2633 | 2777 | 'filename' => $working_file |
| 2634 | 2778 | ); |
| 2779 | + } |
|
| 2635 | 2780 | |
| 2636 | 2781 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
| 2637 | 2782 | { |
| 2638 | - if (basename($working_file) == 'Settings.php') |
|
| 2639 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2640 | - else |
|
| 2641 | - @copy($working_file, $working_file . '~'); |
|
| 2783 | + if (basename($working_file) == 'Settings.php') { |
|
| 2784 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2785 | + } else { |
|
| 2786 | + @copy($working_file, $working_file . '~'); |
|
| 2787 | + } |
|
| 2642 | 2788 | } |
| 2643 | 2789 | |
| 2644 | 2790 | package_put_contents($working_file, $working_data, $testing); |
| 2645 | 2791 | } |
| 2646 | 2792 | |
| 2647 | - if ($working_file !== null) |
|
| 2648 | - $actions[] = array( |
|
| 2793 | + if ($working_file !== null) { |
|
| 2794 | + $actions[] = array( |
|
| 2649 | 2795 | 'type' => 'saved', |
| 2650 | 2796 | 'filename' => $working_file, |
| 2651 | 2797 | 'is_custom' => $is_custom, |
| 2652 | 2798 | ); |
| 2799 | + } |
|
| 2653 | 2800 | |
| 2654 | 2801 | $actions[] = array( |
| 2655 | 2802 | 'type' => 'result', |
@@ -2675,17 +2822,19 @@ discard block |
||
| 2675 | 2822 | $mem_check = setMemoryLimit('128M'); |
| 2676 | 2823 | |
| 2677 | 2824 | // Windows doesn't seem to care about the memory_limit. |
| 2678 | - if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) |
|
| 2679 | - $package_cache = array(); |
|
| 2680 | - else |
|
| 2681 | - $package_cache = false; |
|
| 2825 | + if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) { |
|
| 2826 | + $package_cache = array(); |
|
| 2827 | + } else { |
|
| 2828 | + $package_cache = false; |
|
| 2829 | + } |
|
| 2682 | 2830 | } |
| 2683 | 2831 | |
| 2684 | - if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) |
|
| 2685 | - return file_get_contents($filename); |
|
| 2686 | - else |
|
| 2687 | - return $package_cache[$filename]; |
|
| 2688 | -} |
|
| 2832 | + if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) { |
|
| 2833 | + return file_get_contents($filename); |
|
| 2834 | + } else { |
|
| 2835 | + return $package_cache[$filename]; |
|
| 2836 | + } |
|
| 2837 | + } |
|
| 2689 | 2838 | |
| 2690 | 2839 | /** |
| 2691 | 2840 | * Writes data to a file, almost exactly like the file_put_contents() function. |
@@ -2708,19 +2857,22 @@ discard block |
||
| 2708 | 2857 | // Try to increase the memory limit - we don't want to run out of ram! |
| 2709 | 2858 | $mem_check = setMemoryLimit('128M'); |
| 2710 | 2859 | |
| 2711 | - if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) |
|
| 2712 | - $package_cache = array(); |
|
| 2713 | - else |
|
| 2714 | - $package_cache = false; |
|
| 2860 | + if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) { |
|
| 2861 | + $package_cache = array(); |
|
| 2862 | + } else { |
|
| 2863 | + $package_cache = false; |
|
| 2864 | + } |
|
| 2715 | 2865 | } |
| 2716 | 2866 | |
| 2717 | - if (isset($package_ftp)) |
|
| 2718 | - $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2867 | + if (isset($package_ftp)) { |
|
| 2868 | + $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2869 | + } |
|
| 2719 | 2870 | |
| 2720 | - if (!file_exists($filename) && isset($package_ftp)) |
|
| 2721 | - $package_ftp->create_file($ftp_file); |
|
| 2722 | - elseif (!file_exists($filename)) |
|
| 2723 | - @touch($filename); |
|
| 2871 | + if (!file_exists($filename) && isset($package_ftp)) { |
|
| 2872 | + $package_ftp->create_file($ftp_file); |
|
| 2873 | + } elseif (!file_exists($filename)) { |
|
| 2874 | + @touch($filename); |
|
| 2875 | + } |
|
| 2724 | 2876 | |
| 2725 | 2877 | package_chmod($filename); |
| 2726 | 2878 | |
@@ -2729,22 +2881,23 @@ discard block |
||
| 2729 | 2881 | $fp = @fopen($filename, in_array(substr($filename, -3), $text_filetypes) ? 'w' : 'wb'); |
| 2730 | 2882 | |
| 2731 | 2883 | // We should show an error message or attempt a rollback, no? |
| 2732 | - if (!$fp) |
|
| 2733 | - return false; |
|
| 2884 | + if (!$fp) { |
|
| 2885 | + return false; |
|
| 2886 | + } |
|
| 2734 | 2887 | |
| 2735 | 2888 | fwrite($fp, $data); |
| 2736 | 2889 | fclose($fp); |
| 2737 | - } |
|
| 2738 | - elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) |
|
| 2739 | - return strlen($data); |
|
| 2740 | - else |
|
| 2890 | + } elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) { |
|
| 2891 | + return strlen($data); |
|
| 2892 | + } else |
|
| 2741 | 2893 | { |
| 2742 | 2894 | $package_cache[$filename] = $data; |
| 2743 | 2895 | |
| 2744 | 2896 | // Permission denied, eh? |
| 2745 | 2897 | $fp = @fopen($filename, 'r+'); |
| 2746 | - if (!$fp) |
|
| 2747 | - return false; |
|
| 2898 | + if (!$fp) { |
|
| 2899 | + return false; |
|
| 2900 | + } |
|
| 2748 | 2901 | fclose($fp); |
| 2749 | 2902 | } |
| 2750 | 2903 | |
@@ -2761,19 +2914,22 @@ discard block |
||
| 2761 | 2914 | global $package_ftp, $package_cache; |
| 2762 | 2915 | static $text_filetypes = array('php', 'txt', '.js', 'css', 'vbs', 'tml', 'htm'); |
| 2763 | 2916 | |
| 2764 | - if (empty($package_cache)) |
|
| 2765 | - return; |
|
| 2917 | + if (empty($package_cache)) { |
|
| 2918 | + return; |
|
| 2919 | + } |
|
| 2766 | 2920 | |
| 2767 | 2921 | // First, let's check permissions! |
| 2768 | 2922 | foreach ($package_cache as $filename => $data) |
| 2769 | 2923 | { |
| 2770 | - if (isset($package_ftp)) |
|
| 2771 | - $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2924 | + if (isset($package_ftp)) { |
|
| 2925 | + $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2926 | + } |
|
| 2772 | 2927 | |
| 2773 | - if (!file_exists($filename) && isset($package_ftp)) |
|
| 2774 | - $package_ftp->create_file($ftp_file); |
|
| 2775 | - elseif (!file_exists($filename)) |
|
| 2776 | - @touch($filename); |
|
| 2928 | + if (!file_exists($filename) && isset($package_ftp)) { |
|
| 2929 | + $package_ftp->create_file($ftp_file); |
|
| 2930 | + } elseif (!file_exists($filename)) { |
|
| 2931 | + @touch($filename); |
|
| 2932 | + } |
|
| 2777 | 2933 | |
| 2778 | 2934 | $result = package_chmod($filename); |
| 2779 | 2935 | |
@@ -2826,8 +2982,9 @@ discard block |
||
| 2826 | 2982 | { |
| 2827 | 2983 | global $package_ftp; |
| 2828 | 2984 | |
| 2829 | - if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') |
|
| 2830 | - return true; |
|
| 2985 | + if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') { |
|
| 2986 | + return true; |
|
| 2987 | + } |
|
| 2831 | 2988 | |
| 2832 | 2989 | // Start off checking without FTP. |
| 2833 | 2990 | if (!isset($package_ftp) || $package_ftp === false) |
@@ -2849,8 +3006,7 @@ discard block |
||
| 2849 | 3006 | |
| 2850 | 3007 | // Keep track of the writable status here. |
| 2851 | 3008 | $file_permissions = @fileperms($chmod_file); |
| 2852 | - } |
|
| 2853 | - else |
|
| 3009 | + } else |
|
| 2854 | 3010 | { |
| 2855 | 3011 | // This looks odd, but it's an attempt to work around PHP suExec. |
| 2856 | 3012 | if (!file_exists($chmod_file) && $perm_state == 'writable') |
@@ -2860,24 +3016,28 @@ discard block |
||
| 2860 | 3016 | mktree(dirname($chmod_file), 0755); |
| 2861 | 3017 | @touch($chmod_file); |
| 2862 | 3018 | smf_chmod($chmod_file, 0755); |
| 3019 | + } else { |
|
| 3020 | + $file_permissions = @fileperms($chmod_file); |
|
| 2863 | 3021 | } |
| 2864 | - else |
|
| 2865 | - $file_permissions = @fileperms($chmod_file); |
|
| 2866 | 3022 | } |
| 2867 | 3023 | |
| 2868 | 3024 | // This looks odd, but it's another attempt to work around PHP suExec. |
| 2869 | - if ($perm_state != 'writable') |
|
| 2870 | - smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644); |
|
| 2871 | - else |
|
| 3025 | + if ($perm_state != 'writable') { |
|
| 3026 | + smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644); |
|
| 3027 | + } else |
|
| 2872 | 3028 | { |
| 2873 | - if (!@is_writable($chmod_file)) |
|
| 2874 | - smf_chmod($chmod_file, 0755); |
|
| 2875 | - if (!@is_writable($chmod_file)) |
|
| 2876 | - smf_chmod($chmod_file, 0777); |
|
| 2877 | - if (!@is_writable(dirname($chmod_file))) |
|
| 2878 | - smf_chmod($chmod_file, 0755); |
|
| 2879 | - if (!@is_writable(dirname($chmod_file))) |
|
| 2880 | - smf_chmod($chmod_file, 0777); |
|
| 3029 | + if (!@is_writable($chmod_file)) { |
|
| 3030 | + smf_chmod($chmod_file, 0755); |
|
| 3031 | + } |
|
| 3032 | + if (!@is_writable($chmod_file)) { |
|
| 3033 | + smf_chmod($chmod_file, 0777); |
|
| 3034 | + } |
|
| 3035 | + if (!@is_writable(dirname($chmod_file))) { |
|
| 3036 | + smf_chmod($chmod_file, 0755); |
|
| 3037 | + } |
|
| 3038 | + if (!@is_writable(dirname($chmod_file))) { |
|
| 3039 | + smf_chmod($chmod_file, 0777); |
|
| 3040 | + } |
|
| 2881 | 3041 | } |
| 2882 | 3042 | |
| 2883 | 3043 | // The ultimate writable test. |
@@ -2886,20 +3046,22 @@ discard block |
||
| 2886 | 3046 | $fp = is_dir($chmod_file) ? @opendir($chmod_file) : @fopen($chmod_file, 'rb'); |
| 2887 | 3047 | if (@is_writable($chmod_file) && $fp) |
| 2888 | 3048 | { |
| 2889 | - if (!is_dir($chmod_file)) |
|
| 2890 | - fclose($fp); |
|
| 2891 | - else |
|
| 2892 | - closedir($fp); |
|
| 3049 | + if (!is_dir($chmod_file)) { |
|
| 3050 | + fclose($fp); |
|
| 3051 | + } else { |
|
| 3052 | + closedir($fp); |
|
| 3053 | + } |
|
| 2893 | 3054 | |
| 2894 | 3055 | // It worked! |
| 2895 | - if ($track_change) |
|
| 2896 | - $_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions; |
|
| 3056 | + if ($track_change) { |
|
| 3057 | + $_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions; |
|
| 3058 | + } |
|
| 2897 | 3059 | |
| 2898 | 3060 | return true; |
| 2899 | 3061 | } |
| 3062 | + } elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) { |
|
| 3063 | + unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]); |
|
| 2900 | 3064 | } |
| 2901 | - elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) |
|
| 2902 | - unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]); |
|
| 2903 | 3065 | } |
| 2904 | 3066 | |
| 2905 | 3067 | // If we're here we're a failure. |
@@ -2918,31 +3080,33 @@ discard block |
||
| 2918 | 3080 | mktree(dirname($filename), 0755); |
| 2919 | 3081 | $package_ftp->create_file($ftp_file); |
| 2920 | 3082 | $package_ftp->chmod($ftp_file, 0755); |
| 3083 | + } else { |
|
| 3084 | + $file_permissions = @fileperms($filename); |
|
| 2921 | 3085 | } |
| 2922 | - else |
|
| 2923 | - $file_permissions = @fileperms($filename); |
|
| 2924 | 3086 | |
| 2925 | 3087 | if ($perm_state != 'writable') |
| 2926 | 3088 | { |
| 2927 | 3089 | $package_ftp->chmod($ftp_file, $perm_state == 'execute' ? 0755 : 0644); |
| 2928 | - } |
|
| 2929 | - else |
|
| 3090 | + } else |
|
| 2930 | 3091 | { |
| 2931 | - if (!@is_writable($filename)) |
|
| 2932 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 2933 | - if (!@is_writable(dirname($filename))) |
|
| 2934 | - $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 3092 | + if (!@is_writable($filename)) { |
|
| 3093 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 3094 | + } |
|
| 3095 | + if (!@is_writable(dirname($filename))) { |
|
| 3096 | + $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 3097 | + } |
|
| 2935 | 3098 | } |
| 2936 | 3099 | |
| 2937 | 3100 | if (@is_writable($filename)) |
| 2938 | 3101 | { |
| 2939 | - if ($track_change) |
|
| 2940 | - $_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions; |
|
| 3102 | + if ($track_change) { |
|
| 3103 | + $_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions; |
|
| 3104 | + } |
|
| 2941 | 3105 | |
| 2942 | 3106 | return true; |
| 3107 | + } elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) { |
|
| 3108 | + unset($_SESSION['pack_ftp']['original_perms'][$filename]); |
|
| 2943 | 3109 | } |
| 2944 | - elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) |
|
| 2945 | - unset($_SESSION['pack_ftp']['original_perms'][$filename]); |
|
| 2946 | 3110 | } |
| 2947 | 3111 | |
| 2948 | 3112 | // Oh dear, we failed if we get here. |
@@ -2960,11 +3124,13 @@ discard block |
||
| 2960 | 3124 | $n = strlen($pass); |
| 2961 | 3125 | |
| 2962 | 3126 | $salt = session_id(); |
| 2963 | - while (strlen($salt) < $n) |
|
| 2964 | - $salt .= session_id(); |
|
| 3127 | + while (strlen($salt) < $n) { |
|
| 3128 | + $salt .= session_id(); |
|
| 3129 | + } |
|
| 2965 | 3130 | |
| 2966 | - for ($i = 0; $i < $n; $i++) |
|
| 2967 | - $pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32)); |
|
| 3131 | + for ($i = 0; $i < $n; $i++) { |
|
| 3132 | + $pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32)); |
|
| 3133 | + } |
|
| 2968 | 3134 | |
| 2969 | 3135 | return $pass; |
| 2970 | 3136 | } |
@@ -2983,8 +3149,9 @@ discard block |
||
| 2983 | 3149 | $base_files = array('index.php', 'SSI.php', 'agreement.txt', 'cron.php', 'ssi_examples.php', 'ssi_examples.shtml', 'subscriptions.php'); |
| 2984 | 3150 | foreach ($base_files as $file) |
| 2985 | 3151 | { |
| 2986 | - if (file_exists($boarddir . '/' . $file)) |
|
| 2987 | - $files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file; |
|
| 3152 | + if (file_exists($boarddir . '/' . $file)) { |
|
| 3153 | + $files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file; |
|
| 3154 | + } |
|
| 2988 | 3155 | } |
| 2989 | 3156 | |
| 2990 | 3157 | $dirs = array( |
@@ -3001,8 +3168,9 @@ discard block |
||
| 3001 | 3168 | 'theme_dir' => 'theme_dir', |
| 3002 | 3169 | ) |
| 3003 | 3170 | ); |
| 3004 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 3005 | - $dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/'); |
|
| 3171 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 3172 | + $dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/'); |
|
| 3173 | + } |
|
| 3006 | 3174 | $smcFunc['db_free_result']($request); |
| 3007 | 3175 | |
| 3008 | 3176 | try |
@@ -3017,11 +3185,13 @@ discard block |
||
| 3017 | 3185 | |
| 3018 | 3186 | foreach ($iter as $entry => $dir) |
| 3019 | 3187 | { |
| 3020 | - if ($dir->isDir()) |
|
| 3021 | - continue; |
|
| 3188 | + if ($dir->isDir()) { |
|
| 3189 | + continue; |
|
| 3190 | + } |
|
| 3022 | 3191 | |
| 3023 | - if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) |
|
| 3024 | - continue; |
|
| 3192 | + if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) { |
|
| 3193 | + continue; |
|
| 3194 | + } |
|
| 3025 | 3195 | |
| 3026 | 3196 | $files[empty($_REQUEST['use_full_paths']) ? str_replace(realpath($boarddir), '', $entry) : $entry] = $entry; |
| 3027 | 3197 | } |
@@ -3029,26 +3199,30 @@ discard block |
||
| 3029 | 3199 | $obj = new ArrayObject($files); |
| 3030 | 3200 | $iterator = $obj->getIterator(); |
| 3031 | 3201 | |
| 3032 | - if (!file_exists($packagesdir . '/backups')) |
|
| 3033 | - mktree($packagesdir . '/backups', 0777); |
|
| 3034 | - if (!is_writable($packagesdir . '/backups')) |
|
| 3035 | - package_chmod($packagesdir . '/backups'); |
|
| 3202 | + if (!file_exists($packagesdir . '/backups')) { |
|
| 3203 | + mktree($packagesdir . '/backups', 0777); |
|
| 3204 | + } |
|
| 3205 | + if (!is_writable($packagesdir . '/backups')) { |
|
| 3206 | + package_chmod($packagesdir . '/backups'); |
|
| 3207 | + } |
|
| 3036 | 3208 | $output_file = $packagesdir . '/backups/' . strftime('%Y-%m-%d_') . preg_replace('~[$\\\\/:<>|?*"\']~', '', $id); |
| 3037 | 3209 | $output_ext = '.tar'; |
| 3038 | 3210 | |
| 3039 | 3211 | if (file_exists($output_file . $output_ext)) |
| 3040 | 3212 | { |
| 3041 | 3213 | $i = 2; |
| 3042 | - while (file_exists($output_file . '_' . $i . $output_ext)) |
|
| 3043 | - $i++; |
|
| 3214 | + while (file_exists($output_file . '_' . $i . $output_ext)) { |
|
| 3215 | + $i++; |
|
| 3216 | + } |
|
| 3044 | 3217 | $output_file = $output_file . '_' . $i . $output_ext; |
| 3218 | + } else { |
|
| 3219 | + $output_file .= $output_ext; |
|
| 3045 | 3220 | } |
| 3046 | - else |
|
| 3047 | - $output_file .= $output_ext; |
|
| 3048 | 3221 | |
| 3049 | 3222 | @set_time_limit(300); |
| 3050 | - if (function_exists('apache_reset_timeout')) |
|
| 3051 | - @apache_reset_timeout(); |
|
| 3223 | + if (function_exists('apache_reset_timeout')) { |
|
| 3224 | + @apache_reset_timeout(); |
|
| 3225 | + } |
|
| 3052 | 3226 | |
| 3053 | 3227 | $a = new PharData($output_file); |
| 3054 | 3228 | $a->buildFromIterator($iterator); |
@@ -3060,8 +3234,7 @@ discard block |
||
| 3060 | 3234 | */ |
| 3061 | 3235 | unset($a); |
| 3062 | 3236 | unlink($output_file); |
| 3063 | - } |
|
| 3064 | - catch (Exception $e) |
|
| 3237 | + } catch (Exception $e) |
|
| 3065 | 3238 | { |
| 3066 | 3239 | log_error($e->getMessage(), 'backup'); |
| 3067 | 3240 | |
@@ -3093,32 +3266,35 @@ discard block |
||
| 3093 | 3266 | preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match); |
| 3094 | 3267 | |
| 3095 | 3268 | // An FTP url. We should try connecting and RETRieving it... |
| 3096 | - if (empty($match[1])) |
|
| 3097 | - return false; |
|
| 3098 | - elseif ($match[1] == 'ftp') |
|
| 3269 | + if (empty($match[1])) { |
|
| 3270 | + return false; |
|
| 3271 | + } elseif ($match[1] == 'ftp') |
|
| 3099 | 3272 | { |
| 3100 | 3273 | // Include the file containing the ftp_connection class. |
| 3101 | 3274 | require_once($sourcedir . '/Class-Package.php'); |
| 3102 | 3275 | |
| 3103 | 3276 | // Establish a connection and attempt to enable passive mode. |
| 3104 | 3277 | $ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email); |
| 3105 | - if ($ftp->error !== false || !$ftp->passive()) |
|
| 3106 | - return false; |
|
| 3278 | + if ($ftp->error !== false || !$ftp->passive()) { |
|
| 3279 | + return false; |
|
| 3280 | + } |
|
| 3107 | 3281 | |
| 3108 | 3282 | // I want that one *points*! |
| 3109 | 3283 | fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n"); |
| 3110 | 3284 | |
| 3111 | 3285 | // Since passive mode worked (or we would have returned already!) open the connection. |
| 3112 | 3286 | $fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5); |
| 3113 | - if (!$fp) |
|
| 3114 | - return false; |
|
| 3287 | + if (!$fp) { |
|
| 3288 | + return false; |
|
| 3289 | + } |
|
| 3115 | 3290 | |
| 3116 | 3291 | // The server should now say something in acknowledgement. |
| 3117 | 3292 | $ftp->check_response(150); |
| 3118 | 3293 | |
| 3119 | 3294 | $data = ''; |
| 3120 | - while (!feof($fp)) |
|
| 3121 | - $data .= fread($fp, 4096); |
|
| 3295 | + while (!feof($fp)) { |
|
| 3296 | + $data .= fread($fp, 4096); |
|
| 3297 | + } |
|
| 3122 | 3298 | fclose($fp); |
| 3123 | 3299 | |
| 3124 | 3300 | // All done, right? Good. |
@@ -3135,22 +3311,25 @@ discard block |
||
| 3135 | 3311 | $fetch_data->get_url_data($url, $post_data); |
| 3136 | 3312 | |
| 3137 | 3313 | // no errors and a 200 result, then we have a good dataset, well we at least have data ;) |
| 3138 | - if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) |
|
| 3139 | - $data = $fetch_data->result('body'); |
|
| 3140 | - else |
|
| 3141 | - return false; |
|
| 3314 | + if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) { |
|
| 3315 | + $data = $fetch_data->result('body'); |
|
| 3316 | + } else { |
|
| 3317 | + return false; |
|
| 3318 | + } |
|
| 3142 | 3319 | } |
| 3143 | 3320 | // This is more likely; a standard HTTP URL. |
| 3144 | 3321 | elseif (isset($match[1]) && $match[1] == 'http') |
| 3145 | 3322 | { |
| 3146 | - if ($keep_alive && $match[3] == $keep_alive_dom) |
|
| 3147 | - $fp = $keep_alive_fp; |
|
| 3323 | + if ($keep_alive && $match[3] == $keep_alive_dom) { |
|
| 3324 | + $fp = $keep_alive_fp; |
|
| 3325 | + } |
|
| 3148 | 3326 | if (empty($fp)) |
| 3149 | 3327 | { |
| 3150 | 3328 | // Open the socket on the port we want... |
| 3151 | 3329 | $fp = @fsockopen(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? ($match[2] ? 443 : 80) : $match[5], $err, $err, 5); |
| 3152 | - if (!$fp) |
|
| 3153 | - return false; |
|
| 3330 | + if (!$fp) { |
|
| 3331 | + return false; |
|
| 3332 | + } |
|
| 3154 | 3333 | } |
| 3155 | 3334 | |
| 3156 | 3335 | if ($keep_alive) |
@@ -3165,20 +3344,21 @@ discard block |
||
| 3165 | 3344 | fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n"); |
| 3166 | 3345 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
| 3167 | 3346 | fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n"); |
| 3168 | - if ($keep_alive) |
|
| 3169 | - fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n"); |
|
| 3170 | - else |
|
| 3171 | - fwrite($fp, 'Connection: close' . "\r\n\r\n"); |
|
| 3172 | - } |
|
| 3173 | - else |
|
| 3347 | + if ($keep_alive) { |
|
| 3348 | + fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n"); |
|
| 3349 | + } else { |
|
| 3350 | + fwrite($fp, 'Connection: close' . "\r\n\r\n"); |
|
| 3351 | + } |
|
| 3352 | + } else |
|
| 3174 | 3353 | { |
| 3175 | 3354 | fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n"); |
| 3176 | 3355 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
| 3177 | 3356 | fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n"); |
| 3178 | - if ($keep_alive) |
|
| 3179 | - fwrite($fp, 'Connection: Keep-Alive' . "\r\n"); |
|
| 3180 | - else |
|
| 3181 | - fwrite($fp, 'Connection: close' . "\r\n"); |
|
| 3357 | + if ($keep_alive) { |
|
| 3358 | + fwrite($fp, 'Connection: Keep-Alive' . "\r\n"); |
|
| 3359 | + } else { |
|
| 3360 | + fwrite($fp, 'Connection: close' . "\r\n"); |
|
| 3361 | + } |
|
| 3182 | 3362 | fwrite($fp, 'Content-Type: application/x-www-form-urlencoded' . "\r\n"); |
| 3183 | 3363 | fwrite($fp, 'Content-Length: ' . strlen($post_data) . "\r\n\r\n"); |
| 3184 | 3364 | fwrite($fp, $post_data); |
@@ -3191,30 +3371,33 @@ discard block |
||
| 3191 | 3371 | { |
| 3192 | 3372 | $header = ''; |
| 3193 | 3373 | $location = ''; |
| 3194 | - while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
|
| 3195 | - if (strpos($header, 'Location:') !== false) |
|
| 3374 | + while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') { |
|
| 3375 | + if (strpos($header, 'Location:') !== false) |
|
| 3196 | 3376 | $location = trim(substr($header, strpos($header, ':') + 1)); |
| 3377 | + } |
|
| 3197 | 3378 | |
| 3198 | - if (empty($location)) |
|
| 3199 | - return false; |
|
| 3200 | - else |
|
| 3379 | + if (empty($location)) { |
|
| 3380 | + return false; |
|
| 3381 | + } else |
|
| 3201 | 3382 | { |
| 3202 | - if (!$keep_alive) |
|
| 3203 | - fclose($fp); |
|
| 3383 | + if (!$keep_alive) { |
|
| 3384 | + fclose($fp); |
|
| 3385 | + } |
|
| 3204 | 3386 | return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1); |
| 3205 | 3387 | } |
| 3206 | 3388 | } |
| 3207 | 3389 | |
| 3208 | 3390 | // Make sure we get a 200 OK. |
| 3209 | - elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) |
|
| 3210 | - return false; |
|
| 3391 | + elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) { |
|
| 3392 | + return false; |
|
| 3393 | + } |
|
| 3211 | 3394 | |
| 3212 | 3395 | // Skip the headers... |
| 3213 | 3396 | while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
| 3214 | 3397 | { |
| 3215 | - if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) |
|
| 3216 | - $content_length = $match[1]; |
|
| 3217 | - elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
| 3398 | + if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) { |
|
| 3399 | + $content_length = $match[1]; |
|
| 3400 | + } elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
| 3218 | 3401 | { |
| 3219 | 3402 | $keep_alive_dom = null; |
| 3220 | 3403 | $keep_alive = false; |
@@ -3226,19 +3409,20 @@ discard block |
||
| 3226 | 3409 | $data = ''; |
| 3227 | 3410 | if (isset($content_length)) |
| 3228 | 3411 | { |
| 3229 | - while (!feof($fp) && strlen($data) < $content_length) |
|
| 3230 | - $data .= fread($fp, $content_length - strlen($data)); |
|
| 3231 | - } |
|
| 3232 | - else |
|
| 3412 | + while (!feof($fp) && strlen($data) < $content_length) { |
|
| 3413 | + $data .= fread($fp, $content_length - strlen($data)); |
|
| 3414 | + } |
|
| 3415 | + } else |
|
| 3233 | 3416 | { |
| 3234 | - while (!feof($fp)) |
|
| 3235 | - $data .= fread($fp, 4096); |
|
| 3417 | + while (!feof($fp)) { |
|
| 3418 | + $data .= fread($fp, 4096); |
|
| 3419 | + } |
|
| 3236 | 3420 | } |
| 3237 | 3421 | |
| 3238 | - if (!$keep_alive) |
|
| 3239 | - fclose($fp); |
|
| 3240 | - } |
|
| 3241 | - else |
|
| 3422 | + if (!$keep_alive) { |
|
| 3423 | + fclose($fp); |
|
| 3424 | + } |
|
| 3425 | + } else |
|
| 3242 | 3426 | { |
| 3243 | 3427 | // Umm, this shouldn't happen? |
| 3244 | 3428 | trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE); |
@@ -1451,7 +1451,7 @@ discard block |
||
| 1451 | 1451 | * @param resource $socket Socket to send on |
| 1452 | 1452 | * @param string $code The expected response code |
| 1453 | 1453 | * @param string $response The response from the SMTP server |
| 1454 | - * @return bool Whether it responded as such. |
|
| 1454 | + * @return string|boolean Whether it responded as such. |
|
| 1455 | 1455 | */ |
| 1456 | 1456 | function server_parse($message, $socket, $code, &$response = null) |
| 1457 | 1457 | { |
@@ -2265,7 +2265,7 @@ discard block |
||
| 2265 | 2265 | * @param array $msgs Array of message ids |
| 2266 | 2266 | * @param bool $approve Whether to approve the posts (if false, posts are unapproved) |
| 2267 | 2267 | * @param bool $notify Whether to notify users |
| 2268 | - * @return bool Whether the operation was successful |
|
| 2268 | + * @return null|boolean Whether the operation was successful |
|
| 2269 | 2269 | */ |
| 2270 | 2270 | function approvePosts($msgs, $approve = true, $notify = true) |
| 2271 | 2271 | { |
@@ -2518,7 +2518,7 @@ discard block |
||
| 2518 | 2518 | * |
| 2519 | 2519 | * @param array $topics Array of topic ids |
| 2520 | 2520 | * @param bool $approve Whether to approve the topics. If false, unapproves them instead |
| 2521 | - * @return bool Whether the operation was successful |
|
| 2521 | + * @return null|boolean Whether the operation was successful |
|
| 2522 | 2522 | */ |
| 2523 | 2523 | function approveTopics($topics, $approve = true) |
| 2524 | 2524 | { |
@@ -2908,7 +2908,7 @@ discard block |
||
| 2908 | 2908 | * |
| 2909 | 2909 | * @param resource $dict An enchant or pspell dictionary resource set up by {@link spell_init()} |
| 2910 | 2910 | * @param string $word A word to check the spelling of |
| 2911 | - * @return bool Whether or not the specified word is spelled properly |
|
| 2911 | + * @return boolean|null Whether or not the specified word is spelled properly |
|
| 2912 | 2912 | */ |
| 2913 | 2913 | function spell_check($dict, $word) |
| 2914 | 2914 | { |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 3 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * Takes a message and parses it, returning nothing. |
@@ -46,17 +47,19 @@ discard block |
||
| 46 | 47 | $message = preg_replace('~\.{100,}~', '...', $message); |
| 47 | 48 | |
| 48 | 49 | // Trim off trailing quotes - these often happen by accident. |
| 49 | - while (substr($message, -7) == '[quote]') |
|
| 50 | - $message = substr($message, 0, -7); |
|
| 51 | - while (substr($message, 0, 8) == '[/quote]') |
|
| 52 | - $message = substr($message, 8); |
|
| 50 | + while (substr($message, -7) == '[quote]') { |
|
| 51 | + $message = substr($message, 0, -7); |
|
| 52 | + } |
|
| 53 | + while (substr($message, 0, 8) == '[/quote]') { |
|
| 54 | + $message = substr($message, 8); |
|
| 55 | + } |
|
| 53 | 56 | |
| 54 | 57 | // Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed. |
| 55 | 58 | $in_tag = false; |
| 56 | 59 | $had_tag = false; |
| 57 | 60 | $codeopen = 0; |
| 58 | - if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) |
|
| 59 | - foreach ($matches[0] as $index => $dummy) |
|
| 61 | + if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) { |
|
| 62 | + foreach ($matches[0] as $index => $dummy) |
|
| 60 | 63 | { |
| 61 | 64 | // Closing? |
| 62 | 65 | if (!empty($matches[2][$index])) |
@@ -64,6 +67,7 @@ discard block |
||
| 64 | 67 | // If it's closing and we're not in a tag we need to open it... |
| 65 | 68 | if (!$in_tag) |
| 66 | 69 | $codeopen = true; |
| 70 | + } |
|
| 67 | 71 | // Either way we ain't in one any more. |
| 68 | 72 | $in_tag = false; |
| 69 | 73 | } |
@@ -72,17 +76,20 @@ discard block |
||
| 72 | 76 | { |
| 73 | 77 | $had_tag = true; |
| 74 | 78 | // If we're in a tag don't do nought! |
| 75 | - if (!$in_tag) |
|
| 76 | - $in_tag = true; |
|
| 79 | + if (!$in_tag) { |
|
| 80 | + $in_tag = true; |
|
| 81 | + } |
|
| 77 | 82 | } |
| 78 | 83 | } |
| 79 | 84 | |
| 80 | 85 | // If we have an open tag, close it. |
| 81 | - if ($in_tag) |
|
| 82 | - $message .= '[/code]'; |
|
| 86 | + if ($in_tag) { |
|
| 87 | + $message .= '[/code]'; |
|
| 88 | + } |
|
| 83 | 89 | // Open any ones that need to be open, only if we've never had a tag. |
| 84 | - if ($codeopen && !$had_tag) |
|
| 85 | - $message = '[code]' . $message; |
|
| 90 | + if ($codeopen && !$had_tag) { |
|
| 91 | + $message = '[code]' . $message; |
|
| 92 | + } |
|
| 86 | 93 | |
| 87 | 94 | // Now that we've fixed all the code tags, let's fix the img and url tags... |
| 88 | 95 | $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE); |
@@ -108,23 +115,26 @@ discard block |
||
| 108 | 115 | fixTags($message); |
| 109 | 116 | |
| 110 | 117 | // Replace /me.+?\n with [me=name]dsf[/me]\n. |
| 111 | - if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) |
|
| 112 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
| 113 | - else |
|
| 114 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
| 118 | + if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) { |
|
| 119 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
| 120 | + } else { |
|
| 121 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
| 122 | + } |
|
| 115 | 123 | |
| 116 | 124 | if (!$previewing && strpos($message, '[html]') !== false) |
| 117 | 125 | { |
| 118 | - if (allowedTo('admin_forum')) |
|
| 119 | - $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) { |
|
| 126 | + if (allowedTo('admin_forum')) { |
|
| 127 | + $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) { |
|
| 120 | 128 | return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => ' ', ' ' => '  ', '[' => '[', ']' => ']')) . '[/html]'; |
| 129 | + } |
|
| 121 | 130 | }, $message); |
| 122 | 131 | |
| 123 | 132 | // We should edit them out, or else if an admin edits the message they will get shown... |
| 124 | 133 | else |
| 125 | 134 | { |
| 126 | - while (strpos($message, '[html]') !== false) |
|
| 127 | - $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
| 135 | + while (strpos($message, '[html]') !== false) { |
|
| 136 | + $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
| 137 | + } |
|
| 128 | 138 | } |
| 129 | 139 | } |
| 130 | 140 | |
@@ -146,10 +156,12 @@ discard block |
||
| 146 | 156 | |
| 147 | 157 | $list_open = substr_count($message, '[list]') + substr_count($message, '[list '); |
| 148 | 158 | $list_close = substr_count($message, '[/list]'); |
| 149 | - if ($list_close - $list_open > 0) |
|
| 150 | - $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
| 151 | - if ($list_open - $list_close > 0) |
|
| 152 | - $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
| 159 | + if ($list_close - $list_open > 0) { |
|
| 160 | + $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
| 161 | + } |
|
| 162 | + if ($list_open - $list_close > 0) { |
|
| 163 | + $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
| 164 | + } |
|
| 153 | 165 | |
| 154 | 166 | $mistake_fixes = array( |
| 155 | 167 | // Find [table]s not followed by [tr]. |
@@ -198,8 +210,9 @@ discard block |
||
| 198 | 210 | ); |
| 199 | 211 | |
| 200 | 212 | // Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.) |
| 201 | - for ($j = 0; $j < 3; $j++) |
|
| 202 | - $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
| 213 | + for ($j = 0; $j < 3; $j++) { |
|
| 214 | + $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
| 215 | + } |
|
| 203 | 216 | |
| 204 | 217 | // Remove empty bbc from the sections outside the code tags |
| 205 | 218 | $allowedEmpty = array( |
@@ -209,24 +222,28 @@ discard block |
||
| 209 | 222 | |
| 210 | 223 | require_once($sourcedir . '/Subs.php'); |
| 211 | 224 | |
| 212 | - foreach (($codes = parse_bbc(false)) as $code) |
|
| 213 | - if (!in_array($code['tag'], $allowedEmpty)) |
|
| 225 | + foreach (($codes = parse_bbc(false)) as $code) { |
|
| 226 | + if (!in_array($code['tag'], $allowedEmpty)) |
|
| 214 | 227 | $alltags[] = $code['tag']; |
| 228 | + } |
|
| 215 | 229 | |
| 216 | 230 | $alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b'; |
| 217 | 231 | |
| 218 | - while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) |
|
| 219 | - $message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message); |
|
| 232 | + while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) { |
|
| 233 | + $message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message); |
|
| 234 | + } |
|
| 220 | 235 | |
| 221 | 236 | // Restore code blocks |
| 222 | - if (!empty($code_tags)) |
|
| 223 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 237 | + if (!empty($code_tags)) { |
|
| 238 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 239 | + } |
|
| 224 | 240 | |
| 225 | 241 | // Restore white space entities |
| 226 | - if (!$previewing) |
|
| 227 | - $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 228 | - else |
|
| 229 | - $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 242 | + if (!$previewing) { |
|
| 243 | + $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 244 | + } else { |
|
| 245 | + $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 246 | + } |
|
| 230 | 247 | |
| 231 | 248 | // Now let's quickly clean up things that will slow our parser (which are common in posted code.) |
| 232 | 249 | $message = strtr($message, array('[]' => '[]', '['' => '['')); |
@@ -269,8 +286,9 @@ discard block |
||
| 269 | 286 | return "[time]" . timeformat("$m[1]", false) . "[/time]"; |
| 270 | 287 | }, $message); |
| 271 | 288 | |
| 272 | - if (!empty($code_tags)) |
|
| 273 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 289 | + if (!empty($code_tags)) { |
|
| 290 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 291 | + } |
|
| 274 | 292 | |
| 275 | 293 | // Change breaks back to \n's and &nsbp; back to spaces. |
| 276 | 294 | return preg_replace('~<br( /)?' . '>~', "\n", str_replace(' ', ' ', $message)); |
@@ -351,8 +369,9 @@ discard block |
||
| 351 | 369 | ); |
| 352 | 370 | |
| 353 | 371 | // Fix each type of tag. |
| 354 | - foreach ($fixArray as $param) |
|
| 355 | - fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
| 372 | + foreach ($fixArray as $param) { |
|
| 373 | + fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
| 374 | + } |
|
| 356 | 375 | |
| 357 | 376 | // Now fix possible security problems with images loading links automatically... |
| 358 | 377 | $message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m) |
@@ -388,16 +407,19 @@ discard block |
||
| 388 | 407 | $desired_height = $height; |
| 389 | 408 | } |
| 390 | 409 | // Scale it to the width... |
| 391 | - elseif (empty($desired_width) && !empty($height)) |
|
| 392 | - $desired_width = (int) (($desired_height * $width) / $height); |
|
| 410 | + elseif (empty($desired_width) && !empty($height)) { |
|
| 411 | + $desired_width = (int) (($desired_height * $width) / $height); |
|
| 412 | + } |
|
| 393 | 413 | // Scale if to the height. |
| 394 | - elseif (!empty($width)) |
|
| 395 | - $desired_height = (int) (($desired_width * $height) / $width); |
|
| 414 | + elseif (!empty($width)) { |
|
| 415 | + $desired_height = (int) (($desired_width * $height) / $width); |
|
| 416 | + } |
|
| 396 | 417 | } |
| 397 | 418 | |
| 398 | 419 | // If the width and height are fine, just continue along... |
| 399 | - if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) |
|
| 400 | - continue; |
|
| 420 | + if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) { |
|
| 421 | + continue; |
|
| 422 | + } |
|
| 401 | 423 | |
| 402 | 424 | // Too bad, it's too wide. Make it as wide as the maximum. |
| 403 | 425 | if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width'])) |
@@ -417,8 +439,9 @@ discard block |
||
| 417 | 439 | } |
| 418 | 440 | |
| 419 | 441 | // If any img tags were actually changed... |
| 420 | - if (!empty($replaces)) |
|
| 421 | - $message = strtr($message, $replaces); |
|
| 442 | + if (!empty($replaces)) { |
|
| 443 | + $message = strtr($message, $replaces); |
|
| 444 | + } |
|
| 422 | 445 | } |
| 423 | 446 | } |
| 424 | 447 | |
@@ -437,10 +460,11 @@ discard block |
||
| 437 | 460 | { |
| 438 | 461 | global $boardurl, $scripturl; |
| 439 | 462 | |
| 440 | - if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) |
|
| 441 | - $domain_url = $match[1]; |
|
| 442 | - else |
|
| 443 | - $domain_url = $boardurl . '/'; |
|
| 463 | + if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) { |
|
| 464 | + $domain_url = $match[1]; |
|
| 465 | + } else { |
|
| 466 | + $domain_url = $boardurl . '/'; |
|
| 467 | + } |
|
| 444 | 468 | |
| 445 | 469 | $replaces = array(); |
| 446 | 470 | |
@@ -448,11 +472,11 @@ discard block |
||
| 448 | 472 | { |
| 449 | 473 | $quoted = preg_match('~\[(' . $myTag . ')="~', $message); |
| 450 | 474 | preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '"(.*?)"' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
| 475 | + } elseif ($hasEqualSign) { |
|
| 476 | + preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
| 477 | + } else { |
|
| 478 | + preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
| 451 | 479 | } |
| 452 | - elseif ($hasEqualSign) |
|
| 453 | - preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
| 454 | - else |
|
| 455 | - preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
| 456 | 480 | |
| 457 | 481 | foreach ($matches[0] as $k => $dummy) |
| 458 | 482 | { |
@@ -465,49 +489,53 @@ discard block |
||
| 465 | 489 | foreach ($protocols as $protocol) |
| 466 | 490 | { |
| 467 | 491 | $found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0; |
| 468 | - if ($found) |
|
| 469 | - break; |
|
| 492 | + if ($found) { |
|
| 493 | + break; |
|
| 494 | + } |
|
| 470 | 495 | } |
| 471 | 496 | |
| 472 | 497 | if (!$found && $protocols[0] == 'http') |
| 473 | 498 | { |
| 474 | - if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') |
|
| 475 | - $replace = $domain_url . $replace; |
|
| 476 | - elseif (substr($replace, 0, 1) == '?') |
|
| 477 | - $replace = $scripturl . $replace; |
|
| 478 | - elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
| 499 | + if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') { |
|
| 500 | + $replace = $domain_url . $replace; |
|
| 501 | + } elseif (substr($replace, 0, 1) == '?') { |
|
| 502 | + $replace = $scripturl . $replace; |
|
| 503 | + } elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
| 479 | 504 | { |
| 480 | 505 | $replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1)); |
| 481 | 506 | $this_tag = 'iurl'; |
| 482 | 507 | $this_close = 'iurl'; |
| 508 | + } elseif (substr($replace, 0, 2) != '//') { |
|
| 509 | + $replace = $protocols[0] . '://' . $replace; |
|
| 483 | 510 | } |
| 484 | - elseif (substr($replace, 0, 2) != '//') |
|
| 485 | - $replace = $protocols[0] . '://' . $replace; |
|
| 486 | - } |
|
| 487 | - elseif (!$found && $protocols[0] == 'ftp') |
|
| 488 | - $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
| 489 | - elseif (!$found) |
|
| 490 | - $replace = $protocols[0] . '://' . $replace; |
|
| 491 | - |
|
| 492 | - if ($hasEqualSign && $embeddedUrl) |
|
| 493 | - $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
| 494 | - elseif ($hasEqualSign) |
|
| 495 | - $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
| 496 | - elseif ($embeddedUrl) |
|
| 497 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
| 498 | - else |
|
| 499 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
| 511 | + } elseif (!$found && $protocols[0] == 'ftp') { |
|
| 512 | + $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
| 513 | + } elseif (!$found) { |
|
| 514 | + $replace = $protocols[0] . '://' . $replace; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + if ($hasEqualSign && $embeddedUrl) { |
|
| 518 | + $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
| 519 | + } elseif ($hasEqualSign) { |
|
| 520 | + $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
| 521 | + } elseif ($embeddedUrl) { |
|
| 522 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
| 523 | + } else { |
|
| 524 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
| 525 | + } |
|
| 500 | 526 | } |
| 501 | 527 | |
| 502 | 528 | foreach ($replaces as $k => $v) |
| 503 | 529 | { |
| 504 | - if ($k == $v) |
|
| 505 | - unset($replaces[$k]); |
|
| 530 | + if ($k == $v) { |
|
| 531 | + unset($replaces[$k]); |
|
| 532 | + } |
|
| 506 | 533 | } |
| 507 | 534 | |
| 508 | - if (!empty($replaces)) |
|
| 509 | - $message = strtr($message, $replaces); |
|
| 510 | -} |
|
| 535 | + if (!empty($replaces)) { |
|
| 536 | + $message = strtr($message, $replaces); |
|
| 537 | + } |
|
| 538 | + } |
|
| 511 | 539 | |
| 512 | 540 | /** |
| 513 | 541 | * This function sends an email to the specified recipient(s). |
@@ -551,8 +579,9 @@ discard block |
||
| 551 | 579 | } |
| 552 | 580 | |
| 553 | 581 | // Nothing left? Nothing else to do |
| 554 | - if (empty($to_array)) |
|
| 555 | - return true; |
|
| 582 | + if (empty($to_array)) { |
|
| 583 | + return true; |
|
| 584 | + } |
|
| 556 | 585 | |
| 557 | 586 | // Once upon a time, Hotmail could not interpret non-ASCII mails. |
| 558 | 587 | // In honour of those days, it's still called the 'hotmail fix'. |
@@ -569,15 +598,17 @@ discard block |
||
| 569 | 598 | } |
| 570 | 599 | |
| 571 | 600 | // Call this function recursively for the hotmail addresses. |
| 572 | - if (!empty($hotmail_to)) |
|
| 573 | - $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
| 601 | + if (!empty($hotmail_to)) { |
|
| 602 | + $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
| 603 | + } |
|
| 574 | 604 | |
| 575 | 605 | // The remaining addresses no longer need the fix. |
| 576 | 606 | $hotmail_fix = false; |
| 577 | 607 | |
| 578 | 608 | // No other addresses left? Return instantly. |
| 579 | - if (empty($to_array)) |
|
| 580 | - return $mail_result; |
|
| 609 | + if (empty($to_array)) { |
|
| 610 | + return $mail_result; |
|
| 611 | + } |
|
| 581 | 612 | } |
| 582 | 613 | |
| 583 | 614 | // Get rid of entities. |
@@ -602,13 +633,15 @@ discard block |
||
| 602 | 633 | $headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break; |
| 603 | 634 | $headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break; |
| 604 | 635 | |
| 605 | - if ($message_id !== null && empty($modSettings['mail_no_message_id'])) |
|
| 606 | - $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
| 636 | + if ($message_id !== null && empty($modSettings['mail_no_message_id'])) { |
|
| 637 | + $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
| 638 | + } |
|
| 607 | 639 | $headers .= 'X-Mailer: SMF' . $line_break; |
| 608 | 640 | |
| 609 | 641 | // Pass this to the integration before we start modifying the output -- it'll make it easier later. |
| 610 | - if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) |
|
| 611 | - return false; |
|
| 642 | + if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) { |
|
| 643 | + return false; |
|
| 644 | + } |
|
| 612 | 645 | |
| 613 | 646 | // Save the original message... |
| 614 | 647 | $orig_message = $message; |
@@ -657,17 +690,19 @@ discard block |
||
| 657 | 690 | } |
| 658 | 691 | |
| 659 | 692 | // Are we using the mail queue, if so this is where we butt in... |
| 660 | - if ($priority != 0) |
|
| 661 | - return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
| 693 | + if ($priority != 0) { |
|
| 694 | + return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
| 695 | + } |
|
| 662 | 696 | |
| 663 | 697 | // If it's a priority mail, send it now - note though that this should NOT be used for sending many at once. |
| 664 | 698 | elseif (!empty($modSettings['mail_limit'])) |
| 665 | 699 | { |
| 666 | 700 | list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']); |
| 667 | - if (empty($mails_this_minute) || time() > $last_mail_time + 60) |
|
| 668 | - $new_queue_stat = time() . '|' . 1; |
|
| 669 | - else |
|
| 670 | - $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
| 701 | + if (empty($mails_this_minute) || time() > $last_mail_time + 60) { |
|
| 702 | + $new_queue_stat = time() . '|' . 1; |
|
| 703 | + } else { |
|
| 704 | + $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
| 705 | + } |
|
| 671 | 706 | |
| 672 | 707 | updateSettings(array('mail_recent' => $new_queue_stat)); |
| 673 | 708 | } |
@@ -692,12 +727,13 @@ discard block |
||
| 692 | 727 | |
| 693 | 728 | // Wait, wait, I'm still sending here! |
| 694 | 729 | @set_time_limit(300); |
| 695 | - if (function_exists('apache_reset_timeout')) |
|
| 696 | - @apache_reset_timeout(); |
|
| 730 | + if (function_exists('apache_reset_timeout')) { |
|
| 731 | + @apache_reset_timeout(); |
|
| 732 | + } |
|
| 697 | 733 | } |
| 734 | + } else { |
|
| 735 | + $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
| 698 | 736 | } |
| 699 | - else |
|
| 700 | - $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
| 701 | 737 | |
| 702 | 738 | // Everything go smoothly? |
| 703 | 739 | return $mail_result; |
@@ -723,8 +759,9 @@ discard block |
||
| 723 | 759 | static $cur_insert = array(); |
| 724 | 760 | static $cur_insert_len = 0; |
| 725 | 761 | |
| 726 | - if ($cur_insert_len == 0) |
|
| 727 | - $cur_insert = array(); |
|
| 762 | + if ($cur_insert_len == 0) { |
|
| 763 | + $cur_insert = array(); |
|
| 764 | + } |
|
| 728 | 765 | |
| 729 | 766 | // If we're flushing, make the final inserts - also if we're near the MySQL length limit! |
| 730 | 767 | if (($flush || $cur_insert_len > 800000) && !empty($cur_insert)) |
@@ -799,8 +836,9 @@ discard block |
||
| 799 | 836 | } |
| 800 | 837 | |
| 801 | 838 | // If they are using SSI there is a good chance obExit will never be called. So lets be nice and flush it for them. |
| 802 | - if (SMF === 'SSI' || SMF === 'BACKGROUND') |
|
| 803 | - return AddMailQueue(true); |
|
| 839 | + if (SMF === 'SSI' || SMF === 'BACKGROUND') { |
|
| 840 | + return AddMailQueue(true); |
|
| 841 | + } |
|
| 804 | 842 | |
| 805 | 843 | return true; |
| 806 | 844 | } |
@@ -831,23 +869,26 @@ discard block |
||
| 831 | 869 | 'sent' => array() |
| 832 | 870 | ); |
| 833 | 871 | |
| 834 | - if ($from === null) |
|
| 835 | - $from = array( |
|
| 872 | + if ($from === null) { |
|
| 873 | + $from = array( |
|
| 836 | 874 | 'id' => $user_info['id'], |
| 837 | 875 | 'name' => $user_info['name'], |
| 838 | 876 | 'username' => $user_info['username'] |
| 839 | 877 | ); |
| 878 | + } |
|
| 840 | 879 | |
| 841 | 880 | // This is the one that will go in their inbox. |
| 842 | 881 | $htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES); |
| 843 | 882 | preparsecode($htmlmessage); |
| 844 | 883 | $htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => '')); |
| 845 | - if ($smcFunc['strlen']($htmlsubject) > 100) |
|
| 846 | - $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
| 884 | + if ($smcFunc['strlen']($htmlsubject) > 100) { |
|
| 885 | + $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
| 886 | + } |
|
| 847 | 887 | |
| 848 | 888 | // Make sure is an array |
| 849 | - if (!is_array($recipients)) |
|
| 850 | - $recipients = array($recipients); |
|
| 889 | + if (!is_array($recipients)) { |
|
| 890 | + $recipients = array($recipients); |
|
| 891 | + } |
|
| 851 | 892 | |
| 852 | 893 | // Integrated PMs |
| 853 | 894 | call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message)); |
@@ -875,21 +916,23 @@ discard block |
||
| 875 | 916 | 'usernames' => array_keys($usernames), |
| 876 | 917 | ) |
| 877 | 918 | ); |
| 878 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 879 | - if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
| 919 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 920 | + if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
| 880 | 921 | $usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member']; |
| 922 | + } |
|
| 881 | 923 | $smcFunc['db_free_result']($request); |
| 882 | 924 | |
| 883 | 925 | // Replace the usernames with IDs. Drop usernames that couldn't be found. |
| 884 | - foreach ($recipients as $rec_type => $rec) |
|
| 885 | - foreach ($rec as $id => $member) |
|
| 926 | + foreach ($recipients as $rec_type => $rec) { |
|
| 927 | + foreach ($rec as $id => $member) |
|
| 886 | 928 | { |
| 887 | 929 | if (is_numeric($recipients[$rec_type][$id])) |
| 888 | 930 | continue; |
| 931 | + } |
|
| 889 | 932 | |
| 890 | - if (!empty($usernames[$member])) |
|
| 891 | - $recipients[$rec_type][$id] = $usernames[$member]; |
|
| 892 | - else |
|
| 933 | + if (!empty($usernames[$member])) { |
|
| 934 | + $recipients[$rec_type][$id] = $usernames[$member]; |
|
| 935 | + } else |
|
| 893 | 936 | { |
| 894 | 937 | $log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]); |
| 895 | 938 | unset($recipients[$rec_type][$id]); |
@@ -927,8 +970,9 @@ discard block |
||
| 927 | 970 | $delete = false; |
| 928 | 971 | foreach ($criteria as $criterium) |
| 929 | 972 | { |
| 930 | - if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) |
|
| 931 | - $delete = true; |
|
| 973 | + if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) { |
|
| 974 | + $delete = true; |
|
| 975 | + } |
|
| 932 | 976 | // If we're adding and one criteria don't match then we stop! |
| 933 | 977 | elseif (!$row['is_or']) |
| 934 | 978 | { |
@@ -936,8 +980,9 @@ discard block |
||
| 936 | 980 | break; |
| 937 | 981 | } |
| 938 | 982 | } |
| 939 | - if ($delete) |
|
| 940 | - $deletes[$row['id_member']] = 1; |
|
| 983 | + if ($delete) { |
|
| 984 | + $deletes[$row['id_member']] = 1; |
|
| 985 | + } |
|
| 941 | 986 | } |
| 942 | 987 | $smcFunc['db_free_result']($request); |
| 943 | 988 | |
@@ -952,8 +997,9 @@ discard block |
||
| 952 | 997 | array( |
| 953 | 998 | ) |
| 954 | 999 | ); |
| 955 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 956 | - $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
| 1000 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1001 | + $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
| 1002 | + } |
|
| 957 | 1003 | $smcFunc['db_free_result']($request); |
| 958 | 1004 | } |
| 959 | 1005 | |
@@ -961,8 +1007,9 @@ discard block |
||
| 961 | 1007 | require_once($sourcedir . '/Subs-Members.php'); |
| 962 | 1008 | $pmReadGroups = groupsAllowedTo('pm_read'); |
| 963 | 1009 | |
| 964 | - if (empty($modSettings['permission_enable_deny'])) |
|
| 965 | - $pmReadGroups['denied'] = array(); |
|
| 1010 | + if (empty($modSettings['permission_enable_deny'])) { |
|
| 1011 | + $pmReadGroups['denied'] = array(); |
|
| 1012 | + } |
|
| 966 | 1013 | |
| 967 | 1014 | // Load their alert preferences |
| 968 | 1015 | require_once($sourcedir . '/Subs-Notify.php'); |
@@ -994,8 +1041,9 @@ discard block |
||
| 994 | 1041 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 995 | 1042 | { |
| 996 | 1043 | // Don't do anything for members to be deleted! |
| 997 | - if (isset($deletes[$row['id_member']])) |
|
| 998 | - continue; |
|
| 1044 | + if (isset($deletes[$row['id_member']])) { |
|
| 1045 | + continue; |
|
| 1046 | + } |
|
| 999 | 1047 | |
| 1000 | 1048 | // Load the preferences for this member (if any) |
| 1001 | 1049 | $prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array(); |
@@ -1016,8 +1064,9 @@ discard block |
||
| 1016 | 1064 | { |
| 1017 | 1065 | foreach ($groups as $id) |
| 1018 | 1066 | { |
| 1019 | - if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) |
|
| 1020 | - $message_limit = $message_limit_cache[$id]; |
|
| 1067 | + if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) { |
|
| 1068 | + $message_limit = $message_limit_cache[$id]; |
|
| 1069 | + } |
|
| 1021 | 1070 | } |
| 1022 | 1071 | |
| 1023 | 1072 | if ($message_limit > 0 && $message_limit <= $row['instant_messages']) |
@@ -1065,8 +1114,9 @@ discard block |
||
| 1065 | 1114 | $smcFunc['db_free_result']($request); |
| 1066 | 1115 | |
| 1067 | 1116 | // Only 'send' the message if there are any recipients left. |
| 1068 | - if (empty($all_to)) |
|
| 1069 | - return $log; |
|
| 1117 | + if (empty($all_to)) { |
|
| 1118 | + return $log; |
|
| 1119 | + } |
|
| 1070 | 1120 | |
| 1071 | 1121 | // Insert the message itself and then grab the last insert id. |
| 1072 | 1122 | $id_pm = $smcFunc['db_insert']('', |
@@ -1087,8 +1137,8 @@ discard block |
||
| 1087 | 1137 | if (!empty($id_pm)) |
| 1088 | 1138 | { |
| 1089 | 1139 | // If this is new we need to set it part of it's own conversation. |
| 1090 | - if (empty($pm_head)) |
|
| 1091 | - $smcFunc['db_query']('', ' |
|
| 1140 | + if (empty($pm_head)) { |
|
| 1141 | + $smcFunc['db_query']('', ' |
|
| 1092 | 1142 | UPDATE {db_prefix}personal_messages |
| 1093 | 1143 | SET id_pm_head = {int:id_pm_head} |
| 1094 | 1144 | WHERE id_pm = {int:id_pm_head}', |
@@ -1096,6 +1146,7 @@ discard block |
||
| 1096 | 1146 | 'id_pm_head' => $id_pm, |
| 1097 | 1147 | ) |
| 1098 | 1148 | ); |
| 1149 | + } |
|
| 1099 | 1150 | |
| 1100 | 1151 | // Some people think manually deleting personal_messages is fun... it's not. We protect against it though :) |
| 1101 | 1152 | $smcFunc['db_query']('', ' |
@@ -1111,8 +1162,9 @@ discard block |
||
| 1111 | 1162 | foreach ($all_to as $to) |
| 1112 | 1163 | { |
| 1113 | 1164 | $insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1); |
| 1114 | - if (!in_array($to, $recipients['bcc'])) |
|
| 1115 | - $to_list[] = $to; |
|
| 1165 | + if (!in_array($to, $recipients['bcc'])) { |
|
| 1166 | + $to_list[] = $to; |
|
| 1167 | + } |
|
| 1116 | 1168 | } |
| 1117 | 1169 | |
| 1118 | 1170 | $smcFunc['db_insert']('insert', |
@@ -1130,9 +1182,9 @@ discard block |
||
| 1130 | 1182 | { |
| 1131 | 1183 | censorText($message); |
| 1132 | 1184 | $message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '[' => '[', ']' => ']'))))); |
| 1185 | + } else { |
|
| 1186 | + $message = ''; |
|
| 1133 | 1187 | } |
| 1134 | - else |
|
| 1135 | - $message = ''; |
|
| 1136 | 1188 | |
| 1137 | 1189 | $to_names = array(); |
| 1138 | 1190 | if (count($to_list) > 1) |
@@ -1145,8 +1197,9 @@ discard block |
||
| 1145 | 1197 | 'to_members' => $to_list, |
| 1146 | 1198 | ) |
| 1147 | 1199 | ); |
| 1148 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1149 | - $to_names[] = un_htmlspecialchars($row['real_name']); |
|
| 1200 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1201 | + $to_names[] = un_htmlspecialchars($row['real_name']); |
|
| 1202 | + } |
|
| 1150 | 1203 | $smcFunc['db_free_result']($request); |
| 1151 | 1204 | } |
| 1152 | 1205 | $replacements = array( |
@@ -1174,11 +1227,13 @@ discard block |
||
| 1174 | 1227 | loadLanguage('index+PersonalMessage'); |
| 1175 | 1228 | |
| 1176 | 1229 | // Add one to their unread and read message counts. |
| 1177 | - foreach ($all_to as $k => $id) |
|
| 1178 | - if (isset($deletes[$id])) |
|
| 1230 | + foreach ($all_to as $k => $id) { |
|
| 1231 | + if (isset($deletes[$id])) |
|
| 1179 | 1232 | unset($all_to[$k]); |
| 1180 | - if (!empty($all_to)) |
|
| 1181 | - updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
| 1233 | + } |
|
| 1234 | + if (!empty($all_to)) { |
|
| 1235 | + updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
| 1236 | + } |
|
| 1182 | 1237 | |
| 1183 | 1238 | return $log; |
| 1184 | 1239 | } |
@@ -1208,15 +1263,17 @@ discard block |
||
| 1208 | 1263 | // Let's, for now, assume there are only 'ish characters. |
| 1209 | 1264 | $simple = true; |
| 1210 | 1265 | |
| 1211 | - foreach ($matches[1] as $entity) |
|
| 1212 | - if ($entity > 128) |
|
| 1266 | + foreach ($matches[1] as $entity) { |
|
| 1267 | + if ($entity > 128) |
|
| 1213 | 1268 | $simple = false; |
| 1269 | + } |
|
| 1214 | 1270 | unset($matches); |
| 1215 | 1271 | |
| 1216 | - if ($simple) |
|
| 1217 | - $string = preg_replace_callback('~&#(\d{3,8});~', function($m) |
|
| 1272 | + if ($simple) { |
|
| 1273 | + $string = preg_replace_callback('~&#(\d{3,8});~', function($m) |
|
| 1218 | 1274 | { |
| 1219 | 1275 | return chr("$m[1]"); |
| 1276 | + } |
|
| 1220 | 1277 | }, $string); |
| 1221 | 1278 | else |
| 1222 | 1279 | { |
@@ -1224,8 +1281,9 @@ discard block |
||
| 1224 | 1281 | if (!$context['utf8'] && function_exists('iconv')) |
| 1225 | 1282 | { |
| 1226 | 1283 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
| 1227 | - if ($newstring) |
|
| 1228 | - $string = $newstring; |
|
| 1284 | + if ($newstring) { |
|
| 1285 | + $string = $newstring; |
|
| 1286 | + } |
|
| 1229 | 1287 | } |
| 1230 | 1288 | |
| 1231 | 1289 | $string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string); |
@@ -1241,23 +1299,25 @@ discard block |
||
| 1241 | 1299 | if (!$context['utf8'] && function_exists('iconv')) |
| 1242 | 1300 | { |
| 1243 | 1301 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
| 1244 | - if ($newstring) |
|
| 1245 | - $string = $newstring; |
|
| 1302 | + if ($newstring) { |
|
| 1303 | + $string = $newstring; |
|
| 1304 | + } |
|
| 1246 | 1305 | } |
| 1247 | 1306 | |
| 1248 | 1307 | $entityConvert = function($m) |
| 1249 | 1308 | { |
| 1250 | 1309 | $c = $m[1]; |
| 1251 | - if (strlen($c) === 1 && ord($c[0]) <= 0x7F) |
|
| 1252 | - return $c; |
|
| 1253 | - elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) |
|
| 1254 | - return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
| 1255 | - elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) |
|
| 1256 | - return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
| 1257 | - elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) |
|
| 1258 | - return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
| 1259 | - else |
|
| 1260 | - return ""; |
|
| 1310 | + if (strlen($c) === 1 && ord($c[0]) <= 0x7F) { |
|
| 1311 | + return $c; |
|
| 1312 | + } elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) { |
|
| 1313 | + return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
| 1314 | + } elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) { |
|
| 1315 | + return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
| 1316 | + } elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) { |
|
| 1317 | + return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
| 1318 | + } else { |
|
| 1319 | + return ""; |
|
| 1320 | + } |
|
| 1261 | 1321 | }; |
| 1262 | 1322 | |
| 1263 | 1323 | // Convert all 'special' characters to HTML entities. |
@@ -1271,19 +1331,20 @@ discard block |
||
| 1271 | 1331 | $string = base64_encode($string); |
| 1272 | 1332 | |
| 1273 | 1333 | // Show the characterset and the transfer-encoding for header strings. |
| 1274 | - if ($with_charset) |
|
| 1275 | - $string = '=?' . $charset . '?B?' . $string . '?='; |
|
| 1334 | + if ($with_charset) { |
|
| 1335 | + $string = '=?' . $charset . '?B?' . $string . '?='; |
|
| 1336 | + } |
|
| 1276 | 1337 | |
| 1277 | 1338 | // Break it up in lines (mail body). |
| 1278 | - else |
|
| 1279 | - $string = chunk_split($string, 76, $line_break); |
|
| 1339 | + else { |
|
| 1340 | + $string = chunk_split($string, 76, $line_break); |
|
| 1341 | + } |
|
| 1280 | 1342 | |
| 1281 | 1343 | return array($charset, $string, 'base64'); |
| 1344 | + } else { |
|
| 1345 | + return array($charset, $string, '7bit'); |
|
| 1346 | + } |
|
| 1282 | 1347 | } |
| 1283 | - |
|
| 1284 | - else |
|
| 1285 | - return array($charset, $string, '7bit'); |
|
| 1286 | -} |
|
| 1287 | 1348 | |
| 1288 | 1349 | /** |
| 1289 | 1350 | * Sends mail, like mail() but over SMTP. |
@@ -1307,8 +1368,9 @@ discard block |
||
| 1307 | 1368 | if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
| 1308 | 1369 | { |
| 1309 | 1370 | $socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2); |
| 1310 | - if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) |
|
| 1311 | - $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
| 1371 | + if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) { |
|
| 1372 | + $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
| 1373 | + } |
|
| 1312 | 1374 | |
| 1313 | 1375 | if ($socket) |
| 1314 | 1376 | { |
@@ -1329,8 +1391,9 @@ discard block |
||
| 1329 | 1391 | // Maybe we can still save this? The port might be wrong. |
| 1330 | 1392 | if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25)) |
| 1331 | 1393 | { |
| 1332 | - if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) |
|
| 1333 | - log_error($txt['smtp_port_ssl']); |
|
| 1394 | + if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) { |
|
| 1395 | + log_error($txt['smtp_port_ssl']); |
|
| 1396 | + } |
|
| 1334 | 1397 | } |
| 1335 | 1398 | |
| 1336 | 1399 | // Unable to connect! Don't show any error message, but just log one and try to continue anyway. |
@@ -1342,20 +1405,23 @@ discard block |
||
| 1342 | 1405 | } |
| 1343 | 1406 | |
| 1344 | 1407 | // Wait for a response of 220, without "-" continuer. |
| 1345 | - if (!server_parse(null, $socket, '220')) |
|
| 1346 | - return false; |
|
| 1408 | + if (!server_parse(null, $socket, '220')) { |
|
| 1409 | + return false; |
|
| 1410 | + } |
|
| 1347 | 1411 | |
| 1348 | 1412 | // Try and determine the servers name, fall back to the mail servers if not found |
| 1349 | 1413 | $helo = false; |
| 1350 | - if (function_exists('gethostname') && gethostname() !== false) |
|
| 1351 | - $helo = gethostname(); |
|
| 1352 | - elseif (function_exists('php_uname')) |
|
| 1353 | - $helo = php_uname('n'); |
|
| 1354 | - elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) |
|
| 1355 | - $helo = $_SERVER['SERVER_NAME']; |
|
| 1414 | + if (function_exists('gethostname') && gethostname() !== false) { |
|
| 1415 | + $helo = gethostname(); |
|
| 1416 | + } elseif (function_exists('php_uname')) { |
|
| 1417 | + $helo = php_uname('n'); |
|
| 1418 | + } elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) { |
|
| 1419 | + $helo = $_SERVER['SERVER_NAME']; |
|
| 1420 | + } |
|
| 1356 | 1421 | |
| 1357 | - if (empty($helo)) |
|
| 1358 | - $helo = $modSettings['smtp_host']; |
|
| 1422 | + if (empty($helo)) { |
|
| 1423 | + $helo = $modSettings['smtp_host']; |
|
| 1424 | + } |
|
| 1359 | 1425 | |
| 1360 | 1426 | // SMTP = 1, SMTP - STARTTLS = 2 |
| 1361 | 1427 | if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
@@ -1367,33 +1433,39 @@ discard block |
||
| 1367 | 1433 | if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response)) |
| 1368 | 1434 | { |
| 1369 | 1435 | // Send STARTTLS to enable encryption |
| 1370 | - if (!server_parse('STARTTLS', $socket, '220')) |
|
| 1371 | - return false; |
|
| 1436 | + if (!server_parse('STARTTLS', $socket, '220')) { |
|
| 1437 | + return false; |
|
| 1438 | + } |
|
| 1372 | 1439 | // Enable the encryption |
| 1373 | - if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) |
|
| 1374 | - return false; |
|
| 1440 | + if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
| 1441 | + return false; |
|
| 1442 | + } |
|
| 1375 | 1443 | // Send the EHLO command again |
| 1376 | - if (!server_parse('EHLO ' . $helo, $socket, null) == '250') |
|
| 1377 | - return false; |
|
| 1444 | + if (!server_parse('EHLO ' . $helo, $socket, null) == '250') { |
|
| 1445 | + return false; |
|
| 1446 | + } |
|
| 1378 | 1447 | } |
| 1379 | 1448 | |
| 1380 | - if (!server_parse('AUTH LOGIN', $socket, '334')) |
|
| 1381 | - return false; |
|
| 1449 | + if (!server_parse('AUTH LOGIN', $socket, '334')) { |
|
| 1450 | + return false; |
|
| 1451 | + } |
|
| 1382 | 1452 | // Send the username and password, encoded. |
| 1383 | - if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) |
|
| 1384 | - return false; |
|
| 1453 | + if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) { |
|
| 1454 | + return false; |
|
| 1455 | + } |
|
| 1385 | 1456 | // The password is already encoded ;) |
| 1386 | - if (!server_parse($modSettings['smtp_password'], $socket, '235')) |
|
| 1387 | - return false; |
|
| 1457 | + if (!server_parse($modSettings['smtp_password'], $socket, '235')) { |
|
| 1458 | + return false; |
|
| 1459 | + } |
|
| 1460 | + } elseif (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
| 1461 | + return false; |
|
| 1388 | 1462 | } |
| 1389 | - elseif (!server_parse('HELO ' . $helo, $socket, '250')) |
|
| 1390 | - return false; |
|
| 1391 | - } |
|
| 1392 | - else |
|
| 1463 | + } else |
|
| 1393 | 1464 | { |
| 1394 | 1465 | // Just say "helo". |
| 1395 | - if (!server_parse('HELO ' . $helo, $socket, '250')) |
|
| 1396 | - return false; |
|
| 1466 | + if (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
| 1467 | + return false; |
|
| 1468 | + } |
|
| 1397 | 1469 | } |
| 1398 | 1470 | |
| 1399 | 1471 | // Fix the message for any lines beginning with a period! (the first is ignored, you see.) |
@@ -1406,31 +1478,38 @@ discard block |
||
| 1406 | 1478 | // Reset the connection to send another email. |
| 1407 | 1479 | if ($i != 0) |
| 1408 | 1480 | { |
| 1409 | - if (!server_parse('RSET', $socket, '250')) |
|
| 1410 | - return false; |
|
| 1481 | + if (!server_parse('RSET', $socket, '250')) { |
|
| 1482 | + return false; |
|
| 1483 | + } |
|
| 1411 | 1484 | } |
| 1412 | 1485 | |
| 1413 | 1486 | // From, to, and then start the data... |
| 1414 | - if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) |
|
| 1415 | - return false; |
|
| 1416 | - if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) |
|
| 1417 | - return false; |
|
| 1418 | - if (!server_parse('DATA', $socket, '354')) |
|
| 1419 | - return false; |
|
| 1487 | + if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) { |
|
| 1488 | + return false; |
|
| 1489 | + } |
|
| 1490 | + if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) { |
|
| 1491 | + return false; |
|
| 1492 | + } |
|
| 1493 | + if (!server_parse('DATA', $socket, '354')) { |
|
| 1494 | + return false; |
|
| 1495 | + } |
|
| 1420 | 1496 | fputs($socket, 'Subject: ' . $subject . "\r\n"); |
| 1421 | - if (strlen($mail_to) > 0) |
|
| 1422 | - fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
| 1497 | + if (strlen($mail_to) > 0) { |
|
| 1498 | + fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
| 1499 | + } |
|
| 1423 | 1500 | fputs($socket, $headers . "\r\n\r\n"); |
| 1424 | 1501 | fputs($socket, $message . "\r\n"); |
| 1425 | 1502 | |
| 1426 | 1503 | // Send a ., or in other words "end of data". |
| 1427 | - if (!server_parse('.', $socket, '250')) |
|
| 1428 | - return false; |
|
| 1504 | + if (!server_parse('.', $socket, '250')) { |
|
| 1505 | + return false; |
|
| 1506 | + } |
|
| 1429 | 1507 | |
| 1430 | 1508 | // Almost done, almost done... don't stop me just yet! |
| 1431 | 1509 | @set_time_limit(300); |
| 1432 | - if (function_exists('apache_reset_timeout')) |
|
| 1433 | - @apache_reset_timeout(); |
|
| 1510 | + if (function_exists('apache_reset_timeout')) { |
|
| 1511 | + @apache_reset_timeout(); |
|
| 1512 | + } |
|
| 1434 | 1513 | } |
| 1435 | 1514 | fputs($socket, 'QUIT' . "\r\n"); |
| 1436 | 1515 | fclose($socket); |
@@ -1454,8 +1533,9 @@ discard block |
||
| 1454 | 1533 | { |
| 1455 | 1534 | global $txt; |
| 1456 | 1535 | |
| 1457 | - if ($message !== null) |
|
| 1458 | - fputs($socket, $message . "\r\n"); |
|
| 1536 | + if ($message !== null) { |
|
| 1537 | + fputs($socket, $message . "\r\n"); |
|
| 1538 | + } |
|
| 1459 | 1539 | |
| 1460 | 1540 | // No response yet. |
| 1461 | 1541 | $server_response = ''; |
@@ -1471,8 +1551,9 @@ discard block |
||
| 1471 | 1551 | $response .= $server_response; |
| 1472 | 1552 | } |
| 1473 | 1553 | |
| 1474 | - if ($code === null) |
|
| 1475 | - return substr($server_response, 0, 3); |
|
| 1554 | + if ($code === null) { |
|
| 1555 | + return substr($server_response, 0, 3); |
|
| 1556 | + } |
|
| 1476 | 1557 | |
| 1477 | 1558 | if (substr($server_response, 0, 3) != $code) |
| 1478 | 1559 | { |
@@ -1502,8 +1583,9 @@ discard block |
||
| 1502 | 1583 | // Create a pspell or enchant dictionary resource |
| 1503 | 1584 | $dict = spell_init(); |
| 1504 | 1585 | |
| 1505 | - if (!isset($_POST['spellstring']) || !$dict) |
|
| 1506 | - die; |
|
| 1586 | + if (!isset($_POST['spellstring']) || !$dict) { |
|
| 1587 | + die; |
|
| 1588 | + } |
|
| 1507 | 1589 | |
| 1508 | 1590 | // Construct a bit of Javascript code. |
| 1509 | 1591 | $context['spell_js'] = ' |
@@ -1521,8 +1603,9 @@ discard block |
||
| 1521 | 1603 | $check_word = explode('|', $alphas[$i]); |
| 1522 | 1604 | |
| 1523 | 1605 | // If the word is a known word, or spelled right... |
| 1524 | - if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) |
|
| 1525 | - continue; |
|
| 1606 | + if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) { |
|
| 1607 | + continue; |
|
| 1608 | + } |
|
| 1526 | 1609 | |
| 1527 | 1610 | // Find the word, and move up the "last occurrence" to here. |
| 1528 | 1611 | $found_words = true; |
@@ -1536,20 +1619,23 @@ discard block |
||
| 1536 | 1619 | if (!empty($suggestions)) |
| 1537 | 1620 | { |
| 1538 | 1621 | // But first check they aren't going to be censored - no naughty words! |
| 1539 | - foreach ($suggestions as $k => $word) |
|
| 1540 | - if ($suggestions[$k] != censorText($word)) |
|
| 1622 | + foreach ($suggestions as $k => $word) { |
|
| 1623 | + if ($suggestions[$k] != censorText($word)) |
|
| 1541 | 1624 | unset($suggestions[$k]); |
| 1625 | + } |
|
| 1542 | 1626 | |
| 1543 | - if (!empty($suggestions)) |
|
| 1544 | - $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
| 1627 | + if (!empty($suggestions)) { |
|
| 1628 | + $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
| 1629 | + } |
|
| 1545 | 1630 | } |
| 1546 | 1631 | |
| 1547 | 1632 | $context['spell_js'] .= ']),'; |
| 1548 | 1633 | } |
| 1549 | 1634 | |
| 1550 | 1635 | // If words were found, take off the last comma. |
| 1551 | - if ($found_words) |
|
| 1552 | - $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
| 1636 | + if ($found_words) { |
|
| 1637 | + $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
| 1638 | + } |
|
| 1553 | 1639 | |
| 1554 | 1640 | $context['spell_js'] .= ' |
| 1555 | 1641 | );'; |
@@ -1584,11 +1670,13 @@ discard block |
||
| 1584 | 1670 | global $user_info, $smcFunc; |
| 1585 | 1671 | |
| 1586 | 1672 | // Can't do it if there's no topics. |
| 1587 | - if (empty($topics)) |
|
| 1588 | - return; |
|
| 1673 | + if (empty($topics)) { |
|
| 1674 | + return; |
|
| 1675 | + } |
|
| 1589 | 1676 | // It must be an array - it must! |
| 1590 | - if (!is_array($topics)) |
|
| 1591 | - $topics = array($topics); |
|
| 1677 | + if (!is_array($topics)) { |
|
| 1678 | + $topics = array($topics); |
|
| 1679 | + } |
|
| 1592 | 1680 | |
| 1593 | 1681 | // Get the subject and body... |
| 1594 | 1682 | $result = $smcFunc['db_query']('', ' |
@@ -1636,14 +1724,15 @@ discard block |
||
| 1636 | 1724 | } |
| 1637 | 1725 | $smcFunc['db_free_result']($result); |
| 1638 | 1726 | |
| 1639 | - if (!empty($task_rows)) |
|
| 1640 | - $smcFunc['db_insert']('', |
|
| 1727 | + if (!empty($task_rows)) { |
|
| 1728 | + $smcFunc['db_insert']('', |
|
| 1641 | 1729 | '{db_prefix}background_tasks', |
| 1642 | 1730 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 1643 | 1731 | $task_rows, |
| 1644 | 1732 | array('id_task') |
| 1645 | 1733 | ); |
| 1646 | -} |
|
| 1734 | + } |
|
| 1735 | + } |
|
| 1647 | 1736 | |
| 1648 | 1737 | /** |
| 1649 | 1738 | * Create a post, either as new topic (id_topic = 0) or in an existing one. |
@@ -1681,9 +1770,9 @@ discard block |
||
| 1681 | 1770 | $msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true; |
| 1682 | 1771 | |
| 1683 | 1772 | // We need to know if the topic is approved. If we're told that's great - if not find out. |
| 1684 | - if (!$modSettings['postmod_active']) |
|
| 1685 | - $topicOptions['is_approved'] = true; |
|
| 1686 | - elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
| 1773 | + if (!$modSettings['postmod_active']) { |
|
| 1774 | + $topicOptions['is_approved'] = true; |
|
| 1775 | + } elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
| 1687 | 1776 | { |
| 1688 | 1777 | $request = $smcFunc['db_query']('', ' |
| 1689 | 1778 | SELECT approved |
@@ -1706,8 +1795,7 @@ discard block |
||
| 1706 | 1795 | $posterOptions['id'] = 0; |
| 1707 | 1796 | $posterOptions['name'] = $txt['guest_title']; |
| 1708 | 1797 | $posterOptions['email'] = ''; |
| 1709 | - } |
|
| 1710 | - elseif ($posterOptions['id'] != $user_info['id']) |
|
| 1798 | + } elseif ($posterOptions['id'] != $user_info['id']) |
|
| 1711 | 1799 | { |
| 1712 | 1800 | $request = $smcFunc['db_query']('', ' |
| 1713 | 1801 | SELECT member_name, email_address |
@@ -1725,12 +1813,11 @@ discard block |
||
| 1725 | 1813 | $posterOptions['id'] = 0; |
| 1726 | 1814 | $posterOptions['name'] = $txt['guest_title']; |
| 1727 | 1815 | $posterOptions['email'] = ''; |
| 1816 | + } else { |
|
| 1817 | + list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
| 1728 | 1818 | } |
| 1729 | - else |
|
| 1730 | - list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
| 1731 | 1819 | $smcFunc['db_free_result']($request); |
| 1732 | - } |
|
| 1733 | - else |
|
| 1820 | + } else |
|
| 1734 | 1821 | { |
| 1735 | 1822 | $posterOptions['name'] = $user_info['name']; |
| 1736 | 1823 | $posterOptions['email'] = $user_info['email']; |
@@ -1740,8 +1827,9 @@ discard block |
||
| 1740 | 1827 | if (!empty($modSettings['enable_mentions'])) |
| 1741 | 1828 | { |
| 1742 | 1829 | $msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']); |
| 1743 | - if (!empty($msgOptions['mentioned_members'])) |
|
| 1744 | - $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
| 1830 | + if (!empty($msgOptions['mentioned_members'])) { |
|
| 1831 | + $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
| 1832 | + } |
|
| 1745 | 1833 | } |
| 1746 | 1834 | |
| 1747 | 1835 | // It's do or die time: forget any user aborts! |
@@ -1774,12 +1862,13 @@ discard block |
||
| 1774 | 1862 | ); |
| 1775 | 1863 | |
| 1776 | 1864 | // Something went wrong creating the message... |
| 1777 | - if (empty($msgOptions['id'])) |
|
| 1778 | - return false; |
|
| 1865 | + if (empty($msgOptions['id'])) { |
|
| 1866 | + return false; |
|
| 1867 | + } |
|
| 1779 | 1868 | |
| 1780 | 1869 | // Fix the attachments. |
| 1781 | - if (!empty($msgOptions['attachments'])) |
|
| 1782 | - $smcFunc['db_query']('', ' |
|
| 1870 | + if (!empty($msgOptions['attachments'])) { |
|
| 1871 | + $smcFunc['db_query']('', ' |
|
| 1783 | 1872 | UPDATE {db_prefix}attachments |
| 1784 | 1873 | SET id_msg = {int:id_msg} |
| 1785 | 1874 | WHERE id_attach IN ({array_int:attachment_list})', |
@@ -1788,6 +1877,7 @@ discard block |
||
| 1788 | 1877 | 'id_msg' => $msgOptions['id'], |
| 1789 | 1878 | ) |
| 1790 | 1879 | ); |
| 1880 | + } |
|
| 1791 | 1881 | |
| 1792 | 1882 | // What if we want to export new posts out to a CMS? |
| 1793 | 1883 | call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters)); |
@@ -1864,20 +1954,23 @@ discard block |
||
| 1864 | 1954 | 'id_topic' => $topicOptions['id'], |
| 1865 | 1955 | 'counter_increment' => 1, |
| 1866 | 1956 | ); |
| 1867 | - if ($msgOptions['approved']) |
|
| 1868 | - $topics_columns = array( |
|
| 1957 | + if ($msgOptions['approved']) { |
|
| 1958 | + $topics_columns = array( |
|
| 1869 | 1959 | 'id_member_updated = {int:poster_id}', |
| 1870 | 1960 | 'id_last_msg = {int:id_msg}', |
| 1871 | 1961 | 'num_replies = num_replies + {int:counter_increment}', |
| 1872 | 1962 | ); |
| 1873 | - else |
|
| 1874 | - $topics_columns = array( |
|
| 1963 | + } else { |
|
| 1964 | + $topics_columns = array( |
|
| 1875 | 1965 | 'unapproved_posts = unapproved_posts + {int:counter_increment}', |
| 1876 | 1966 | ); |
| 1877 | - if ($topicOptions['lock_mode'] !== null) |
|
| 1878 | - $topics_columns[] = 'locked = {int:locked}'; |
|
| 1879 | - if ($topicOptions['sticky_mode'] !== null) |
|
| 1880 | - $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
| 1967 | + } |
|
| 1968 | + if ($topicOptions['lock_mode'] !== null) { |
|
| 1969 | + $topics_columns[] = 'locked = {int:locked}'; |
|
| 1970 | + } |
|
| 1971 | + if ($topicOptions['sticky_mode'] !== null) { |
|
| 1972 | + $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
| 1973 | + } |
|
| 1881 | 1974 | |
| 1882 | 1975 | call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions)); |
| 1883 | 1976 | |
@@ -1906,8 +1999,8 @@ discard block |
||
| 1906 | 1999 | ); |
| 1907 | 2000 | |
| 1908 | 2001 | // Increase the number of posts and topics on the board. |
| 1909 | - if ($msgOptions['approved']) |
|
| 1910 | - $smcFunc['db_query']('', ' |
|
| 2002 | + if ($msgOptions['approved']) { |
|
| 2003 | + $smcFunc['db_query']('', ' |
|
| 1911 | 2004 | UPDATE {db_prefix}boards |
| 1912 | 2005 | SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . ' |
| 1913 | 2006 | WHERE id_board = {int:id_board}', |
@@ -1915,7 +2008,7 @@ discard block |
||
| 1915 | 2008 | 'id_board' => $topicOptions['board'], |
| 1916 | 2009 | ) |
| 1917 | 2010 | ); |
| 1918 | - else |
|
| 2011 | + } else |
|
| 1919 | 2012 | { |
| 1920 | 2013 | $smcFunc['db_query']('', ' |
| 1921 | 2014 | UPDATE {db_prefix}boards |
@@ -1985,8 +2078,8 @@ discard block |
||
| 1985 | 2078 | } |
| 1986 | 2079 | } |
| 1987 | 2080 | |
| 1988 | - if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) |
|
| 1989 | - $smcFunc['db_insert']('', |
|
| 2081 | + if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) { |
|
| 2082 | + $smcFunc['db_insert']('', |
|
| 1990 | 2083 | '{db_prefix}background_tasks', |
| 1991 | 2084 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 1992 | 2085 | array( |
@@ -1998,19 +2091,22 @@ discard block |
||
| 1998 | 2091 | ), |
| 1999 | 2092 | array('id_task') |
| 2000 | 2093 | ); |
| 2094 | + } |
|
| 2001 | 2095 | |
| 2002 | 2096 | // If there's a custom search index, it may need updating... |
| 2003 | 2097 | require_once($sourcedir . '/Search.php'); |
| 2004 | 2098 | $searchAPI = findSearchAPI(); |
| 2005 | - if (is_callable(array($searchAPI, 'postCreated'))) |
|
| 2006 | - $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
| 2099 | + if (is_callable(array($searchAPI, 'postCreated'))) { |
|
| 2100 | + $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
| 2101 | + } |
|
| 2007 | 2102 | |
| 2008 | 2103 | // Increase the post counter for the user that created the post. |
| 2009 | 2104 | if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved']) |
| 2010 | 2105 | { |
| 2011 | 2106 | // Are you the one that happened to create this post? |
| 2012 | - if ($user_info['id'] == $posterOptions['id']) |
|
| 2013 | - $user_info['posts']++; |
|
| 2107 | + if ($user_info['id'] == $posterOptions['id']) { |
|
| 2108 | + $user_info['posts']++; |
|
| 2109 | + } |
|
| 2014 | 2110 | updateMemberData($posterOptions['id'], array('posts' => '+')); |
| 2015 | 2111 | } |
| 2016 | 2112 | |
@@ -2018,19 +2114,21 @@ discard block |
||
| 2018 | 2114 | $_SESSION['last_read_topic'] = 0; |
| 2019 | 2115 | |
| 2020 | 2116 | // Better safe than sorry. |
| 2021 | - if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) |
|
| 2022 | - $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
| 2117 | + if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) { |
|
| 2118 | + $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
| 2119 | + } |
|
| 2023 | 2120 | |
| 2024 | 2121 | // Update all the stats so everyone knows about this new topic and message. |
| 2025 | 2122 | updateStats('message', true, $msgOptions['id']); |
| 2026 | 2123 | |
| 2027 | 2124 | // Update the last message on the board assuming it's approved AND the topic is. |
| 2028 | - if ($msgOptions['approved']) |
|
| 2029 | - updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
| 2125 | + if ($msgOptions['approved']) { |
|
| 2126 | + updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
| 2127 | + } |
|
| 2030 | 2128 | |
| 2031 | 2129 | // Queue createPost background notification |
| 2032 | - if ($msgOptions['send_notifications'] && $msgOptions['approved']) |
|
| 2033 | - $smcFunc['db_insert']('', |
|
| 2130 | + if ($msgOptions['send_notifications'] && $msgOptions['approved']) { |
|
| 2131 | + $smcFunc['db_insert']('', |
|
| 2034 | 2132 | '{db_prefix}background_tasks', |
| 2035 | 2133 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 2036 | 2134 | array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array( |
@@ -2041,6 +2139,7 @@ discard block |
||
| 2041 | 2139 | )), 0), |
| 2042 | 2140 | array('id_task') |
| 2043 | 2141 | ); |
| 2142 | + } |
|
| 2044 | 2143 | |
| 2045 | 2144 | // Alright, done now... we can abort now, I guess... at least this much is done. |
| 2046 | 2145 | ignore_user_abort($previous_ignore_user_abort); |
@@ -2067,14 +2166,18 @@ discard block |
||
| 2067 | 2166 | |
| 2068 | 2167 | // This is longer than it has to be, but makes it so we only set/change what we have to. |
| 2069 | 2168 | $messages_columns = array(); |
| 2070 | - if (isset($posterOptions['name'])) |
|
| 2071 | - $messages_columns['poster_name'] = $posterOptions['name']; |
|
| 2072 | - if (isset($posterOptions['email'])) |
|
| 2073 | - $messages_columns['poster_email'] = $posterOptions['email']; |
|
| 2074 | - if (isset($msgOptions['icon'])) |
|
| 2075 | - $messages_columns['icon'] = $msgOptions['icon']; |
|
| 2076 | - if (isset($msgOptions['subject'])) |
|
| 2077 | - $messages_columns['subject'] = $msgOptions['subject']; |
|
| 2169 | + if (isset($posterOptions['name'])) { |
|
| 2170 | + $messages_columns['poster_name'] = $posterOptions['name']; |
|
| 2171 | + } |
|
| 2172 | + if (isset($posterOptions['email'])) { |
|
| 2173 | + $messages_columns['poster_email'] = $posterOptions['email']; |
|
| 2174 | + } |
|
| 2175 | + if (isset($msgOptions['icon'])) { |
|
| 2176 | + $messages_columns['icon'] = $msgOptions['icon']; |
|
| 2177 | + } |
|
| 2178 | + if (isset($msgOptions['subject'])) { |
|
| 2179 | + $messages_columns['subject'] = $msgOptions['subject']; |
|
| 2180 | + } |
|
| 2078 | 2181 | if (isset($msgOptions['body'])) |
| 2079 | 2182 | { |
| 2080 | 2183 | $messages_columns['body'] = $msgOptions['body']; |
@@ -2101,8 +2204,9 @@ discard block |
||
| 2101 | 2204 | $messages_columns['modified_reason'] = $msgOptions['modify_reason']; |
| 2102 | 2205 | $messages_columns['id_msg_modified'] = $modSettings['maxMsgID']; |
| 2103 | 2206 | } |
| 2104 | - if (isset($msgOptions['smileys_enabled'])) |
|
| 2105 | - $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
| 2207 | + if (isset($msgOptions['smileys_enabled'])) { |
|
| 2208 | + $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
| 2209 | + } |
|
| 2106 | 2210 | |
| 2107 | 2211 | // Which columns need to be ints? |
| 2108 | 2212 | $messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled'); |
@@ -2120,23 +2224,27 @@ discard block |
||
| 2120 | 2224 | { |
| 2121 | 2225 | preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match); |
| 2122 | 2226 | |
| 2123 | - if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) |
|
| 2124 | - foreach ($match[1] as $i => $oldID) |
|
| 2227 | + if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) { |
|
| 2228 | + foreach ($match[1] as $i => $oldID) |
|
| 2125 | 2229 | $oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]); |
| 2230 | + } |
|
| 2126 | 2231 | |
| 2127 | - if (empty($modSettings['search_custom_index_config'])) |
|
| 2128 | - unset($msgOptions['old_body']); |
|
| 2232 | + if (empty($modSettings['search_custom_index_config'])) { |
|
| 2233 | + unset($msgOptions['old_body']); |
|
| 2234 | + } |
|
| 2129 | 2235 | } |
| 2130 | 2236 | |
| 2131 | 2237 | $mentions = Mentions::getMentionedMembers($msgOptions['body']); |
| 2132 | 2238 | $messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions); |
| 2133 | 2239 | |
| 2134 | 2240 | // Remove the poster. |
| 2135 | - if (isset($mentions[$user_info['id']])) |
|
| 2136 | - unset($mentions[$user_info['id']]); |
|
| 2241 | + if (isset($mentions[$user_info['id']])) { |
|
| 2242 | + unset($mentions[$user_info['id']]); |
|
| 2243 | + } |
|
| 2137 | 2244 | |
| 2138 | - if (isset($oldmentions[$user_info['id']])) |
|
| 2139 | - unset($oldmentions[$user_info['id']]); |
|
| 2245 | + if (isset($oldmentions[$user_info['id']])) { |
|
| 2246 | + unset($oldmentions[$user_info['id']]); |
|
| 2247 | + } |
|
| 2140 | 2248 | |
| 2141 | 2249 | if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions)) |
| 2142 | 2250 | { |
@@ -2166,8 +2274,9 @@ discard block |
||
| 2166 | 2274 | } |
| 2167 | 2275 | |
| 2168 | 2276 | // Nothing to do? |
| 2169 | - if (empty($messages_columns)) |
|
| 2170 | - return true; |
|
| 2277 | + if (empty($messages_columns)) { |
|
| 2278 | + return true; |
|
| 2279 | + } |
|
| 2171 | 2280 | |
| 2172 | 2281 | // Change the post. |
| 2173 | 2282 | $smcFunc['db_query']('', ' |
@@ -2228,8 +2337,9 @@ discard block |
||
| 2228 | 2337 | // If there's a custom search index, it needs to be modified... |
| 2229 | 2338 | require_once($sourcedir . '/Search.php'); |
| 2230 | 2339 | $searchAPI = findSearchAPI(); |
| 2231 | - if (is_callable(array($searchAPI, 'postModified'))) |
|
| 2232 | - $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
| 2340 | + if (is_callable(array($searchAPI, 'postModified'))) { |
|
| 2341 | + $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
| 2342 | + } |
|
| 2233 | 2343 | |
| 2234 | 2344 | if (isset($msgOptions['subject'])) |
| 2235 | 2345 | { |
@@ -2243,14 +2353,16 @@ discard block |
||
| 2243 | 2353 | 'id_first_msg' => $msgOptions['id'], |
| 2244 | 2354 | ) |
| 2245 | 2355 | ); |
| 2246 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 2247 | - updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
| 2356 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 2357 | + updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
| 2358 | + } |
|
| 2248 | 2359 | $smcFunc['db_free_result']($request); |
| 2249 | 2360 | } |
| 2250 | 2361 | |
| 2251 | 2362 | // Finally, if we are setting the approved state we need to do much more work :( |
| 2252 | - if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) |
|
| 2253 | - approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
| 2363 | + if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) { |
|
| 2364 | + approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
| 2365 | + } |
|
| 2254 | 2366 | |
| 2255 | 2367 | return true; |
| 2256 | 2368 | } |
@@ -2267,11 +2379,13 @@ discard block |
||
| 2267 | 2379 | { |
| 2268 | 2380 | global $smcFunc; |
| 2269 | 2381 | |
| 2270 | - if (!is_array($msgs)) |
|
| 2271 | - $msgs = array($msgs); |
|
| 2382 | + if (!is_array($msgs)) { |
|
| 2383 | + $msgs = array($msgs); |
|
| 2384 | + } |
|
| 2272 | 2385 | |
| 2273 | - if (empty($msgs)) |
|
| 2274 | - return false; |
|
| 2386 | + if (empty($msgs)) { |
|
| 2387 | + return false; |
|
| 2388 | + } |
|
| 2275 | 2389 | |
| 2276 | 2390 | // May as well start at the beginning, working out *what* we need to change. |
| 2277 | 2391 | $request = $smcFunc['db_query']('', ' |
@@ -2303,20 +2417,22 @@ discard block |
||
| 2303 | 2417 | $topics[] = $row['id_topic']; |
| 2304 | 2418 | |
| 2305 | 2419 | // Ensure our change array exists already. |
| 2306 | - if (!isset($topic_changes[$row['id_topic']])) |
|
| 2307 | - $topic_changes[$row['id_topic']] = array( |
|
| 2420 | + if (!isset($topic_changes[$row['id_topic']])) { |
|
| 2421 | + $topic_changes[$row['id_topic']] = array( |
|
| 2308 | 2422 | 'id_last_msg' => $row['id_last_msg'], |
| 2309 | 2423 | 'approved' => $row['topic_approved'], |
| 2310 | 2424 | 'replies' => 0, |
| 2311 | 2425 | 'unapproved_posts' => 0, |
| 2312 | 2426 | ); |
| 2313 | - if (!isset($board_changes[$row['id_board']])) |
|
| 2314 | - $board_changes[$row['id_board']] = array( |
|
| 2427 | + } |
|
| 2428 | + if (!isset($board_changes[$row['id_board']])) { |
|
| 2429 | + $board_changes[$row['id_board']] = array( |
|
| 2315 | 2430 | 'posts' => 0, |
| 2316 | 2431 | 'topics' => 0, |
| 2317 | 2432 | 'unapproved_posts' => 0, |
| 2318 | 2433 | 'unapproved_topics' => 0, |
| 2319 | 2434 | ); |
| 2435 | + } |
|
| 2320 | 2436 | |
| 2321 | 2437 | // If it's the first message then the topic state changes! |
| 2322 | 2438 | if ($row['id_msg'] == $row['id_first_msg']) |
@@ -2337,14 +2453,13 @@ discard block |
||
| 2337 | 2453 | 'poster' => $row['id_member'], |
| 2338 | 2454 | 'new_topic' => true, |
| 2339 | 2455 | ); |
| 2340 | - } |
|
| 2341 | - else |
|
| 2456 | + } else |
|
| 2342 | 2457 | { |
| 2343 | 2458 | $topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1; |
| 2344 | 2459 | |
| 2345 | 2460 | // This will be a post... but don't notify unless it's not followed by approved ones. |
| 2346 | - if ($row['id_msg'] > $row['id_last_msg']) |
|
| 2347 | - $notification_posts[$row['id_topic']] = array( |
|
| 2461 | + if ($row['id_msg'] > $row['id_last_msg']) { |
|
| 2462 | + $notification_posts[$row['id_topic']] = array( |
|
| 2348 | 2463 | 'id' => $row['id_msg'], |
| 2349 | 2464 | 'body' => $row['body'], |
| 2350 | 2465 | 'subject' => $row['subject'], |
@@ -2355,28 +2470,33 @@ discard block |
||
| 2355 | 2470 | 'new_topic' => false, |
| 2356 | 2471 | 'msg' => $row['id_msg'], |
| 2357 | 2472 | ); |
| 2473 | + } |
|
| 2358 | 2474 | } |
| 2359 | 2475 | |
| 2360 | 2476 | // If this is being approved and id_msg is higher than the current id_last_msg then it changes. |
| 2361 | - if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) |
|
| 2362 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
| 2477 | + if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) { |
|
| 2478 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
| 2479 | + } |
|
| 2363 | 2480 | // If this is being unapproved, and it's equal to the id_last_msg we need to find a new one! |
| 2364 | - elseif (!$approve) |
|
| 2365 | - // Default to the first message and then we'll override in a bit ;) |
|
| 2481 | + elseif (!$approve) { |
|
| 2482 | + // Default to the first message and then we'll override in a bit ;) |
|
| 2366 | 2483 | $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg']; |
| 2484 | + } |
|
| 2367 | 2485 | |
| 2368 | 2486 | $topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1; |
| 2369 | 2487 | $board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1; |
| 2370 | 2488 | $board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1; |
| 2371 | 2489 | |
| 2372 | 2490 | // Post count for the user? |
| 2373 | - if ($row['id_member'] && empty($row['count_posts'])) |
|
| 2374 | - $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
| 2491 | + if ($row['id_member'] && empty($row['count_posts'])) { |
|
| 2492 | + $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
| 2493 | + } |
|
| 2375 | 2494 | } |
| 2376 | 2495 | $smcFunc['db_free_result']($request); |
| 2377 | 2496 | |
| 2378 | - if (empty($msgs)) |
|
| 2379 | - return; |
|
| 2497 | + if (empty($msgs)) { |
|
| 2498 | + return; |
|
| 2499 | + } |
|
| 2380 | 2500 | |
| 2381 | 2501 | // Now we have the differences make the changes, first the easy one. |
| 2382 | 2502 | $smcFunc['db_query']('', ' |
@@ -2403,14 +2523,15 @@ discard block |
||
| 2403 | 2523 | 'approved' => 1, |
| 2404 | 2524 | ) |
| 2405 | 2525 | ); |
| 2406 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2407 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
| 2526 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2527 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
| 2528 | + } |
|
| 2408 | 2529 | $smcFunc['db_free_result']($request); |
| 2409 | 2530 | } |
| 2410 | 2531 | |
| 2411 | 2532 | // ... next the topics... |
| 2412 | - foreach ($topic_changes as $id => $changes) |
|
| 2413 | - $smcFunc['db_query']('', ' |
|
| 2533 | + foreach ($topic_changes as $id => $changes) { |
|
| 2534 | + $smcFunc['db_query']('', ' |
|
| 2414 | 2535 | UPDATE {db_prefix}topics |
| 2415 | 2536 | SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
| 2416 | 2537 | num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg} |
@@ -2423,10 +2544,11 @@ discard block |
||
| 2423 | 2544 | 'id_topic' => $id, |
| 2424 | 2545 | ) |
| 2425 | 2546 | ); |
| 2547 | + } |
|
| 2426 | 2548 | |
| 2427 | 2549 | // ... finally the boards... |
| 2428 | - foreach ($board_changes as $id => $changes) |
|
| 2429 | - $smcFunc['db_query']('', ' |
|
| 2550 | + foreach ($board_changes as $id => $changes) { |
|
| 2551 | + $smcFunc['db_query']('', ' |
|
| 2430 | 2552 | UPDATE {db_prefix}boards |
| 2431 | 2553 | SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
| 2432 | 2554 | num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics} |
@@ -2439,13 +2561,14 @@ discard block |
||
| 2439 | 2561 | 'id_board' => $id, |
| 2440 | 2562 | ) |
| 2441 | 2563 | ); |
| 2564 | + } |
|
| 2442 | 2565 | |
| 2443 | 2566 | // Finally, least importantly, notifications! |
| 2444 | 2567 | if ($approve) |
| 2445 | 2568 | { |
| 2446 | 2569 | $task_rows = array(); |
| 2447 | - foreach (array_merge($notification_topics, $notification_posts) as $topic) |
|
| 2448 | - $task_rows[] = array( |
|
| 2570 | + foreach (array_merge($notification_topics, $notification_posts) as $topic) { |
|
| 2571 | + $task_rows[] = array( |
|
| 2449 | 2572 | '$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array( |
| 2450 | 2573 | 'msgOptions' => array( |
| 2451 | 2574 | 'id' => $topic['msg'], |
@@ -2463,14 +2586,16 @@ discard block |
||
| 2463 | 2586 | 'type' => $topic['new_topic'] ? 'topic' : 'reply', |
| 2464 | 2587 | )), 0 |
| 2465 | 2588 | ); |
| 2589 | + } |
|
| 2466 | 2590 | |
| 2467 | - if ($notify) |
|
| 2468 | - $smcFunc['db_insert']('', |
|
| 2591 | + if ($notify) { |
|
| 2592 | + $smcFunc['db_insert']('', |
|
| 2469 | 2593 | '{db_prefix}background_tasks', |
| 2470 | 2594 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 2471 | 2595 | $task_rows, |
| 2472 | 2596 | array('id_task') |
| 2473 | 2597 | ); |
| 2598 | + } |
|
| 2474 | 2599 | |
| 2475 | 2600 | $smcFunc['db_query']('', ' |
| 2476 | 2601 | DELETE FROM {db_prefix}approval_queue |
@@ -2486,8 +2611,9 @@ discard block |
||
| 2486 | 2611 | else |
| 2487 | 2612 | { |
| 2488 | 2613 | $msgInserts = array(); |
| 2489 | - foreach ($msgs as $msg) |
|
| 2490 | - $msgInserts[] = array($msg); |
|
| 2614 | + foreach ($msgs as $msg) { |
|
| 2615 | + $msgInserts[] = array($msg); |
|
| 2616 | + } |
|
| 2491 | 2617 | |
| 2492 | 2618 | $smcFunc['db_insert']('ignore', |
| 2493 | 2619 | '{db_prefix}approval_queue', |
@@ -2501,9 +2627,10 @@ discard block |
||
| 2501 | 2627 | updateLastMessages(array_keys($board_changes)); |
| 2502 | 2628 | |
| 2503 | 2629 | // Post count for the members? |
| 2504 | - if (!empty($member_post_changes)) |
|
| 2505 | - foreach ($member_post_changes as $id_member => $count_change) |
|
| 2630 | + if (!empty($member_post_changes)) { |
|
| 2631 | + foreach ($member_post_changes as $id_member => $count_change) |
|
| 2506 | 2632 | updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change)); |
| 2633 | + } |
|
| 2507 | 2634 | |
| 2508 | 2635 | return true; |
| 2509 | 2636 | } |
@@ -2520,11 +2647,13 @@ discard block |
||
| 2520 | 2647 | { |
| 2521 | 2648 | global $smcFunc; |
| 2522 | 2649 | |
| 2523 | - if (!is_array($topics)) |
|
| 2524 | - $topics = array($topics); |
|
| 2650 | + if (!is_array($topics)) { |
|
| 2651 | + $topics = array($topics); |
|
| 2652 | + } |
|
| 2525 | 2653 | |
| 2526 | - if (empty($topics)) |
|
| 2527 | - return false; |
|
| 2654 | + if (empty($topics)) { |
|
| 2655 | + return false; |
|
| 2656 | + } |
|
| 2528 | 2657 | |
| 2529 | 2658 | $approve_type = $approve ? 0 : 1; |
| 2530 | 2659 | |
@@ -2540,8 +2669,9 @@ discard block |
||
| 2540 | 2669 | ) |
| 2541 | 2670 | ); |
| 2542 | 2671 | $msgs = array(); |
| 2543 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2544 | - $msgs[] = $row['id_msg']; |
|
| 2672 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2673 | + $msgs[] = $row['id_msg']; |
|
| 2674 | + } |
|
| 2545 | 2675 | $smcFunc['db_free_result']($request); |
| 2546 | 2676 | |
| 2547 | 2677 | return approvePosts($msgs, $approve); |
@@ -2564,11 +2694,13 @@ discard block |
||
| 2564 | 2694 | global $board_info, $board, $smcFunc; |
| 2565 | 2695 | |
| 2566 | 2696 | // Please - let's be sane. |
| 2567 | - if (empty($setboards)) |
|
| 2568 | - return false; |
|
| 2697 | + if (empty($setboards)) { |
|
| 2698 | + return false; |
|
| 2699 | + } |
|
| 2569 | 2700 | |
| 2570 | - if (!is_array($setboards)) |
|
| 2571 | - $setboards = array($setboards); |
|
| 2701 | + if (!is_array($setboards)) { |
|
| 2702 | + $setboards = array($setboards); |
|
| 2703 | + } |
|
| 2572 | 2704 | |
| 2573 | 2705 | // If we don't know the id_msg we need to find it. |
| 2574 | 2706 | if (!$id_msg) |
@@ -2586,15 +2718,16 @@ discard block |
||
| 2586 | 2718 | ) |
| 2587 | 2719 | ); |
| 2588 | 2720 | $lastMsg = array(); |
| 2589 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2590 | - $lastMsg[$row['id_board']] = $row['id_msg']; |
|
| 2721 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2722 | + $lastMsg[$row['id_board']] = $row['id_msg']; |
|
| 2723 | + } |
|
| 2591 | 2724 | $smcFunc['db_free_result']($request); |
| 2592 | - } |
|
| 2593 | - else |
|
| 2725 | + } else |
|
| 2594 | 2726 | { |
| 2595 | 2727 | // Just to note - there should only be one board passed if we are doing this. |
| 2596 | - foreach ($setboards as $id_board) |
|
| 2597 | - $lastMsg[$id_board] = $id_msg; |
|
| 2728 | + foreach ($setboards as $id_board) { |
|
| 2729 | + $lastMsg[$id_board] = $id_msg; |
|
| 2730 | + } |
|
| 2598 | 2731 | } |
| 2599 | 2732 | |
| 2600 | 2733 | $parent_boards = array(); |
@@ -2609,10 +2742,11 @@ discard block |
||
| 2609 | 2742 | $lastModified[$id_board] = 0; |
| 2610 | 2743 | } |
| 2611 | 2744 | |
| 2612 | - if (!empty($board) && $id_board == $board) |
|
| 2613 | - $parents = $board_info['parent_boards']; |
|
| 2614 | - else |
|
| 2615 | - $parents = getBoardParents($id_board); |
|
| 2745 | + if (!empty($board) && $id_board == $board) { |
|
| 2746 | + $parents = $board_info['parent_boards']; |
|
| 2747 | + } else { |
|
| 2748 | + $parents = getBoardParents($id_board); |
|
| 2749 | + } |
|
| 2616 | 2750 | |
| 2617 | 2751 | // Ignore any parents on the top child level. |
| 2618 | 2752 | // @todo Why? |
@@ -2621,10 +2755,11 @@ discard block |
||
| 2621 | 2755 | if ($parent['level'] != 0) |
| 2622 | 2756 | { |
| 2623 | 2757 | // If we're already doing this one as a board, is this a higher last modified? |
| 2624 | - if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) |
|
| 2625 | - $lastModified[$id] = $lastModified[$id_board]; |
|
| 2626 | - elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) |
|
| 2627 | - $parent_boards[$id] = $lastModified[$id_board]; |
|
| 2758 | + if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) { |
|
| 2759 | + $lastModified[$id] = $lastModified[$id_board]; |
|
| 2760 | + } elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) { |
|
| 2761 | + $parent_boards[$id] = $lastModified[$id_board]; |
|
| 2762 | + } |
|
| 2628 | 2763 | } |
| 2629 | 2764 | } |
| 2630 | 2765 | } |
@@ -2637,23 +2772,24 @@ discard block |
||
| 2637 | 2772 | // Finally, to save on queries make the changes... |
| 2638 | 2773 | foreach ($parent_boards as $id => $msg) |
| 2639 | 2774 | { |
| 2640 | - if (!isset($parent_updates[$msg])) |
|
| 2641 | - $parent_updates[$msg] = array($id); |
|
| 2642 | - else |
|
| 2643 | - $parent_updates[$msg][] = $id; |
|
| 2775 | + if (!isset($parent_updates[$msg])) { |
|
| 2776 | + $parent_updates[$msg] = array($id); |
|
| 2777 | + } else { |
|
| 2778 | + $parent_updates[$msg][] = $id; |
|
| 2779 | + } |
|
| 2644 | 2780 | } |
| 2645 | 2781 | |
| 2646 | 2782 | foreach ($lastMsg as $id => $msg) |
| 2647 | 2783 | { |
| 2648 | - if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) |
|
| 2649 | - $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
| 2784 | + if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) { |
|
| 2785 | + $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
| 2650 | 2786 | 'id' => $msg, |
| 2651 | 2787 | 'updated' => $lastModified[$id], |
| 2652 | 2788 | 'boards' => array($id) |
| 2653 | 2789 | ); |
| 2654 | - |
|
| 2655 | - else |
|
| 2656 | - $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
| 2790 | + } else { |
|
| 2791 | + $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
| 2792 | + } |
|
| 2657 | 2793 | } |
| 2658 | 2794 | |
| 2659 | 2795 | // Now commit the changes! |
@@ -2745,11 +2881,13 @@ discard block |
||
| 2745 | 2881 | global $txt, $mbname, $scripturl, $settings; |
| 2746 | 2882 | |
| 2747 | 2883 | // First things first, load up the email templates language file, if we need to. |
| 2748 | - if ($loadLang) |
|
| 2749 | - loadLanguage('EmailTemplates', $lang); |
|
| 2884 | + if ($loadLang) { |
|
| 2885 | + loadLanguage('EmailTemplates', $lang); |
|
| 2886 | + } |
|
| 2750 | 2887 | |
| 2751 | - if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) |
|
| 2752 | - fatal_lang_error('email_no_template', 'template', array($template)); |
|
| 2888 | + if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) { |
|
| 2889 | + fatal_lang_error('email_no_template', 'template', array($template)); |
|
| 2890 | + } |
|
| 2753 | 2891 | |
| 2754 | 2892 | $ret = array( |
| 2755 | 2893 | 'subject' => $txt[$template . '_subject'], |
@@ -2799,17 +2937,18 @@ discard block |
||
| 2799 | 2937 | function user_info_callback($matches) |
| 2800 | 2938 | { |
| 2801 | 2939 | global $user_info; |
| 2802 | - if (empty($matches[1])) |
|
| 2803 | - return ''; |
|
| 2940 | + if (empty($matches[1])) { |
|
| 2941 | + return ''; |
|
| 2942 | + } |
|
| 2804 | 2943 | |
| 2805 | 2944 | $use_ref = true; |
| 2806 | 2945 | $ref = &$user_info; |
| 2807 | 2946 | |
| 2808 | 2947 | foreach (explode('.', $matches[1]) as $index) |
| 2809 | 2948 | { |
| 2810 | - if ($use_ref && isset($ref[$index])) |
|
| 2811 | - $ref = &$ref[$index]; |
|
| 2812 | - else |
|
| 2949 | + if ($use_ref && isset($ref[$index])) { |
|
| 2950 | + $ref = &$ref[$index]; |
|
| 2951 | + } else |
|
| 2813 | 2952 | { |
| 2814 | 2953 | $use_ref = false; |
| 2815 | 2954 | break; |
@@ -2846,8 +2985,7 @@ discard block |
||
| 2846 | 2985 | if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale)) |
| 2847 | 2986 | { |
| 2848 | 2987 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale); |
| 2849 | - } |
|
| 2850 | - elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
| 2988 | + } elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
| 2851 | 2989 | { |
| 2852 | 2990 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']); |
| 2853 | 2991 | } |
@@ -2857,8 +2995,7 @@ discard block |
||
| 2857 | 2995 | { |
| 2858 | 2996 | $context['provider'] = 'enchant'; |
| 2859 | 2997 | return $enchant_link; |
| 2860 | - } |
|
| 2861 | - else |
|
| 2998 | + } else |
|
| 2862 | 2999 | { |
| 2863 | 3000 | // Free up any resources used... |
| 2864 | 3001 | @enchant_broker_free($context['enchant_broker']); |
@@ -2879,8 +3016,9 @@ discard block |
||
| 2879 | 3016 | $pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER); |
| 2880 | 3017 | |
| 2881 | 3018 | // Most people don't have anything but English installed... So we use English as a last resort. |
| 2882 | - if (!$pspell_link) |
|
| 2883 | - $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
| 3019 | + if (!$pspell_link) { |
|
| 3020 | + $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
| 3021 | + } |
|
| 2884 | 3022 | |
| 2885 | 3023 | error_reporting($old); |
| 2886 | 3024 | ob_end_clean(); |
@@ -2920,8 +3058,7 @@ discard block |
||
| 2920 | 3058 | $word = iconv($txt['lang_character_set'], 'UTF-8', $word); |
| 2921 | 3059 | } |
| 2922 | 3060 | return enchant_dict_check($dict, $word); |
| 2923 | - } |
|
| 2924 | - elseif ($context['provider'] == 'pspell') |
|
| 3061 | + } elseif ($context['provider'] == 'pspell') |
|
| 2925 | 3062 | { |
| 2926 | 3063 | return pspell_check($dict, $word); |
| 2927 | 3064 | } |
@@ -2957,13 +3094,11 @@ discard block |
||
| 2957 | 3094 | } |
| 2958 | 3095 | |
| 2959 | 3096 | return $suggestions; |
| 2960 | - } |
|
| 2961 | - else |
|
| 3097 | + } else |
|
| 2962 | 3098 | { |
| 2963 | 3099 | return enchant_dict_suggest($dict, $word); |
| 2964 | 3100 | } |
| 2965 | - } |
|
| 2966 | - elseif ($context['provider'] == 'pspell') |
|
| 3101 | + } elseif ($context['provider'] == 'pspell') |
|
| 2967 | 3102 | { |
| 2968 | 3103 | return pspell_suggest($dict, $word); |
| 2969 | 3104 | } |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | * |
| 567 | 567 | * @param int $report_id The report ID is used to fire a notification about the event. |
| 568 | 568 | * @param array $data a formatted array of data to be inserted. Should be already properly sanitized. |
| 569 | - * @return bool Boolean false if no data was provided. |
|
| 569 | + * @return false|null Boolean false if no data was provided. |
|
| 570 | 570 | */ |
| 571 | 571 | function saveModComment($report_id, $data) |
| 572 | 572 | { |
@@ -632,8 +632,8 @@ discard block |
||
| 632 | 632 | * Saves the new information whenever a moderator comment is edited. |
| 633 | 633 | * |
| 634 | 634 | * @param int $comment_id The edited moderator comment ID. |
| 635 | - * @param array $data The new data to de inserted. Should be already properly sanitized. |
|
| 636 | - * @return bool Boolean false if no data or no comment ID was provided. |
|
| 635 | + * @param string $edited_comment |
|
| 636 | + * @return false|null Boolean false if no data or no comment ID was provided. |
|
| 637 | 637 | */ |
| 638 | 638 | function editModComment($comment_id, $edited_comment) |
| 639 | 639 | { |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | * Deletes a moderator comment from the DB. |
| 658 | 658 | * |
| 659 | 659 | * @param int $comment_id The moderator comment ID used to identify which report will be deleted. |
| 660 | - * @return bool Boolean false if no data was provided. |
|
| 660 | + * @return false|null Boolean false if no data was provided. |
|
| 661 | 661 | */ |
| 662 | 662 | function deleteModComment($comment_id) |
| 663 | 663 | { |
@@ -130,7 +130,6 @@ |
||
| 130 | 130 | * |
| 131 | 131 | * @param int $closed 1 for counting closed reports, 0 for open ones. |
| 132 | 132 | * @return integer How many reports. |
| 133 | - |
|
| 134 | 133 | */ |
| 135 | 134 | function countReports($closed = 0) |
| 136 | 135 | { |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $smcFunc['db_query']('', ' |
| 50 | 50 | UPDATE {db_prefix}log_reported |
| 51 | 51 | SET {raw:action} = {string:value} |
| 52 | - '. (is_array($report_id) ? 'WHERE id_report IN ({array_int:id_report})' : 'WHERE id_report = {int:id_report}') .' |
|
| 52 | + '. (is_array($report_id) ? 'WHERE id_report IN ({array_int:id_report})' : 'WHERE id_report = {int:id_report}') . ' |
|
| 53 | 53 | ' . $board_query, |
| 54 | 54 | array( |
| 55 | 55 | 'action' => $action, |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | ) |
| 98 | 98 | ); |
| 99 | 99 | |
| 100 | - while($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 100 | + while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 101 | 101 | $extra[$row['id_report']] = array( |
| 102 | 102 | 'report' => $row['id_report'], |
| 103 | 103 | 'member' => $row['id_member'], |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 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 | * Updates a report with the given parameters. Logs each action via logAction() |
@@ -28,19 +29,20 @@ discard block |
||
| 28 | 29 | global $smcFunc, $user_info, $context; |
| 29 | 30 | |
| 30 | 31 | // Don't bother. |
| 31 | - if (empty($action) || empty($report_id)) |
|
| 32 | - return false; |
|
| 32 | + if (empty($action) || empty($report_id)) { |
|
| 33 | + return false; |
|
| 34 | + } |
|
| 33 | 35 | |
| 34 | 36 | // Add the "_all" thingy. |
| 35 | - if ($action == 'ignore') |
|
| 36 | - $action = 'ignore_all'; |
|
| 37 | + if ($action == 'ignore') { |
|
| 38 | + $action = 'ignore_all'; |
|
| 39 | + } |
|
| 37 | 40 | |
| 38 | 41 | // We don't need the board query for reported members |
| 39 | 42 | if ($context['report_type'] == 'members') |
| 40 | 43 | { |
| 41 | 44 | $board_query = ''; |
| 42 | - } |
|
| 43 | - else |
|
| 45 | + } else |
|
| 44 | 46 | { |
| 45 | 47 | $board_query = ' AND ' . $user_info['mod_cache']['bq']; |
| 46 | 48 | } |
@@ -76,17 +78,17 @@ discard block |
||
| 76 | 78 | ) |
| 77 | 79 | ); |
| 78 | 80 | |
| 79 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 80 | - $extra[$row['id_report']] = array( |
|
| 81 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 82 | + $extra[$row['id_report']] = array( |
|
| 81 | 83 | 'report' => $row['id_report'], |
| 82 | 84 | 'board' => $row['id_board'], |
| 83 | 85 | 'message' => $row['id_msg'], |
| 84 | 86 | 'topic' => $row['id_topic'], |
| 85 | 87 | ); |
| 88 | + } |
|
| 86 | 89 | |
| 87 | 90 | $smcFunc['db_free_result']($request); |
| 88 | - } |
|
| 89 | - else |
|
| 91 | + } else |
|
| 90 | 92 | { |
| 91 | 93 | $request = $smcFunc['db_query']('', ' |
| 92 | 94 | SELECT id_report, id_member, membername |
@@ -97,28 +99,32 @@ discard block |
||
| 97 | 99 | ) |
| 98 | 100 | ); |
| 99 | 101 | |
| 100 | - while($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 101 | - $extra[$row['id_report']] = array( |
|
| 102 | + while($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 103 | + $extra[$row['id_report']] = array( |
|
| 102 | 104 | 'report' => $row['id_report'], |
| 103 | 105 | 'member' => $row['id_member'], |
| 104 | 106 | ); |
| 107 | + } |
|
| 105 | 108 | |
| 106 | 109 | $smcFunc['db_free_result']($request); |
| 107 | 110 | } |
| 108 | 111 | |
| 109 | 112 | // Back to "ignore". |
| 110 | - if ($action == 'ignore_all') |
|
| 111 | - $action = 'ignore'; |
|
| 113 | + if ($action == 'ignore_all') { |
|
| 114 | + $action = 'ignore'; |
|
| 115 | + } |
|
| 112 | 116 | |
| 113 | 117 | $log_report = $action == 'ignore' ? (!empty($value) ? 'ignore' : 'unignore') : (!empty($value) ? 'close' : 'open'); |
| 114 | 118 | |
| 115 | - if ($context['report_type'] == 'members') |
|
| 116 | - $log_report .= '_user'; |
|
| 119 | + if ($context['report_type'] == 'members') { |
|
| 120 | + $log_report .= '_user'; |
|
| 121 | + } |
|
| 117 | 122 | |
| 118 | 123 | // Log this action. |
| 119 | - if (!empty($extra)) |
|
| 120 | - foreach ($extra as $report) |
|
| 124 | + if (!empty($extra)) { |
|
| 125 | + foreach ($extra as $report) |
|
| 121 | 126 | logAction($log_report . '_report', $report); |
| 127 | + } |
|
| 122 | 128 | |
| 123 | 129 | // Time to update. |
| 124 | 130 | updateSettings(array('last_mod_report_action' => time())); |
@@ -142,14 +148,12 @@ discard block |
||
| 142 | 148 | if ($context['report_type'] == 'members') |
| 143 | 149 | { |
| 144 | 150 | $and = 'lr.id_board = 0'; |
| 145 | - } |
|
| 146 | - else |
|
| 151 | + } else |
|
| 147 | 152 | { |
| 148 | 153 | if ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1') |
| 149 | 154 | { |
| 150 | 155 | $bq = $user_info['mod_cache']['bq']; |
| 151 | - } |
|
| 152 | - else |
|
| 156 | + } else |
|
| 153 | 157 | { |
| 154 | 158 | $bq = 'lr.' . $user_info['mod_cache']['bq']; |
| 155 | 159 | } |
@@ -205,8 +209,7 @@ discard block |
||
| 205 | 209 | 'max' => 10, |
| 206 | 210 | ) |
| 207 | 211 | ); |
| 208 | - } |
|
| 209 | - else |
|
| 212 | + } else |
|
| 210 | 213 | { |
| 211 | 214 | $request = $smcFunc['db_query']('', ' |
| 212 | 215 | SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body, |
@@ -254,8 +257,7 @@ discard block |
||
| 254 | 257 | 'href' => $scripturl . '?action=profile;u=' . $row['id_user'], |
| 255 | 258 | ), |
| 256 | 259 | ); |
| 257 | - } |
|
| 258 | - else |
|
| 260 | + } else |
|
| 259 | 261 | { |
| 260 | 262 | $report_boards_ids[] = $row['id_board']; |
| 261 | 263 | $extraDetails = array( |
@@ -295,14 +297,16 @@ discard block |
||
| 295 | 297 | ) |
| 296 | 298 | ); |
| 297 | 299 | |
| 298 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 299 | - $board_names[$row['id_board']] = $row['name']; |
|
| 300 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 301 | + $board_names[$row['id_board']] = $row['name']; |
|
| 302 | + } |
|
| 300 | 303 | |
| 301 | 304 | $smcFunc['db_free_result']($request); |
| 302 | 305 | |
| 303 | - foreach ($reports as $id_report => $report) |
|
| 304 | - if (!empty($board_names[$report['topic']['id_board']])) |
|
| 306 | + foreach ($reports as $id_report => $report) { |
|
| 307 | + if (!empty($board_names[$report['topic']['id_board']])) |
|
| 305 | 308 | $reports[$id_report]['topic']['board_name'] = $board_names[$report['topic']['id_board']]; |
| 309 | + } |
|
| 306 | 310 | } |
| 307 | 311 | |
| 308 | 312 | // Now get all the people who reported it. |
@@ -352,10 +356,11 @@ discard block |
||
| 352 | 356 | { |
| 353 | 357 | global $user_info, $smcFunc; |
| 354 | 358 | |
| 355 | - if ($type == 'members') |
|
| 356 | - $bq = ''; |
|
| 357 | - else |
|
| 358 | - $bq = ' AND ' . $user_info['mod_cache']['bq']; |
|
| 359 | + if ($type == 'members') { |
|
| 360 | + $bq = ''; |
|
| 361 | + } else { |
|
| 362 | + $bq = ' AND ' . $user_info['mod_cache']['bq']; |
|
| 363 | + } |
|
| 359 | 364 | |
| 360 | 365 | $request = $smcFunc['db_query']('', ' |
| 361 | 366 | SELECT COUNT(*) |
@@ -394,8 +399,9 @@ discard block |
||
| 394 | 399 | { |
| 395 | 400 | global $smcFunc, $user_info, $context; |
| 396 | 401 | |
| 397 | - if (empty($report_id)) |
|
| 398 | - return false; |
|
| 402 | + if (empty($report_id)) { |
|
| 403 | + return false; |
|
| 404 | + } |
|
| 399 | 405 | |
| 400 | 406 | // We don't need all this info if we're only getting user info |
| 401 | 407 | if ($context['report_type'] == 'members') |
@@ -413,8 +419,7 @@ discard block |
||
| 413 | 419 | 'id_report' => $report_id, |
| 414 | 420 | ) |
| 415 | 421 | ); |
| 416 | - } |
|
| 417 | - else |
|
| 422 | + } else |
|
| 418 | 423 | { |
| 419 | 424 | // Get the report details, need this so we can limit access to a particular board. |
| 420 | 425 | $request = $smcFunc['db_query']('', ' |
@@ -433,8 +438,9 @@ discard block |
||
| 433 | 438 | } |
| 434 | 439 | |
| 435 | 440 | // So did we find anything? |
| 436 | - if (!$smcFunc['db_num_rows']($request)) |
|
| 437 | - return false; |
|
| 441 | + if (!$smcFunc['db_num_rows']($request)) { |
|
| 442 | + return false; |
|
| 443 | + } |
|
| 438 | 444 | |
| 439 | 445 | // Woohoo we found a report and they can see it! |
| 440 | 446 | $row = $smcFunc['db_fetch_assoc']($request); |
@@ -453,8 +459,9 @@ discard block |
||
| 453 | 459 | { |
| 454 | 460 | global $smcFunc, $scripturl, $user_info, $txt; |
| 455 | 461 | |
| 456 | - if (empty($report_id)) |
|
| 457 | - return false; |
|
| 462 | + if (empty($report_id)) { |
|
| 463 | + return false; |
|
| 464 | + } |
|
| 458 | 465 | |
| 459 | 466 | $report = array( |
| 460 | 467 | 'comments' => array(), |
@@ -535,8 +542,9 @@ discard block |
||
| 535 | 542 | { |
| 536 | 543 | global $smcFunc, $user_info; |
| 537 | 544 | |
| 538 | - if (empty($comment_id)) |
|
| 539 | - return false; |
|
| 545 | + if (empty($comment_id)) { |
|
| 546 | + return false; |
|
| 547 | + } |
|
| 540 | 548 | |
| 541 | 549 | $request = $smcFunc['db_query']('', ' |
| 542 | 550 | SELECT id_comment, id_notice, log_time, body, id_member |
@@ -553,8 +561,9 @@ discard block |
||
| 553 | 561 | $smcFunc['db_free_result']($request); |
| 554 | 562 | |
| 555 | 563 | // Add the permission |
| 556 | - if (!empty($comment)) |
|
| 557 | - $comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member'])); |
|
| 564 | + if (!empty($comment)) { |
|
| 565 | + $comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member'])); |
|
| 566 | + } |
|
| 558 | 567 | |
| 559 | 568 | return $comment; |
| 560 | 569 | } |
@@ -570,8 +579,9 @@ discard block |
||
| 570 | 579 | { |
| 571 | 580 | global $smcFunc, $user_info, $context; |
| 572 | 581 | |
| 573 | - if (empty($data)) |
|
| 574 | - return false; |
|
| 582 | + if (empty($data)) { |
|
| 583 | + return false; |
|
| 584 | + } |
|
| 575 | 585 | |
| 576 | 586 | $data = array_merge(array($user_info['id'], $user_info['name'], 'reportc', ''), $data); |
| 577 | 587 | |
@@ -600,8 +610,7 @@ discard block |
||
| 600 | 610 | 'comment_id' => $last_comment, |
| 601 | 611 | 'time' => time(), |
| 602 | 612 | ); |
| 603 | - } |
|
| 604 | - else |
|
| 613 | + } else |
|
| 605 | 614 | { |
| 606 | 615 | $prefix = 'Msg'; |
| 607 | 616 | $data = array( |
@@ -617,14 +626,15 @@ discard block |
||
| 617 | 626 | } |
| 618 | 627 | |
| 619 | 628 | // And get ready to notify people. |
| 620 | - if (!empty($report)) |
|
| 621 | - $smcFunc['db_insert']('insert', |
|
| 629 | + if (!empty($report)) { |
|
| 630 | + $smcFunc['db_insert']('insert', |
|
| 622 | 631 | '{db_prefix}background_tasks', |
| 623 | 632 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 624 | 633 | array('$sourcedir/tasks/' . $prefix . 'ReportReply-Notify.php', $prefix . 'ReportReply_Notify_Background', json_encode($data), 0), |
| 625 | 634 | array('id_task') |
| 626 | 635 | ); |
| 627 | -} |
|
| 636 | + } |
|
| 637 | + } |
|
| 628 | 638 | |
| 629 | 639 | /** |
| 630 | 640 | * Saves the new information whenever a moderator comment is edited. |
@@ -637,8 +647,9 @@ discard block |
||
| 637 | 647 | { |
| 638 | 648 | global $smcFunc; |
| 639 | 649 | |
| 640 | - if (empty($comment_id) || empty($edited_comment)) |
|
| 641 | - return false; |
|
| 650 | + if (empty($comment_id) || empty($edited_comment)) { |
|
| 651 | + return false; |
|
| 652 | + } |
|
| 642 | 653 | |
| 643 | 654 | $smcFunc['db_query']('', ' |
| 644 | 655 | UPDATE {db_prefix}log_comments |
@@ -661,8 +672,9 @@ discard block |
||
| 661 | 672 | { |
| 662 | 673 | global $smcFunc; |
| 663 | 674 | |
| 664 | - if (empty($comment_id)) |
|
| 665 | - return false; |
|
| 675 | + if (empty($comment_id)) { |
|
| 676 | + return false; |
|
| 677 | + } |
|
| 666 | 678 | |
| 667 | 679 | $smcFunc['db_query']('', ' |
| 668 | 680 | DELETE FROM {db_prefix}log_comments |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | * Used by VerificationCode() (Register.php). |
| 25 | 25 | * |
| 26 | 26 | * @param string $word |
| 27 | - * @return boolean false on failure |
|
| 27 | + * @return null|false false on failure |
|
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | 30 | function createWaveFile($word) |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20); |
| 39 | 39 | |
| 40 | 40 | // Fixate randomization for this word. |
| 41 | - $tmp = unpack('n', md5($word . session_id())); |
|
| 41 | + $tmp = unpack('n', md5($word . session_id())); |
|
| 42 | 42 | mt_srand(end($tmp)); |
| 43 | 43 | |
| 44 | 44 | // Try to see if there's a sound font in the user's language. |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 3 |
| 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 | * Creates a wave file that spells the letters of $word. |
@@ -32,8 +33,9 @@ discard block |
||
| 32 | 33 | global $settings, $user_info; |
| 33 | 34 | |
| 34 | 35 | // Allow max 2 requests per 20 seconds. |
| 35 | - if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) |
|
| 36 | - die(header('HTTP/1.1 400 Bad Request')); |
|
| 36 | + if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) { |
|
| 37 | + die(header('HTTP/1.1 400 Bad Request')); |
|
| 38 | + } |
|
| 37 | 39 | cache_put_data('wave_file/' . $user_info['ip'], $ip ? $ip + 1 : 1, 20); |
| 38 | 40 | cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20); |
| 39 | 41 | |
@@ -42,16 +44,19 @@ discard block |
||
| 42 | 44 | mt_srand(end($tmp)); |
| 43 | 45 | |
| 44 | 46 | // Try to see if there's a sound font in the user's language. |
| 45 | - if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) |
|
| 46 | - $sound_language = $user_info['language']; |
|
| 47 | + if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) { |
|
| 48 | + $sound_language = $user_info['language']; |
|
| 49 | + } |
|
| 47 | 50 | |
| 48 | 51 | // English should be there. |
| 49 | - elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) |
|
| 50 | - $sound_language = 'english'; |
|
| 52 | + elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) { |
|
| 53 | + $sound_language = 'english'; |
|
| 54 | + } |
|
| 51 | 55 | |
| 52 | 56 | // Guess not... |
| 53 | - else |
|
| 54 | - return false; |
|
| 57 | + else { |
|
| 58 | + return false; |
|
| 59 | + } |
|
| 55 | 60 | |
| 56 | 61 | // File names are in lower case so lets make sure that we are only using a lower case string |
| 57 | 62 | $word = strtolower($word); |
@@ -61,20 +66,25 @@ discard block |
||
| 61 | 66 | for ($i = 0; $i < strlen($word); $i++) |
| 62 | 67 | { |
| 63 | 68 | $sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav')); |
| 64 | - if (strpos($sound_letter, 'data') === false) |
|
| 65 | - return false; |
|
| 69 | + if (strpos($sound_letter, 'data') === false) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 66 | 72 | |
| 67 | 73 | $sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8); |
| 68 | 74 | switch ($word{$i} === 's' ? 0 : mt_rand(0, 2)) |
| 69 | 75 | { |
| 70 | - case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) |
|
| 71 | - for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) |
|
| 72 | - $sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF))); |
|
| 76 | + case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) { |
|
| 77 | + for ($k = 0, $m = round(mt_rand(15, 25) / 10); |
|
| 78 | + } |
|
| 79 | + $k < $m; $k++) { |
|
| 80 | + $sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF))); |
|
| 81 | + } |
|
| 73 | 82 | break; |
| 74 | 83 | |
| 75 | 84 | case 1: |
| 76 | - for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) |
|
| 77 | - $sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : ''); |
|
| 85 | + for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) { |
|
| 86 | + $sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : ''); |
|
| 87 | + } |
|
| 78 | 88 | $sound_word .= str_repeat($sound_letter{$n}, 2); |
| 79 | 89 | break; |
| 80 | 90 | |
@@ -82,10 +92,12 @@ discard block |
||
| 82 | 92 | $shift = 0; |
| 83 | 93 | for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) |
| 84 | 94 | { |
| 85 | - if (mt_rand(0, 10) === 0) |
|
| 86 | - $shift += mt_rand(-3, 3); |
|
| 87 | - for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) |
|
| 88 | - $sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF)); |
|
| 95 | + if (mt_rand(0, 10) === 0) { |
|
| 96 | + $shift += mt_rand(-3, 3); |
|
| 97 | + } |
|
| 98 | + for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) { |
|
| 99 | + $sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF)); |
|
| 100 | + } |
|
| 89 | 101 | } |
| 90 | 102 | break; |
| 91 | 103 | |
@@ -425,7 +425,7 @@ |
||
| 425 | 425 | * |
| 426 | 426 | * This is a recursive function, it will call itself if there are subdirs inside the main directory. |
| 427 | 427 | * @param string $path The absolute path to the directory to be removed |
| 428 | - * @return bool true when success, false on error. |
|
| 428 | + * @return false|null true when success, false on error. |
|
| 429 | 429 | */ |
| 430 | 430 | function remove_dir($path) |
| 431 | 431 | { |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 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 | * Gets a single theme's info. |
@@ -27,8 +28,9 @@ discard block |
||
| 27 | 28 | global $smcFunc, $modSettings; |
| 28 | 29 | |
| 29 | 30 | // No data, no fun! |
| 30 | - if (empty($id)) |
|
| 31 | - return false; |
|
| 31 | + if (empty($id)) { |
|
| 32 | + return false; |
|
| 33 | + } |
|
| 32 | 34 | |
| 33 | 35 | // Make sure $id is an int. |
| 34 | 36 | $id = (int) $id; |
@@ -171,8 +173,9 @@ discard block |
||
| 171 | 173 | global $sourcedir, $forum_version, $txt, $scripturl, $context; |
| 172 | 174 | global $explicit_images; |
| 173 | 175 | |
| 174 | - if (empty($path)) |
|
| 175 | - return false; |
|
| 176 | + if (empty($path)) { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 176 | 179 | |
| 177 | 180 | $xml_data = array(); |
| 178 | 181 | $explicit_images = false; |
@@ -229,9 +232,10 @@ discard block |
||
| 229 | 232 | ); |
| 230 | 233 | |
| 231 | 234 | // Assign the values to be stored. |
| 232 | - foreach ($xml_elements as $var => $name) |
|
| 233 | - if (!empty($theme_info_xml[$name])) |
|
| 235 | + foreach ($xml_elements as $var => $name) { |
|
| 236 | + if (!empty($theme_info_xml[$name])) |
|
| 234 | 237 | $xml_data[$var] = $theme_info_xml[$name]; |
| 238 | + } |
|
| 235 | 239 | |
| 236 | 240 | // Add the supported versions. |
| 237 | 241 | $xml_data['install_for'] = $install_versions; |
@@ -243,8 +247,9 @@ discard block |
||
| 243 | 247 | $explicit_images = true; |
| 244 | 248 | } |
| 245 | 249 | |
| 246 | - if (!empty($theme_info_xml['extra'])) |
|
| 247 | - $xml_data += smf_json_decode($theme_info_xml['extra'], true); |
|
| 250 | + if (!empty($theme_info_xml['extra'])) { |
|
| 251 | + $xml_data += smf_json_decode($theme_info_xml['extra'], true); |
|
| 252 | + } |
|
| 248 | 253 | |
| 249 | 254 | return $xml_data; |
| 250 | 255 | } |
@@ -262,12 +267,14 @@ discard block |
||
| 262 | 267 | global $settings, $explicit_images; |
| 263 | 268 | |
| 264 | 269 | // External use? no problem! |
| 265 | - if ($to_install) |
|
| 266 | - $context['to_install'] = $to_install; |
|
| 270 | + if ($to_install) { |
|
| 271 | + $context['to_install'] = $to_install; |
|
| 272 | + } |
|
| 267 | 273 | |
| 268 | 274 | // One last check. |
| 269 | - if (empty($context['to_install']['theme_dir']) || basename($context['to_install']['theme_dir']) == 'Themes') |
|
| 270 | - fatal_lang_error('theme_install_invalid_dir', false); |
|
| 275 | + if (empty($context['to_install']['theme_dir']) || basename($context['to_install']['theme_dir']) == 'Themes') { |
|
| 276 | + fatal_lang_error('theme_install_invalid_dir', false); |
|
| 277 | + } |
|
| 271 | 278 | |
| 272 | 279 | // OK, is this a newer version of an already installed theme? |
| 273 | 280 | if (!empty($context['to_install']['version'])) |
@@ -292,8 +299,8 @@ discard block |
||
| 292 | 299 | $smcFunc['db_free_result']($request); |
| 293 | 300 | |
| 294 | 301 | // Got something, lets figure it out what to do next. |
| 295 | - if (!empty($to_update) && !empty($to_update['version'])) |
|
| 296 | - switch (compareVersions($context['to_install']['version'], $to_update['version'])) |
|
| 302 | + if (!empty($to_update) && !empty($to_update['version'])) { |
|
| 303 | + switch (compareVersions($context['to_install']['version'], $to_update['version'])) |
|
| 297 | 304 | { |
| 298 | 305 | case 1: // Got a newer version, update the old entry. |
| 299 | 306 | $smcFunc['db_query']('', ' |
@@ -307,6 +314,7 @@ discard block |
||
| 307 | 314 | 'id_theme' => $to_update['id_theme'], |
| 308 | 315 | ) |
| 309 | 316 | ); |
| 317 | + } |
|
| 310 | 318 | |
| 311 | 319 | // Done with the update, tell the user about it. |
| 312 | 320 | $context['to_install']['updated'] = true; |
@@ -372,13 +380,15 @@ discard block |
||
| 372 | 380 | $context['to_install']['base_theme_url'] = $temp['theme_url']; |
| 373 | 381 | $context['to_install']['base_theme_dir'] = $temp['theme_dir']; |
| 374 | 382 | |
| 375 | - if (empty($explicit_images) && !empty($context['to_install']['base_theme_url'])) |
|
| 376 | - $context['to_install']['theme_url'] = $context['to_install']['base_theme_url']; |
|
| 383 | + if (empty($explicit_images) && !empty($context['to_install']['base_theme_url'])) { |
|
| 384 | + $context['to_install']['theme_url'] = $context['to_install']['base_theme_url']; |
|
| 385 | + } |
|
| 377 | 386 | } |
| 378 | 387 | |
| 379 | 388 | // Nope, sorry, couldn't find any theme already installed. |
| 380 | - else |
|
| 381 | - fatal_lang_error('package_get_error_theme_no_based_on_found', false, $context['to_install']['based_on']); |
|
| 389 | + else { |
|
| 390 | + fatal_lang_error('package_get_error_theme_no_based_on_found', false, $context['to_install']['based_on']); |
|
| 391 | + } |
|
| 382 | 392 | } |
| 383 | 393 | |
| 384 | 394 | unset($context['to_install']['based_on']); |
@@ -401,16 +411,18 @@ discard block |
||
| 401 | 411 | call_integration_hook('integrate_theme_install', array(&$context['to_install'], $id_theme)); |
| 402 | 412 | |
| 403 | 413 | $inserts = array(); |
| 404 | - foreach ($context['to_install'] as $var => $val) |
|
| 405 | - $inserts[] = array($id_theme, $var, $val); |
|
| 414 | + foreach ($context['to_install'] as $var => $val) { |
|
| 415 | + $inserts[] = array($id_theme, $var, $val); |
|
| 416 | + } |
|
| 406 | 417 | |
| 407 | - if (!empty($inserts)) |
|
| 408 | - $smcFunc['db_insert']('insert', |
|
| 418 | + if (!empty($inserts)) { |
|
| 419 | + $smcFunc['db_insert']('insert', |
|
| 409 | 420 | '{db_prefix}themes', |
| 410 | 421 | array('id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'), |
| 411 | 422 | $inserts, |
| 412 | 423 | array('id_theme', 'variable') |
| 413 | 424 | ); |
| 425 | + } |
|
| 414 | 426 | |
| 415 | 427 | // Update the known and enable Theme's settings. |
| 416 | 428 | $known = strtr($modSettings['knownThemes'] . ',' . $id_theme, array(',,' => ',')); |
@@ -429,21 +441,24 @@ discard block |
||
| 429 | 441 | */ |
| 430 | 442 | function remove_dir($path) |
| 431 | 443 | { |
| 432 | - if (empty($path)) |
|
| 433 | - return false; |
|
| 444 | + if (empty($path)) { |
|
| 445 | + return false; |
|
| 446 | + } |
|
| 434 | 447 | |
| 435 | 448 | if (is_dir($path)) |
| 436 | 449 | { |
| 437 | 450 | $objects = scandir($path); |
| 438 | 451 | |
| 439 | - foreach ($objects as $object) |
|
| 440 | - if ($object != '.' && $object != '..') |
|
| 452 | + foreach ($objects as $object) { |
|
| 453 | + if ($object != '.' && $object != '..') |
|
| 441 | 454 | { |
| 442 | 455 | if (filetype($path . '/' . $object) == 'dir') |
| 443 | 456 | remove_dir($path . '/' . $object); |
| 457 | + } |
|
| 444 | 458 | |
| 445 | - else |
|
| 446 | - unlink($path . '/' . $object); |
|
| 459 | + else { |
|
| 460 | + unlink($path . '/' . $object); |
|
| 461 | + } |
|
| 447 | 462 | } |
| 448 | 463 | } |
| 449 | 464 | |
@@ -462,8 +477,9 @@ discard block |
||
| 462 | 477 | global $smcFunc, $modSettings; |
| 463 | 478 | |
| 464 | 479 | // Can't delete the default theme, sorry! |
| 465 | - if (empty($themeID) || $themeID == 1) |
|
| 466 | - return false; |
|
| 480 | + if (empty($themeID) || $themeID == 1) { |
|
| 481 | + return false; |
|
| 482 | + } |
|
| 467 | 483 | |
| 468 | 484 | $known = explode(',', $modSettings['knownThemes']); |
| 469 | 485 | $enable = explode(',', $modSettings['enableThemes']); |
@@ -513,8 +529,9 @@ discard block |
||
| 513 | 529 | updateSettings(array('enableThemes' => $enable, 'knownThemes' => $known)); |
| 514 | 530 | |
| 515 | 531 | // Fix it if the theme was the overall default theme. |
| 516 | - if ($modSettings['theme_guests'] == $themeID) |
|
| 517 | - updateSettings(array('theme_guests' => '1')); |
|
| 532 | + if ($modSettings['theme_guests'] == $themeID) { |
|
| 533 | + updateSettings(array('theme_guests' => '1')); |
|
| 534 | + } |
|
| 518 | 535 | |
| 519 | 536 | return true; |
| 520 | 537 | } |
@@ -531,13 +548,15 @@ discard block |
||
| 531 | 548 | global $scripturl, $txt, $context; |
| 532 | 549 | |
| 533 | 550 | // Is it even a directory? |
| 534 | - if (!is_dir($path)) |
|
| 535 | - fatal_lang_error('error_invalid_dir', 'critical'); |
|
| 551 | + if (!is_dir($path)) { |
|
| 552 | + fatal_lang_error('error_invalid_dir', 'critical'); |
|
| 553 | + } |
|
| 536 | 554 | |
| 537 | 555 | $dir = dir($path); |
| 538 | 556 | $entries = array(); |
| 539 | - while ($entry = $dir->read()) |
|
| 540 | - $entries[] = $entry; |
|
| 557 | + while ($entry = $dir->read()) { |
|
| 558 | + $entries[] = $entry; |
|
| 559 | + } |
|
| 541 | 560 | $dir->close(); |
| 542 | 561 | |
| 543 | 562 | natcasesort($entries); |
@@ -548,11 +567,12 @@ discard block |
||
| 548 | 567 | foreach ($entries as $entry) |
| 549 | 568 | { |
| 550 | 569 | // Skip all dot files, including .htaccess. |
| 551 | - if (substr($entry, 0, 1) == '.' || $entry == 'CVS') |
|
| 552 | - continue; |
|
| 570 | + if (substr($entry, 0, 1) == '.' || $entry == 'CVS') { |
|
| 571 | + continue; |
|
| 572 | + } |
|
| 553 | 573 | |
| 554 | - if (is_dir($path . '/' . $entry)) |
|
| 555 | - $listing1[] = array( |
|
| 574 | + if (is_dir($path . '/' . $entry)) { |
|
| 575 | + $listing1[] = array( |
|
| 556 | 576 | 'filename' => $entry, |
| 557 | 577 | 'is_writable' => is_writable($path . '/' . $entry), |
| 558 | 578 | 'is_directory' => true, |
@@ -562,13 +582,14 @@ discard block |
||
| 562 | 582 | 'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $relative . $entry, |
| 563 | 583 | 'size' => '', |
| 564 | 584 | ); |
| 565 | - else |
|
| 585 | + } else |
|
| 566 | 586 | { |
| 567 | 587 | $size = filesize($path . '/' . $entry); |
| 568 | - if ($size > 2048 || $size == 1024) |
|
| 569 | - $size = comma_format($size / 1024) . ' ' . $txt['themeadmin_edit_kilobytes']; |
|
| 570 | - else |
|
| 571 | - $size = comma_format($size) . ' ' . $txt['themeadmin_edit_bytes']; |
|
| 588 | + if ($size > 2048 || $size == 1024) { |
|
| 589 | + $size = comma_format($size / 1024) . ' ' . $txt['themeadmin_edit_kilobytes']; |
|
| 590 | + } else { |
|
| 591 | + $size = comma_format($size) . ' ' . $txt['themeadmin_edit_bytes']; |
|
| 592 | + } |
|
| 572 | 593 | |
| 573 | 594 | $listing2[] = array( |
| 574 | 595 | 'filename' => $entry, |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | * - caches the formatting data from the setting for optimization. |
| 677 | 677 | * |
| 678 | 678 | * @param float $number A number |
| 679 | - * @param bool|int $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined |
|
| 679 | + * @param integer $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined |
|
| 680 | 680 | * @return string A formatted number |
| 681 | 681 | */ |
| 682 | 682 | function comma_format($number, $override_decimal_count = false) |
@@ -4987,7 +4987,7 @@ discard block |
||
| 4987 | 4987 | |
| 4988 | 4988 | /** |
| 4989 | 4989 | * @param string $ip_address An IP address in IPv4, IPv6 or decimal notation |
| 4990 | - * @return binary The IP address in binary or false |
|
| 4990 | + * @return string The IP address in binary or false |
|
| 4991 | 4991 | */ |
| 4992 | 4992 | function inet_ptod($ip_address) |
| 4993 | 4993 | { |
@@ -5385,7 +5385,7 @@ discard block |
||
| 5385 | 5385 | * It assumes the data is already a string. |
| 5386 | 5386 | * @param string $data The data to print |
| 5387 | 5387 | * @param string $type The content type. Defaults to Json. |
| 5388 | - * @return void |
|
| 5388 | + * @return false|null |
|
| 5389 | 5389 | */ |
| 5390 | 5390 | function smf_serverResponse($data = '', $type = 'Content-Type: application/json') |
| 5391 | 5391 | { |
@@ -5265,7 +5265,6 @@ discard block |
||
| 5265 | 5265 | |
| 5266 | 5266 | /** |
| 5267 | 5267 | * Tries different modes to make file/dirs writable. Wrapper function for chmod() |
| 5268 | - |
|
| 5269 | 5268 | * @param string $file The file/dir full path. |
| 5270 | 5269 | * @param int $value Not needed, added for legacy reasons. |
| 5271 | 5270 | * @return boolean true if the file/dir is already writable or the function was able to make it writable, false if the function couldn't make the file/dir writable. |
@@ -5305,7 +5304,6 @@ discard block |
||
| 5305 | 5304 | |
| 5306 | 5305 | /** |
| 5307 | 5306 | * Wrapper function for json_decode() with error handling. |
| 5308 | - |
|
| 5309 | 5307 | * @param string $json The string to decode. |
| 5310 | 5308 | * @param bool $returnAsArray To return the decoded string as an array or an object, SMF only uses Arrays but to keep on compatibility with json_decode its set to false as default. |
| 5311 | 5309 | * @param bool $logIt To specify if the error will be logged if theres any. |
@@ -1097,7 +1097,7 @@ discard block |
||
| 1097 | 1097 | 'height' => array('optional' => true, 'match' => '(\d+)'), |
| 1098 | 1098 | ), |
| 1099 | 1099 | 'content' => '$1', |
| 1100 | - 'validate' => function (&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt) |
|
| 1100 | + 'validate' => function(&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt) |
|
| 1101 | 1101 | { |
| 1102 | 1102 | $returnContext = ''; |
| 1103 | 1103 | |
@@ -1132,7 +1132,7 @@ discard block |
||
| 1132 | 1132 | } |
| 1133 | 1133 | |
| 1134 | 1134 | if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
| 1135 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '"></a>'; |
|
| 1135 | + $returnContext .= '<a href="' . $currentAttachment['href'] . ';image" id="link_' . $currentAttachment['id'] . '" onclick="' . $currentAttachment['thumbnail']['javascript'] . '"><img src="' . $currentAttachment['thumbnail']['href'] . '"' . $alt . $title . ' id="thumb_' . $currentAttachment['id'] . '"></a>'; |
|
| 1136 | 1136 | else |
| 1137 | 1137 | $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . '/>'; |
| 1138 | 1138 | } |
@@ -1161,7 +1161,7 @@ discard block |
||
| 1161 | 1161 | 'type' => 'unparsed_content', |
| 1162 | 1162 | 'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>', |
| 1163 | 1163 | // @todo Maybe this can be simplified? |
| 1164 | - 'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context) |
|
| 1164 | + 'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context) |
|
| 1165 | 1165 | { |
| 1166 | 1166 | if (!isset($disabled['code'])) |
| 1167 | 1167 | { |
@@ -1198,7 +1198,7 @@ discard block |
||
| 1198 | 1198 | 'type' => 'unparsed_equals_content', |
| 1199 | 1199 | 'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> ($2) <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>', |
| 1200 | 1200 | // @todo Maybe this can be simplified? |
| 1201 | - 'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context) |
|
| 1201 | + 'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context) |
|
| 1202 | 1202 | { |
| 1203 | 1203 | if (!isset($disabled['code'])) |
| 1204 | 1204 | { |
@@ -1242,7 +1242,7 @@ discard block |
||
| 1242 | 1242 | 'type' => 'unparsed_content', |
| 1243 | 1243 | 'content' => '<a href="mailto:$1" class="bbc_email">$1</a>', |
| 1244 | 1244 | // @todo Should this respect guest_hideContacts? |
| 1245 | - 'validate' => function (&$tag, &$data, $disabled) |
|
| 1245 | + 'validate' => function(&$tag, &$data, $disabled) |
|
| 1246 | 1246 | { |
| 1247 | 1247 | $data = strtr($data, array('<br>' => '')); |
| 1248 | 1248 | }, |
@@ -1261,7 +1261,7 @@ discard block |
||
| 1261 | 1261 | 'type' => 'unparsed_commas_content', |
| 1262 | 1262 | 'test' => '\d+,\d+\]', |
| 1263 | 1263 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
| 1264 | - 'validate' => function (&$tag, &$data, $disabled) |
|
| 1264 | + 'validate' => function(&$tag, &$data, $disabled) |
|
| 1265 | 1265 | { |
| 1266 | 1266 | if (isset($disabled['url'])) |
| 1267 | 1267 | $tag['content'] = '$1'; |
@@ -1306,7 +1306,7 @@ discard block |
||
| 1306 | 1306 | 'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'), |
| 1307 | 1307 | ), |
| 1308 | 1308 | 'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">', |
| 1309 | - 'validate' => function (&$tag, &$data, $disabled) |
|
| 1309 | + 'validate' => function(&$tag, &$data, $disabled) |
|
| 1310 | 1310 | { |
| 1311 | 1311 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
| 1312 | 1312 | |
@@ -1329,7 +1329,7 @@ discard block |
||
| 1329 | 1329 | 'tag' => 'img', |
| 1330 | 1330 | 'type' => 'unparsed_content', |
| 1331 | 1331 | 'content' => '<img src="$1" alt="" class="bbc_img">', |
| 1332 | - 'validate' => function (&$tag, &$data, $disabled) |
|
| 1332 | + 'validate' => function(&$tag, &$data, $disabled) |
|
| 1333 | 1333 | { |
| 1334 | 1334 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
| 1335 | 1335 | |
@@ -1352,7 +1352,7 @@ discard block |
||
| 1352 | 1352 | 'tag' => 'iurl', |
| 1353 | 1353 | 'type' => 'unparsed_content', |
| 1354 | 1354 | 'content' => '<a href="$1" class="bbc_link">$1</a>', |
| 1355 | - 'validate' => function (&$tag, &$data, $disabled) |
|
| 1355 | + 'validate' => function(&$tag, &$data, $disabled) |
|
| 1356 | 1356 | { |
| 1357 | 1357 | $data = strtr($data, array('<br>' => '')); |
| 1358 | 1358 | $scheme = parse_url($data, PHP_URL_SCHEME); |
@@ -1366,7 +1366,7 @@ discard block |
||
| 1366 | 1366 | 'quoted' => 'optional', |
| 1367 | 1367 | 'before' => '<a href="$1" class="bbc_link">', |
| 1368 | 1368 | 'after' => '</a>', |
| 1369 | - 'validate' => function (&$tag, &$data, $disabled) |
|
| 1369 | + 'validate' => function(&$tag, &$data, $disabled) |
|
| 1370 | 1370 | { |
| 1371 | 1371 | if (substr($data, 0, 1) == '#') |
| 1372 | 1372 | $data = '#post_' . substr($data, 1); |
@@ -1446,7 +1446,7 @@ discard block |
||
| 1446 | 1446 | 'tag' => 'php', |
| 1447 | 1447 | 'type' => 'unparsed_content', |
| 1448 | 1448 | 'content' => '<span class="phpcode">$1</span>', |
| 1449 | - 'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled) |
|
| 1449 | + 'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled) |
|
| 1450 | 1450 | { |
| 1451 | 1451 | if (!isset($disabled['php'])) |
| 1452 | 1452 | { |
@@ -1544,7 +1544,7 @@ discard block |
||
| 1544 | 1544 | 'test' => '[1-7]\]', |
| 1545 | 1545 | 'before' => '<span style="font-size: $1;" class="bbc_size">', |
| 1546 | 1546 | 'after' => '</span>', |
| 1547 | - 'validate' => function (&$tag, &$data, $disabled) |
|
| 1547 | + 'validate' => function(&$tag, &$data, $disabled) |
|
| 1548 | 1548 | { |
| 1549 | 1549 | $sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95); |
| 1550 | 1550 | $data = $sizes[$data] . 'em'; |
@@ -1582,7 +1582,7 @@ discard block |
||
| 1582 | 1582 | 'tag' => 'time', |
| 1583 | 1583 | 'type' => 'unparsed_content', |
| 1584 | 1584 | 'content' => '$1', |
| 1585 | - 'validate' => function (&$tag, &$data, $disabled) |
|
| 1585 | + 'validate' => function(&$tag, &$data, $disabled) |
|
| 1586 | 1586 | { |
| 1587 | 1587 | if (is_numeric($data)) |
| 1588 | 1588 | $data = timeformat($data); |
@@ -1610,7 +1610,7 @@ discard block |
||
| 1610 | 1610 | 'tag' => 'url', |
| 1611 | 1611 | 'type' => 'unparsed_content', |
| 1612 | 1612 | 'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>', |
| 1613 | - 'validate' => function (&$tag, &$data, $disabled) |
|
| 1613 | + 'validate' => function(&$tag, &$data, $disabled) |
|
| 1614 | 1614 | { |
| 1615 | 1615 | $data = strtr($data, array('<br>' => '')); |
| 1616 | 1616 | $scheme = parse_url($data, PHP_URL_SCHEME); |
@@ -1624,7 +1624,7 @@ discard block |
||
| 1624 | 1624 | 'quoted' => 'optional', |
| 1625 | 1625 | 'before' => '<a href="$1" class="bbc_link" target="_blank">', |
| 1626 | 1626 | 'after' => '</a>', |
| 1627 | - 'validate' => function (&$tag, &$data, $disabled) |
|
| 1627 | + 'validate' => function(&$tag, &$data, $disabled) |
|
| 1628 | 1628 | { |
| 1629 | 1629 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1630 | 1630 | if (empty($scheme)) |
@@ -1650,7 +1650,7 @@ discard block |
||
| 1650 | 1650 | { |
| 1651 | 1651 | if (isset($temp_bbc)) |
| 1652 | 1652 | $bbc_codes = $temp_bbc; |
| 1653 | - usort($codes, function ($a, $b) { |
|
| 1653 | + usort($codes, function($a, $b) { |
|
| 1654 | 1654 | return strcmp($a['tag'], $b['tag']); |
| 1655 | 1655 | }); |
| 1656 | 1656 | return $codes; |
@@ -1888,7 +1888,7 @@ discard block |
||
| 1888 | 1888 | # a run of Unicode domain name characters and a dot |
| 1889 | 1889 | [\p{L}\p{M}\p{N}\-.:@]+\. |
| 1890 | 1890 | # and then a TLD valid in the DNS or the reserved "local" TLD |
| 1891 | - (?:'. $modSettings['tld_regex'] .'|local) |
|
| 1891 | + (?:'. $modSettings['tld_regex'] . '|local) |
|
| 1892 | 1892 | ) |
| 1893 | 1893 | # followed by a non-domain character or end of line |
| 1894 | 1894 | (?=[^\p{L}\p{N}\-.]|$) |
@@ -1956,7 +1956,7 @@ discard block |
||
| 1956 | 1956 | )? |
| 1957 | 1957 | '; |
| 1958 | 1958 | |
| 1959 | - $data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) { |
|
| 1959 | + $data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) { |
|
| 1960 | 1960 | $url = array_shift($matches); |
| 1961 | 1961 | |
| 1962 | 1962 | $scheme = parse_url($url, PHP_URL_SCHEME); |
@@ -2685,7 +2685,7 @@ discard block |
||
| 2685 | 2685 | for ($i = 0, $n = count($smileysfrom); $i < $n; $i++) |
| 2686 | 2686 | { |
| 2687 | 2687 | $specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES); |
| 2688 | - $smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')). '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" class="smiley">'; |
|
| 2688 | + $smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" class="smiley">'; |
|
| 2689 | 2689 | |
| 2690 | 2690 | $smileyPregReplacements[$smileysfrom[$i]] = $smileyCode; |
| 2691 | 2691 | |
@@ -2702,7 +2702,7 @@ discard block |
||
| 2702 | 2702 | |
| 2703 | 2703 | // Replace away! |
| 2704 | 2704 | $message = preg_replace_callback($smileyPregSearch, |
| 2705 | - function ($matches) use ($smileyPregReplacements) |
|
| 2705 | + function($matches) use ($smileyPregReplacements) |
|
| 2706 | 2706 | { |
| 2707 | 2707 | return $smileyPregReplacements[$matches[1]]; |
| 2708 | 2708 | }, $message); |
@@ -2768,13 +2768,13 @@ discard block |
||
| 2768 | 2768 | { |
| 2769 | 2769 | if (defined('SID') && SID != '') |
| 2770 | 2770 | $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
| 2771 | - function ($m) use ($scripturl) |
|
| 2771 | + function($m) use ($scripturl) |
|
| 2772 | 2772 | { |
| 2773 | - return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
|
| 2773 | + return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : ""); |
|
| 2774 | 2774 | }, $setLocation); |
| 2775 | 2775 | else |
| 2776 | 2776 | $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
| 2777 | - function ($m) use ($scripturl) |
|
| 2777 | + function($m) use ($scripturl) |
|
| 2778 | 2778 | { |
| 2779 | 2779 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
| 2780 | 2780 | }, $setLocation); |
@@ -3097,7 +3097,7 @@ discard block |
||
| 3097 | 3097 | |
| 3098 | 3098 | // Add a generic "Are you sure?" confirmation message. |
| 3099 | 3099 | addInlineJavaScript(' |
| 3100 | - var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
|
| 3100 | + var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';'); |
|
| 3101 | 3101 | |
| 3102 | 3102 | // Now add the capping code for avatars. |
| 3103 | 3103 | if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') |
@@ -3458,7 +3458,7 @@ discard block |
||
| 3458 | 3458 | |
| 3459 | 3459 | else |
| 3460 | 3460 | echo ' |
| 3461 | - <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; |
|
| 3461 | + <script src="', $settings['theme_url'], '/scripts/minified', ($do_deferred ? '_deferred' : ''), '.js', $minSeed, '"></script>'; |
|
| 3462 | 3462 | } |
| 3463 | 3463 | |
| 3464 | 3464 | // Inline JavaScript - Actually useful some times! |
@@ -3536,14 +3536,14 @@ discard block |
||
| 3536 | 3536 | |
| 3537 | 3537 | else |
| 3538 | 3538 | echo ' |
| 3539 | - <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; |
|
| 3539 | + <link rel="stylesheet" href="', $settings['theme_url'], '/css/minified.css', $minSeed, '">'; |
|
| 3540 | 3540 | } |
| 3541 | 3541 | |
| 3542 | 3542 | // Print the rest after the minified files. |
| 3543 | 3543 | if (!empty($normal)) |
| 3544 | 3544 | foreach ($normal as $nf) |
| 3545 | 3545 | echo ' |
| 3546 | - <link rel="stylesheet" href="', $nf ,'">'; |
|
| 3546 | + <link rel="stylesheet" href="', $nf, '">'; |
|
| 3547 | 3547 | |
| 3548 | 3548 | if ($db_show_debug === true) |
| 3549 | 3549 | { |
@@ -3559,7 +3559,7 @@ discard block |
||
| 3559 | 3559 | <style>'; |
| 3560 | 3560 | |
| 3561 | 3561 | foreach ($context['css_header'] as $css) |
| 3562 | - echo $css .' |
|
| 3562 | + echo $css . ' |
|
| 3563 | 3563 | '; |
| 3564 | 3564 | |
| 3565 | 3565 | echo' |
@@ -3588,27 +3588,27 @@ discard block |
||
| 3588 | 3588 | return false; |
| 3589 | 3589 | |
| 3590 | 3590 | // Did we already did this? |
| 3591 | - $toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); |
|
| 3591 | + $toCache = cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type, 86400); |
|
| 3592 | 3592 | |
| 3593 | 3593 | // Already done? |
| 3594 | 3594 | if (!empty($toCache)) |
| 3595 | 3595 | return true; |
| 3596 | 3596 | |
| 3597 | 3597 | // No namespaces, sorry! |
| 3598 | - $classType = 'MatthiasMullie\\Minify\\'. strtoupper($type); |
|
| 3598 | + $classType = 'MatthiasMullie\\Minify\\' . strtoupper($type); |
|
| 3599 | 3599 | |
| 3600 | 3600 | // Temp path. |
| 3601 | - $cTempPath = $settings['theme_dir'] .'/'. ($type == 'css' ? 'css' : 'scripts') .'/'; |
|
| 3601 | + $cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/'; |
|
| 3602 | 3602 | |
| 3603 | 3603 | // What kind of file are we going to create? |
| 3604 | - $toCreate = $cTempPath .'minified'. ($do_deferred ? '_deferred' : '') .'.'. $type; |
|
| 3604 | + $toCreate = $cTempPath . 'minified' . ($do_deferred ? '_deferred' : '') . '.' . $type; |
|
| 3605 | 3605 | |
| 3606 | 3606 | // File has to exists, if it isn't try to create it. |
| 3607 | 3607 | if ((!file_exists($toCreate) && @fopen($toCreate, 'w') === false) || !smf_chmod($toCreate)) |
| 3608 | 3608 | { |
| 3609 | 3609 | loadLanguage('Errors'); |
| 3610 | 3610 | log_error(sprintf($txt['file_not_created'], $toCreate), 'general'); |
| 3611 | - cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null); |
|
| 3611 | + cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null); |
|
| 3612 | 3612 | |
| 3613 | 3613 | // The process failed so roll back to print each individual file. |
| 3614 | 3614 | return $data; |
@@ -3643,14 +3643,14 @@ discard block |
||
| 3643 | 3643 | { |
| 3644 | 3644 | loadLanguage('Errors'); |
| 3645 | 3645 | log_error(sprintf($txt['file_not_created'], $toCreate), 'general'); |
| 3646 | - cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null); |
|
| 3646 | + cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null); |
|
| 3647 | 3647 | |
| 3648 | 3648 | // The process failed so roll back to print each individual file. |
| 3649 | 3649 | return $data; |
| 3650 | 3650 | } |
| 3651 | 3651 | |
| 3652 | 3652 | // And create a long lived cache entry. |
| 3653 | - cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, $toCreate, 86400); |
|
| 3653 | + cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, $toCreate, 86400); |
|
| 3654 | 3654 | |
| 3655 | 3655 | return true; |
| 3656 | 3656 | } |
@@ -3707,7 +3707,7 @@ discard block |
||
| 3707 | 3707 | else |
| 3708 | 3708 | $path = $modSettings['attachmentUploadDir']; |
| 3709 | 3709 | |
| 3710 | - return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
|
| 3710 | + return $path . '/' . $attachment_id . '_' . $file_hash . '.dat'; |
|
| 3711 | 3711 | } |
| 3712 | 3712 | |
| 3713 | 3713 | /** |
@@ -3751,10 +3751,10 @@ discard block |
||
| 3751 | 3751 | $valid_low = isValidIP($ip_parts[0]); |
| 3752 | 3752 | $valid_high = isValidIP($ip_parts[1]); |
| 3753 | 3753 | $count = 0; |
| 3754 | - $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
|
| 3754 | + $mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.'); |
|
| 3755 | 3755 | $max = ($mode == ':' ? 'ffff' : '255'); |
| 3756 | 3756 | $min = 0; |
| 3757 | - if(!$valid_low) |
|
| 3757 | + if (!$valid_low) |
|
| 3758 | 3758 | { |
| 3759 | 3759 | $ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]); |
| 3760 | 3760 | $valid_low = isValidIP($ip_parts[0]); |
@@ -3768,7 +3768,7 @@ discard block |
||
| 3768 | 3768 | } |
| 3769 | 3769 | |
| 3770 | 3770 | $count = 0; |
| 3771 | - if(!$valid_high) |
|
| 3771 | + if (!$valid_high) |
|
| 3772 | 3772 | { |
| 3773 | 3773 | $ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]); |
| 3774 | 3774 | $valid_high = isValidIP($ip_parts[1]); |
@@ -3781,7 +3781,7 @@ discard block |
||
| 3781 | 3781 | } |
| 3782 | 3782 | } |
| 3783 | 3783 | |
| 3784 | - if($valid_high && $valid_low) |
|
| 3784 | + if ($valid_high && $valid_low) |
|
| 3785 | 3785 | { |
| 3786 | 3786 | $ip_array['low'] = $ip_parts[0]; |
| 3787 | 3787 | $ip_array['high'] = $ip_parts[1]; |
@@ -3963,7 +3963,7 @@ discard block |
||
| 3963 | 3963 | addInlineJavaScript(' |
| 3964 | 3964 | var user_menus = new smc_PopupMenu(); |
| 3965 | 3965 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
| 3966 | - user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
|
| 3966 | + user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true); |
|
| 3967 | 3967 | if ($context['allow_pm']) |
| 3968 | 3968 | addInlineJavaScript(' |
| 3969 | 3969 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
@@ -4588,7 +4588,7 @@ discard block |
||
| 4588 | 4588 | // No? try a fallback to $sourcedir |
| 4589 | 4589 | else |
| 4590 | 4590 | { |
| 4591 | - $absPath = $sourcedir .'/'. $file; |
|
| 4591 | + $absPath = $sourcedir . '/' . $file; |
|
| 4592 | 4592 | |
| 4593 | 4593 | if (file_exists($absPath)) |
| 4594 | 4594 | require_once($absPath); |
@@ -4669,15 +4669,15 @@ discard block |
||
| 4669 | 4669 | |
| 4670 | 4670 | // UTF-8 occurences of MS special characters |
| 4671 | 4671 | $findchars_utf8 = array( |
| 4672 | - "\xe2\80\x9a", // single low-9 quotation mark |
|
| 4673 | - "\xe2\80\x9e", // double low-9 quotation mark |
|
| 4674 | - "\xe2\80\xa6", // horizontal ellipsis |
|
| 4675 | - "\xe2\x80\x98", // left single curly quote |
|
| 4676 | - "\xe2\x80\x99", // right single curly quote |
|
| 4677 | - "\xe2\x80\x9c", // left double curly quote |
|
| 4678 | - "\xe2\x80\x9d", // right double curly quote |
|
| 4679 | - "\xe2\x80\x93", // en dash |
|
| 4680 | - "\xe2\x80\x94", // em dash |
|
| 4672 | + "\xe2\80\x9a", // single low-9 quotation mark |
|
| 4673 | + "\xe2\80\x9e", // double low-9 quotation mark |
|
| 4674 | + "\xe2\80\xa6", // horizontal ellipsis |
|
| 4675 | + "\xe2\x80\x98", // left single curly quote |
|
| 4676 | + "\xe2\x80\x99", // right single curly quote |
|
| 4677 | + "\xe2\x80\x9c", // left double curly quote |
|
| 4678 | + "\xe2\x80\x9d", // right double curly quote |
|
| 4679 | + "\xe2\x80\x93", // en dash |
|
| 4680 | + "\xe2\x80\x94", // em dash |
|
| 4681 | 4681 | ); |
| 4682 | 4682 | |
| 4683 | 4683 | // windows 1252 / iso equivalents |
@@ -4695,15 +4695,15 @@ discard block |
||
| 4695 | 4695 | |
| 4696 | 4696 | // safe replacements |
| 4697 | 4697 | $replacechars = array( |
| 4698 | - ',', // ‚ |
|
| 4699 | - ',,', // „ |
|
| 4700 | - '...', // … |
|
| 4701 | - "'", // ‘ |
|
| 4702 | - "'", // ’ |
|
| 4703 | - '"', // “ |
|
| 4704 | - '"', // ” |
|
| 4705 | - '-', // – |
|
| 4706 | - '--', // — |
|
| 4698 | + ',', // ‚ |
|
| 4699 | + ',,', // „ |
|
| 4700 | + '...', // … |
|
| 4701 | + "'", // ‘ |
|
| 4702 | + "'", // ’ |
|
| 4703 | + '"', // “ |
|
| 4704 | + '"', // ” |
|
| 4705 | + '-', // – |
|
| 4706 | + '--', // — |
|
| 4707 | 4707 | ); |
| 4708 | 4708 | |
| 4709 | 4709 | if ($context['utf8']) |
@@ -5066,7 +5066,7 @@ discard block |
||
| 5066 | 5066 | */ |
| 5067 | 5067 | function inet_dtop($bin) |
| 5068 | 5068 | { |
| 5069 | - if(empty($bin)) |
|
| 5069 | + if (empty($bin)) |
|
| 5070 | 5070 | return ''; |
| 5071 | 5071 | |
| 5072 | 5072 | global $db_type; |
@@ -5097,28 +5097,28 @@ discard block |
||
| 5097 | 5097 | */ |
| 5098 | 5098 | function _safe_serialize($value) |
| 5099 | 5099 | { |
| 5100 | - if(is_null($value)) |
|
| 5100 | + if (is_null($value)) |
|
| 5101 | 5101 | return 'N;'; |
| 5102 | 5102 | |
| 5103 | - if(is_bool($value)) |
|
| 5104 | - return 'b:'. (int) $value .';'; |
|
| 5103 | + if (is_bool($value)) |
|
| 5104 | + return 'b:' . (int) $value . ';'; |
|
| 5105 | 5105 | |
| 5106 | - if(is_int($value)) |
|
| 5107 | - return 'i:'. $value .';'; |
|
| 5106 | + if (is_int($value)) |
|
| 5107 | + return 'i:' . $value . ';'; |
|
| 5108 | 5108 | |
| 5109 | - if(is_float($value)) |
|
| 5110 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5109 | + if (is_float($value)) |
|
| 5110 | + return 'd:' . str_replace(',', '.', $value) . ';'; |
|
| 5111 | 5111 | |
| 5112 | - if(is_string($value)) |
|
| 5113 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5112 | + if (is_string($value)) |
|
| 5113 | + return 's:' . strlen($value) . ':"' . $value . '";'; |
|
| 5114 | 5114 | |
| 5115 | - if(is_array($value)) |
|
| 5115 | + if (is_array($value)) |
|
| 5116 | 5116 | { |
| 5117 | 5117 | $out = ''; |
| 5118 | - foreach($value as $k => $v) |
|
| 5118 | + foreach ($value as $k => $v) |
|
| 5119 | 5119 | $out .= _safe_serialize($k) . _safe_serialize($v); |
| 5120 | 5120 | |
| 5121 | - return 'a:'. count($value) .':{'. $out .'}'; |
|
| 5121 | + return 'a:' . count($value) . ':{' . $out . '}'; |
|
| 5122 | 5122 | } |
| 5123 | 5123 | |
| 5124 | 5124 | // safe_serialize cannot serialize resources or objects. |
@@ -5160,7 +5160,7 @@ discard block |
||
| 5160 | 5160 | function _safe_unserialize($str) |
| 5161 | 5161 | { |
| 5162 | 5162 | // Input is not a string. |
| 5163 | - if(empty($str) || !is_string($str)) |
|
| 5163 | + if (empty($str) || !is_string($str)) |
|
| 5164 | 5164 | return false; |
| 5165 | 5165 | |
| 5166 | 5166 | $stack = array(); |
@@ -5174,40 +5174,40 @@ discard block |
||
| 5174 | 5174 | * 3 - in array, expecting value or another array |
| 5175 | 5175 | */ |
| 5176 | 5176 | $state = 0; |
| 5177 | - while($state != 1) |
|
| 5177 | + while ($state != 1) |
|
| 5178 | 5178 | { |
| 5179 | 5179 | $type = isset($str[0]) ? $str[0] : ''; |
| 5180 | - if($type == '}') |
|
| 5180 | + if ($type == '}') |
|
| 5181 | 5181 | $str = substr($str, 1); |
| 5182 | 5182 | |
| 5183 | - else if($type == 'N' && $str[1] == ';') |
|
| 5183 | + else if ($type == 'N' && $str[1] == ';') |
|
| 5184 | 5184 | { |
| 5185 | 5185 | $value = null; |
| 5186 | 5186 | $str = substr($str, 2); |
| 5187 | 5187 | } |
| 5188 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5188 | + else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5189 | 5189 | { |
| 5190 | 5190 | $value = $matches[1] == '1' ? true : false; |
| 5191 | 5191 | $str = substr($str, 4); |
| 5192 | 5192 | } |
| 5193 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5193 | + else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5194 | 5194 | { |
| 5195 | - $value = (int)$matches[1]; |
|
| 5195 | + $value = (int) $matches[1]; |
|
| 5196 | 5196 | $str = $matches[2]; |
| 5197 | 5197 | } |
| 5198 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5198 | + else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5199 | 5199 | { |
| 5200 | - $value = (float)$matches[1]; |
|
| 5200 | + $value = (float) $matches[1]; |
|
| 5201 | 5201 | $str = $matches[3]; |
| 5202 | 5202 | } |
| 5203 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5203 | + else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";') |
|
| 5204 | 5204 | { |
| 5205 | - $value = substr($matches[2], 0, (int)$matches[1]); |
|
| 5206 | - $str = substr($matches[2], (int)$matches[1] + 2); |
|
| 5205 | + $value = substr($matches[2], 0, (int) $matches[1]); |
|
| 5206 | + $str = substr($matches[2], (int) $matches[1] + 2); |
|
| 5207 | 5207 | } |
| 5208 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5208 | + else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5209 | 5209 | { |
| 5210 | - $expectedLength = (int)$matches[1]; |
|
| 5210 | + $expectedLength = (int) $matches[1]; |
|
| 5211 | 5211 | $str = $matches[2]; |
| 5212 | 5212 | } |
| 5213 | 5213 | |
@@ -5215,10 +5215,10 @@ discard block |
||
| 5215 | 5215 | else |
| 5216 | 5216 | return false; |
| 5217 | 5217 | |
| 5218 | - switch($state) |
|
| 5218 | + switch ($state) |
|
| 5219 | 5219 | { |
| 5220 | 5220 | case 3: // In array, expecting value or another array. |
| 5221 | - if($type == 'a') |
|
| 5221 | + if ($type == 'a') |
|
| 5222 | 5222 | { |
| 5223 | 5223 | $stack[] = &$list; |
| 5224 | 5224 | $list[$key] = array(); |
@@ -5227,7 +5227,7 @@ discard block |
||
| 5227 | 5227 | $state = 2; |
| 5228 | 5228 | break; |
| 5229 | 5229 | } |
| 5230 | - if($type != '}') |
|
| 5230 | + if ($type != '}') |
|
| 5231 | 5231 | { |
| 5232 | 5232 | $list[$key] = $value; |
| 5233 | 5233 | $state = 2; |
@@ -5238,29 +5238,29 @@ discard block |
||
| 5238 | 5238 | return false; |
| 5239 | 5239 | |
| 5240 | 5240 | case 2: // in array, expecting end of array or a key |
| 5241 | - if($type == '}') |
|
| 5241 | + if ($type == '}') |
|
| 5242 | 5242 | { |
| 5243 | 5243 | // Array size is less than expected. |
| 5244 | - if(count($list) < end($expected)) |
|
| 5244 | + if (count($list) < end($expected)) |
|
| 5245 | 5245 | return false; |
| 5246 | 5246 | |
| 5247 | 5247 | unset($list); |
| 5248 | - $list = &$stack[count($stack)-1]; |
|
| 5248 | + $list = &$stack[count($stack) - 1]; |
|
| 5249 | 5249 | array_pop($stack); |
| 5250 | 5250 | |
| 5251 | 5251 | // Go to terminal state if we're at the end of the root array. |
| 5252 | 5252 | array_pop($expected); |
| 5253 | 5253 | |
| 5254 | - if(count($expected) == 0) |
|
| 5254 | + if (count($expected) == 0) |
|
| 5255 | 5255 | $state = 1; |
| 5256 | 5256 | |
| 5257 | 5257 | break; |
| 5258 | 5258 | } |
| 5259 | 5259 | |
| 5260 | - if($type == 'i' || $type == 's') |
|
| 5260 | + if ($type == 'i' || $type == 's') |
|
| 5261 | 5261 | { |
| 5262 | 5262 | // Array size exceeds expected length. |
| 5263 | - if(count($list) >= end($expected)) |
|
| 5263 | + if (count($list) >= end($expected)) |
|
| 5264 | 5264 | return false; |
| 5265 | 5265 | |
| 5266 | 5266 | $key = $value; |
@@ -5273,7 +5273,7 @@ discard block |
||
| 5273 | 5273 | |
| 5274 | 5274 | // Expecting array or value. |
| 5275 | 5275 | case 0: |
| 5276 | - if($type == 'a') |
|
| 5276 | + if ($type == 'a') |
|
| 5277 | 5277 | { |
| 5278 | 5278 | $data = array(); |
| 5279 | 5279 | $list = &$data; |
@@ -5282,7 +5282,7 @@ discard block |
||
| 5282 | 5282 | break; |
| 5283 | 5283 | } |
| 5284 | 5284 | |
| 5285 | - if($type != '}') |
|
| 5285 | + if ($type != '}') |
|
| 5286 | 5286 | { |
| 5287 | 5287 | $data = $value; |
| 5288 | 5288 | $state = 1; |
@@ -5295,7 +5295,7 @@ discard block |
||
| 5295 | 5295 | } |
| 5296 | 5296 | |
| 5297 | 5297 | // Trailing data in input. |
| 5298 | - if(!empty($str)) |
|
| 5298 | + if (!empty($str)) |
|
| 5299 | 5299 | return false; |
| 5300 | 5300 | |
| 5301 | 5301 | return $data; |
@@ -5349,7 +5349,7 @@ discard block |
||
| 5349 | 5349 | // Set different modes. |
| 5350 | 5350 | $chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666); |
| 5351 | 5351 | |
| 5352 | - foreach($chmodValues as $val) |
|
| 5352 | + foreach ($chmodValues as $val) |
|
| 5353 | 5353 | { |
| 5354 | 5354 | // If it's writable, break out of the loop. |
| 5355 | 5355 | if (is_writable($file)) |
@@ -5384,13 +5384,13 @@ discard block |
||
| 5384 | 5384 | $returnArray = @json_decode($json, $returnAsArray); |
| 5385 | 5385 | |
| 5386 | 5386 | // PHP 5.3 so no json_last_error_msg() |
| 5387 | - switch(json_last_error()) |
|
| 5387 | + switch (json_last_error()) |
|
| 5388 | 5388 | { |
| 5389 | 5389 | case JSON_ERROR_NONE: |
| 5390 | 5390 | $jsonError = false; |
| 5391 | 5391 | break; |
| 5392 | 5392 | case JSON_ERROR_DEPTH: |
| 5393 | - $jsonError = 'JSON_ERROR_DEPTH'; |
|
| 5393 | + $jsonError = 'JSON_ERROR_DEPTH'; |
|
| 5394 | 5394 | break; |
| 5395 | 5395 | case JSON_ERROR_STATE_MISMATCH: |
| 5396 | 5396 | $jsonError = 'JSON_ERROR_STATE_MISMATCH'; |
@@ -5418,10 +5418,10 @@ discard block |
||
| 5418 | 5418 | loadLanguage('Errors'); |
| 5419 | 5419 | |
| 5420 | 5420 | if (!empty($jsonDebug)) |
| 5421 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5421 | + log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5422 | 5422 | |
| 5423 | 5423 | else |
| 5424 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5424 | + log_error($txt['json_' . $jsonError], 'critical'); |
|
| 5425 | 5425 | |
| 5426 | 5426 | // Everyone expects an array. |
| 5427 | 5427 | return array(); |
@@ -5525,7 +5525,7 @@ discard block |
||
| 5525 | 5525 | }); |
| 5526 | 5526 | |
| 5527 | 5527 | // Convert Punycode to Unicode |
| 5528 | - $tlds = array_map(function ($input) { |
|
| 5528 | + $tlds = array_map(function($input) { |
|
| 5529 | 5529 | $prefix = 'xn--'; |
| 5530 | 5530 | $safe_char = 0xFFFC; |
| 5531 | 5531 | $base = 36; |
@@ -5541,7 +5541,7 @@ discard block |
||
| 5541 | 5541 | |
| 5542 | 5542 | foreach ($enco_parts as $encoded) |
| 5543 | 5543 | { |
| 5544 | - if (strpos($encoded,$prefix) !== 0 || strlen(trim(str_replace($prefix,'',$encoded))) == 0) |
|
| 5544 | + if (strpos($encoded, $prefix) !== 0 || strlen(trim(str_replace($prefix, '', $encoded))) == 0) |
|
| 5545 | 5545 | { |
| 5546 | 5546 | $output_parts[] = $encoded; |
| 5547 | 5547 | continue; |
@@ -5552,7 +5552,7 @@ discard block |
||
| 5552 | 5552 | $idx = 0; |
| 5553 | 5553 | $char = 0x80; |
| 5554 | 5554 | $decoded = array(); |
| 5555 | - $output=''; |
|
| 5555 | + $output = ''; |
|
| 5556 | 5556 | $delim_pos = strrpos($encoded, '-'); |
| 5557 | 5557 | |
| 5558 | 5558 | if ($delim_pos > strlen($prefix)) |
@@ -5568,7 +5568,7 @@ discard block |
||
| 5568 | 5568 | |
| 5569 | 5569 | for ($enco_idx = $delim_pos ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len) |
| 5570 | 5570 | { |
| 5571 | - for ($old_idx = $idx, $w = 1, $k = $base; 1 ; $k += $base) |
|
| 5571 | + for ($old_idx = $idx, $w = 1, $k = $base; 1; $k += $base) |
|
| 5572 | 5572 | { |
| 5573 | 5573 | $cp = ord($encoded{$enco_idx++}); |
| 5574 | 5574 | $digit = ($cp - 48 < 10) ? $cp - 22 : (($cp - 65 < 26) ? $cp - 65 : (($cp - 97 < 26) ? $cp - 97 : $base)); |
@@ -5609,15 +5609,15 @@ discard block |
||
| 5609 | 5609 | |
| 5610 | 5610 | // 2 bytes |
| 5611 | 5611 | elseif ($v < (1 << 11)) |
| 5612 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 5612 | + $output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63)); |
|
| 5613 | 5613 | |
| 5614 | 5614 | // 3 bytes |
| 5615 | 5615 | elseif ($v < (1 << 16)) |
| 5616 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5616 | + $output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63)); |
|
| 5617 | 5617 | |
| 5618 | 5618 | // 4 bytes |
| 5619 | 5619 | elseif ($v < (1 << 21)) |
| 5620 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5620 | + $output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63)); |
|
| 5621 | 5621 | |
| 5622 | 5622 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
| 5623 | 5623 | else |
@@ -5724,7 +5724,7 @@ discard block |
||
| 5724 | 5724 | } |
| 5725 | 5725 | |
| 5726 | 5726 | // This recursive function creates the index array from the strings |
| 5727 | - $add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index) |
|
| 5727 | + $add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index) |
|
| 5728 | 5728 | { |
| 5729 | 5729 | static $depth = 0; |
| 5730 | 5730 | $depth++; |
@@ -5751,7 +5751,7 @@ discard block |
||
| 5751 | 5751 | }; |
| 5752 | 5752 | |
| 5753 | 5753 | // This recursive function turns the index array into a regular expression |
| 5754 | - $index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex) |
|
| 5754 | + $index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex) |
|
| 5755 | 5755 | { |
| 5756 | 5756 | static $depth = 0; |
| 5757 | 5757 | $depth++; |
@@ -5775,11 +5775,11 @@ discard block |
||
| 5775 | 5775 | |
| 5776 | 5776 | if (count(array_keys($value)) == 1) |
| 5777 | 5777 | { |
| 5778 | - $new_key_array = explode('(?'.'>', $sub_regex); |
|
| 5778 | + $new_key_array = explode('(?' . '>', $sub_regex); |
|
| 5779 | 5779 | $new_key .= $new_key_array[0]; |
| 5780 | 5780 | } |
| 5781 | 5781 | else |
| 5782 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5782 | + $sub_regex = '(?' . '>' . $sub_regex . ')'; |
|
| 5783 | 5783 | } |
| 5784 | 5784 | |
| 5785 | 5785 | if ($depth > 1) |
@@ -5819,7 +5819,7 @@ discard block |
||
| 5819 | 5819 | $index = $add_string_to_index($string, $index); |
| 5820 | 5820 | |
| 5821 | 5821 | while (!empty($index)) |
| 5822 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 5822 | + $regexes[] = '(?' . '>' . $index_to_regex($index, $delim) . ')'; |
|
| 5823 | 5823 | |
| 5824 | 5824 | // Restore PHP's internal character encoding to whatever it was originally |
| 5825 | 5825 | if (!empty($current_encoding)) |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 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 | * Update some basic statistics. |
@@ -122,10 +123,11 @@ discard block |
||
| 122 | 123 | $smcFunc['db_free_result']($result); |
| 123 | 124 | |
| 124 | 125 | // Add this to the number of unapproved members |
| 125 | - if (!empty($changes['unapprovedMembers'])) |
|
| 126 | - $changes['unapprovedMembers'] += $coppa_approvals; |
|
| 127 | - else |
|
| 128 | - $changes['unapprovedMembers'] = $coppa_approvals; |
|
| 126 | + if (!empty($changes['unapprovedMembers'])) { |
|
| 127 | + $changes['unapprovedMembers'] += $coppa_approvals; |
|
| 128 | + } else { |
|
| 129 | + $changes['unapprovedMembers'] = $coppa_approvals; |
|
| 130 | + } |
|
| 129 | 131 | } |
| 130 | 132 | } |
| 131 | 133 | } |
@@ -133,9 +135,9 @@ discard block |
||
| 133 | 135 | break; |
| 134 | 136 | |
| 135 | 137 | case 'message': |
| 136 | - if ($parameter1 === true && $parameter2 !== null) |
|
| 137 | - updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
| 138 | - else |
|
| 138 | + if ($parameter1 === true && $parameter2 !== null) { |
|
| 139 | + updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
| 140 | + } else |
|
| 139 | 141 | { |
| 140 | 142 | // SUM and MAX on a smaller table is better for InnoDB tables. |
| 141 | 143 | $result = $smcFunc['db_query']('', ' |
@@ -175,23 +177,25 @@ discard block |
||
| 175 | 177 | $parameter2 = text2words($parameter2); |
| 176 | 178 | |
| 177 | 179 | $inserts = array(); |
| 178 | - foreach ($parameter2 as $word) |
|
| 179 | - $inserts[] = array($word, $parameter1); |
|
| 180 | + foreach ($parameter2 as $word) { |
|
| 181 | + $inserts[] = array($word, $parameter1); |
|
| 182 | + } |
|
| 180 | 183 | |
| 181 | - if (!empty($inserts)) |
|
| 182 | - $smcFunc['db_insert']('ignore', |
|
| 184 | + if (!empty($inserts)) { |
|
| 185 | + $smcFunc['db_insert']('ignore', |
|
| 183 | 186 | '{db_prefix}log_search_subjects', |
| 184 | 187 | array('word' => 'string', 'id_topic' => 'int'), |
| 185 | 188 | $inserts, |
| 186 | 189 | array('word', 'id_topic') |
| 187 | 190 | ); |
| 191 | + } |
|
| 188 | 192 | } |
| 189 | 193 | break; |
| 190 | 194 | |
| 191 | 195 | case 'topic': |
| 192 | - if ($parameter1 === true) |
|
| 193 | - updateSettings(array('totalTopics' => true), true); |
|
| 194 | - else |
|
| 196 | + if ($parameter1 === true) { |
|
| 197 | + updateSettings(array('totalTopics' => true), true); |
|
| 198 | + } else |
|
| 195 | 199 | { |
| 196 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. |
| 197 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. |
@@ -212,8 +216,9 @@ discard block |
||
| 212 | 216 | |
| 213 | 217 | case 'postgroups': |
| 214 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. |
| 215 | - if ($parameter2 !== null && !in_array('posts', $parameter2)) |
|
| 216 | - return; |
|
| 219 | + if ($parameter2 !== null && !in_array('posts', $parameter2)) { |
|
| 220 | + return; |
|
| 221 | + } |
|
| 217 | 222 | |
| 218 | 223 | $postgroups = cache_get_data('updateStats:postgroups', 360); |
| 219 | 224 | if ($postgroups == null || $parameter1 == null) |
@@ -228,8 +233,9 @@ discard block |
||
| 228 | 233 | ) |
| 229 | 234 | ); |
| 230 | 235 | $postgroups = array(); |
| 231 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 232 | - $postgroups[$row['id_group']] = $row['min_posts']; |
|
| 236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 237 | + $postgroups[$row['id_group']] = $row['min_posts']; |
|
| 238 | + } |
|
| 233 | 239 | $smcFunc['db_free_result']($request); |
| 234 | 240 | |
| 235 | 241 | // Sort them this way because if it's done with MySQL it causes a filesort :(. |
@@ -239,8 +245,9 @@ discard block |
||
| 239 | 245 | } |
| 240 | 246 | |
| 241 | 247 | // Oh great, they've screwed their post groups. |
| 242 | - if (empty($postgroups)) |
|
| 243 | - return; |
|
| 248 | + if (empty($postgroups)) { |
|
| 249 | + return; |
|
| 250 | + } |
|
| 244 | 251 | |
| 245 | 252 | // Set all membergroups from most posts to least posts. |
| 246 | 253 | $conditions = ''; |
@@ -298,10 +305,9 @@ discard block |
||
| 298 | 305 | { |
| 299 | 306 | $condition = 'id_member IN ({array_int:members})'; |
| 300 | 307 | $parameters['members'] = $members; |
| 301 | - } |
|
| 302 | - elseif ($members === null) |
|
| 303 | - $condition = '1=1'; |
|
| 304 | - else |
|
| 308 | + } elseif ($members === null) { |
|
| 309 | + $condition = '1=1'; |
|
| 310 | + } else |
|
| 305 | 311 | { |
| 306 | 312 | $condition = 'id_member = {int:member}'; |
| 307 | 313 | $parameters['member'] = $members; |
@@ -341,9 +347,9 @@ discard block |
||
| 341 | 347 | if (count($vars_to_integrate) != 0) |
| 342 | 348 | { |
| 343 | 349 | // Fetch a list of member_names if necessary |
| 344 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) |
|
| 345 | - $member_names = array($user_info['username']); |
|
| 346 | - else |
|
| 350 | + if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { |
|
| 351 | + $member_names = array($user_info['username']); |
|
| 352 | + } else |
|
| 347 | 353 | { |
| 348 | 354 | $member_names = array(); |
| 349 | 355 | $request = $smcFunc['db_query']('', ' |
@@ -352,14 +358,16 @@ discard block |
||
| 352 | 358 | WHERE ' . $condition, |
| 353 | 359 | $parameters |
| 354 | 360 | ); |
| 355 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 356 | - $member_names[] = $row['member_name']; |
|
| 361 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 362 | + $member_names[] = $row['member_name']; |
|
| 363 | + } |
|
| 357 | 364 | $smcFunc['db_free_result']($request); |
| 358 | 365 | } |
| 359 | 366 | |
| 360 | - if (!empty($member_names)) |
|
| 361 | - foreach ($vars_to_integrate as $var) |
|
| 367 | + if (!empty($member_names)) { |
|
| 368 | + foreach ($vars_to_integrate as $var) |
|
| 362 | 369 | call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); |
| 370 | + } |
|
| 363 | 371 | } |
| 364 | 372 | } |
| 365 | 373 | |
@@ -367,16 +375,17 @@ discard block |
||
| 367 | 375 | foreach ($data as $var => $val) |
| 368 | 376 | { |
| 369 | 377 | $type = 'string'; |
| 370 | - if (in_array($var, $knownInts)) |
|
| 371 | - $type = 'int'; |
|
| 372 | - elseif (in_array($var, $knownFloats)) |
|
| 373 | - $type = 'float'; |
|
| 374 | - elseif ($var == 'birthdate') |
|
| 375 | - $type = 'date'; |
|
| 376 | - elseif ($var == 'member_ip') |
|
| 377 | - $type = 'inet'; |
|
| 378 | - elseif ($var == 'member_ip2') |
|
| 379 | - $type = 'inet'; |
|
| 378 | + if (in_array($var, $knownInts)) { |
|
| 379 | + $type = 'int'; |
|
| 380 | + } elseif (in_array($var, $knownFloats)) { |
|
| 381 | + $type = 'float'; |
|
| 382 | + } elseif ($var == 'birthdate') { |
|
| 383 | + $type = 'date'; |
|
| 384 | + } elseif ($var == 'member_ip') { |
|
| 385 | + $type = 'inet'; |
|
| 386 | + } elseif ($var == 'member_ip2') { |
|
| 387 | + $type = 'inet'; |
|
| 388 | + } |
|
| 380 | 389 | |
| 381 | 390 | // Doing an increment? |
| 382 | 391 | if ($type == 'int' && ($val === '+' || $val === '-')) |
@@ -390,8 +399,9 @@ discard block |
||
| 390 | 399 | { |
| 391 | 400 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
| 392 | 401 | { |
| 393 | - if ($match[1] != '+ ') |
|
| 394 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
| 402 | + if ($match[1] != '+ ') { |
|
| 403 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
| 404 | + } |
|
| 395 | 405 | $type = 'raw'; |
| 396 | 406 | } |
| 397 | 407 | } |
@@ -412,8 +422,9 @@ discard block |
||
| 412 | 422 | // Clear any caching? |
| 413 | 423 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
| 414 | 424 | { |
| 415 | - if (!is_array($members)) |
|
| 416 | - $members = array($members); |
|
| 425 | + if (!is_array($members)) { |
|
| 426 | + $members = array($members); |
|
| 427 | + } |
|
| 417 | 428 | |
| 418 | 429 | foreach ($members as $member) |
| 419 | 430 | { |
@@ -446,29 +457,32 @@ discard block |
||
| 446 | 457 | { |
| 447 | 458 | global $modSettings, $smcFunc; |
| 448 | 459 | |
| 449 | - if (empty($changeArray) || !is_array($changeArray)) |
|
| 450 | - return; |
|
| 460 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
| 461 | + return; |
|
| 462 | + } |
|
| 451 | 463 | |
| 452 | 464 | $toRemove = array(); |
| 453 | 465 | |
| 454 | 466 | // Go check if there is any setting to be removed. |
| 455 | - foreach ($changeArray as $k => $v) |
|
| 456 | - if ($v === null) |
|
| 467 | + foreach ($changeArray as $k => $v) { |
|
| 468 | + if ($v === null) |
|
| 457 | 469 | { |
| 458 | 470 | // Found some, remove them from the original array and add them to ours. |
| 459 | 471 | unset($changeArray[$k]); |
| 472 | + } |
|
| 460 | 473 | $toRemove[] = $k; |
| 461 | 474 | } |
| 462 | 475 | |
| 463 | 476 | // Proceed with the deletion. |
| 464 | - if (!empty($toRemove)) |
|
| 465 | - $smcFunc['db_query']('', ' |
|
| 477 | + if (!empty($toRemove)) { |
|
| 478 | + $smcFunc['db_query']('', ' |
|
| 466 | 479 | DELETE FROM {db_prefix}settings |
| 467 | 480 | WHERE variable IN ({array_string:remove})', |
| 468 | 481 | array( |
| 469 | 482 | 'remove' => $toRemove, |
| 470 | 483 | ) |
| 471 | 484 | ); |
| 485 | + } |
|
| 472 | 486 | |
| 473 | 487 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
| 474 | 488 | if ($update) |
@@ -497,19 +511,22 @@ discard block |
||
| 497 | 511 | foreach ($changeArray as $variable => $value) |
| 498 | 512 | { |
| 499 | 513 | // Don't bother if it's already like that ;). |
| 500 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
| 501 | - continue; |
|
| 514 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
| 515 | + continue; |
|
| 516 | + } |
|
| 502 | 517 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
| 503 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
| 504 | - continue; |
|
| 518 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
| 519 | + continue; |
|
| 520 | + } |
|
| 505 | 521 | |
| 506 | 522 | $replaceArray[] = array($variable, $value); |
| 507 | 523 | |
| 508 | 524 | $modSettings[$variable] = $value; |
| 509 | 525 | } |
| 510 | 526 | |
| 511 | - if (empty($replaceArray)) |
|
| 512 | - return; |
|
| 527 | + if (empty($replaceArray)) { |
|
| 528 | + return; |
|
| 529 | + } |
|
| 513 | 530 | |
| 514 | 531 | $smcFunc['db_insert']('replace', |
| 515 | 532 | '{db_prefix}settings', |
@@ -555,14 +572,17 @@ discard block |
||
| 555 | 572 | $start_invalid = $start < 0; |
| 556 | 573 | |
| 557 | 574 | // Make sure $start is a proper variable - not less than 0. |
| 558 | - if ($start_invalid) |
|
| 559 | - $start = 0; |
|
| 575 | + if ($start_invalid) { |
|
| 576 | + $start = 0; |
|
| 577 | + } |
|
| 560 | 578 | // Not greater than the upper bound. |
| 561 | - elseif ($start >= $max_value) |
|
| 562 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
| 579 | + elseif ($start >= $max_value) { |
|
| 580 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
| 581 | + } |
|
| 563 | 582 | // And it has to be a multiple of $num_per_page! |
| 564 | - else |
|
| 565 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
| 583 | + else { |
|
| 584 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
| 585 | + } |
|
| 566 | 586 | |
| 567 | 587 | $context['current_page'] = $start / $num_per_page; |
| 568 | 588 | |
@@ -592,77 +612,87 @@ discard block |
||
| 592 | 612 | |
| 593 | 613 | // Show all the pages. |
| 594 | 614 | $display_page = 1; |
| 595 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
| 596 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
| 615 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
| 616 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
| 617 | + } |
|
| 597 | 618 | |
| 598 | 619 | // Show the right arrow. |
| 599 | 620 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
| 600 | - if ($start != $counter - $max_value && !$start_invalid) |
|
| 601 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
| 602 | - } |
|
| 603 | - else |
|
| 621 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
| 622 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
| 623 | + } |
|
| 624 | + } else |
|
| 604 | 625 | { |
| 605 | 626 | // If they didn't enter an odd value, pretend they did. |
| 606 | 627 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
| 607 | 628 | |
| 608 | 629 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
| 609 | - if (!empty($start) && $show_prevnext) |
|
| 610 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
| 611 | - else |
|
| 612 | - $pageindex .= ''; |
|
| 630 | + if (!empty($start) && $show_prevnext) { |
|
| 631 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
| 632 | + } else { |
|
| 633 | + $pageindex .= ''; |
|
| 634 | + } |
|
| 613 | 635 | |
| 614 | 636 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
| 615 | - if ($start > $num_per_page * $PageContiguous) |
|
| 616 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
| 637 | + if ($start > $num_per_page * $PageContiguous) { |
|
| 638 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
| 639 | + } |
|
| 617 | 640 | |
| 618 | 641 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
| 619 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
| 620 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 642 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
| 643 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 621 | 644 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
| 622 | 645 | '{FIRST_PAGE}' => $num_per_page, |
| 623 | 646 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
| 624 | 647 | '{PER_PAGE}' => $num_per_page, |
| 625 | 648 | )); |
| 649 | + } |
|
| 626 | 650 | |
| 627 | 651 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
| 628 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
| 629 | - if ($start >= $num_per_page * $nCont) |
|
| 652 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
| 653 | + if ($start >= $num_per_page * $nCont) |
|
| 630 | 654 | { |
| 631 | 655 | $tmpStart = $start - $num_per_page * $nCont; |
| 656 | + } |
|
| 632 | 657 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
| 633 | 658 | } |
| 634 | 659 | |
| 635 | 660 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
| 636 | - if (!$start_invalid) |
|
| 637 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
| 638 | - else |
|
| 639 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
| 661 | + if (!$start_invalid) { |
|
| 662 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
| 663 | + } else { |
|
| 664 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
| 665 | + } |
|
| 640 | 666 | |
| 641 | 667 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
| 642 | 668 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
| 643 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
|
| 644 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
| 669 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
| 670 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
| 645 | 671 | { |
| 646 | 672 | $tmpStart = $start + $num_per_page * $nCont; |
| 673 | + } |
|
| 647 | 674 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
| 648 | 675 | } |
| 649 | 676 | |
| 650 | 677 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
| 651 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
| 652 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 678 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
| 679 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 653 | 680 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
| 654 | 681 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
| 655 | 682 | '{LAST_PAGE}' => $tmpMaxPages, |
| 656 | 683 | '{PER_PAGE}' => $num_per_page, |
| 657 | 684 | )); |
| 685 | + } |
|
| 658 | 686 | |
| 659 | 687 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
| 660 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
| 661 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
| 688 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
| 689 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
| 690 | + } |
|
| 662 | 691 | |
| 663 | 692 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
| 664 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
| 665 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
| 693 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
| 694 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
| 695 | + } |
|
| 666 | 696 | } |
| 667 | 697 | $pageindex .= $settings['page_index']['extra_after']; |
| 668 | 698 | |
@@ -688,8 +718,9 @@ discard block |
||
| 688 | 718 | if ($decimal_separator === null) |
| 689 | 719 | { |
| 690 | 720 | // Not set for whatever reason? |
| 691 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
| 692 | - return $number; |
|
| 721 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
| 722 | + return $number; |
|
| 723 | + } |
|
| 693 | 724 | |
| 694 | 725 | // Cache these each load... |
| 695 | 726 | $thousands_separator = $matches[1]; |
@@ -721,17 +752,20 @@ discard block |
||
| 721 | 752 | static $non_twelve_hour; |
| 722 | 753 | |
| 723 | 754 | // Offset the time. |
| 724 | - if (!$offset_type) |
|
| 725 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 755 | + if (!$offset_type) { |
|
| 756 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 757 | + } |
|
| 726 | 758 | // Just the forum offset? |
| 727 | - elseif ($offset_type == 'forum') |
|
| 728 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
| 729 | - else |
|
| 730 | - $time = $log_time; |
|
| 759 | + elseif ($offset_type == 'forum') { |
|
| 760 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
| 761 | + } else { |
|
| 762 | + $time = $log_time; |
|
| 763 | + } |
|
| 731 | 764 | |
| 732 | 765 | // We can't have a negative date (on Windows, at least.) |
| 733 | - if ($log_time < 0) |
|
| 734 | - $log_time = 0; |
|
| 766 | + if ($log_time < 0) { |
|
| 767 | + $log_time = 0; |
|
| 768 | + } |
|
| 735 | 769 | |
| 736 | 770 | // Today and Yesterday? |
| 737 | 771 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -748,46 +782,53 @@ discard block |
||
| 748 | 782 | { |
| 749 | 783 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
| 750 | 784 | $today_fmt = $h . ':%M' . $s . ' %p'; |
| 785 | + } else { |
|
| 786 | + $today_fmt = '%H:%M' . $s; |
|
| 751 | 787 | } |
| 752 | - else |
|
| 753 | - $today_fmt = '%H:%M' . $s; |
|
| 754 | 788 | |
| 755 | 789 | // Same day of the year, same year.... Today! |
| 756 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
| 757 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 790 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
| 791 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 792 | + } |
|
| 758 | 793 | |
| 759 | 794 | // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year... |
| 760 | - if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) |
|
| 761 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 795 | + if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) { |
|
| 796 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 797 | + } |
|
| 762 | 798 | } |
| 763 | 799 | |
| 764 | 800 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
| 765 | 801 | |
| 766 | 802 | if (setlocale(LC_TIME, $txt['lang_locale'])) |
| 767 | 803 | { |
| 768 | - if (!isset($non_twelve_hour)) |
|
| 769 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
| 770 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
| 771 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 804 | + if (!isset($non_twelve_hour)) { |
|
| 805 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
| 806 | + } |
|
| 807 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
| 808 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 809 | + } |
|
| 772 | 810 | |
| 773 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
| 774 | - if (strpos($str, $token) !== false) |
|
| 811 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
| 812 | + if (strpos($str, $token) !== false) |
|
| 775 | 813 | $str = str_replace($token, strftime($token, $time), $str); |
| 776 | - } |
|
| 777 | - else |
|
| 814 | + } |
|
| 815 | + } else |
|
| 778 | 816 | { |
| 779 | 817 | // Do-it-yourself time localization. Fun. |
| 780 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
| 781 | - if (strpos($str, $token) !== false) |
|
| 818 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
| 819 | + if (strpos($str, $token) !== false) |
|
| 782 | 820 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
| 821 | + } |
|
| 783 | 822 | |
| 784 | - if (strpos($str, '%p') !== false) |
|
| 785 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 823 | + if (strpos($str, '%p') !== false) { |
|
| 824 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 825 | + } |
|
| 786 | 826 | } |
| 787 | 827 | |
| 788 | 828 | // Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that. |
| 789 | - if ($context['server']['is_windows'] && strpos($str, '%e') !== false) |
|
| 790 | - $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
| 829 | + if ($context['server']['is_windows'] && strpos($str, '%e') !== false) { |
|
| 830 | + $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
| 831 | + } |
|
| 791 | 832 | |
| 792 | 833 | // Format any other characters.. |
| 793 | 834 | return strftime($str, $time); |
@@ -809,16 +850,19 @@ discard block |
||
| 809 | 850 | static $translation = array(); |
| 810 | 851 | |
| 811 | 852 | // Determine the character set... Default to UTF-8 |
| 812 | - if (empty($context['character_set'])) |
|
| 813 | - $charset = 'UTF-8'; |
|
| 853 | + if (empty($context['character_set'])) { |
|
| 854 | + $charset = 'UTF-8'; |
|
| 855 | + } |
|
| 814 | 856 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
| 815 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
| 816 | - $charset = 'ISO-8859-1'; |
|
| 817 | - else |
|
| 818 | - $charset = $context['character_set']; |
|
| 857 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
| 858 | + $charset = 'ISO-8859-1'; |
|
| 859 | + } else { |
|
| 860 | + $charset = $context['character_set']; |
|
| 861 | + } |
|
| 819 | 862 | |
| 820 | - if (empty($translation)) |
|
| 821 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
| 863 | + if (empty($translation)) { |
|
| 864 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
| 865 | + } |
|
| 822 | 866 | |
| 823 | 867 | return strtr($string, $translation); |
| 824 | 868 | } |
@@ -840,8 +884,9 @@ discard block |
||
| 840 | 884 | global $smcFunc; |
| 841 | 885 | |
| 842 | 886 | // It was already short enough! |
| 843 | - if ($smcFunc['strlen']($subject) <= $len) |
|
| 844 | - return $subject; |
|
| 887 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
| 888 | + return $subject; |
|
| 889 | + } |
|
| 845 | 890 | |
| 846 | 891 | // Shorten it by the length it was too long, and strip off junk from the end. |
| 847 | 892 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -860,10 +905,11 @@ discard block |
||
| 860 | 905 | { |
| 861 | 906 | global $user_info, $modSettings; |
| 862 | 907 | |
| 863 | - if ($timestamp === null) |
|
| 864 | - $timestamp = time(); |
|
| 865 | - elseif ($timestamp == 0) |
|
| 866 | - return 0; |
|
| 908 | + if ($timestamp === null) { |
|
| 909 | + $timestamp = time(); |
|
| 910 | + } elseif ($timestamp == 0) { |
|
| 911 | + return 0; |
|
| 912 | + } |
|
| 867 | 913 | |
| 868 | 914 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
| 869 | 915 | } |
@@ -892,8 +938,9 @@ discard block |
||
| 892 | 938 | $array[$i] = $array[$j]; |
| 893 | 939 | $array[$j] = $temp; |
| 894 | 940 | |
| 895 | - for ($i = 1; $p[$i] == 0; $i++) |
|
| 896 | - $p[$i] = 1; |
|
| 941 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
| 942 | + $p[$i] = 1; |
|
| 943 | + } |
|
| 897 | 944 | |
| 898 | 945 | $orders[] = $array; |
| 899 | 946 | } |
@@ -925,12 +972,14 @@ discard block |
||
| 925 | 972 | static $disabled; |
| 926 | 973 | |
| 927 | 974 | // Don't waste cycles |
| 928 | - if ($message === '') |
|
| 929 | - return ''; |
|
| 975 | + if ($message === '') { |
|
| 976 | + return ''; |
|
| 977 | + } |
|
| 930 | 978 | |
| 931 | 979 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
| 932 | - if (!isset($context['utf8'])) |
|
| 933 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
| 980 | + if (!isset($context['utf8'])) { |
|
| 981 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
| 982 | + } |
|
| 934 | 983 | |
| 935 | 984 | // Clean up any cut/paste issues we may have |
| 936 | 985 | $message = sanitizeMSCutPaste($message); |
@@ -942,13 +991,15 @@ discard block |
||
| 942 | 991 | return $message; |
| 943 | 992 | } |
| 944 | 993 | |
| 945 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
| 946 | - $smileys = (bool) $smileys; |
|
| 994 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
| 995 | + $smileys = (bool) $smileys; |
|
| 996 | + } |
|
| 947 | 997 | |
| 948 | 998 | if (empty($modSettings['enableBBC']) && $message !== false) |
| 949 | 999 | { |
| 950 | - if ($smileys === true) |
|
| 951 | - parsesmileys($message); |
|
| 1000 | + if ($smileys === true) { |
|
| 1001 | + parsesmileys($message); |
|
| 1002 | + } |
|
| 952 | 1003 | |
| 953 | 1004 | return $message; |
| 954 | 1005 | } |
@@ -961,8 +1012,9 @@ discard block |
||
| 961 | 1012 | } |
| 962 | 1013 | |
| 963 | 1014 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
| 964 | - if (!empty($modSettings['autoLinkUrls'])) |
|
| 965 | - set_tld_regex(); |
|
| 1015 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
| 1016 | + set_tld_regex(); |
|
| 1017 | + } |
|
| 966 | 1018 | |
| 967 | 1019 | // Allow mods access before entering the main parse_bbc loop |
| 968 | 1020 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -976,12 +1028,14 @@ discard block |
||
| 976 | 1028 | |
| 977 | 1029 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
| 978 | 1030 | |
| 979 | - foreach ($temp as $tag) |
|
| 980 | - $disabled[trim($tag)] = true; |
|
| 1031 | + foreach ($temp as $tag) { |
|
| 1032 | + $disabled[trim($tag)] = true; |
|
| 1033 | + } |
|
| 981 | 1034 | } |
| 982 | 1035 | |
| 983 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
| 984 | - $disabled['flash'] = true; |
|
| 1036 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
| 1037 | + $disabled['flash'] = true; |
|
| 1038 | + } |
|
| 985 | 1039 | |
| 986 | 1040 | /* The following bbc are formatted as an array, with keys as follows: |
| 987 | 1041 | |
@@ -1102,8 +1156,9 @@ discard block |
||
| 1102 | 1156 | $returnContext = ''; |
| 1103 | 1157 | |
| 1104 | 1158 | // BBC or the entire attachments feature is disabled |
| 1105 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
| 1106 | - return $data; |
|
| 1159 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
| 1160 | + return $data; |
|
| 1161 | + } |
|
| 1107 | 1162 | |
| 1108 | 1163 | // Save the attach ID. |
| 1109 | 1164 | $attachID = $data; |
@@ -1114,8 +1169,9 @@ discard block |
||
| 1114 | 1169 | $currentAttachment = parseAttachBBC($attachID); |
| 1115 | 1170 | |
| 1116 | 1171 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. |
| 1117 | - if (is_string($currentAttachment)) |
|
| 1118 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
| 1172 | + if (is_string($currentAttachment)) { |
|
| 1173 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
| 1174 | + } |
|
| 1119 | 1175 | |
| 1120 | 1176 | if (!empty($currentAttachment['is_image'])) |
| 1121 | 1177 | { |
@@ -1131,15 +1187,17 @@ discard block |
||
| 1131 | 1187 | $height = ' height="' . $currentAttachment['height'] . '"'; |
| 1132 | 1188 | } |
| 1133 | 1189 | |
| 1134 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
| 1135 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '"></a>'; |
|
| 1136 | - else |
|
| 1137 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . '/>'; |
|
| 1190 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
| 1191 | + $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '"></a>'; |
|
| 1192 | + } else { |
|
| 1193 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . '/>'; |
|
| 1194 | + } |
|
| 1138 | 1195 | } |
| 1139 | 1196 | |
| 1140 | 1197 | // No image. Show a link. |
| 1141 | - else |
|
| 1142 | - $returnContext .= $currentAttachment['link']; |
|
| 1198 | + else { |
|
| 1199 | + $returnContext .= $currentAttachment['link']; |
|
| 1200 | + } |
|
| 1143 | 1201 | |
| 1144 | 1202 | // Gotta append what we just did. |
| 1145 | 1203 | $data = $returnContext; |
@@ -1170,8 +1228,9 @@ discard block |
||
| 1170 | 1228 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
| 1171 | 1229 | { |
| 1172 | 1230 | // Do PHP code coloring? |
| 1173 | - if ($php_parts[$php_i] != '<?php') |
|
| 1174 | - continue; |
|
| 1231 | + if ($php_parts[$php_i] != '<?php') { |
|
| 1232 | + continue; |
|
| 1233 | + } |
|
| 1175 | 1234 | |
| 1176 | 1235 | $php_string = ''; |
| 1177 | 1236 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1187,8 +1246,9 @@ discard block |
||
| 1187 | 1246 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
| 1188 | 1247 | |
| 1189 | 1248 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
| 1190 | - if ($context['browser']['is_opera']) |
|
| 1191 | - $data .= ' '; |
|
| 1249 | + if ($context['browser']['is_opera']) { |
|
| 1250 | + $data .= ' '; |
|
| 1251 | + } |
|
| 1192 | 1252 | } |
| 1193 | 1253 | }, |
| 1194 | 1254 | 'block_level' => true, |
@@ -1207,8 +1267,9 @@ discard block |
||
| 1207 | 1267 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
| 1208 | 1268 | { |
| 1209 | 1269 | // Do PHP code coloring? |
| 1210 | - if ($php_parts[$php_i] != '<?php') |
|
| 1211 | - continue; |
|
| 1270 | + if ($php_parts[$php_i] != '<?php') { |
|
| 1271 | + continue; |
|
| 1272 | + } |
|
| 1212 | 1273 | |
| 1213 | 1274 | $php_string = ''; |
| 1214 | 1275 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1224,8 +1285,9 @@ discard block |
||
| 1224 | 1285 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
| 1225 | 1286 | |
| 1226 | 1287 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
| 1227 | - if ($context['browser']['is_opera']) |
|
| 1228 | - $data[0] .= ' '; |
|
| 1288 | + if ($context['browser']['is_opera']) { |
|
| 1289 | + $data[0] .= ' '; |
|
| 1290 | + } |
|
| 1229 | 1291 | } |
| 1230 | 1292 | }, |
| 1231 | 1293 | 'block_level' => true, |
@@ -1263,11 +1325,13 @@ discard block |
||
| 1263 | 1325 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
| 1264 | 1326 | 'validate' => function (&$tag, &$data, $disabled) |
| 1265 | 1327 | { |
| 1266 | - if (isset($disabled['url'])) |
|
| 1267 | - $tag['content'] = '$1'; |
|
| 1328 | + if (isset($disabled['url'])) { |
|
| 1329 | + $tag['content'] = '$1'; |
|
| 1330 | + } |
|
| 1268 | 1331 | $scheme = parse_url($data[0], PHP_URL_SCHEME); |
| 1269 | - if (empty($scheme)) |
|
| 1270 | - $data[0] = '//' . ltrim($data[0], ':/'); |
|
| 1332 | + if (empty($scheme)) { |
|
| 1333 | + $data[0] = '//' . ltrim($data[0], ':/'); |
|
| 1334 | + } |
|
| 1271 | 1335 | }, |
| 1272 | 1336 | 'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>', |
| 1273 | 1337 | ), |
@@ -1314,14 +1378,16 @@ discard block |
||
| 1314 | 1378 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1315 | 1379 | if ($image_proxy_enabled) |
| 1316 | 1380 | { |
| 1317 | - if (empty($scheme)) |
|
| 1318 | - $data = 'http://' . ltrim($data, ':/'); |
|
| 1381 | + if (empty($scheme)) { |
|
| 1382 | + $data = 'http://' . ltrim($data, ':/'); |
|
| 1383 | + } |
|
| 1319 | 1384 | |
| 1320 | - if ($scheme != 'https') |
|
| 1321 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1385 | + if ($scheme != 'https') { |
|
| 1386 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1387 | + } |
|
| 1388 | + } elseif (empty($scheme)) { |
|
| 1389 | + $data = '//' . ltrim($data, ':/'); |
|
| 1322 | 1390 | } |
| 1323 | - elseif (empty($scheme)) |
|
| 1324 | - $data = '//' . ltrim($data, ':/'); |
|
| 1325 | 1391 | }, |
| 1326 | 1392 | 'disabled_content' => '($1)', |
| 1327 | 1393 | ), |
@@ -1337,14 +1403,16 @@ discard block |
||
| 1337 | 1403 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1338 | 1404 | if ($image_proxy_enabled) |
| 1339 | 1405 | { |
| 1340 | - if (empty($scheme)) |
|
| 1341 | - $data = 'http://' . ltrim($data, ':/'); |
|
| 1406 | + if (empty($scheme)) { |
|
| 1407 | + $data = 'http://' . ltrim($data, ':/'); |
|
| 1408 | + } |
|
| 1342 | 1409 | |
| 1343 | - if ($scheme != 'https') |
|
| 1344 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1410 | + if ($scheme != 'https') { |
|
| 1411 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1412 | + } |
|
| 1413 | + } elseif (empty($scheme)) { |
|
| 1414 | + $data = '//' . ltrim($data, ':/'); |
|
| 1345 | 1415 | } |
| 1346 | - elseif (empty($scheme)) |
|
| 1347 | - $data = '//' . ltrim($data, ':/'); |
|
| 1348 | 1416 | }, |
| 1349 | 1417 | 'disabled_content' => '($1)', |
| 1350 | 1418 | ), |
@@ -1356,8 +1424,9 @@ discard block |
||
| 1356 | 1424 | { |
| 1357 | 1425 | $data = strtr($data, array('<br>' => '')); |
| 1358 | 1426 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1359 | - if (empty($scheme)) |
|
| 1360 | - $data = '//' . ltrim($data, ':/'); |
|
| 1427 | + if (empty($scheme)) { |
|
| 1428 | + $data = '//' . ltrim($data, ':/'); |
|
| 1429 | + } |
|
| 1361 | 1430 | }, |
| 1362 | 1431 | ), |
| 1363 | 1432 | array( |
@@ -1368,13 +1437,14 @@ discard block |
||
| 1368 | 1437 | 'after' => '</a>', |
| 1369 | 1438 | 'validate' => function (&$tag, &$data, $disabled) |
| 1370 | 1439 | { |
| 1371 | - if (substr($data, 0, 1) == '#') |
|
| 1372 | - $data = '#post_' . substr($data, 1); |
|
| 1373 | - else |
|
| 1440 | + if (substr($data, 0, 1) == '#') { |
|
| 1441 | + $data = '#post_' . substr($data, 1); |
|
| 1442 | + } else |
|
| 1374 | 1443 | { |
| 1375 | 1444 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1376 | - if (empty($scheme)) |
|
| 1377 | - $data = '//' . ltrim($data, ':/'); |
|
| 1445 | + if (empty($scheme)) { |
|
| 1446 | + $data = '//' . ltrim($data, ':/'); |
|
| 1447 | + } |
|
| 1378 | 1448 | } |
| 1379 | 1449 | }, |
| 1380 | 1450 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1452,8 +1522,9 @@ discard block |
||
| 1452 | 1522 | { |
| 1453 | 1523 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
| 1454 | 1524 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
| 1455 | - if ($add_begin) |
|
| 1456 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
| 1525 | + if ($add_begin) { |
|
| 1526 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
| 1527 | + } |
|
| 1457 | 1528 | } |
| 1458 | 1529 | }, |
| 1459 | 1530 | 'block_level' => false, |
@@ -1584,10 +1655,11 @@ discard block |
||
| 1584 | 1655 | 'content' => '$1', |
| 1585 | 1656 | 'validate' => function (&$tag, &$data, $disabled) |
| 1586 | 1657 | { |
| 1587 | - if (is_numeric($data)) |
|
| 1588 | - $data = timeformat($data); |
|
| 1589 | - else |
|
| 1590 | - $tag['content'] = '[time]$1[/time]'; |
|
| 1658 | + if (is_numeric($data)) { |
|
| 1659 | + $data = timeformat($data); |
|
| 1660 | + } else { |
|
| 1661 | + $tag['content'] = '[time]$1[/time]'; |
|
| 1662 | + } |
|
| 1591 | 1663 | }, |
| 1592 | 1664 | ), |
| 1593 | 1665 | array( |
@@ -1614,8 +1686,9 @@ discard block |
||
| 1614 | 1686 | { |
| 1615 | 1687 | $data = strtr($data, array('<br>' => '')); |
| 1616 | 1688 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1617 | - if (empty($scheme)) |
|
| 1618 | - $data = '//' . ltrim($data, ':/'); |
|
| 1689 | + if (empty($scheme)) { |
|
| 1690 | + $data = '//' . ltrim($data, ':/'); |
|
| 1691 | + } |
|
| 1619 | 1692 | }, |
| 1620 | 1693 | ), |
| 1621 | 1694 | array( |
@@ -1627,8 +1700,9 @@ discard block |
||
| 1627 | 1700 | 'validate' => function (&$tag, &$data, $disabled) |
| 1628 | 1701 | { |
| 1629 | 1702 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1630 | - if (empty($scheme)) |
|
| 1631 | - $data = '//' . ltrim($data, ':/'); |
|
| 1703 | + if (empty($scheme)) { |
|
| 1704 | + $data = '//' . ltrim($data, ':/'); |
|
| 1705 | + } |
|
| 1632 | 1706 | }, |
| 1633 | 1707 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
| 1634 | 1708 | 'disabled_after' => ' ($1)', |
@@ -1648,8 +1722,9 @@ discard block |
||
| 1648 | 1722 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
| 1649 | 1723 | if ($message === false) |
| 1650 | 1724 | { |
| 1651 | - if (isset($temp_bbc)) |
|
| 1652 | - $bbc_codes = $temp_bbc; |
|
| 1725 | + if (isset($temp_bbc)) { |
|
| 1726 | + $bbc_codes = $temp_bbc; |
|
| 1727 | + } |
|
| 1653 | 1728 | usort($codes, function ($a, $b) { |
| 1654 | 1729 | return strcmp($a['tag'], $b['tag']); |
| 1655 | 1730 | }); |
@@ -1669,8 +1744,9 @@ discard block |
||
| 1669 | 1744 | ); |
| 1670 | 1745 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
| 1671 | 1746 | { |
| 1672 | - foreach ($itemcodes as $c => $dummy) |
|
| 1673 | - $bbc_codes[$c] = array(); |
|
| 1747 | + foreach ($itemcodes as $c => $dummy) { |
|
| 1748 | + $bbc_codes[$c] = array(); |
|
| 1749 | + } |
|
| 1674 | 1750 | } |
| 1675 | 1751 | |
| 1676 | 1752 | // Shhhh! |
@@ -1691,12 +1767,14 @@ discard block |
||
| 1691 | 1767 | foreach ($codes as $code) |
| 1692 | 1768 | { |
| 1693 | 1769 | // Make it easier to process parameters later |
| 1694 | - if (!empty($code['parameters'])) |
|
| 1695 | - ksort($code['parameters'], SORT_STRING); |
|
| 1770 | + if (!empty($code['parameters'])) { |
|
| 1771 | + ksort($code['parameters'], SORT_STRING); |
|
| 1772 | + } |
|
| 1696 | 1773 | |
| 1697 | 1774 | // If we are not doing every tag only do ones we are interested in. |
| 1698 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
| 1699 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
| 1775 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
| 1776 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
| 1777 | + } |
|
| 1700 | 1778 | } |
| 1701 | 1779 | $codes = null; |
| 1702 | 1780 | } |
@@ -1707,8 +1785,9 @@ discard block |
||
| 1707 | 1785 | // It's likely this will change if the message is modified. |
| 1708 | 1786 | $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); |
| 1709 | 1787 | |
| 1710 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
| 1711 | - return $temp; |
|
| 1788 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
| 1789 | + return $temp; |
|
| 1790 | + } |
|
| 1712 | 1791 | |
| 1713 | 1792 | $cache_t = microtime(); |
| 1714 | 1793 | } |
@@ -1740,8 +1819,9 @@ discard block |
||
| 1740 | 1819 | $disabled['flash'] = true; |
| 1741 | 1820 | |
| 1742 | 1821 | // @todo Change maybe? |
| 1743 | - if (!isset($_GET['images'])) |
|
| 1744 | - $disabled['img'] = true; |
|
| 1822 | + if (!isset($_GET['images'])) { |
|
| 1823 | + $disabled['img'] = true; |
|
| 1824 | + } |
|
| 1745 | 1825 | |
| 1746 | 1826 | // @todo Interface/setting to add more? |
| 1747 | 1827 | } |
@@ -1765,8 +1845,9 @@ discard block |
||
| 1765 | 1845 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
| 1766 | 1846 | |
| 1767 | 1847 | // Failsafe. |
| 1768 | - if ($pos === false || $last_pos > $pos) |
|
| 1769 | - $pos = strlen($message) + 1; |
|
| 1848 | + if ($pos === false || $last_pos > $pos) { |
|
| 1849 | + $pos = strlen($message) + 1; |
|
| 1850 | + } |
|
| 1770 | 1851 | |
| 1771 | 1852 | // Can't have a one letter smiley, URL, or email! (sorry.) |
| 1772 | 1853 | if ($last_pos < $pos - 1) |
@@ -1785,8 +1866,9 @@ discard block |
||
| 1785 | 1866 | |
| 1786 | 1867 | // <br> should be empty. |
| 1787 | 1868 | $empty_tags = array('br', 'hr'); |
| 1788 | - foreach ($empty_tags as $tag) |
|
| 1789 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
| 1869 | + foreach ($empty_tags as $tag) { |
|
| 1870 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
| 1871 | + } |
|
| 1790 | 1872 | |
| 1791 | 1873 | // b, u, i, s, pre... basic tags. |
| 1792 | 1874 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote'); |
@@ -1795,8 +1877,9 @@ discard block |
||
| 1795 | 1877 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
| 1796 | 1878 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
| 1797 | 1879 | |
| 1798 | - if ($diff > 0) |
|
| 1799 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
| 1880 | + if ($diff > 0) { |
|
| 1881 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
| 1882 | + } |
|
| 1800 | 1883 | } |
| 1801 | 1884 | |
| 1802 | 1885 | // Do <img ...> - with security... action= -> action-. |
@@ -1809,8 +1892,9 @@ discard block |
||
| 1809 | 1892 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
| 1810 | 1893 | |
| 1811 | 1894 | // Remove action= from the URL - no funny business, now. |
| 1812 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
| 1813 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
| 1895 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
| 1896 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
| 1897 | + } |
|
| 1814 | 1898 | |
| 1815 | 1899 | // Check if the image is larger than allowed. |
| 1816 | 1900 | if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) |
@@ -1831,9 +1915,9 @@ discard block |
||
| 1831 | 1915 | |
| 1832 | 1916 | // Set the new image tag. |
| 1833 | 1917 | $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]'; |
| 1918 | + } else { |
|
| 1919 | + $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
| 1834 | 1920 | } |
| 1835 | - else |
|
| 1836 | - $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
| 1837 | 1921 | } |
| 1838 | 1922 | |
| 1839 | 1923 | $data = strtr($data, $replaces); |
@@ -1846,16 +1930,18 @@ discard block |
||
| 1846 | 1930 | $no_autolink_area = false; |
| 1847 | 1931 | if (!empty($open_tags)) |
| 1848 | 1932 | { |
| 1849 | - foreach ($open_tags as $open_tag) |
|
| 1850 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
| 1933 | + foreach ($open_tags as $open_tag) { |
|
| 1934 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
| 1851 | 1935 | $no_autolink_area = true; |
| 1936 | + } |
|
| 1852 | 1937 | } |
| 1853 | 1938 | |
| 1854 | 1939 | // Don't go backwards. |
| 1855 | 1940 | // @todo Don't think is the real solution.... |
| 1856 | 1941 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
| 1857 | - if ($pos < $lastAutoPos) |
|
| 1858 | - $no_autolink_area = true; |
|
| 1942 | + if ($pos < $lastAutoPos) { |
|
| 1943 | + $no_autolink_area = true; |
|
| 1944 | + } |
|
| 1859 | 1945 | $lastAutoPos = $pos; |
| 1860 | 1946 | |
| 1861 | 1947 | if (!$no_autolink_area) |
@@ -1964,17 +2050,19 @@ discard block |
||
| 1964 | 2050 | if ($scheme == 'mailto') |
| 1965 | 2051 | { |
| 1966 | 2052 | $email_address = str_replace('mailto:', '', $url); |
| 1967 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
| 1968 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
| 1969 | - else |
|
| 1970 | - return $url; |
|
| 2053 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
| 2054 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
| 2055 | + } else { |
|
| 2056 | + return $url; |
|
| 2057 | + } |
|
| 1971 | 2058 | } |
| 1972 | 2059 | |
| 1973 | 2060 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
| 1974 | - if (empty($scheme)) |
|
| 1975 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
| 1976 | - else |
|
| 1977 | - $fullUrl = $url; |
|
| 2061 | + if (empty($scheme)) { |
|
| 2062 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
| 2063 | + } else { |
|
| 2064 | + $fullUrl = $url; |
|
| 2065 | + } |
|
| 1978 | 2066 | |
| 1979 | 2067 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
| 1980 | 2068 | }, $data); |
@@ -2023,16 +2111,18 @@ discard block |
||
| 2023 | 2111 | } |
| 2024 | 2112 | |
| 2025 | 2113 | // Are we there yet? Are we there yet? |
| 2026 | - if ($pos >= strlen($message) - 1) |
|
| 2027 | - break; |
|
| 2114 | + if ($pos >= strlen($message) - 1) { |
|
| 2115 | + break; |
|
| 2116 | + } |
|
| 2028 | 2117 | |
| 2029 | 2118 | $tags = strtolower($message[$pos + 1]); |
| 2030 | 2119 | |
| 2031 | 2120 | if ($tags == '/' && !empty($open_tags)) |
| 2032 | 2121 | { |
| 2033 | 2122 | $pos2 = strpos($message, ']', $pos + 1); |
| 2034 | - if ($pos2 == $pos + 2) |
|
| 2035 | - continue; |
|
| 2123 | + if ($pos2 == $pos + 2) { |
|
| 2124 | + continue; |
|
| 2125 | + } |
|
| 2036 | 2126 | |
| 2037 | 2127 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
| 2038 | 2128 | |
@@ -2042,8 +2132,9 @@ discard block |
||
| 2042 | 2132 | do |
| 2043 | 2133 | { |
| 2044 | 2134 | $tag = array_pop($open_tags); |
| 2045 | - if (!$tag) |
|
| 2046 | - break; |
|
| 2135 | + if (!$tag) { |
|
| 2136 | + break; |
|
| 2137 | + } |
|
| 2047 | 2138 | |
| 2048 | 2139 | if (!empty($tag['block_level'])) |
| 2049 | 2140 | { |
@@ -2057,10 +2148,11 @@ discard block |
||
| 2057 | 2148 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
| 2058 | 2149 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
| 2059 | 2150 | { |
| 2060 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
| 2061 | - if ($temp['tag'] == $look_for) |
|
| 2151 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
| 2152 | + if ($temp['tag'] == $look_for) |
|
| 2062 | 2153 | { |
| 2063 | 2154 | $block_level = !empty($temp['block_level']); |
| 2155 | + } |
|
| 2064 | 2156 | break; |
| 2065 | 2157 | } |
| 2066 | 2158 | } |
@@ -2082,15 +2174,15 @@ discard block |
||
| 2082 | 2174 | { |
| 2083 | 2175 | $open_tags = $to_close; |
| 2084 | 2176 | continue; |
| 2085 | - } |
|
| 2086 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
| 2177 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
| 2087 | 2178 | { |
| 2088 | 2179 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
| 2089 | 2180 | { |
| 2090 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
| 2091 | - if ($temp['tag'] == $look_for) |
|
| 2181 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
| 2182 | + if ($temp['tag'] == $look_for) |
|
| 2092 | 2183 | { |
| 2093 | 2184 | $block_level = !empty($temp['block_level']); |
| 2185 | + } |
|
| 2094 | 2186 | break; |
| 2095 | 2187 | } |
| 2096 | 2188 | } |
@@ -2098,8 +2190,9 @@ discard block |
||
| 2098 | 2190 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
| 2099 | 2191 | if (!$block_level) |
| 2100 | 2192 | { |
| 2101 | - foreach ($to_close as $tag) |
|
| 2102 | - array_push($open_tags, $tag); |
|
| 2193 | + foreach ($to_close as $tag) { |
|
| 2194 | + array_push($open_tags, $tag); |
|
| 2195 | + } |
|
| 2103 | 2196 | continue; |
| 2104 | 2197 | } |
| 2105 | 2198 | } |
@@ -2111,10 +2204,12 @@ discard block |
||
| 2111 | 2204 | $pos2 = $pos - 1; |
| 2112 | 2205 | |
| 2113 | 2206 | // See the comment at the end of the big loop - just eating whitespace ;). |
| 2114 | - if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') |
|
| 2115 | - $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
| 2116 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) |
|
| 2117 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2207 | + if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') { |
|
| 2208 | + $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
| 2209 | + } |
|
| 2210 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) { |
|
| 2211 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2212 | + } |
|
| 2118 | 2213 | } |
| 2119 | 2214 | |
| 2120 | 2215 | if (!empty($to_close)) |
@@ -2127,8 +2222,9 @@ discard block |
||
| 2127 | 2222 | } |
| 2128 | 2223 | |
| 2129 | 2224 | // No tags for this character, so just keep going (fastest possible course.) |
| 2130 | - if (!isset($bbc_codes[$tags])) |
|
| 2131 | - continue; |
|
| 2225 | + if (!isset($bbc_codes[$tags])) { |
|
| 2226 | + continue; |
|
| 2227 | + } |
|
| 2132 | 2228 | |
| 2133 | 2229 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
| 2134 | 2230 | $tag = null; |
@@ -2137,44 +2233,52 @@ discard block |
||
| 2137 | 2233 | $pt_strlen = strlen($possible['tag']); |
| 2138 | 2234 | |
| 2139 | 2235 | // Not a match? |
| 2140 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
| 2141 | - continue; |
|
| 2236 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
| 2237 | + continue; |
|
| 2238 | + } |
|
| 2142 | 2239 | |
| 2143 | 2240 | $next_c = $message[$pos + 1 + $pt_strlen]; |
| 2144 | 2241 | |
| 2145 | 2242 | // A test validation? |
| 2146 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
| 2147 | - continue; |
|
| 2243 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
| 2244 | + continue; |
|
| 2245 | + } |
|
| 2148 | 2246 | // Do we want parameters? |
| 2149 | 2247 | elseif (!empty($possible['parameters'])) |
| 2150 | 2248 | { |
| 2151 | - if ($next_c != ' ') |
|
| 2152 | - continue; |
|
| 2153 | - } |
|
| 2154 | - elseif (isset($possible['type'])) |
|
| 2249 | + if ($next_c != ' ') { |
|
| 2250 | + continue; |
|
| 2251 | + } |
|
| 2252 | + } elseif (isset($possible['type'])) |
|
| 2155 | 2253 | { |
| 2156 | 2254 | // Do we need an equal sign? |
| 2157 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
| 2158 | - continue; |
|
| 2255 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
| 2256 | + continue; |
|
| 2257 | + } |
|
| 2159 | 2258 | // Maybe we just want a /... |
| 2160 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
| 2161 | - continue; |
|
| 2259 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
| 2260 | + continue; |
|
| 2261 | + } |
|
| 2162 | 2262 | // An immediate ]? |
| 2163 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
| 2164 | - continue; |
|
| 2263 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
| 2264 | + continue; |
|
| 2265 | + } |
|
| 2165 | 2266 | } |
| 2166 | 2267 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
| 2167 | - elseif ($next_c != ']') |
|
| 2168 | - continue; |
|
| 2268 | + elseif ($next_c != ']') { |
|
| 2269 | + continue; |
|
| 2270 | + } |
|
| 2169 | 2271 | |
| 2170 | 2272 | // Check allowed tree? |
| 2171 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
| 2172 | - continue; |
|
| 2173 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
| 2174 | - continue; |
|
| 2273 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
| 2274 | + continue; |
|
| 2275 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
| 2276 | + continue; |
|
| 2277 | + } |
|
| 2175 | 2278 | // If this is in the list of disallowed child tags, don't parse it. |
| 2176 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
| 2177 | - continue; |
|
| 2279 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
| 2280 | + continue; |
|
| 2281 | + } |
|
| 2178 | 2282 | |
| 2179 | 2283 | $pos1 = $pos + 1 + $pt_strlen + 1; |
| 2180 | 2284 | |
@@ -2186,8 +2290,9 @@ discard block |
||
| 2186 | 2290 | foreach ($open_tags as $open_quote) |
| 2187 | 2291 | { |
| 2188 | 2292 | // Every parent quote this quote has flips the styling |
| 2189 | - if ($open_quote['tag'] == 'quote') |
|
| 2190 | - $quote_alt = !$quote_alt; |
|
| 2293 | + if ($open_quote['tag'] == 'quote') { |
|
| 2294 | + $quote_alt = !$quote_alt; |
|
| 2295 | + } |
|
| 2191 | 2296 | } |
| 2192 | 2297 | // Add a class to the quote to style alternating blockquotes |
| 2193 | 2298 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2198,8 +2303,9 @@ discard block |
||
| 2198 | 2303 | { |
| 2199 | 2304 | // Build a regular expression for each parameter for the current tag. |
| 2200 | 2305 | $preg = array(); |
| 2201 | - foreach ($possible['parameters'] as $p => $info) |
|
| 2202 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
| 2306 | + foreach ($possible['parameters'] as $p => $info) { |
|
| 2307 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
| 2308 | + } |
|
| 2203 | 2309 | |
| 2204 | 2310 | // Extract the string that potentially holds our parameters. |
| 2205 | 2311 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2219,24 +2325,27 @@ discard block |
||
| 2219 | 2325 | |
| 2220 | 2326 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
| 2221 | 2327 | |
| 2222 | - if ($match) |
|
| 2223 | - $blob_counter = count($blobs) + 1; |
|
| 2328 | + if ($match) { |
|
| 2329 | + $blob_counter = count($blobs) + 1; |
|
| 2330 | + } |
|
| 2224 | 2331 | } |
| 2225 | 2332 | |
| 2226 | 2333 | // Didn't match our parameter list, try the next possible. |
| 2227 | - if (!$match) |
|
| 2228 | - continue; |
|
| 2334 | + if (!$match) { |
|
| 2335 | + continue; |
|
| 2336 | + } |
|
| 2229 | 2337 | |
| 2230 | 2338 | $params = array(); |
| 2231 | 2339 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
| 2232 | 2340 | { |
| 2233 | 2341 | $key = strtok(ltrim($matches[$i]), '='); |
| 2234 | - if (isset($possible['parameters'][$key]['value'])) |
|
| 2235 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
| 2236 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
| 2237 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
| 2238 | - else |
|
| 2239 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
| 2342 | + if (isset($possible['parameters'][$key]['value'])) { |
|
| 2343 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
| 2344 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
| 2345 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
| 2346 | + } else { |
|
| 2347 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
| 2348 | + } |
|
| 2240 | 2349 | |
| 2241 | 2350 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
| 2242 | 2351 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2244,23 +2353,26 @@ discard block |
||
| 2244 | 2353 | |
| 2245 | 2354 | foreach ($possible['parameters'] as $p => $info) |
| 2246 | 2355 | { |
| 2247 | - if (!isset($params['{' . $p . '}'])) |
|
| 2248 | - $params['{' . $p . '}'] = ''; |
|
| 2356 | + if (!isset($params['{' . $p . '}'])) { |
|
| 2357 | + $params['{' . $p . '}'] = ''; |
|
| 2358 | + } |
|
| 2249 | 2359 | } |
| 2250 | 2360 | |
| 2251 | 2361 | $tag = $possible; |
| 2252 | 2362 | |
| 2253 | 2363 | // Put the parameters into the string. |
| 2254 | - if (isset($tag['before'])) |
|
| 2255 | - $tag['before'] = strtr($tag['before'], $params); |
|
| 2256 | - if (isset($tag['after'])) |
|
| 2257 | - $tag['after'] = strtr($tag['after'], $params); |
|
| 2258 | - if (isset($tag['content'])) |
|
| 2259 | - $tag['content'] = strtr($tag['content'], $params); |
|
| 2364 | + if (isset($tag['before'])) { |
|
| 2365 | + $tag['before'] = strtr($tag['before'], $params); |
|
| 2366 | + } |
|
| 2367 | + if (isset($tag['after'])) { |
|
| 2368 | + $tag['after'] = strtr($tag['after'], $params); |
|
| 2369 | + } |
|
| 2370 | + if (isset($tag['content'])) { |
|
| 2371 | + $tag['content'] = strtr($tag['content'], $params); |
|
| 2372 | + } |
|
| 2260 | 2373 | |
| 2261 | 2374 | $pos1 += strlen($given_param_string); |
| 2262 | - } |
|
| 2263 | - else |
|
| 2375 | + } else |
|
| 2264 | 2376 | { |
| 2265 | 2377 | $tag = $possible; |
| 2266 | 2378 | $params = array(); |
@@ -2271,8 +2383,9 @@ discard block |
||
| 2271 | 2383 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
| 2272 | 2384 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
| 2273 | 2385 | { |
| 2274 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
| 2275 | - continue; |
|
| 2386 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
| 2387 | + continue; |
|
| 2388 | + } |
|
| 2276 | 2389 | |
| 2277 | 2390 | $tag = $itemcodes[$message[$pos + 1]]; |
| 2278 | 2391 | |
@@ -2293,9 +2406,9 @@ discard block |
||
| 2293 | 2406 | { |
| 2294 | 2407 | array_pop($open_tags); |
| 2295 | 2408 | $code = '</li>'; |
| 2409 | + } else { |
|
| 2410 | + $code = ''; |
|
| 2296 | 2411 | } |
| 2297 | - else |
|
| 2298 | - $code = ''; |
|
| 2299 | 2412 | |
| 2300 | 2413 | // Now we open a new tag. |
| 2301 | 2414 | $open_tags[] = array( |
@@ -2342,12 +2455,14 @@ discard block |
||
| 2342 | 2455 | } |
| 2343 | 2456 | |
| 2344 | 2457 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
| 2345 | - if ($tag === null) |
|
| 2346 | - continue; |
|
| 2458 | + if ($tag === null) { |
|
| 2459 | + continue; |
|
| 2460 | + } |
|
| 2347 | 2461 | |
| 2348 | 2462 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
| 2349 | - if (isset($inside['disallow_children'])) |
|
| 2350 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
| 2463 | + if (isset($inside['disallow_children'])) { |
|
| 2464 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
| 2465 | + } |
|
| 2351 | 2466 | |
| 2352 | 2467 | // Is this tag disabled? |
| 2353 | 2468 | if (isset($disabled[$tag['tag']])) |
@@ -2357,14 +2472,13 @@ discard block |
||
| 2357 | 2472 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
| 2358 | 2473 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
| 2359 | 2474 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
| 2360 | - } |
|
| 2361 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
| 2475 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
| 2362 | 2476 | { |
| 2363 | 2477 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
| 2364 | 2478 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
| 2479 | + } else { |
|
| 2480 | + $tag['content'] = $tag['disabled_content']; |
|
| 2365 | 2481 | } |
| 2366 | - else |
|
| 2367 | - $tag['content'] = $tag['disabled_content']; |
|
| 2368 | 2482 | } |
| 2369 | 2483 | |
| 2370 | 2484 | // we use this a lot |
@@ -2374,8 +2488,9 @@ discard block |
||
| 2374 | 2488 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
| 2375 | 2489 | { |
| 2376 | 2490 | $n = count($open_tags) - 1; |
| 2377 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
| 2378 | - $n--; |
|
| 2491 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
| 2492 | + $n--; |
|
| 2493 | + } |
|
| 2379 | 2494 | |
| 2380 | 2495 | // Close all the non block level tags so this tag isn't surrounded by them. |
| 2381 | 2496 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2386,10 +2501,12 @@ discard block |
||
| 2386 | 2501 | $pos1 += $ot_strlen + 2; |
| 2387 | 2502 | |
| 2388 | 2503 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
| 2389 | - if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') |
|
| 2390 | - $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
| 2391 | - if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) |
|
| 2392 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2504 | + if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') { |
|
| 2505 | + $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
| 2506 | + } |
|
| 2507 | + if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) { |
|
| 2508 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2509 | + } |
|
| 2393 | 2510 | |
| 2394 | 2511 | array_pop($open_tags); |
| 2395 | 2512 | } |
@@ -2407,16 +2524,19 @@ discard block |
||
| 2407 | 2524 | elseif ($tag['type'] == 'unparsed_content') |
| 2408 | 2525 | { |
| 2409 | 2526 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
| 2410 | - if ($pos2 === false) |
|
| 2411 | - continue; |
|
| 2527 | + if ($pos2 === false) { |
|
| 2528 | + continue; |
|
| 2529 | + } |
|
| 2412 | 2530 | |
| 2413 | 2531 | $data = substr($message, $pos1, $pos2 - $pos1); |
| 2414 | 2532 | |
| 2415 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
| 2416 | - $data = substr($data, 4); |
|
| 2533 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
| 2534 | + $data = substr($data, 4); |
|
| 2535 | + } |
|
| 2417 | 2536 | |
| 2418 | - if (isset($tag['validate'])) |
|
| 2419 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2537 | + if (isset($tag['validate'])) { |
|
| 2538 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2539 | + } |
|
| 2420 | 2540 | |
| 2421 | 2541 | $code = strtr($tag['content'], array('$1' => $data)); |
| 2422 | 2542 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2432,34 +2552,40 @@ discard block |
||
| 2432 | 2552 | if (isset($tag['quoted'])) |
| 2433 | 2553 | { |
| 2434 | 2554 | $quoted = substr($message, $pos1, 6) == '"'; |
| 2435 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
| 2436 | - continue; |
|
| 2555 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
| 2556 | + continue; |
|
| 2557 | + } |
|
| 2437 | 2558 | |
| 2438 | - if ($quoted) |
|
| 2439 | - $pos1 += 6; |
|
| 2559 | + if ($quoted) { |
|
| 2560 | + $pos1 += 6; |
|
| 2561 | + } |
|
| 2562 | + } else { |
|
| 2563 | + $quoted = false; |
|
| 2440 | 2564 | } |
| 2441 | - else |
|
| 2442 | - $quoted = false; |
|
| 2443 | 2565 | |
| 2444 | 2566 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
| 2445 | - if ($pos2 === false) |
|
| 2446 | - continue; |
|
| 2567 | + if ($pos2 === false) { |
|
| 2568 | + continue; |
|
| 2569 | + } |
|
| 2447 | 2570 | |
| 2448 | 2571 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
| 2449 | - if ($pos3 === false) |
|
| 2450 | - continue; |
|
| 2572 | + if ($pos3 === false) { |
|
| 2573 | + continue; |
|
| 2574 | + } |
|
| 2451 | 2575 | |
| 2452 | 2576 | $data = array( |
| 2453 | 2577 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
| 2454 | 2578 | substr($message, $pos1, $pos2 - $pos1) |
| 2455 | 2579 | ); |
| 2456 | 2580 | |
| 2457 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
| 2458 | - $data[0] = substr($data[0], 4); |
|
| 2581 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
| 2582 | + $data[0] = substr($data[0], 4); |
|
| 2583 | + } |
|
| 2459 | 2584 | |
| 2460 | 2585 | // Validation for my parking, please! |
| 2461 | - if (isset($tag['validate'])) |
|
| 2462 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2586 | + if (isset($tag['validate'])) { |
|
| 2587 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2588 | + } |
|
| 2463 | 2589 | |
| 2464 | 2590 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
| 2465 | 2591 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2476,23 +2602,27 @@ discard block |
||
| 2476 | 2602 | elseif ($tag['type'] == 'unparsed_commas_content') |
| 2477 | 2603 | { |
| 2478 | 2604 | $pos2 = strpos($message, ']', $pos1); |
| 2479 | - if ($pos2 === false) |
|
| 2480 | - continue; |
|
| 2605 | + if ($pos2 === false) { |
|
| 2606 | + continue; |
|
| 2607 | + } |
|
| 2481 | 2608 | |
| 2482 | 2609 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
| 2483 | - if ($pos3 === false) |
|
| 2484 | - continue; |
|
| 2610 | + if ($pos3 === false) { |
|
| 2611 | + continue; |
|
| 2612 | + } |
|
| 2485 | 2613 | |
| 2486 | 2614 | // We want $1 to be the content, and the rest to be csv. |
| 2487 | 2615 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
| 2488 | 2616 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
| 2489 | 2617 | |
| 2490 | - if (isset($tag['validate'])) |
|
| 2491 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2618 | + if (isset($tag['validate'])) { |
|
| 2619 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2620 | + } |
|
| 2492 | 2621 | |
| 2493 | 2622 | $code = $tag['content']; |
| 2494 | - foreach ($data as $k => $d) |
|
| 2495 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2623 | + foreach ($data as $k => $d) { |
|
| 2624 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2625 | + } |
|
| 2496 | 2626 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
| 2497 | 2627 | $pos += strlen($code) - 1 + 2; |
| 2498 | 2628 | } |
@@ -2500,24 +2630,28 @@ discard block |
||
| 2500 | 2630 | elseif ($tag['type'] == 'unparsed_commas') |
| 2501 | 2631 | { |
| 2502 | 2632 | $pos2 = strpos($message, ']', $pos1); |
| 2503 | - if ($pos2 === false) |
|
| 2504 | - continue; |
|
| 2633 | + if ($pos2 === false) { |
|
| 2634 | + continue; |
|
| 2635 | + } |
|
| 2505 | 2636 | |
| 2506 | 2637 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
| 2507 | 2638 | |
| 2508 | - if (isset($tag['validate'])) |
|
| 2509 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2639 | + if (isset($tag['validate'])) { |
|
| 2640 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2641 | + } |
|
| 2510 | 2642 | |
| 2511 | 2643 | // Fix after, for disabled code mainly. |
| 2512 | - foreach ($data as $k => $d) |
|
| 2513 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
| 2644 | + foreach ($data as $k => $d) { |
|
| 2645 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
| 2646 | + } |
|
| 2514 | 2647 | |
| 2515 | 2648 | $open_tags[] = $tag; |
| 2516 | 2649 | |
| 2517 | 2650 | // Replace them out, $1, $2, $3, $4, etc. |
| 2518 | 2651 | $code = $tag['before']; |
| 2519 | - foreach ($data as $k => $d) |
|
| 2520 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2652 | + foreach ($data as $k => $d) { |
|
| 2653 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2654 | + } |
|
| 2521 | 2655 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
| 2522 | 2656 | $pos += strlen($code) - 1 + 2; |
| 2523 | 2657 | } |
@@ -2528,28 +2662,33 @@ discard block |
||
| 2528 | 2662 | if (isset($tag['quoted'])) |
| 2529 | 2663 | { |
| 2530 | 2664 | $quoted = substr($message, $pos1, 6) == '"'; |
| 2531 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
| 2532 | - continue; |
|
| 2665 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
| 2666 | + continue; |
|
| 2667 | + } |
|
| 2533 | 2668 | |
| 2534 | - if ($quoted) |
|
| 2535 | - $pos1 += 6; |
|
| 2669 | + if ($quoted) { |
|
| 2670 | + $pos1 += 6; |
|
| 2671 | + } |
|
| 2672 | + } else { |
|
| 2673 | + $quoted = false; |
|
| 2536 | 2674 | } |
| 2537 | - else |
|
| 2538 | - $quoted = false; |
|
| 2539 | 2675 | |
| 2540 | 2676 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
| 2541 | - if ($pos2 === false) |
|
| 2542 | - continue; |
|
| 2677 | + if ($pos2 === false) { |
|
| 2678 | + continue; |
|
| 2679 | + } |
|
| 2543 | 2680 | |
| 2544 | 2681 | $data = substr($message, $pos1, $pos2 - $pos1); |
| 2545 | 2682 | |
| 2546 | 2683 | // Validation for my parking, please! |
| 2547 | - if (isset($tag['validate'])) |
|
| 2548 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2684 | + if (isset($tag['validate'])) { |
|
| 2685 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2686 | + } |
|
| 2549 | 2687 | |
| 2550 | 2688 | // For parsed content, we must recurse to avoid security problems. |
| 2551 | - if ($tag['type'] != 'unparsed_equals') |
|
| 2552 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
| 2689 | + if ($tag['type'] != 'unparsed_equals') { |
|
| 2690 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
| 2691 | + } |
|
| 2553 | 2692 | |
| 2554 | 2693 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
| 2555 | 2694 | |
@@ -2561,34 +2700,40 @@ discard block |
||
| 2561 | 2700 | } |
| 2562 | 2701 | |
| 2563 | 2702 | // If this is block level, eat any breaks after it. |
| 2564 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
| 2565 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
| 2703 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
| 2704 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
| 2705 | + } |
|
| 2566 | 2706 | |
| 2567 | 2707 | // Are we trimming outside this tag? |
| 2568 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
| 2569 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
| 2708 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
| 2709 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
| 2710 | + } |
|
| 2570 | 2711 | } |
| 2571 | 2712 | |
| 2572 | 2713 | // Close any remaining tags. |
| 2573 | - while ($tag = array_pop($open_tags)) |
|
| 2574 | - $message .= "\n" . $tag['after'] . "\n"; |
|
| 2714 | + while ($tag = array_pop($open_tags)) { |
|
| 2715 | + $message .= "\n" . $tag['after'] . "\n"; |
|
| 2716 | + } |
|
| 2575 | 2717 | |
| 2576 | 2718 | // Parse the smileys within the parts where it can be done safely. |
| 2577 | 2719 | if ($smileys === true) |
| 2578 | 2720 | { |
| 2579 | 2721 | $message_parts = explode("\n", $message); |
| 2580 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
| 2581 | - parsesmileys($message_parts[$i]); |
|
| 2722 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
| 2723 | + parsesmileys($message_parts[$i]); |
|
| 2724 | + } |
|
| 2582 | 2725 | |
| 2583 | 2726 | $message = implode('', $message_parts); |
| 2584 | 2727 | } |
| 2585 | 2728 | |
| 2586 | 2729 | // No smileys, just get rid of the markers. |
| 2587 | - else |
|
| 2588 | - $message = strtr($message, array("\n" => '')); |
|
| 2730 | + else { |
|
| 2731 | + $message = strtr($message, array("\n" => '')); |
|
| 2732 | + } |
|
| 2589 | 2733 | |
| 2590 | - if ($message !== '' && $message[0] === ' ') |
|
| 2591 | - $message = ' ' . substr($message, 1); |
|
| 2734 | + if ($message !== '' && $message[0] === ' ') { |
|
| 2735 | + $message = ' ' . substr($message, 1); |
|
| 2736 | + } |
|
| 2592 | 2737 | |
| 2593 | 2738 | // Cleanup whitespace. |
| 2594 | 2739 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2597,15 +2742,16 @@ discard block |
||
| 2597 | 2742 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
| 2598 | 2743 | |
| 2599 | 2744 | // Cache the output if it took some time... |
| 2600 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
| 2601 | - cache_put_data($cache_key, $message, 240); |
|
| 2745 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
| 2746 | + cache_put_data($cache_key, $message, 240); |
|
| 2747 | + } |
|
| 2602 | 2748 | |
| 2603 | 2749 | // If this was a force parse revert if needed. |
| 2604 | 2750 | if (!empty($parse_tags)) |
| 2605 | 2751 | { |
| 2606 | - if (empty($temp_bbc)) |
|
| 2607 | - $bbc_codes = array(); |
|
| 2608 | - else |
|
| 2752 | + if (empty($temp_bbc)) { |
|
| 2753 | + $bbc_codes = array(); |
|
| 2754 | + } else |
|
| 2609 | 2755 | { |
| 2610 | 2756 | $bbc_codes = $temp_bbc; |
| 2611 | 2757 | unset($temp_bbc); |
@@ -2632,8 +2778,9 @@ discard block |
||
| 2632 | 2778 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
| 2633 | 2779 | |
| 2634 | 2780 | // No smiley set at all?! |
| 2635 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
| 2636 | - return; |
|
| 2781 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
| 2782 | + return; |
|
| 2783 | + } |
|
| 2637 | 2784 | |
| 2638 | 2785 | // If smileyPregSearch hasn't been set, do it now. |
| 2639 | 2786 | if (empty($smileyPregSearch)) |
@@ -2644,8 +2791,7 @@ discard block |
||
| 2644 | 2791 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); |
| 2645 | 2792 | $smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif'); |
| 2646 | 2793 | $smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', ''); |
| 2647 | - } |
|
| 2648 | - else |
|
| 2794 | + } else |
|
| 2649 | 2795 | { |
| 2650 | 2796 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
| 2651 | 2797 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2669,9 +2815,9 @@ discard block |
||
| 2669 | 2815 | $smcFunc['db_free_result']($result); |
| 2670 | 2816 | |
| 2671 | 2817 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
| 2818 | + } else { |
|
| 2819 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
| 2672 | 2820 | } |
| 2673 | - else |
|
| 2674 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
| 2675 | 2821 | } |
| 2676 | 2822 | |
| 2677 | 2823 | // The non-breaking-space is a complex thing... |
@@ -2748,35 +2894,41 @@ discard block |
||
| 2748 | 2894 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
| 2749 | 2895 | |
| 2750 | 2896 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
| 2751 | - if (!empty($context['flush_mail'])) |
|
| 2752 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2897 | + if (!empty($context['flush_mail'])) { |
|
| 2898 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2753 | 2899 | AddMailQueue(true); |
| 2900 | + } |
|
| 2754 | 2901 | |
| 2755 | 2902 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
| 2756 | 2903 | |
| 2757 | - if ($add) |
|
| 2758 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
| 2904 | + if ($add) { |
|
| 2905 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
| 2906 | + } |
|
| 2759 | 2907 | |
| 2760 | 2908 | // Put the session ID in. |
| 2761 | - if (defined('SID') && SID != '') |
|
| 2762 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
| 2909 | + if (defined('SID') && SID != '') { |
|
| 2910 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
| 2911 | + } |
|
| 2763 | 2912 | // Keep that debug in their for template debugging! |
| 2764 | - elseif (isset($_GET['debug'])) |
|
| 2765 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
| 2913 | + elseif (isset($_GET['debug'])) { |
|
| 2914 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
| 2915 | + } |
|
| 2766 | 2916 | |
| 2767 | 2917 | if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed']))) |
| 2768 | 2918 | { |
| 2769 | - if (defined('SID') && SID != '') |
|
| 2770 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
| 2919 | + if (defined('SID') && SID != '') { |
|
| 2920 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
| 2771 | 2921 | function ($m) use ($scripturl) |
| 2772 | 2922 | { |
| 2773 | 2923 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
| 2924 | + } |
|
| 2774 | 2925 | }, $setLocation); |
| 2775 | - else |
|
| 2776 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
| 2926 | + else { |
|
| 2927 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
| 2777 | 2928 | function ($m) use ($scripturl) |
| 2778 | 2929 | { |
| 2779 | 2930 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
| 2931 | + } |
|
| 2780 | 2932 | }, $setLocation); |
| 2781 | 2933 | } |
| 2782 | 2934 | |
@@ -2787,8 +2939,9 @@ discard block |
||
| 2787 | 2939 | header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
| 2788 | 2940 | |
| 2789 | 2941 | // Debugging. |
| 2790 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 2791 | - $_SESSION['debug_redirect'] = $db_cache; |
|
| 2942 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 2943 | + $_SESSION['debug_redirect'] = $db_cache; |
|
| 2944 | + } |
|
| 2792 | 2945 | |
| 2793 | 2946 | obExit(false); |
| 2794 | 2947 | } |
@@ -2807,51 +2960,60 @@ discard block |
||
| 2807 | 2960 | |
| 2808 | 2961 | // Attempt to prevent a recursive loop. |
| 2809 | 2962 | ++$level; |
| 2810 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
| 2811 | - exit; |
|
| 2812 | - if ($from_fatal_error) |
|
| 2813 | - $has_fatal_error = true; |
|
| 2963 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
| 2964 | + exit; |
|
| 2965 | + } |
|
| 2966 | + if ($from_fatal_error) { |
|
| 2967 | + $has_fatal_error = true; |
|
| 2968 | + } |
|
| 2814 | 2969 | |
| 2815 | 2970 | // Clear out the stat cache. |
| 2816 | 2971 | trackStats(); |
| 2817 | 2972 | |
| 2818 | 2973 | // If we have mail to send, send it. |
| 2819 | - if (!empty($context['flush_mail'])) |
|
| 2820 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2974 | + if (!empty($context['flush_mail'])) { |
|
| 2975 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2821 | 2976 | AddMailQueue(true); |
| 2977 | + } |
|
| 2822 | 2978 | |
| 2823 | 2979 | $do_header = $header === null ? !$header_done : $header; |
| 2824 | - if ($do_footer === null) |
|
| 2825 | - $do_footer = $do_header; |
|
| 2980 | + if ($do_footer === null) { |
|
| 2981 | + $do_footer = $do_header; |
|
| 2982 | + } |
|
| 2826 | 2983 | |
| 2827 | 2984 | // Has the template/header been done yet? |
| 2828 | 2985 | if ($do_header) |
| 2829 | 2986 | { |
| 2830 | 2987 | // Was the page title set last minute? Also update the HTML safe one. |
| 2831 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
| 2832 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
| 2988 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
| 2989 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
| 2990 | + } |
|
| 2833 | 2991 | |
| 2834 | 2992 | // Start up the session URL fixer. |
| 2835 | 2993 | ob_start('ob_sessrewrite'); |
| 2836 | 2994 | |
| 2837 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
| 2838 | - $buffers = explode(',', $settings['output_buffers']); |
|
| 2839 | - elseif (!empty($settings['output_buffers'])) |
|
| 2840 | - $buffers = $settings['output_buffers']; |
|
| 2841 | - else |
|
| 2842 | - $buffers = array(); |
|
| 2995 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
| 2996 | + $buffers = explode(',', $settings['output_buffers']); |
|
| 2997 | + } elseif (!empty($settings['output_buffers'])) { |
|
| 2998 | + $buffers = $settings['output_buffers']; |
|
| 2999 | + } else { |
|
| 3000 | + $buffers = array(); |
|
| 3001 | + } |
|
| 2843 | 3002 | |
| 2844 | - if (isset($modSettings['integrate_buffer'])) |
|
| 2845 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
| 3003 | + if (isset($modSettings['integrate_buffer'])) { |
|
| 3004 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
| 3005 | + } |
|
| 2846 | 3006 | |
| 2847 | - if (!empty($buffers)) |
|
| 2848 | - foreach ($buffers as $function) |
|
| 3007 | + if (!empty($buffers)) { |
|
| 3008 | + foreach ($buffers as $function) |
|
| 2849 | 3009 | { |
| 2850 | 3010 | $call = call_helper($function, true); |
| 3011 | + } |
|
| 2851 | 3012 | |
| 2852 | 3013 | // Is it valid? |
| 2853 | - if (!empty($call)) |
|
| 2854 | - ob_start($call); |
|
| 3014 | + if (!empty($call)) { |
|
| 3015 | + ob_start($call); |
|
| 3016 | + } |
|
| 2855 | 3017 | } |
| 2856 | 3018 | |
| 2857 | 3019 | // Display the screen in the logical order. |
@@ -2863,8 +3025,9 @@ discard block |
||
| 2863 | 3025 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
| 2864 | 3026 | |
| 2865 | 3027 | // Anything special to put out? |
| 2866 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
| 2867 | - echo $context['insert_after_template']; |
|
| 3028 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
| 3029 | + echo $context['insert_after_template']; |
|
| 3030 | + } |
|
| 2868 | 3031 | |
| 2869 | 3032 | // Just so we don't get caught in an endless loop of errors from the footer... |
| 2870 | 3033 | if (!$footer_done) |
@@ -2873,14 +3036,16 @@ discard block |
||
| 2873 | 3036 | template_footer(); |
| 2874 | 3037 | |
| 2875 | 3038 | // (since this is just debugging... it's okay that it's after </html>.) |
| 2876 | - if (!isset($_REQUEST['xml'])) |
|
| 2877 | - displayDebug(); |
|
| 3039 | + if (!isset($_REQUEST['xml'])) { |
|
| 3040 | + displayDebug(); |
|
| 3041 | + } |
|
| 2878 | 3042 | } |
| 2879 | 3043 | } |
| 2880 | 3044 | |
| 2881 | 3045 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
| 2882 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
| 2883 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
| 3046 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
| 3047 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
| 3048 | + } |
|
| 2884 | 3049 | |
| 2885 | 3050 | // For session check verification.... don't switch browsers... |
| 2886 | 3051 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -2889,9 +3054,10 @@ discard block |
||
| 2889 | 3054 | call_integration_hook('integrate_exit', array($do_footer)); |
| 2890 | 3055 | |
| 2891 | 3056 | // Don't exit if we're coming from index.php; that will pass through normally. |
| 2892 | - if (!$from_index) |
|
| 2893 | - exit; |
|
| 2894 | -} |
|
| 3057 | + if (!$from_index) { |
|
| 3058 | + exit; |
|
| 3059 | + } |
|
| 3060 | + } |
|
| 2895 | 3061 | |
| 2896 | 3062 | /** |
| 2897 | 3063 | * Get the size of a specified image with better error handling. |
@@ -2910,8 +3076,9 @@ discard block |
||
| 2910 | 3076 | $url = str_replace(' ', '%20', $url); |
| 2911 | 3077 | |
| 2912 | 3078 | // Can we pull this from the cache... please please? |
| 2913 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
| 2914 | - return $temp; |
|
| 3079 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
| 3080 | + return $temp; |
|
| 3081 | + } |
|
| 2915 | 3082 | $t = microtime(); |
| 2916 | 3083 | |
| 2917 | 3084 | // Get the host to pester... |
@@ -2921,12 +3088,10 @@ discard block |
||
| 2921 | 3088 | if ($url == '' || $url == 'http://' || $url == 'https://') |
| 2922 | 3089 | { |
| 2923 | 3090 | return false; |
| 2924 | - } |
|
| 2925 | - elseif (!isset($match[1])) |
|
| 3091 | + } elseif (!isset($match[1])) |
|
| 2926 | 3092 | { |
| 2927 | 3093 | $size = @getimagesize($url); |
| 2928 | - } |
|
| 2929 | - else |
|
| 3094 | + } else |
|
| 2930 | 3095 | { |
| 2931 | 3096 | // Try to connect to the server... give it half a second. |
| 2932 | 3097 | $temp = 0; |
@@ -2965,12 +3130,14 @@ discard block |
||
| 2965 | 3130 | } |
| 2966 | 3131 | |
| 2967 | 3132 | // If we didn't get it, we failed. |
| 2968 | - if (!isset($size)) |
|
| 2969 | - $size = false; |
|
| 3133 | + if (!isset($size)) { |
|
| 3134 | + $size = false; |
|
| 3135 | + } |
|
| 2970 | 3136 | |
| 2971 | 3137 | // If this took a long time, we may never have to do it again, but then again we might... |
| 2972 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
| 2973 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
| 3138 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
| 3139 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
| 3140 | + } |
|
| 2974 | 3141 | |
| 2975 | 3142 | // Didn't work. |
| 2976 | 3143 | return $size; |
@@ -2988,8 +3155,9 @@ discard block |
||
| 2988 | 3155 | |
| 2989 | 3156 | // Under SSI this function can be called more then once. That can cause some problems. |
| 2990 | 3157 | // So only run the function once unless we are forced to run it again. |
| 2991 | - if ($loaded && !$forceload) |
|
| 2992 | - return; |
|
| 3158 | + if ($loaded && !$forceload) { |
|
| 3159 | + return; |
|
| 3160 | + } |
|
| 2993 | 3161 | |
| 2994 | 3162 | $loaded = true; |
| 2995 | 3163 | |
@@ -3001,14 +3169,16 @@ discard block |
||
| 3001 | 3169 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
| 3002 | 3170 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
| 3003 | 3171 | { |
| 3004 | - if (trim($context['news_lines'][$i]) == '') |
|
| 3005 | - continue; |
|
| 3172 | + if (trim($context['news_lines'][$i]) == '') { |
|
| 3173 | + continue; |
|
| 3174 | + } |
|
| 3006 | 3175 | |
| 3007 | 3176 | // Clean it up for presentation ;). |
| 3008 | 3177 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
| 3009 | 3178 | } |
| 3010 | - if (!empty($context['news_lines'])) |
|
| 3011 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
| 3179 | + if (!empty($context['news_lines'])) { |
|
| 3180 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
| 3181 | + } |
|
| 3012 | 3182 | |
| 3013 | 3183 | if (!$user_info['is_guest']) |
| 3014 | 3184 | { |
@@ -3017,40 +3187,48 @@ discard block |
||
| 3017 | 3187 | $context['user']['alerts'] = &$user_info['alerts']; |
| 3018 | 3188 | |
| 3019 | 3189 | // Personal message popup... |
| 3020 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
| 3021 | - $context['user']['popup_messages'] = true; |
|
| 3022 | - else |
|
| 3023 | - $context['user']['popup_messages'] = false; |
|
| 3190 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
| 3191 | + $context['user']['popup_messages'] = true; |
|
| 3192 | + } else { |
|
| 3193 | + $context['user']['popup_messages'] = false; |
|
| 3194 | + } |
|
| 3024 | 3195 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
| 3025 | 3196 | |
| 3026 | - if (allowedTo('moderate_forum')) |
|
| 3027 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
| 3197 | + if (allowedTo('moderate_forum')) { |
|
| 3198 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
| 3199 | + } |
|
| 3028 | 3200 | |
| 3029 | 3201 | $context['user']['avatar'] = array(); |
| 3030 | 3202 | |
| 3031 | 3203 | // Check for gravatar first since we might be forcing them... |
| 3032 | 3204 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
| 3033 | 3205 | { |
| 3034 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
| 3035 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
| 3036 | - else |
|
| 3037 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
| 3206 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
| 3207 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
| 3208 | + } else { |
|
| 3209 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
| 3210 | + } |
|
| 3038 | 3211 | } |
| 3039 | 3212 | // Uploaded? |
| 3040 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
| 3041 | - $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
| 3213 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
| 3214 | + $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
| 3215 | + } |
|
| 3042 | 3216 | // Full URL? |
| 3043 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
| 3044 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
| 3217 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
| 3218 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
| 3219 | + } |
|
| 3045 | 3220 | // Otherwise we assume it's server stored. |
| 3046 | - elseif ($user_info['avatar']['url'] != '') |
|
| 3047 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
| 3221 | + elseif ($user_info['avatar']['url'] != '') { |
|
| 3222 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
| 3223 | + } |
|
| 3048 | 3224 | // No avatar at all? Fine, we have a big fat default avatar ;) |
| 3049 | - else |
|
| 3050 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
| 3225 | + else { |
|
| 3226 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
| 3227 | + } |
|
| 3051 | 3228 | |
| 3052 | - if (!empty($context['user']['avatar'])) |
|
| 3053 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
| 3229 | + if (!empty($context['user']['avatar'])) { |
|
| 3230 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
| 3231 | + } |
|
| 3054 | 3232 | |
| 3055 | 3233 | // Figure out how long they've been logged in. |
| 3056 | 3234 | $context['user']['total_time_logged_in'] = array( |
@@ -3058,8 +3236,7 @@ discard block |
||
| 3058 | 3236 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
| 3059 | 3237 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
| 3060 | 3238 | ); |
| 3061 | - } |
|
| 3062 | - else |
|
| 3239 | + } else |
|
| 3063 | 3240 | { |
| 3064 | 3241 | $context['user']['messages'] = 0; |
| 3065 | 3242 | $context['user']['unread_messages'] = 0; |
@@ -3067,12 +3244,14 @@ discard block |
||
| 3067 | 3244 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
| 3068 | 3245 | $context['user']['popup_messages'] = false; |
| 3069 | 3246 | |
| 3070 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
| 3071 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
| 3247 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
| 3248 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
| 3249 | + } |
|
| 3072 | 3250 | |
| 3073 | 3251 | // If we've upgraded recently, go easy on the passwords. |
| 3074 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
| 3075 | - $context['disable_login_hashing'] = true; |
|
| 3252 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
| 3253 | + $context['disable_login_hashing'] = true; |
|
| 3254 | + } |
|
| 3076 | 3255 | } |
| 3077 | 3256 | |
| 3078 | 3257 | // Setup the main menu items. |
@@ -3085,8 +3264,8 @@ discard block |
||
| 3085 | 3264 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
| 3086 | 3265 | |
| 3087 | 3266 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
| 3088 | - if ($context['show_pm_popup']) |
|
| 3089 | - addInlineJavaScript(' |
|
| 3267 | + if ($context['show_pm_popup']) { |
|
| 3268 | + addInlineJavaScript(' |
|
| 3090 | 3269 | jQuery(document).ready(function($) { |
| 3091 | 3270 | new smc_Popup({ |
| 3092 | 3271 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3094,15 +3273,17 @@ discard block |
||
| 3094 | 3273 | icon_class: \'generic_icons mail_new\' |
| 3095 | 3274 | }); |
| 3096 | 3275 | });'); |
| 3276 | + } |
|
| 3097 | 3277 | |
| 3098 | 3278 | // Add a generic "Are you sure?" confirmation message. |
| 3099 | 3279 | addInlineJavaScript(' |
| 3100 | 3280 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
| 3101 | 3281 | |
| 3102 | 3282 | // Now add the capping code for avatars. |
| 3103 | - if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') |
|
| 3104 | - addInlineCss(' |
|
| 3283 | + if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') { |
|
| 3284 | + addInlineCss(' |
|
| 3105 | 3285 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
| 3286 | + } |
|
| 3106 | 3287 | |
| 3107 | 3288 | // This looks weird, but it's because BoardIndex.php references the variable. |
| 3108 | 3289 | $context['common_stats']['latest_member'] = array( |
@@ -3119,11 +3300,13 @@ discard block |
||
| 3119 | 3300 | ); |
| 3120 | 3301 | $context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']); |
| 3121 | 3302 | |
| 3122 | - if (empty($settings['theme_version'])) |
|
| 3123 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
| 3303 | + if (empty($settings['theme_version'])) { |
|
| 3304 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
| 3305 | + } |
|
| 3124 | 3306 | |
| 3125 | - if (!isset($context['page_title'])) |
|
| 3126 | - $context['page_title'] = ''; |
|
| 3307 | + if (!isset($context['page_title'])) { |
|
| 3308 | + $context['page_title'] = ''; |
|
| 3309 | + } |
|
| 3127 | 3310 | |
| 3128 | 3311 | // Set some specific vars. |
| 3129 | 3312 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3133,21 +3316,23 @@ discard block |
||
| 3133 | 3316 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
| 3134 | 3317 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
| 3135 | 3318 | |
| 3136 | - if (!empty($context['meta_keywords'])) |
|
| 3137 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
| 3319 | + if (!empty($context['meta_keywords'])) { |
|
| 3320 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
| 3321 | + } |
|
| 3138 | 3322 | |
| 3139 | - if (!empty($context['canonical_url'])) |
|
| 3140 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
| 3323 | + if (!empty($context['canonical_url'])) { |
|
| 3324 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
| 3325 | + } |
|
| 3141 | 3326 | |
| 3142 | - if (!empty($settings['og_image'])) |
|
| 3143 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
| 3327 | + if (!empty($settings['og_image'])) { |
|
| 3328 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
| 3329 | + } |
|
| 3144 | 3330 | |
| 3145 | 3331 | if (!empty($context['meta_description'])) |
| 3146 | 3332 | { |
| 3147 | 3333 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
| 3148 | 3334 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
| 3149 | - } |
|
| 3150 | - else |
|
| 3335 | + } else |
|
| 3151 | 3336 | { |
| 3152 | 3337 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
| 3153 | 3338 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3172,8 +3357,9 @@ discard block |
||
| 3172 | 3357 | $memory_needed = memoryReturnBytes($needed); |
| 3173 | 3358 | |
| 3174 | 3359 | // should we account for how much is currently being used? |
| 3175 | - if ($in_use) |
|
| 3176 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
| 3360 | + if ($in_use) { |
|
| 3361 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
| 3362 | + } |
|
| 3177 | 3363 | |
| 3178 | 3364 | // if more is needed, request it |
| 3179 | 3365 | if ($memory_current < $memory_needed) |
@@ -3196,8 +3382,9 @@ discard block |
||
| 3196 | 3382 | */ |
| 3197 | 3383 | function memoryReturnBytes($val) |
| 3198 | 3384 | { |
| 3199 | - if (is_integer($val)) |
|
| 3200 | - return $val; |
|
| 3385 | + if (is_integer($val)) { |
|
| 3386 | + return $val; |
|
| 3387 | + } |
|
| 3201 | 3388 | |
| 3202 | 3389 | // Separate the number from the designator |
| 3203 | 3390 | $val = trim($val); |
@@ -3233,10 +3420,11 @@ discard block |
||
| 3233 | 3420 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
| 3234 | 3421 | |
| 3235 | 3422 | // Are we debugging the template/html content? |
| 3236 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
| 3237 | - header('Content-Type: application/xhtml+xml'); |
|
| 3238 | - elseif (!isset($_REQUEST['xml'])) |
|
| 3239 | - header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3423 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
| 3424 | + header('Content-Type: application/xhtml+xml'); |
|
| 3425 | + } elseif (!isset($_REQUEST['xml'])) { |
|
| 3426 | + header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3427 | + } |
|
| 3240 | 3428 | } |
| 3241 | 3429 | |
| 3242 | 3430 | header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3245,8 +3433,9 @@ discard block |
||
| 3245 | 3433 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
| 3246 | 3434 | { |
| 3247 | 3435 | $position = array_search('body', $context['template_layers']); |
| 3248 | - if ($position === false) |
|
| 3249 | - $position = array_search('main', $context['template_layers']); |
|
| 3436 | + if ($position === false) { |
|
| 3437 | + $position = array_search('main', $context['template_layers']); |
|
| 3438 | + } |
|
| 3250 | 3439 | |
| 3251 | 3440 | if ($position !== false) |
| 3252 | 3441 | { |
@@ -3274,23 +3463,25 @@ discard block |
||
| 3274 | 3463 | |
| 3275 | 3464 | foreach ($securityFiles as $i => $securityFile) |
| 3276 | 3465 | { |
| 3277 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
| 3278 | - unset($securityFiles[$i]); |
|
| 3466 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
| 3467 | + unset($securityFiles[$i]); |
|
| 3468 | + } |
|
| 3279 | 3469 | } |
| 3280 | 3470 | |
| 3281 | 3471 | // We are already checking so many files...just few more doesn't make any difference! :P |
| 3282 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
| 3283 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
| 3284 | - |
|
| 3285 | - else |
|
| 3286 | - $path = $modSettings['attachmentUploadDir']; |
|
| 3472 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
| 3473 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
| 3474 | + } else { |
|
| 3475 | + $path = $modSettings['attachmentUploadDir']; |
|
| 3476 | + } |
|
| 3287 | 3477 | |
| 3288 | 3478 | secureDirectory($path, true); |
| 3289 | 3479 | secureDirectory($cachedir); |
| 3290 | 3480 | |
| 3291 | 3481 | // If agreement is enabled, at least the english version shall exists |
| 3292 | - if ($modSettings['requireAgreement']) |
|
| 3293 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
| 3482 | + if ($modSettings['requireAgreement']) { |
|
| 3483 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
| 3484 | + } |
|
| 3294 | 3485 | |
| 3295 | 3486 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
| 3296 | 3487 | { |
@@ -3305,18 +3496,21 @@ discard block |
||
| 3305 | 3496 | echo ' |
| 3306 | 3497 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
| 3307 | 3498 | |
| 3308 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
| 3309 | - echo ' |
|
| 3499 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
| 3500 | + echo ' |
|
| 3310 | 3501 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
| 3502 | + } |
|
| 3311 | 3503 | } |
| 3312 | 3504 | |
| 3313 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
| 3314 | - echo ' |
|
| 3505 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
| 3506 | + echo ' |
|
| 3315 | 3507 | <strong>', $txt['cache_writable'], '</strong><br>'; |
| 3508 | + } |
|
| 3316 | 3509 | |
| 3317 | - if (!empty($agreement)) |
|
| 3318 | - echo ' |
|
| 3510 | + if (!empty($agreement)) { |
|
| 3511 | + echo ' |
|
| 3319 | 3512 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
| 3513 | + } |
|
| 3320 | 3514 | |
| 3321 | 3515 | echo ' |
| 3322 | 3516 | </p> |
@@ -3331,16 +3525,18 @@ discard block |
||
| 3331 | 3525 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
| 3332 | 3526 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
| 3333 | 3527 | |
| 3334 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
| 3335 | - echo ' |
|
| 3528 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
| 3529 | + echo ' |
|
| 3336 | 3530 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
| 3531 | + } |
|
| 3337 | 3532 | |
| 3338 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
| 3339 | - echo ' |
|
| 3533 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
| 3534 | + echo ' |
|
| 3340 | 3535 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
| 3341 | - else |
|
| 3342 | - echo ' |
|
| 3536 | + } else { |
|
| 3537 | + echo ' |
|
| 3343 | 3538 | <div>', $txt['your_ban_expires_never'], '</div>'; |
| 3539 | + } |
|
| 3344 | 3540 | |
| 3345 | 3541 | echo ' |
| 3346 | 3542 | </div>'; |
@@ -3356,8 +3552,9 @@ discard block |
||
| 3356 | 3552 | global $forum_copyright, $software_year, $forum_version; |
| 3357 | 3553 | |
| 3358 | 3554 | // Don't display copyright for things like SSI. |
| 3359 | - if (!isset($forum_version) || !isset($software_year)) |
|
| 3360 | - return; |
|
| 3555 | + if (!isset($forum_version) || !isset($software_year)) { |
|
| 3556 | + return; |
|
| 3557 | + } |
|
| 3361 | 3558 | |
| 3362 | 3559 | // Put in the version... |
| 3363 | 3560 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3375,9 +3572,10 @@ discard block |
||
| 3375 | 3572 | $context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3)); |
| 3376 | 3573 | $context['load_queries'] = $db_count; |
| 3377 | 3574 | |
| 3378 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
| 3379 | - loadSubTemplate($layer . '_below', true); |
|
| 3380 | -} |
|
| 3575 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
| 3576 | + loadSubTemplate($layer . '_below', true); |
|
| 3577 | + } |
|
| 3578 | + } |
|
| 3381 | 3579 | |
| 3382 | 3580 | /** |
| 3383 | 3581 | * Output the Javascript files |
@@ -3408,8 +3606,7 @@ discard block |
||
| 3408 | 3606 | { |
| 3409 | 3607 | echo ' |
| 3410 | 3608 | var ', $key, ';'; |
| 3411 | - } |
|
| 3412 | - else |
|
| 3609 | + } else |
|
| 3413 | 3610 | { |
| 3414 | 3611 | echo ' |
| 3415 | 3612 | var ', $key, ' = ', $value, ';'; |
@@ -3424,26 +3621,27 @@ discard block |
||
| 3424 | 3621 | foreach ($context['javascript_files'] as $id => $js_file) |
| 3425 | 3622 | { |
| 3426 | 3623 | // Last minute call! allow theme authors to disable single files. |
| 3427 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
| 3428 | - continue; |
|
| 3624 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
| 3625 | + continue; |
|
| 3626 | + } |
|
| 3429 | 3627 | |
| 3430 | 3628 | // By default all files don't get minimized unless the file explicitly says so! |
| 3431 | 3629 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
| 3432 | 3630 | { |
| 3433 | - if ($do_deferred && !empty($js_file['options']['defer'])) |
|
| 3434 | - $toMinifyDefer[] = $js_file; |
|
| 3435 | - |
|
| 3436 | - elseif (!$do_deferred && empty($js_file['options']['defer'])) |
|
| 3437 | - $toMinify[] = $js_file; |
|
| 3631 | + if ($do_deferred && !empty($js_file['options']['defer'])) { |
|
| 3632 | + $toMinifyDefer[] = $js_file; |
|
| 3633 | + } elseif (!$do_deferred && empty($js_file['options']['defer'])) { |
|
| 3634 | + $toMinify[] = $js_file; |
|
| 3635 | + } |
|
| 3438 | 3636 | |
| 3439 | 3637 | // Grab a random seed. |
| 3440 | - if (!isset($minSeed)) |
|
| 3441 | - $minSeed = $js_file['options']['seed']; |
|
| 3442 | - } |
|
| 3443 | - |
|
| 3444 | - elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) |
|
| 3445 | - echo ' |
|
| 3638 | + if (!isset($minSeed)) { |
|
| 3639 | + $minSeed = $js_file['options']['seed']; |
|
| 3640 | + } |
|
| 3641 | + } elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) { |
|
| 3642 | + echo ' |
|
| 3446 | 3643 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>'; |
| 3644 | + } |
|
| 3447 | 3645 | } |
| 3448 | 3646 | |
| 3449 | 3647 | if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer))) |
@@ -3451,14 +3649,14 @@ discard block |
||
| 3451 | 3649 | $result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred); |
| 3452 | 3650 | |
| 3453 | 3651 | // Minify process couldn't work, print each individual files. |
| 3454 | - if (!empty($result) && is_array($result)) |
|
| 3455 | - foreach ($result as $minFailedFile) |
|
| 3652 | + if (!empty($result) && is_array($result)) { |
|
| 3653 | + foreach ($result as $minFailedFile) |
|
| 3456 | 3654 | echo ' |
| 3457 | 3655 | <script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>'; |
| 3458 | - |
|
| 3459 | - else |
|
| 3460 | - echo ' |
|
| 3656 | + } else { |
|
| 3657 | + echo ' |
|
| 3461 | 3658 | <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; |
| 3659 | + } |
|
| 3462 | 3660 | } |
| 3463 | 3661 | |
| 3464 | 3662 | // Inline JavaScript - Actually useful some times! |
@@ -3469,8 +3667,9 @@ discard block |
||
| 3469 | 3667 | echo ' |
| 3470 | 3668 | <script>'; |
| 3471 | 3669 | |
| 3472 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
| 3473 | - echo $js_code; |
|
| 3670 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
| 3671 | + echo $js_code; |
|
| 3672 | + } |
|
| 3474 | 3673 | |
| 3475 | 3674 | echo ' |
| 3476 | 3675 | </script>'; |
@@ -3481,8 +3680,9 @@ discard block |
||
| 3481 | 3680 | echo ' |
| 3482 | 3681 | <script>'; |
| 3483 | 3682 | |
| 3484 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
| 3485 | - echo $js_code; |
|
| 3683 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
| 3684 | + echo $js_code; |
|
| 3685 | + } |
|
| 3486 | 3686 | |
| 3487 | 3687 | echo ' |
| 3488 | 3688 | </script>'; |
@@ -3507,8 +3707,9 @@ discard block |
||
| 3507 | 3707 | foreach ($context['css_files'] as $id => $file) |
| 3508 | 3708 | { |
| 3509 | 3709 | // Last minute call! allow theme authors to disable single files. |
| 3510 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
| 3511 | - continue; |
|
| 3710 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
| 3711 | + continue; |
|
| 3712 | + } |
|
| 3512 | 3713 | |
| 3513 | 3714 | // By default all files don't get minimized unless the file explicitly says so! |
| 3514 | 3715 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
@@ -3516,12 +3717,12 @@ discard block |
||
| 3516 | 3717 | $toMinify[] = $file; |
| 3517 | 3718 | |
| 3518 | 3719 | // Grab a random seed. |
| 3519 | - if (!isset($minSeed)) |
|
| 3520 | - $minSeed = $file['options']['seed']; |
|
| 3720 | + if (!isset($minSeed)) { |
|
| 3721 | + $minSeed = $file['options']['seed']; |
|
| 3722 | + } |
|
| 3723 | + } else { |
|
| 3724 | + $normal[] = $file['fileUrl']; |
|
| 3521 | 3725 | } |
| 3522 | - |
|
| 3523 | - else |
|
| 3524 | - $normal[] = $file['fileUrl']; |
|
| 3525 | 3726 | } |
| 3526 | 3727 | |
| 3527 | 3728 | if (!empty($toMinify)) |
@@ -3529,28 +3730,30 @@ discard block |
||
| 3529 | 3730 | $result = custMinify($toMinify, 'css'); |
| 3530 | 3731 | |
| 3531 | 3732 | // Minify process couldn't work, print each individual files. |
| 3532 | - if (!empty($result) && is_array($result)) |
|
| 3533 | - foreach ($result as $minFailedFile) |
|
| 3733 | + if (!empty($result) && is_array($result)) { |
|
| 3734 | + foreach ($result as $minFailedFile) |
|
| 3534 | 3735 | echo ' |
| 3535 | 3736 | <link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">'; |
| 3536 | - |
|
| 3537 | - else |
|
| 3538 | - echo ' |
|
| 3737 | + } else { |
|
| 3738 | + echo ' |
|
| 3539 | 3739 | <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; |
| 3740 | + } |
|
| 3540 | 3741 | } |
| 3541 | 3742 | |
| 3542 | 3743 | // Print the rest after the minified files. |
| 3543 | - if (!empty($normal)) |
|
| 3544 | - foreach ($normal as $nf) |
|
| 3744 | + if (!empty($normal)) { |
|
| 3745 | + foreach ($normal as $nf) |
|
| 3545 | 3746 | echo ' |
| 3546 | 3747 | <link rel="stylesheet" href="', $nf ,'">'; |
| 3748 | + } |
|
| 3547 | 3749 | |
| 3548 | 3750 | if ($db_show_debug === true) |
| 3549 | 3751 | { |
| 3550 | 3752 | // Try to keep only what's useful. |
| 3551 | 3753 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
| 3552 | - foreach ($context['css_files'] as $file) |
|
| 3553 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
| 3754 | + foreach ($context['css_files'] as $file) { |
|
| 3755 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
| 3756 | + } |
|
| 3554 | 3757 | } |
| 3555 | 3758 | |
| 3556 | 3759 | if (!empty($context['css_header'])) |
@@ -3558,9 +3761,10 @@ discard block |
||
| 3558 | 3761 | echo ' |
| 3559 | 3762 | <style>'; |
| 3560 | 3763 | |
| 3561 | - foreach ($context['css_header'] as $css) |
|
| 3562 | - echo $css .' |
|
| 3764 | + foreach ($context['css_header'] as $css) { |
|
| 3765 | + echo $css .' |
|
| 3563 | 3766 | '; |
| 3767 | + } |
|
| 3564 | 3768 | |
| 3565 | 3769 | echo' |
| 3566 | 3770 | </style>'; |
@@ -3584,15 +3788,17 @@ discard block |
||
| 3584 | 3788 | $type = !empty($type) && in_array($type, $types) ? $type : false; |
| 3585 | 3789 | $data = !empty($data) ? $data : false; |
| 3586 | 3790 | |
| 3587 | - if (empty($type) || empty($data)) |
|
| 3588 | - return false; |
|
| 3791 | + if (empty($type) || empty($data)) { |
|
| 3792 | + return false; |
|
| 3793 | + } |
|
| 3589 | 3794 | |
| 3590 | 3795 | // Did we already did this? |
| 3591 | 3796 | $toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); |
| 3592 | 3797 | |
| 3593 | 3798 | // Already done? |
| 3594 | - if (!empty($toCache)) |
|
| 3595 | - return true; |
|
| 3799 | + if (!empty($toCache)) { |
|
| 3800 | + return true; |
|
| 3801 | + } |
|
| 3596 | 3802 | |
| 3597 | 3803 | // No namespaces, sorry! |
| 3598 | 3804 | $classType = 'MatthiasMullie\\Minify\\'. strtoupper($type); |
@@ -3674,8 +3880,9 @@ discard block |
||
| 3674 | 3880 | global $modSettings, $smcFunc; |
| 3675 | 3881 | |
| 3676 | 3882 | // Just make up a nice hash... |
| 3677 | - if ($new) |
|
| 3678 | - return sha1(md5($filename . time()) . mt_rand()); |
|
| 3883 | + if ($new) { |
|
| 3884 | + return sha1(md5($filename . time()) . mt_rand()); |
|
| 3885 | + } |
|
| 3679 | 3886 | |
| 3680 | 3887 | // Just make sure that attachment id is only a int |
| 3681 | 3888 | $attachment_id = (int) $attachment_id; |
@@ -3692,23 +3899,25 @@ discard block |
||
| 3692 | 3899 | 'id_attach' => $attachment_id, |
| 3693 | 3900 | )); |
| 3694 | 3901 | |
| 3695 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 3696 | - return false; |
|
| 3902 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 3903 | + return false; |
|
| 3904 | + } |
|
| 3697 | 3905 | |
| 3698 | 3906 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
| 3699 | 3907 | $smcFunc['db_free_result']($request); |
| 3700 | 3908 | } |
| 3701 | 3909 | |
| 3702 | 3910 | // Still no hash? mmm... |
| 3703 | - if (empty($file_hash)) |
|
| 3704 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
| 3911 | + if (empty($file_hash)) { |
|
| 3912 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
| 3913 | + } |
|
| 3705 | 3914 | |
| 3706 | 3915 | // Are we using multiple directories? |
| 3707 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
| 3708 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
| 3709 | - |
|
| 3710 | - else |
|
| 3711 | - $path = $modSettings['attachmentUploadDir']; |
|
| 3916 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
| 3917 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
| 3918 | + } else { |
|
| 3919 | + $path = $modSettings['attachmentUploadDir']; |
|
| 3920 | + } |
|
| 3712 | 3921 | |
| 3713 | 3922 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
| 3714 | 3923 | } |
@@ -3723,8 +3932,9 @@ discard block |
||
| 3723 | 3932 | function ip2range($fullip) |
| 3724 | 3933 | { |
| 3725 | 3934 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
| 3726 | - if ($fullip == 'unknown') |
|
| 3727 | - $fullip = '255.255.255.255'; |
|
| 3935 | + if ($fullip == 'unknown') { |
|
| 3936 | + $fullip = '255.255.255.255'; |
|
| 3937 | + } |
|
| 3728 | 3938 | |
| 3729 | 3939 | $ip_parts = explode('-', $fullip); |
| 3730 | 3940 | $ip_array = array(); |
@@ -3748,10 +3958,11 @@ discard block |
||
| 3748 | 3958 | $ip_array['low'] = $ip_parts[0]; |
| 3749 | 3959 | $ip_array['high'] = $ip_parts[1]; |
| 3750 | 3960 | return $ip_array; |
| 3751 | - } |
|
| 3752 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
| 3961 | + } elseif (count($ip_parts) == 2) { |
|
| 3962 | + // if ip 22.22.*-22.22.* |
|
| 3753 | 3963 | { |
| 3754 | 3964 | $valid_low = isValidIP($ip_parts[0]); |
| 3965 | + } |
|
| 3755 | 3966 | $valid_high = isValidIP($ip_parts[1]); |
| 3756 | 3967 | $count = 0; |
| 3757 | 3968 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -3766,7 +3977,9 @@ discard block |
||
| 3766 | 3977 | $ip_parts[0] .= $mode . $min; |
| 3767 | 3978 | $valid_low = isValidIP($ip_parts[0]); |
| 3768 | 3979 | $count++; |
| 3769 | - if ($count > 9) break; |
|
| 3980 | + if ($count > 9) { |
|
| 3981 | + break; |
|
| 3982 | + } |
|
| 3770 | 3983 | } |
| 3771 | 3984 | } |
| 3772 | 3985 | |
@@ -3780,7 +3993,9 @@ discard block |
||
| 3780 | 3993 | $ip_parts[1] .= $mode . $max; |
| 3781 | 3994 | $valid_high = isValidIP($ip_parts[1]); |
| 3782 | 3995 | $count++; |
| 3783 | - if ($count > 9) break; |
|
| 3996 | + if ($count > 9) { |
|
| 3997 | + break; |
|
| 3998 | + } |
|
| 3784 | 3999 | } |
| 3785 | 4000 | } |
| 3786 | 4001 | |
@@ -3805,46 +4020,54 @@ discard block |
||
| 3805 | 4020 | { |
| 3806 | 4021 | global $modSettings; |
| 3807 | 4022 | |
| 3808 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
| 3809 | - return $host; |
|
| 4023 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
| 4024 | + return $host; |
|
| 4025 | + } |
|
| 3810 | 4026 | $t = microtime(); |
| 3811 | 4027 | |
| 3812 | 4028 | // Try the Linux host command, perhaps? |
| 3813 | 4029 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
| 3814 | 4030 | { |
| 3815 | - if (!isset($modSettings['host_to_dis'])) |
|
| 3816 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
| 3817 | - else |
|
| 3818 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
| 4031 | + if (!isset($modSettings['host_to_dis'])) { |
|
| 4032 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
| 4033 | + } else { |
|
| 4034 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
| 4035 | + } |
|
| 3819 | 4036 | |
| 3820 | 4037 | // Did host say it didn't find anything? |
| 3821 | - if (strpos($test, 'not found') !== false) |
|
| 3822 | - $host = ''; |
|
| 4038 | + if (strpos($test, 'not found') !== false) { |
|
| 4039 | + $host = ''; |
|
| 4040 | + } |
|
| 3823 | 4041 | // Invalid server option? |
| 3824 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
| 3825 | - updateSettings(array('host_to_dis' => 1)); |
|
| 4042 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
| 4043 | + updateSettings(array('host_to_dis' => 1)); |
|
| 4044 | + } |
|
| 3826 | 4045 | // Maybe it found something, after all? |
| 3827 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
| 3828 | - $host = $match[1]; |
|
| 4046 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
| 4047 | + $host = $match[1]; |
|
| 4048 | + } |
|
| 3829 | 4049 | } |
| 3830 | 4050 | |
| 3831 | 4051 | // This is nslookup; usually only Windows, but possibly some Unix? |
| 3832 | 4052 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
| 3833 | 4053 | { |
| 3834 | 4054 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
| 3835 | - if (strpos($test, 'Non-existent domain') !== false) |
|
| 3836 | - $host = ''; |
|
| 3837 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
| 3838 | - $host = $match[1]; |
|
| 4055 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
| 4056 | + $host = ''; |
|
| 4057 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
| 4058 | + $host = $match[1]; |
|
| 4059 | + } |
|
| 3839 | 4060 | } |
| 3840 | 4061 | |
| 3841 | 4062 | // This is the last try :/. |
| 3842 | - if (!isset($host) || $host === false) |
|
| 3843 | - $host = @gethostbyaddr($ip); |
|
| 4063 | + if (!isset($host) || $host === false) { |
|
| 4064 | + $host = @gethostbyaddr($ip); |
|
| 4065 | + } |
|
| 3844 | 4066 | |
| 3845 | 4067 | // It took a long time, so let's cache it! |
| 3846 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
| 3847 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
| 4068 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
| 4069 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
| 4070 | + } |
|
| 3848 | 4071 | |
| 3849 | 4072 | return $host; |
| 3850 | 4073 | } |
@@ -3880,20 +4103,21 @@ discard block |
||
| 3880 | 4103 | { |
| 3881 | 4104 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
| 3882 | 4105 | $total = 0; |
| 3883 | - for ($i = 0; $i < $max_chars; $i++) |
|
| 3884 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
| 4106 | + for ($i = 0; $i < $max_chars; $i++) { |
|
| 4107 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
| 4108 | + } |
|
| 3885 | 4109 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
| 3886 | 4110 | } |
| 3887 | 4111 | } |
| 3888 | 4112 | return array_unique($returned_ints); |
| 3889 | - } |
|
| 3890 | - else |
|
| 4113 | + } else |
|
| 3891 | 4114 | { |
| 3892 | 4115 | // Trim characters before and after and add slashes for database insertion. |
| 3893 | 4116 | $returned_words = array(); |
| 3894 | - foreach ($words as $word) |
|
| 3895 | - if (($word = trim($word, '-_\'')) !== '') |
|
| 4117 | + foreach ($words as $word) { |
|
| 4118 | + if (($word = trim($word, '-_\'')) !== '') |
|
| 3896 | 4119 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
| 4120 | + } |
|
| 3897 | 4121 | |
| 3898 | 4122 | // Filter out all words that occur more than once. |
| 3899 | 4123 | return array_unique($returned_words); |
@@ -3915,16 +4139,18 @@ discard block |
||
| 3915 | 4139 | global $settings, $txt; |
| 3916 | 4140 | |
| 3917 | 4141 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
| 3918 | - if (function_exists('template_create_button') && !$force_use) |
|
| 3919 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
| 4142 | + if (function_exists('template_create_button') && !$force_use) { |
|
| 4143 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
| 4144 | + } |
|
| 3920 | 4145 | |
| 3921 | - if (!$settings['use_image_buttons']) |
|
| 3922 | - return $txt[$alt]; |
|
| 3923 | - elseif (!empty($settings['use_buttons'])) |
|
| 3924 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
| 3925 | - else |
|
| 3926 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
| 3927 | -} |
|
| 4146 | + if (!$settings['use_image_buttons']) { |
|
| 4147 | + return $txt[$alt]; |
|
| 4148 | + } elseif (!empty($settings['use_buttons'])) { |
|
| 4149 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
| 4150 | + } else { |
|
| 4151 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
| 4152 | + } |
|
| 4153 | + } |
|
| 3928 | 4154 | |
| 3929 | 4155 | /** |
| 3930 | 4156 | * Sets up all of the top menu buttons |
@@ -3967,9 +4193,10 @@ discard block |
||
| 3967 | 4193 | var user_menus = new smc_PopupMenu(); |
| 3968 | 4194 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
| 3969 | 4195 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
| 3970 | - if ($context['allow_pm']) |
|
| 3971 | - addInlineJavaScript(' |
|
| 4196 | + if ($context['allow_pm']) { |
|
| 4197 | + addInlineJavaScript(' |
|
| 3972 | 4198 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
| 4199 | + } |
|
| 3973 | 4200 | |
| 3974 | 4201 | if (!empty($modSettings['enable_ajax_alerts'])) |
| 3975 | 4202 | { |
@@ -4129,88 +4356,96 @@ discard block |
||
| 4129 | 4356 | |
| 4130 | 4357 | // Now we put the buttons in the context so the theme can use them. |
| 4131 | 4358 | $menu_buttons = array(); |
| 4132 | - foreach ($buttons as $act => $button) |
|
| 4133 | - if (!empty($button['show'])) |
|
| 4359 | + foreach ($buttons as $act => $button) { |
|
| 4360 | + if (!empty($button['show'])) |
|
| 4134 | 4361 | { |
| 4135 | 4362 | $button['active_button'] = false; |
| 4363 | + } |
|
| 4136 | 4364 | |
| 4137 | 4365 | // This button needs some action. |
| 4138 | - if (isset($button['action_hook'])) |
|
| 4139 | - $needs_action_hook = true; |
|
| 4366 | + if (isset($button['action_hook'])) { |
|
| 4367 | + $needs_action_hook = true; |
|
| 4368 | + } |
|
| 4140 | 4369 | |
| 4141 | 4370 | // Make sure the last button truly is the last button. |
| 4142 | 4371 | if (!empty($button['is_last'])) |
| 4143 | 4372 | { |
| 4144 | - if (isset($last_button)) |
|
| 4145 | - unset($menu_buttons[$last_button]['is_last']); |
|
| 4373 | + if (isset($last_button)) { |
|
| 4374 | + unset($menu_buttons[$last_button]['is_last']); |
|
| 4375 | + } |
|
| 4146 | 4376 | $last_button = $act; |
| 4147 | 4377 | } |
| 4148 | 4378 | |
| 4149 | 4379 | // Go through the sub buttons if there are any. |
| 4150 | - if (!empty($button['sub_buttons'])) |
|
| 4151 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
| 4380 | + if (!empty($button['sub_buttons'])) { |
|
| 4381 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
| 4152 | 4382 | { |
| 4153 | 4383 | if (empty($subbutton['show'])) |
| 4154 | 4384 | unset($button['sub_buttons'][$key]); |
| 4385 | + } |
|
| 4155 | 4386 | |
| 4156 | 4387 | // 2nd level sub buttons next... |
| 4157 | 4388 | if (!empty($subbutton['sub_buttons'])) |
| 4158 | 4389 | { |
| 4159 | 4390 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
| 4160 | 4391 | { |
| 4161 | - if (empty($sub_button2['show'])) |
|
| 4162 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
| 4392 | + if (empty($sub_button2['show'])) { |
|
| 4393 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
| 4394 | + } |
|
| 4163 | 4395 | } |
| 4164 | 4396 | } |
| 4165 | 4397 | } |
| 4166 | 4398 | |
| 4167 | 4399 | // Does this button have its own icon? |
| 4168 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
| 4169 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4170 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
| 4171 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4172 | - elseif (isset($button['icon'])) |
|
| 4173 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
| 4174 | - else |
|
| 4175 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
| 4400 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
| 4401 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4402 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
| 4403 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4404 | + } elseif (isset($button['icon'])) { |
|
| 4405 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
| 4406 | + } else { |
|
| 4407 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
| 4408 | + } |
|
| 4176 | 4409 | |
| 4177 | 4410 | $menu_buttons[$act] = $button; |
| 4178 | 4411 | } |
| 4179 | 4412 | |
| 4180 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 4181 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
| 4413 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 4414 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
| 4415 | + } |
|
| 4182 | 4416 | } |
| 4183 | 4417 | |
| 4184 | 4418 | $context['menu_buttons'] = $menu_buttons; |
| 4185 | 4419 | |
| 4186 | 4420 | // Logging out requires the session id in the url. |
| 4187 | - if (isset($context['menu_buttons']['logout'])) |
|
| 4188 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
| 4421 | + if (isset($context['menu_buttons']['logout'])) { |
|
| 4422 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
| 4423 | + } |
|
| 4189 | 4424 | |
| 4190 | 4425 | // Figure out which action we are doing so we can set the active tab. |
| 4191 | 4426 | // Default to home. |
| 4192 | 4427 | $current_action = 'home'; |
| 4193 | 4428 | |
| 4194 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
| 4195 | - $current_action = $context['current_action']; |
|
| 4196 | - elseif ($context['current_action'] == 'search2') |
|
| 4197 | - $current_action = 'search'; |
|
| 4198 | - elseif ($context['current_action'] == 'theme') |
|
| 4199 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
| 4200 | - elseif ($context['current_action'] == 'register2') |
|
| 4201 | - $current_action = 'register'; |
|
| 4202 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
| 4203 | - $current_action = 'login'; |
|
| 4204 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
| 4205 | - $current_action = 'moderate'; |
|
| 4429 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
| 4430 | + $current_action = $context['current_action']; |
|
| 4431 | + } elseif ($context['current_action'] == 'search2') { |
|
| 4432 | + $current_action = 'search'; |
|
| 4433 | + } elseif ($context['current_action'] == 'theme') { |
|
| 4434 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
| 4435 | + } elseif ($context['current_action'] == 'register2') { |
|
| 4436 | + $current_action = 'register'; |
|
| 4437 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
| 4438 | + $current_action = 'login'; |
|
| 4439 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
| 4440 | + $current_action = 'moderate'; |
|
| 4441 | + } |
|
| 4206 | 4442 | |
| 4207 | 4443 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
| 4208 | 4444 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
| 4209 | 4445 | { |
| 4210 | 4446 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
| 4211 | 4447 | $context[$current_action] = true; |
| 4212 | - } |
|
| 4213 | - elseif ($context['current_action'] == 'pm') |
|
| 4448 | + } elseif ($context['current_action'] == 'pm') |
|
| 4214 | 4449 | { |
| 4215 | 4450 | $current_action = 'self_pm'; |
| 4216 | 4451 | $context['self_pm'] = true; |
@@ -4253,12 +4488,14 @@ discard block |
||
| 4253 | 4488 | } |
| 4254 | 4489 | |
| 4255 | 4490 | // Not all actions are simple. |
| 4256 | - if (!empty($needs_action_hook)) |
|
| 4257 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
| 4491 | + if (!empty($needs_action_hook)) { |
|
| 4492 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
| 4493 | + } |
|
| 4258 | 4494 | |
| 4259 | - if (isset($context['menu_buttons'][$current_action])) |
|
| 4260 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
| 4261 | -} |
|
| 4495 | + if (isset($context['menu_buttons'][$current_action])) { |
|
| 4496 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
| 4497 | + } |
|
| 4498 | + } |
|
| 4262 | 4499 | |
| 4263 | 4500 | /** |
| 4264 | 4501 | * Generate a random seed and ensure it's stored in settings. |
@@ -4282,16 +4519,19 @@ discard block |
||
| 4282 | 4519 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
| 4283 | 4520 | global $context, $txt; |
| 4284 | 4521 | |
| 4285 | - if ($db_show_debug === true) |
|
| 4286 | - $context['debug']['hooks'][] = $hook; |
|
| 4522 | + if ($db_show_debug === true) { |
|
| 4523 | + $context['debug']['hooks'][] = $hook; |
|
| 4524 | + } |
|
| 4287 | 4525 | |
| 4288 | 4526 | // Need to have some control. |
| 4289 | - if (!isset($context['instances'])) |
|
| 4290 | - $context['instances'] = array(); |
|
| 4527 | + if (!isset($context['instances'])) { |
|
| 4528 | + $context['instances'] = array(); |
|
| 4529 | + } |
|
| 4291 | 4530 | |
| 4292 | 4531 | $results = array(); |
| 4293 | - if (empty($modSettings[$hook])) |
|
| 4294 | - return $results; |
|
| 4532 | + if (empty($modSettings[$hook])) { |
|
| 4533 | + return $results; |
|
| 4534 | + } |
|
| 4295 | 4535 | |
| 4296 | 4536 | // Define some needed vars. |
| 4297 | 4537 | $function = false; |
@@ -4301,14 +4541,16 @@ discard block |
||
| 4301 | 4541 | foreach ($functions as $function) |
| 4302 | 4542 | { |
| 4303 | 4543 | // Hook has been marked as "disabled". Skip it! |
| 4304 | - if (strpos($function, '!') !== false) |
|
| 4305 | - continue; |
|
| 4544 | + if (strpos($function, '!') !== false) { |
|
| 4545 | + continue; |
|
| 4546 | + } |
|
| 4306 | 4547 | |
| 4307 | 4548 | $call = call_helper($function, true); |
| 4308 | 4549 | |
| 4309 | 4550 | // Is it valid? |
| 4310 | - if (!empty($call)) |
|
| 4311 | - $results[$function] = call_user_func_array($call, $parameters); |
|
| 4551 | + if (!empty($call)) { |
|
| 4552 | + $results[$function] = call_user_func_array($call, $parameters); |
|
| 4553 | + } |
|
| 4312 | 4554 | |
| 4313 | 4555 | // Whatever it was suppose to call, it failed :( |
| 4314 | 4556 | elseif (!empty($function)) |
@@ -4324,8 +4566,9 @@ discard block |
||
| 4324 | 4566 | } |
| 4325 | 4567 | |
| 4326 | 4568 | // "Assume" the file resides on $boarddir somewhere... |
| 4327 | - else |
|
| 4328 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4569 | + else { |
|
| 4570 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4571 | + } |
|
| 4329 | 4572 | } |
| 4330 | 4573 | } |
| 4331 | 4574 | |
@@ -4347,12 +4590,14 @@ discard block |
||
| 4347 | 4590 | global $smcFunc, $modSettings; |
| 4348 | 4591 | |
| 4349 | 4592 | // Any objects? |
| 4350 | - if ($object) |
|
| 4351 | - $function = $function . '#'; |
|
| 4593 | + if ($object) { |
|
| 4594 | + $function = $function . '#'; |
|
| 4595 | + } |
|
| 4352 | 4596 | |
| 4353 | 4597 | // Any files to load? |
| 4354 | - if (!empty($file) && is_string($file)) |
|
| 4355 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4598 | + if (!empty($file) && is_string($file)) { |
|
| 4599 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4600 | + } |
|
| 4356 | 4601 | |
| 4357 | 4602 | // Get the correct string. |
| 4358 | 4603 | $integration_call = $function; |
@@ -4374,13 +4619,14 @@ discard block |
||
| 4374 | 4619 | if (!empty($current_functions)) |
| 4375 | 4620 | { |
| 4376 | 4621 | $current_functions = explode(',', $current_functions); |
| 4377 | - if (in_array($integration_call, $current_functions)) |
|
| 4378 | - return; |
|
| 4622 | + if (in_array($integration_call, $current_functions)) { |
|
| 4623 | + return; |
|
| 4624 | + } |
|
| 4379 | 4625 | |
| 4380 | 4626 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
| 4627 | + } else { |
|
| 4628 | + $permanent_functions = array($integration_call); |
|
| 4381 | 4629 | } |
| 4382 | - else |
|
| 4383 | - $permanent_functions = array($integration_call); |
|
| 4384 | 4630 | |
| 4385 | 4631 | updateSettings(array($hook => implode(',', $permanent_functions))); |
| 4386 | 4632 | } |
@@ -4389,8 +4635,9 @@ discard block |
||
| 4389 | 4635 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4390 | 4636 | |
| 4391 | 4637 | // Do nothing, if it's already there. |
| 4392 | - if (in_array($integration_call, $functions)) |
|
| 4393 | - return; |
|
| 4638 | + if (in_array($integration_call, $functions)) { |
|
| 4639 | + return; |
|
| 4640 | + } |
|
| 4394 | 4641 | |
| 4395 | 4642 | $functions[] = $integration_call; |
| 4396 | 4643 | $modSettings[$hook] = implode(',', $functions); |
@@ -4413,12 +4660,14 @@ discard block |
||
| 4413 | 4660 | global $smcFunc, $modSettings; |
| 4414 | 4661 | |
| 4415 | 4662 | // Any objects? |
| 4416 | - if ($object) |
|
| 4417 | - $function = $function . '#'; |
|
| 4663 | + if ($object) { |
|
| 4664 | + $function = $function . '#'; |
|
| 4665 | + } |
|
| 4418 | 4666 | |
| 4419 | 4667 | // Any files to load? |
| 4420 | - if (!empty($file) && is_string($file)) |
|
| 4421 | - $function = $file . '|' . $function; |
|
| 4668 | + if (!empty($file) && is_string($file)) { |
|
| 4669 | + $function = $file . '|' . $function; |
|
| 4670 | + } |
|
| 4422 | 4671 | |
| 4423 | 4672 | // Get the correct string. |
| 4424 | 4673 | $integration_call = $function; |
@@ -4439,16 +4688,18 @@ discard block |
||
| 4439 | 4688 | { |
| 4440 | 4689 | $current_functions = explode(',', $current_functions); |
| 4441 | 4690 | |
| 4442 | - if (in_array($integration_call, $current_functions)) |
|
| 4443 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4691 | + if (in_array($integration_call, $current_functions)) { |
|
| 4692 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4693 | + } |
|
| 4444 | 4694 | } |
| 4445 | 4695 | |
| 4446 | 4696 | // Turn the function list into something usable. |
| 4447 | 4697 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4448 | 4698 | |
| 4449 | 4699 | // You can only remove it if it's available. |
| 4450 | - if (!in_array($integration_call, $functions)) |
|
| 4451 | - return; |
|
| 4700 | + if (!in_array($integration_call, $functions)) { |
|
| 4701 | + return; |
|
| 4702 | + } |
|
| 4452 | 4703 | |
| 4453 | 4704 | $functions = array_diff($functions, array($integration_call)); |
| 4454 | 4705 | $modSettings[$hook] = implode(',', $functions); |
@@ -4469,17 +4720,20 @@ discard block |
||
| 4469 | 4720 | global $context, $smcFunc, $txt, $db_show_debug; |
| 4470 | 4721 | |
| 4471 | 4722 | // Really? |
| 4472 | - if (empty($string)) |
|
| 4473 | - return false; |
|
| 4723 | + if (empty($string)) { |
|
| 4724 | + return false; |
|
| 4725 | + } |
|
| 4474 | 4726 | |
| 4475 | 4727 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
| 4476 | 4728 | // A closure? should be a callable one. |
| 4477 | - if (is_array($string) || $string instanceof Closure) |
|
| 4478 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4729 | + if (is_array($string) || $string instanceof Closure) { |
|
| 4730 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4731 | + } |
|
| 4479 | 4732 | |
| 4480 | 4733 | // No full objects, sorry! pass a method or a property instead! |
| 4481 | - if (is_object($string)) |
|
| 4482 | - return false; |
|
| 4734 | + if (is_object($string)) { |
|
| 4735 | + return false; |
|
| 4736 | + } |
|
| 4483 | 4737 | |
| 4484 | 4738 | // Stay vitaminized my friends... |
| 4485 | 4739 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4488,8 +4742,9 @@ discard block |
||
| 4488 | 4742 | $string = load_file($string); |
| 4489 | 4743 | |
| 4490 | 4744 | // Loaded file failed |
| 4491 | - if (empty($string)) |
|
| 4492 | - return false; |
|
| 4745 | + if (empty($string)) { |
|
| 4746 | + return false; |
|
| 4747 | + } |
|
| 4493 | 4748 | |
| 4494 | 4749 | // Found a method. |
| 4495 | 4750 | if (strpos($string, '::') !== false) |
@@ -4510,8 +4765,9 @@ discard block |
||
| 4510 | 4765 | // Add another one to the list. |
| 4511 | 4766 | if ($db_show_debug === true) |
| 4512 | 4767 | { |
| 4513 | - if (!isset($context['debug']['instances'])) |
|
| 4514 | - $context['debug']['instances'] = array(); |
|
| 4768 | + if (!isset($context['debug']['instances'])) { |
|
| 4769 | + $context['debug']['instances'] = array(); |
|
| 4770 | + } |
|
| 4515 | 4771 | |
| 4516 | 4772 | $context['debug']['instances'][$class] = $class; |
| 4517 | 4773 | } |
@@ -4521,13 +4777,15 @@ discard block |
||
| 4521 | 4777 | } |
| 4522 | 4778 | |
| 4523 | 4779 | // Right then. This is a call to a static method. |
| 4524 | - else |
|
| 4525 | - $func = array($class, $method); |
|
| 4780 | + else { |
|
| 4781 | + $func = array($class, $method); |
|
| 4782 | + } |
|
| 4526 | 4783 | } |
| 4527 | 4784 | |
| 4528 | 4785 | // Nope! just a plain regular function. |
| 4529 | - else |
|
| 4530 | - $func = $string; |
|
| 4786 | + else { |
|
| 4787 | + $func = $string; |
|
| 4788 | + } |
|
| 4531 | 4789 | |
| 4532 | 4790 | // Right, we got what we need, time to do some checks. |
| 4533 | 4791 | if (!is_callable($func, false, $callable_name)) |
@@ -4543,17 +4801,18 @@ discard block |
||
| 4543 | 4801 | else |
| 4544 | 4802 | { |
| 4545 | 4803 | // What are we gonna do about it? |
| 4546 | - if ($return) |
|
| 4547 | - return $func; |
|
| 4804 | + if ($return) { |
|
| 4805 | + return $func; |
|
| 4806 | + } |
|
| 4548 | 4807 | |
| 4549 | 4808 | // If this is a plain function, avoid the heat of calling call_user_func(). |
| 4550 | 4809 | else |
| 4551 | 4810 | { |
| 4552 | - if (is_array($func)) |
|
| 4553 | - call_user_func($func); |
|
| 4554 | - |
|
| 4555 | - else |
|
| 4556 | - $func(); |
|
| 4811 | + if (is_array($func)) { |
|
| 4812 | + call_user_func($func); |
|
| 4813 | + } else { |
|
| 4814 | + $func(); |
|
| 4815 | + } |
|
| 4557 | 4816 | } |
| 4558 | 4817 | } |
| 4559 | 4818 | } |
@@ -4570,31 +4829,34 @@ discard block |
||
| 4570 | 4829 | { |
| 4571 | 4830 | global $sourcedir, $txt, $boarddir, $settings; |
| 4572 | 4831 | |
| 4573 | - if (empty($string)) |
|
| 4574 | - return false; |
|
| 4832 | + if (empty($string)) { |
|
| 4833 | + return false; |
|
| 4834 | + } |
|
| 4575 | 4835 | |
| 4576 | 4836 | if (strpos($string, '|') !== false) |
| 4577 | 4837 | { |
| 4578 | 4838 | list ($file, $string) = explode('|', $string); |
| 4579 | 4839 | |
| 4580 | 4840 | // Match the wildcards to their regular vars. |
| 4581 | - if (empty($settings['theme_dir'])) |
|
| 4582 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4583 | - |
|
| 4584 | - else |
|
| 4585 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4841 | + if (empty($settings['theme_dir'])) { |
|
| 4842 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4843 | + } else { |
|
| 4844 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4845 | + } |
|
| 4586 | 4846 | |
| 4587 | 4847 | // Load the file if it can be loaded. |
| 4588 | - if (file_exists($absPath)) |
|
| 4589 | - require_once($absPath); |
|
| 4848 | + if (file_exists($absPath)) { |
|
| 4849 | + require_once($absPath); |
|
| 4850 | + } |
|
| 4590 | 4851 | |
| 4591 | 4852 | // No? try a fallback to $sourcedir |
| 4592 | 4853 | else |
| 4593 | 4854 | { |
| 4594 | 4855 | $absPath = $sourcedir .'/'. $file; |
| 4595 | 4856 | |
| 4596 | - if (file_exists($absPath)) |
|
| 4597 | - require_once($absPath); |
|
| 4857 | + if (file_exists($absPath)) { |
|
| 4858 | + require_once($absPath); |
|
| 4859 | + } |
|
| 4598 | 4860 | |
| 4599 | 4861 | // Sorry, can't do much for you at this point. |
| 4600 | 4862 | else |
@@ -4621,8 +4883,9 @@ discard block |
||
| 4621 | 4883 | global $user_info, $smcFunc; |
| 4622 | 4884 | |
| 4623 | 4885 | // Make sure we have something to work with. |
| 4624 | - if (empty($topic)) |
|
| 4625 | - return array(); |
|
| 4886 | + if (empty($topic)) { |
|
| 4887 | + return array(); |
|
| 4888 | + } |
|
| 4626 | 4889 | |
| 4627 | 4890 | |
| 4628 | 4891 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -4645,8 +4908,9 @@ discard block |
||
| 4645 | 4908 | 'topic' => $topic, |
| 4646 | 4909 | ) |
| 4647 | 4910 | ); |
| 4648 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 4649 | - $temp[] = (int) $row['content_id']; |
|
| 4911 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 4912 | + $temp[] = (int) $row['content_id']; |
|
| 4913 | + } |
|
| 4650 | 4914 | |
| 4651 | 4915 | cache_put_data($cache_key, $temp, $ttl); |
| 4652 | 4916 | } |
@@ -4667,8 +4931,9 @@ discard block |
||
| 4667 | 4931 | { |
| 4668 | 4932 | global $context; |
| 4669 | 4933 | |
| 4670 | - if (empty($string)) |
|
| 4671 | - return $string; |
|
| 4934 | + if (empty($string)) { |
|
| 4935 | + return $string; |
|
| 4936 | + } |
|
| 4672 | 4937 | |
| 4673 | 4938 | // UTF-8 occurences of MS special characters |
| 4674 | 4939 | $findchars_utf8 = array( |
@@ -4709,10 +4974,11 @@ discard block |
||
| 4709 | 4974 | '--', // — |
| 4710 | 4975 | ); |
| 4711 | 4976 | |
| 4712 | - if ($context['utf8']) |
|
| 4713 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 4714 | - else |
|
| 4715 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 4977 | + if ($context['utf8']) { |
|
| 4978 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 4979 | + } else { |
|
| 4980 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 4981 | + } |
|
| 4716 | 4982 | |
| 4717 | 4983 | return $string; |
| 4718 | 4984 | } |
@@ -4731,49 +4997,59 @@ discard block |
||
| 4731 | 4997 | { |
| 4732 | 4998 | global $context; |
| 4733 | 4999 | |
| 4734 | - if (!isset($matches[2])) |
|
| 4735 | - return ''; |
|
| 5000 | + if (!isset($matches[2])) { |
|
| 5001 | + return ''; |
|
| 5002 | + } |
|
| 4736 | 5003 | |
| 4737 | 5004 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4738 | 5005 | |
| 4739 | 5006 | // remove left to right / right to left overrides |
| 4740 | - if ($num === 0x202D || $num === 0x202E) |
|
| 4741 | - return ''; |
|
| 5007 | + if ($num === 0x202D || $num === 0x202E) { |
|
| 5008 | + return ''; |
|
| 5009 | + } |
|
| 4742 | 5010 | |
| 4743 | 5011 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
| 4744 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
| 4745 | - return '&#' . $num . ';'; |
|
| 5012 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
| 5013 | + return '&#' . $num . ';'; |
|
| 5014 | + } |
|
| 4746 | 5015 | |
| 4747 | 5016 | if (empty($context['utf8'])) |
| 4748 | 5017 | { |
| 4749 | 5018 | // no control characters |
| 4750 | - if ($num < 0x20) |
|
| 4751 | - return ''; |
|
| 5019 | + if ($num < 0x20) { |
|
| 5020 | + return ''; |
|
| 5021 | + } |
|
| 4752 | 5022 | // text is text |
| 4753 | - elseif ($num < 0x80) |
|
| 4754 | - return chr($num); |
|
| 5023 | + elseif ($num < 0x80) { |
|
| 5024 | + return chr($num); |
|
| 5025 | + } |
|
| 4755 | 5026 | // all others get html-ised |
| 4756 | - else |
|
| 4757 | - return '&#' . $matches[2] . ';'; |
|
| 4758 | - } |
|
| 4759 | - else |
|
| 5027 | + else { |
|
| 5028 | + return '&#' . $matches[2] . ';'; |
|
| 5029 | + } |
|
| 5030 | + } else |
|
| 4760 | 5031 | { |
| 4761 | 5032 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
| 4762 | 5033 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
| 4763 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
| 4764 | - return ''; |
|
| 5034 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
| 5035 | + return ''; |
|
| 5036 | + } |
|
| 4765 | 5037 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4766 | - elseif ($num < 0x80) |
|
| 4767 | - return chr($num); |
|
| 5038 | + elseif ($num < 0x80) { |
|
| 5039 | + return chr($num); |
|
| 5040 | + } |
|
| 4768 | 5041 | // <0x800 (2048) |
| 4769 | - elseif ($num < 0x800) |
|
| 4770 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5042 | + elseif ($num < 0x800) { |
|
| 5043 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5044 | + } |
|
| 4771 | 5045 | // < 0x10000 (65536) |
| 4772 | - elseif ($num < 0x10000) |
|
| 4773 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5046 | + elseif ($num < 0x10000) { |
|
| 5047 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5048 | + } |
|
| 4774 | 5049 | // <= 0x10FFFF (1114111) |
| 4775 | - else |
|
| 4776 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5050 | + else { |
|
| 5051 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5052 | + } |
|
| 4777 | 5053 | } |
| 4778 | 5054 | } |
| 4779 | 5055 | |
@@ -4789,28 +5065,34 @@ discard block |
||
| 4789 | 5065 | */ |
| 4790 | 5066 | function fixchar__callback($matches) |
| 4791 | 5067 | { |
| 4792 | - if (!isset($matches[1])) |
|
| 4793 | - return ''; |
|
| 5068 | + if (!isset($matches[1])) { |
|
| 5069 | + return ''; |
|
| 5070 | + } |
|
| 4794 | 5071 | |
| 4795 | 5072 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
| 4796 | 5073 | |
| 4797 | 5074 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
| 4798 | 5075 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
| 4799 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
| 4800 | - return ''; |
|
| 5076 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
| 5077 | + return ''; |
|
| 5078 | + } |
|
| 4801 | 5079 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4802 | - elseif ($num < 0x80) |
|
| 4803 | - return chr($num); |
|
| 5080 | + elseif ($num < 0x80) { |
|
| 5081 | + return chr($num); |
|
| 5082 | + } |
|
| 4804 | 5083 | // <0x800 (2048) |
| 4805 | - elseif ($num < 0x800) |
|
| 4806 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5084 | + elseif ($num < 0x800) { |
|
| 5085 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5086 | + } |
|
| 4807 | 5087 | // < 0x10000 (65536) |
| 4808 | - elseif ($num < 0x10000) |
|
| 4809 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5088 | + elseif ($num < 0x10000) { |
|
| 5089 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5090 | + } |
|
| 4810 | 5091 | // <= 0x10FFFF (1114111) |
| 4811 | - else |
|
| 4812 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 4813 | -} |
|
| 5092 | + else { |
|
| 5093 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5094 | + } |
|
| 5095 | + } |
|
| 4814 | 5096 | |
| 4815 | 5097 | /** |
| 4816 | 5098 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -4823,17 +5105,19 @@ discard block |
||
| 4823 | 5105 | */ |
| 4824 | 5106 | function entity_fix__callback($matches) |
| 4825 | 5107 | { |
| 4826 | - if (!isset($matches[2])) |
|
| 4827 | - return ''; |
|
| 5108 | + if (!isset($matches[2])) { |
|
| 5109 | + return ''; |
|
| 5110 | + } |
|
| 4828 | 5111 | |
| 4829 | 5112 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4830 | 5113 | |
| 4831 | 5114 | // we don't allow control characters, characters out of range, byte markers, etc |
| 4832 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
| 4833 | - return ''; |
|
| 4834 | - else |
|
| 4835 | - return '&#' . $num . ';'; |
|
| 4836 | -} |
|
| 5115 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
| 5116 | + return ''; |
|
| 5117 | + } else { |
|
| 5118 | + return '&#' . $num . ';'; |
|
| 5119 | + } |
|
| 5120 | + } |
|
| 4837 | 5121 | |
| 4838 | 5122 | /** |
| 4839 | 5123 | * Return a Gravatar URL based on |
@@ -4857,18 +5141,23 @@ discard block |
||
| 4857 | 5141 | $ratings = array('G', 'PG', 'R', 'X'); |
| 4858 | 5142 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
| 4859 | 5143 | $url_params = array(); |
| 4860 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
| 4861 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 4862 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
| 4863 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 4864 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
| 4865 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 4866 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
| 4867 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 5144 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
| 5145 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 5146 | + } |
|
| 5147 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
| 5148 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 5149 | + } |
|
| 5150 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
| 5151 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 5152 | + } |
|
| 5153 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
| 5154 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 4868 | 5155 | $size_string = $modSettings['avatar_max_height_external']; |
| 5156 | + } |
|
| 4869 | 5157 | |
| 4870 | - if (!empty($size_string)) |
|
| 4871 | - $url_params[] = 's=' . $size_string; |
|
| 5158 | + if (!empty($size_string)) { |
|
| 5159 | + $url_params[] = 's=' . $size_string; |
|
| 5160 | + } |
|
| 4872 | 5161 | } |
| 4873 | 5162 | $http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www'; |
| 4874 | 5163 | |
@@ -4887,22 +5176,26 @@ discard block |
||
| 4887 | 5176 | static $timezones = null, $lastwhen = null; |
| 4888 | 5177 | |
| 4889 | 5178 | // No point doing this over if we already did it once |
| 4890 | - if (!empty($timezones) && $when == $lastwhen) |
|
| 4891 | - return $timezones; |
|
| 4892 | - else |
|
| 4893 | - $lastwhen = $when; |
|
| 5179 | + if (!empty($timezones) && $when == $lastwhen) { |
|
| 5180 | + return $timezones; |
|
| 5181 | + } else { |
|
| 5182 | + $lastwhen = $when; |
|
| 5183 | + } |
|
| 4894 | 5184 | |
| 4895 | 5185 | // Parseable datetime string? |
| 4896 | - if (is_int($timestamp = strtotime($when))) |
|
| 4897 | - $when = $timestamp; |
|
| 5186 | + if (is_int($timestamp = strtotime($when))) { |
|
| 5187 | + $when = $timestamp; |
|
| 5188 | + } |
|
| 4898 | 5189 | |
| 4899 | 5190 | // A Unix timestamp? |
| 4900 | - elseif (is_numeric($when)) |
|
| 4901 | - $when = intval($when); |
|
| 5191 | + elseif (is_numeric($when)) { |
|
| 5192 | + $when = intval($when); |
|
| 5193 | + } |
|
| 4902 | 5194 | |
| 4903 | 5195 | // Invalid value? Just get current Unix timestamp. |
| 4904 | - else |
|
| 4905 | - $when = time(); |
|
| 5196 | + else { |
|
| 5197 | + $when = time(); |
|
| 5198 | + } |
|
| 4906 | 5199 | |
| 4907 | 5200 | // We'll need this too |
| 4908 | 5201 | $later = (int) date_format(date_add(date_create('@' . $when), date_interval_create_from_date_string('1 year')), 'U'); |
@@ -4965,8 +5258,9 @@ discard block |
||
| 4965 | 5258 | foreach ($priority_countries as $country) |
| 4966 | 5259 | { |
| 4967 | 5260 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
| 4968 | - if (!empty($country_tzids)) |
|
| 4969 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
| 5261 | + if (!empty($country_tzids)) { |
|
| 5262 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
| 5263 | + } |
|
| 4970 | 5264 | } |
| 4971 | 5265 | |
| 4972 | 5266 | // Process the preferred timezones first, then the rest. |
@@ -4976,8 +5270,9 @@ discard block |
||
| 4976 | 5270 | foreach ($tzids as $tzid) |
| 4977 | 5271 | { |
| 4978 | 5272 | // We don't want UTC right now |
| 4979 | - if ($tzid == 'UTC') |
|
| 4980 | - continue; |
|
| 5273 | + if ($tzid == 'UTC') { |
|
| 5274 | + continue; |
|
| 5275 | + } |
|
| 4981 | 5276 | |
| 4982 | 5277 | // First, get the set of transition rules for this tzid |
| 4983 | 5278 | $tzinfo = timezone_transitions_get(timezone_open($tzid), $when, $later); |
@@ -4988,8 +5283,9 @@ discard block |
||
| 4988 | 5283 | $tz_location = timezone_location_get(timezone_open($tzid)); |
| 4989 | 5284 | |
| 4990 | 5285 | // Kazakstan |
| 4991 | - if ($tz_location['country_code'] == 'KZ') |
|
| 4992 | - $tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']); |
|
| 5286 | + if ($tz_location['country_code'] == 'KZ') { |
|
| 5287 | + $tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']); |
|
| 5288 | + } |
|
| 4993 | 5289 | |
| 4994 | 5290 | // Russia likes to experiment with time zones |
| 4995 | 5291 | if ($tz_location['country_code'] == 'RU') |
@@ -5000,19 +5296,22 @@ discard block |
||
| 5000 | 5296 | } |
| 5001 | 5297 | |
| 5002 | 5298 | // Still no good? We'll just mark it as a UTC offset |
| 5003 | - if (strspn($tzinfo[0]['abbr'], '+-') > 0) |
|
| 5004 | - $tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr']; |
|
| 5299 | + if (strspn($tzinfo[0]['abbr'], '+-') > 0) { |
|
| 5300 | + $tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr']; |
|
| 5301 | + } |
|
| 5005 | 5302 | } |
| 5006 | 5303 | |
| 5007 | 5304 | $tzkey = serialize($tzinfo); |
| 5008 | 5305 | |
| 5009 | 5306 | // Don't overwrite our preferred tzids |
| 5010 | - if (empty($zones[$tzkey]['tzid'])) |
|
| 5011 | - $zones[$tzkey]['tzid'] = $tzid; |
|
| 5307 | + if (empty($zones[$tzkey]['tzid'])) { |
|
| 5308 | + $zones[$tzkey]['tzid'] = $tzid; |
|
| 5309 | + } |
|
| 5012 | 5310 | |
| 5013 | 5311 | // A time zone from a prioritized country? |
| 5014 | - if (in_array($tzid, $priority_tzids)) |
|
| 5015 | - $priority_zones[$tzkey] = true; |
|
| 5312 | + if (in_array($tzid, $priority_tzids)) { |
|
| 5313 | + $priority_zones[$tzkey] = true; |
|
| 5314 | + } |
|
| 5016 | 5315 | |
| 5017 | 5316 | // Keep track of the location and offset for this tzid |
| 5018 | 5317 | $tzid_parts = explode('/', $tzid); |
@@ -5030,15 +5329,17 @@ discard block |
||
| 5030 | 5329 | { |
| 5031 | 5330 | $tzinfo = unserialize($tzkey); |
| 5032 | 5331 | |
| 5033 | - if (!empty($timezone_descriptions[$tzvalue['tzid']])) |
|
| 5034 | - $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
| 5035 | - else |
|
| 5036 | - $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
| 5332 | + if (!empty($timezone_descriptions[$tzvalue['tzid']])) { |
|
| 5333 | + $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
| 5334 | + } else { |
|
| 5335 | + $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
| 5336 | + } |
|
| 5037 | 5337 | |
| 5038 | - if (isset($priority_zones[$tzkey])) |
|
| 5039 | - $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
| 5040 | - else |
|
| 5041 | - $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
| 5338 | + if (isset($priority_zones[$tzkey])) { |
|
| 5339 | + $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
| 5340 | + } else { |
|
| 5341 | + $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
| 5342 | + } |
|
| 5042 | 5343 | } |
| 5043 | 5344 | |
| 5044 | 5345 | $timezones = array_merge( |
@@ -5056,8 +5357,9 @@ discard block |
||
| 5056 | 5357 | */ |
| 5057 | 5358 | function inet_ptod($ip_address) |
| 5058 | 5359 | { |
| 5059 | - if (!isValidIP($ip_address)) |
|
| 5060 | - return $ip_address; |
|
| 5360 | + if (!isValidIP($ip_address)) { |
|
| 5361 | + return $ip_address; |
|
| 5362 | + } |
|
| 5061 | 5363 | |
| 5062 | 5364 | $bin = inet_pton($ip_address); |
| 5063 | 5365 | return $bin; |
@@ -5069,13 +5371,15 @@ discard block |
||
| 5069 | 5371 | */ |
| 5070 | 5372 | function inet_dtop($bin) |
| 5071 | 5373 | { |
| 5072 | - if(empty($bin)) |
|
| 5073 | - return ''; |
|
| 5374 | + if(empty($bin)) { |
|
| 5375 | + return ''; |
|
| 5376 | + } |
|
| 5074 | 5377 | |
| 5075 | 5378 | global $db_type; |
| 5076 | 5379 | |
| 5077 | - if ($db_type == 'postgresql') |
|
| 5078 | - return $bin; |
|
| 5380 | + if ($db_type == 'postgresql') { |
|
| 5381 | + return $bin; |
|
| 5382 | + } |
|
| 5079 | 5383 | |
| 5080 | 5384 | $ip_address = inet_ntop($bin); |
| 5081 | 5385 | |
@@ -5100,26 +5404,32 @@ discard block |
||
| 5100 | 5404 | */ |
| 5101 | 5405 | function _safe_serialize($value) |
| 5102 | 5406 | { |
| 5103 | - if(is_null($value)) |
|
| 5104 | - return 'N;'; |
|
| 5407 | + if(is_null($value)) { |
|
| 5408 | + return 'N;'; |
|
| 5409 | + } |
|
| 5105 | 5410 | |
| 5106 | - if(is_bool($value)) |
|
| 5107 | - return 'b:'. (int) $value .';'; |
|
| 5411 | + if(is_bool($value)) { |
|
| 5412 | + return 'b:'. (int) $value .';'; |
|
| 5413 | + } |
|
| 5108 | 5414 | |
| 5109 | - if(is_int($value)) |
|
| 5110 | - return 'i:'. $value .';'; |
|
| 5415 | + if(is_int($value)) { |
|
| 5416 | + return 'i:'. $value .';'; |
|
| 5417 | + } |
|
| 5111 | 5418 | |
| 5112 | - if(is_float($value)) |
|
| 5113 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5419 | + if(is_float($value)) { |
|
| 5420 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5421 | + } |
|
| 5114 | 5422 | |
| 5115 | - if(is_string($value)) |
|
| 5116 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5423 | + if(is_string($value)) { |
|
| 5424 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5425 | + } |
|
| 5117 | 5426 | |
| 5118 | 5427 | if(is_array($value)) |
| 5119 | 5428 | { |
| 5120 | 5429 | $out = ''; |
| 5121 | - foreach($value as $k => $v) |
|
| 5122 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5430 | + foreach($value as $k => $v) { |
|
| 5431 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5432 | + } |
|
| 5123 | 5433 | |
| 5124 | 5434 | return 'a:'. count($value) .':{'. $out .'}'; |
| 5125 | 5435 | } |
@@ -5145,8 +5455,9 @@ discard block |
||
| 5145 | 5455 | |
| 5146 | 5456 | $out = _safe_serialize($value); |
| 5147 | 5457 | |
| 5148 | - if (isset($mbIntEnc)) |
|
| 5149 | - mb_internal_encoding($mbIntEnc); |
|
| 5458 | + if (isset($mbIntEnc)) { |
|
| 5459 | + mb_internal_encoding($mbIntEnc); |
|
| 5460 | + } |
|
| 5150 | 5461 | |
| 5151 | 5462 | return $out; |
| 5152 | 5463 | } |
@@ -5163,8 +5474,9 @@ discard block |
||
| 5163 | 5474 | function _safe_unserialize($str) |
| 5164 | 5475 | { |
| 5165 | 5476 | // Input is not a string. |
| 5166 | - if(empty($str) || !is_string($str)) |
|
| 5167 | - return false; |
|
| 5477 | + if(empty($str) || !is_string($str)) { |
|
| 5478 | + return false; |
|
| 5479 | + } |
|
| 5168 | 5480 | |
| 5169 | 5481 | $stack = array(); |
| 5170 | 5482 | $expected = array(); |
@@ -5180,43 +5492,38 @@ discard block |
||
| 5180 | 5492 | while($state != 1) |
| 5181 | 5493 | { |
| 5182 | 5494 | $type = isset($str[0]) ? $str[0] : ''; |
| 5183 | - if($type == '}') |
|
| 5184 | - $str = substr($str, 1); |
|
| 5185 | - |
|
| 5186 | - else if($type == 'N' && $str[1] == ';') |
|
| 5495 | + if($type == '}') { |
|
| 5496 | + $str = substr($str, 1); |
|
| 5497 | + } else if($type == 'N' && $str[1] == ';') |
|
| 5187 | 5498 | { |
| 5188 | 5499 | $value = null; |
| 5189 | 5500 | $str = substr($str, 2); |
| 5190 | - } |
|
| 5191 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5501 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5192 | 5502 | { |
| 5193 | 5503 | $value = $matches[1] == '1' ? true : false; |
| 5194 | 5504 | $str = substr($str, 4); |
| 5195 | - } |
|
| 5196 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5505 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5197 | 5506 | { |
| 5198 | 5507 | $value = (int)$matches[1]; |
| 5199 | 5508 | $str = $matches[2]; |
| 5200 | - } |
|
| 5201 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5509 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5202 | 5510 | { |
| 5203 | 5511 | $value = (float)$matches[1]; |
| 5204 | 5512 | $str = $matches[3]; |
| 5205 | - } |
|
| 5206 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5513 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5207 | 5514 | { |
| 5208 | 5515 | $value = substr($matches[2], 0, (int)$matches[1]); |
| 5209 | 5516 | $str = substr($matches[2], (int)$matches[1] + 2); |
| 5210 | - } |
|
| 5211 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5517 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5212 | 5518 | { |
| 5213 | 5519 | $expectedLength = (int)$matches[1]; |
| 5214 | 5520 | $str = $matches[2]; |
| 5215 | 5521 | } |
| 5216 | 5522 | |
| 5217 | 5523 | // Object or unknown/malformed type. |
| 5218 | - else |
|
| 5219 | - return false; |
|
| 5524 | + else { |
|
| 5525 | + return false; |
|
| 5526 | + } |
|
| 5220 | 5527 | |
| 5221 | 5528 | switch($state) |
| 5222 | 5529 | { |
@@ -5244,8 +5551,9 @@ discard block |
||
| 5244 | 5551 | if($type == '}') |
| 5245 | 5552 | { |
| 5246 | 5553 | // Array size is less than expected. |
| 5247 | - if(count($list) < end($expected)) |
|
| 5248 | - return false; |
|
| 5554 | + if(count($list) < end($expected)) { |
|
| 5555 | + return false; |
|
| 5556 | + } |
|
| 5249 | 5557 | |
| 5250 | 5558 | unset($list); |
| 5251 | 5559 | $list = &$stack[count($stack)-1]; |
@@ -5254,8 +5562,9 @@ discard block |
||
| 5254 | 5562 | // Go to terminal state if we're at the end of the root array. |
| 5255 | 5563 | array_pop($expected); |
| 5256 | 5564 | |
| 5257 | - if(count($expected) == 0) |
|
| 5258 | - $state = 1; |
|
| 5565 | + if(count($expected) == 0) { |
|
| 5566 | + $state = 1; |
|
| 5567 | + } |
|
| 5259 | 5568 | |
| 5260 | 5569 | break; |
| 5261 | 5570 | } |
@@ -5263,8 +5572,9 @@ discard block |
||
| 5263 | 5572 | if($type == 'i' || $type == 's') |
| 5264 | 5573 | { |
| 5265 | 5574 | // Array size exceeds expected length. |
| 5266 | - if(count($list) >= end($expected)) |
|
| 5267 | - return false; |
|
| 5575 | + if(count($list) >= end($expected)) { |
|
| 5576 | + return false; |
|
| 5577 | + } |
|
| 5268 | 5578 | |
| 5269 | 5579 | $key = $value; |
| 5270 | 5580 | $state = 3; |
@@ -5298,8 +5608,9 @@ discard block |
||
| 5298 | 5608 | } |
| 5299 | 5609 | |
| 5300 | 5610 | // Trailing data in input. |
| 5301 | - if(!empty($str)) |
|
| 5302 | - return false; |
|
| 5611 | + if(!empty($str)) { |
|
| 5612 | + return false; |
|
| 5613 | + } |
|
| 5303 | 5614 | |
| 5304 | 5615 | return $data; |
| 5305 | 5616 | } |
@@ -5322,8 +5633,9 @@ discard block |
||
| 5322 | 5633 | |
| 5323 | 5634 | $out = _safe_unserialize($str); |
| 5324 | 5635 | |
| 5325 | - if (isset($mbIntEnc)) |
|
| 5326 | - mb_internal_encoding($mbIntEnc); |
|
| 5636 | + if (isset($mbIntEnc)) { |
|
| 5637 | + mb_internal_encoding($mbIntEnc); |
|
| 5638 | + } |
|
| 5327 | 5639 | |
| 5328 | 5640 | return $out; |
| 5329 | 5641 | } |
@@ -5338,12 +5650,14 @@ discard block |
||
| 5338 | 5650 | function smf_chmod($file, $value = 0) |
| 5339 | 5651 | { |
| 5340 | 5652 | // No file? no checks! |
| 5341 | - if (empty($file)) |
|
| 5342 | - return false; |
|
| 5653 | + if (empty($file)) { |
|
| 5654 | + return false; |
|
| 5655 | + } |
|
| 5343 | 5656 | |
| 5344 | 5657 | // Already writable? |
| 5345 | - if (is_writable($file)) |
|
| 5346 | - return true; |
|
| 5658 | + if (is_writable($file)) { |
|
| 5659 | + return true; |
|
| 5660 | + } |
|
| 5347 | 5661 | |
| 5348 | 5662 | // Do we have a file or a dir? |
| 5349 | 5663 | $isDir = is_dir($file); |
@@ -5359,10 +5673,9 @@ discard block |
||
| 5359 | 5673 | { |
| 5360 | 5674 | $isWritable = true; |
| 5361 | 5675 | break; |
| 5676 | + } else { |
|
| 5677 | + @chmod($file, $val); |
|
| 5362 | 5678 | } |
| 5363 | - |
|
| 5364 | - else |
|
| 5365 | - @chmod($file, $val); |
|
| 5366 | 5679 | } |
| 5367 | 5680 | |
| 5368 | 5681 | return $isWritable; |
@@ -5381,8 +5694,9 @@ discard block |
||
| 5381 | 5694 | global $txt; |
| 5382 | 5695 | |
| 5383 | 5696 | // Come on... |
| 5384 | - if (empty($json) || !is_string($json)) |
|
| 5385 | - return array(); |
|
| 5697 | + if (empty($json) || !is_string($json)) { |
|
| 5698 | + return array(); |
|
| 5699 | + } |
|
| 5386 | 5700 | |
| 5387 | 5701 | $returnArray = @json_decode($json, $returnAsArray); |
| 5388 | 5702 | |
@@ -5420,11 +5734,11 @@ discard block |
||
| 5420 | 5734 | $jsonDebug = $jsonDebug[0]; |
| 5421 | 5735 | loadLanguage('Errors'); |
| 5422 | 5736 | |
| 5423 | - if (!empty($jsonDebug)) |
|
| 5424 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5425 | - |
|
| 5426 | - else |
|
| 5427 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5737 | + if (!empty($jsonDebug)) { |
|
| 5738 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5739 | + } else { |
|
| 5740 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5741 | + } |
|
| 5428 | 5742 | |
| 5429 | 5743 | // Everyone expects an array. |
| 5430 | 5744 | return array(); |
@@ -5454,8 +5768,9 @@ discard block |
||
| 5454 | 5768 | global $db_show_debug, $modSettings; |
| 5455 | 5769 | |
| 5456 | 5770 | // Defensive programming anyone? |
| 5457 | - if (empty($data)) |
|
| 5458 | - return false; |
|
| 5771 | + if (empty($data)) { |
|
| 5772 | + return false; |
|
| 5773 | + } |
|
| 5459 | 5774 | |
| 5460 | 5775 | // Don't need extra stuff... |
| 5461 | 5776 | $db_show_debug = false; |
@@ -5463,11 +5778,11 @@ discard block |
||
| 5463 | 5778 | // Kill anything else. |
| 5464 | 5779 | ob_end_clean(); |
| 5465 | 5780 | |
| 5466 | - if (!empty($modSettings['CompressedOutput'])) |
|
| 5467 | - @ob_start('ob_gzhandler'); |
|
| 5468 | - |
|
| 5469 | - else |
|
| 5470 | - ob_start(); |
|
| 5781 | + if (!empty($modSettings['CompressedOutput'])) { |
|
| 5782 | + @ob_start('ob_gzhandler'); |
|
| 5783 | + } else { |
|
| 5784 | + ob_start(); |
|
| 5785 | + } |
|
| 5471 | 5786 | |
| 5472 | 5787 | // Set the header. |
| 5473 | 5788 | header($type); |
@@ -5499,8 +5814,9 @@ discard block |
||
| 5499 | 5814 | static $done = false; |
| 5500 | 5815 | |
| 5501 | 5816 | // If we don't need to do anything, don't |
| 5502 | - if (!$update && $done) |
|
| 5503 | - return; |
|
| 5817 | + if (!$update && $done) { |
|
| 5818 | + return; |
|
| 5819 | + } |
|
| 5504 | 5820 | |
| 5505 | 5821 | // Should we get a new copy of the official list of TLDs? |
| 5506 | 5822 | if ($update) |
@@ -5521,10 +5837,11 @@ discard block |
||
| 5521 | 5837 | // Clean $tlds and convert it to an array |
| 5522 | 5838 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
| 5523 | 5839 | $line = trim($line); |
| 5524 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
| 5525 | - return false; |
|
| 5526 | - else |
|
| 5527 | - return true; |
|
| 5840 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
| 5841 | + return false; |
|
| 5842 | + } else { |
|
| 5843 | + return true; |
|
| 5844 | + } |
|
| 5528 | 5845 | }); |
| 5529 | 5846 | |
| 5530 | 5847 | // Convert Punycode to Unicode |
@@ -5578,8 +5895,9 @@ discard block |
||
| 5578 | 5895 | $idx += $digit * $w; |
| 5579 | 5896 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); |
| 5580 | 5897 | |
| 5581 | - if ($digit < $t) |
|
| 5582 | - break; |
|
| 5898 | + if ($digit < $t) { |
|
| 5899 | + break; |
|
| 5900 | + } |
|
| 5583 | 5901 | |
| 5584 | 5902 | $w = (int) ($w * ($base - $t)); |
| 5585 | 5903 | } |
@@ -5588,8 +5906,9 @@ discard block |
||
| 5588 | 5906 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); |
| 5589 | 5907 | $delta += intval($delta / ($deco_len + 1)); |
| 5590 | 5908 | |
| 5591 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) |
|
| 5592 | - $delta = intval($delta / ($base - $tmin)); |
|
| 5909 | + for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { |
|
| 5910 | + $delta = intval($delta / ($base - $tmin)); |
|
| 5911 | + } |
|
| 5593 | 5912 | |
| 5594 | 5913 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); |
| 5595 | 5914 | $is_first = false; |
@@ -5598,8 +5917,9 @@ discard block |
||
| 5598 | 5917 | |
| 5599 | 5918 | if ($deco_len > 0) |
| 5600 | 5919 | { |
| 5601 | - for ($i = $deco_len; $i > $idx; $i--) |
|
| 5602 | - $decoded[$i] = $decoded[($i - 1)]; |
|
| 5920 | + for ($i = $deco_len; $i > $idx; $i--) { |
|
| 5921 | + $decoded[$i] = $decoded[($i - 1)]; |
|
| 5922 | + } |
|
| 5603 | 5923 | } |
| 5604 | 5924 | $decoded[$idx++] = $char; |
| 5605 | 5925 | } |
@@ -5607,24 +5927,29 @@ discard block |
||
| 5607 | 5927 | foreach ($decoded as $k => $v) |
| 5608 | 5928 | { |
| 5609 | 5929 | // 7bit are transferred literally |
| 5610 | - if ($v < 128) |
|
| 5611 | - $output .= chr($v); |
|
| 5930 | + if ($v < 128) { |
|
| 5931 | + $output .= chr($v); |
|
| 5932 | + } |
|
| 5612 | 5933 | |
| 5613 | 5934 | // 2 bytes |
| 5614 | - elseif ($v < (1 << 11)) |
|
| 5615 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 5935 | + elseif ($v < (1 << 11)) { |
|
| 5936 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 5937 | + } |
|
| 5616 | 5938 | |
| 5617 | 5939 | // 3 bytes |
| 5618 | - elseif ($v < (1 << 16)) |
|
| 5619 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5940 | + elseif ($v < (1 << 16)) { |
|
| 5941 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5942 | + } |
|
| 5620 | 5943 | |
| 5621 | 5944 | // 4 bytes |
| 5622 | - elseif ($v < (1 << 21)) |
|
| 5623 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5945 | + elseif ($v < (1 << 21)) { |
|
| 5946 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5947 | + } |
|
| 5624 | 5948 | |
| 5625 | 5949 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
| 5626 | - else |
|
| 5627 | - $output .= $safe_char; |
|
| 5950 | + else { |
|
| 5951 | + $output .= $safe_char; |
|
| 5952 | + } |
|
| 5628 | 5953 | } |
| 5629 | 5954 | |
| 5630 | 5955 | $output_parts[] = $output; |
@@ -5719,8 +6044,7 @@ discard block |
||
| 5719 | 6044 | |
| 5720 | 6045 | $strlen = 'mb_strlen'; |
| 5721 | 6046 | $substr = 'mb_substr'; |
| 5722 | - } |
|
| 5723 | - else |
|
| 6047 | + } else |
|
| 5724 | 6048 | { |
| 5725 | 6049 | $strlen = $smcFunc['strlen']; |
| 5726 | 6050 | $substr = $smcFunc['substr']; |
@@ -5734,20 +6058,21 @@ discard block |
||
| 5734 | 6058 | |
| 5735 | 6059 | $first = $substr($string, 0, 1); |
| 5736 | 6060 | |
| 5737 | - if (empty($index[$first])) |
|
| 5738 | - $index[$first] = array(); |
|
| 6061 | + if (empty($index[$first])) { |
|
| 6062 | + $index[$first] = array(); |
|
| 6063 | + } |
|
| 5739 | 6064 | |
| 5740 | 6065 | if ($strlen($string) > 1) |
| 5741 | 6066 | { |
| 5742 | 6067 | // Sanity check on recursion |
| 5743 | - if ($depth > 99) |
|
| 5744 | - $index[$first][$substr($string, 1)] = ''; |
|
| 5745 | - |
|
| 5746 | - else |
|
| 5747 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 6068 | + if ($depth > 99) { |
|
| 6069 | + $index[$first][$substr($string, 1)] = ''; |
|
| 6070 | + } else { |
|
| 6071 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 6072 | + } |
|
| 6073 | + } else { |
|
| 6074 | + $index[$first][''] = ''; |
|
| 5748 | 6075 | } |
| 5749 | - else |
|
| 5750 | - $index[$first][''] = ''; |
|
| 5751 | 6076 | |
| 5752 | 6077 | $depth--; |
| 5753 | 6078 | return $index; |
@@ -5770,9 +6095,9 @@ discard block |
||
| 5770 | 6095 | $key_regex = preg_quote($key, $delim); |
| 5771 | 6096 | $new_key = $key; |
| 5772 | 6097 | |
| 5773 | - if (empty($value)) |
|
| 5774 | - $sub_regex = ''; |
|
| 5775 | - else |
|
| 6098 | + if (empty($value)) { |
|
| 6099 | + $sub_regex = ''; |
|
| 6100 | + } else |
|
| 5776 | 6101 | { |
| 5777 | 6102 | $sub_regex = $index_to_regex($value, $delim); |
| 5778 | 6103 | |
@@ -5780,22 +6105,22 @@ discard block |
||
| 5780 | 6105 | { |
| 5781 | 6106 | $new_key_array = explode('(?'.'>', $sub_regex); |
| 5782 | 6107 | $new_key .= $new_key_array[0]; |
| 6108 | + } else { |
|
| 6109 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5783 | 6110 | } |
| 5784 | - else |
|
| 5785 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5786 | 6111 | } |
| 5787 | 6112 | |
| 5788 | - if ($depth > 1) |
|
| 5789 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
| 5790 | - else |
|
| 6113 | + if ($depth > 1) { |
|
| 6114 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
| 6115 | + } else |
|
| 5791 | 6116 | { |
| 5792 | 6117 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
| 5793 | 6118 | { |
| 5794 | 6119 | $regex[$new_key] = $key_regex . $sub_regex; |
| 5795 | 6120 | unset($index[$key]); |
| 6121 | + } else { |
|
| 6122 | + break; |
|
| 5796 | 6123 | } |
| 5797 | - else |
|
| 5798 | - break; |
|
| 5799 | 6124 | } |
| 5800 | 6125 | } |
| 5801 | 6126 | |
@@ -5804,10 +6129,11 @@ discard block |
||
| 5804 | 6129 | $l1 = $strlen($k1); |
| 5805 | 6130 | $l2 = $strlen($k2); |
| 5806 | 6131 | |
| 5807 | - if ($l1 == $l2) |
|
| 5808 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 5809 | - else |
|
| 5810 | - return $l1 > $l2 ? -1 : 1; |
|
| 6132 | + if ($l1 == $l2) { |
|
| 6133 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 6134 | + } else { |
|
| 6135 | + return $l1 > $l2 ? -1 : 1; |
|
| 6136 | + } |
|
| 5811 | 6137 | }); |
| 5812 | 6138 | |
| 5813 | 6139 | $depth--; |
@@ -5818,15 +6144,18 @@ discard block |
||
| 5818 | 6144 | $index = array(); |
| 5819 | 6145 | $regexes = array(); |
| 5820 | 6146 | |
| 5821 | - foreach ($strings as $string) |
|
| 5822 | - $index = $add_string_to_index($string, $index); |
|
| 6147 | + foreach ($strings as $string) { |
|
| 6148 | + $index = $add_string_to_index($string, $index); |
|
| 6149 | + } |
|
| 5823 | 6150 | |
| 5824 | - while (!empty($index)) |
|
| 5825 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6151 | + while (!empty($index)) { |
|
| 6152 | + $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6153 | + } |
|
| 5826 | 6154 | |
| 5827 | 6155 | // Restore PHP's internal character encoding to whatever it was originally |
| 5828 | - if (!empty($current_encoding)) |
|
| 5829 | - mb_internal_encoding($current_encoding); |
|
| 6156 | + if (!empty($current_encoding)) { |
|
| 6157 | + mb_internal_encoding($current_encoding); |
|
| 6158 | + } |
|
| 5830 | 6159 | |
| 5831 | 6160 | return $regexes; |
| 5832 | 6161 | } |