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

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