Oppaitime'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.2KB

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