@@ -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'); |