BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

imagetools.class.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * ImageTools Class
  5. * Thumbnail aide, mostly
  6. */
  7. class ImageTools
  8. {
  9. /**
  10. * Determine the image URL. This takes care of the image proxy and thumbnailing.
  11. * @param string $Url
  12. * @param string $Thumb image proxy scale profile to use
  13. * @return string
  14. */
  15. public static function process($Url = '', $Thumb = false)
  16. {
  17. $ENV = ENV::go();
  18. $Psk = $ENV->getPriv('IMAGE_PSK');
  19. if (!$Url) {
  20. return '';
  21. }
  22. if (preg_match('/^https:\/\/('.$ENV->SITE_DOMAIN.'|'.$ENV->IMAGE_DOMAIN.')\//', $Url) || $Url[0] === '/') {
  23. if (strpos($Url, '?') === false) {
  24. $Url .= '?';
  25. }
  26. return $Url;
  27. } else {
  28. return 'https://'
  29. . $ENV->IMAGE_DOMAIN
  30. . ($Thumb?"/$Thumb/":'/')
  31. . '?h='
  32. . rawurlencode(base64_encode(hash_hmac('sha256', $Url, $Psk, true)))
  33. . '&i='
  34. . urlencode($Url);
  35. }
  36. }
  37. /**
  38. * Checks if a link's host is (not) good, otherwise displays an error.
  39. * @param string $Url Link to an image
  40. * @return boolean
  41. */
  42. public static function blacklisted($Url, $ShowError = true)
  43. {
  44. $Blacklist = ['tinypic.com'];
  45. foreach ($Blacklist as $Value) {
  46. if (stripos($Url, $Value) !== false) {
  47. if ($ShowError) {
  48. error($Value . ' is not an allowed image host. Please use a different host.');
  49. }
  50. return true;
  51. }
  52. }
  53. return false;
  54. }
  55. }