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.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. if (!$Url) {
  19. return '';
  20. }
  21. if (preg_match('/^https:\/\/('.SITE_DOMAIN.'|'.$ENV->IMAGE_DOMAIN.')\//', $Url) || $Url[0] === '/') {
  22. if (strpos($Url, '?') === false) {
  23. $Url .= '?';
  24. }
  25. return $Url;
  26. } else {
  27. return 'https://'
  28. . $ENV->IMAGE_DOMAIN
  29. . ($Thumb?"/$Thumb/":'/')
  30. . '?h='
  31. . rawurlencode(base64_encode(hash_hmac('sha256', $Url, IMAGE_PSK, true)))
  32. . '&i='
  33. . urlencode($Url);
  34. }
  35. }
  36. /**
  37. * Checks if a link's host is (not) good, otherwise displays an error.
  38. * @param string $Url Link to an image
  39. * @return boolean
  40. */
  41. public static function blacklisted($Url, $ShowError = true)
  42. {
  43. $Blacklist = ['tinypic.com'];
  44. foreach ($Blacklist as $Value) {
  45. if (stripos($Url, $Value) !== false) {
  46. if ($ShowError) {
  47. error($Value . ' is not an allowed image host. Please use a different host.');
  48. }
  49. return true;
  50. }
  51. }
  52. return false;
  53. }
  54. }