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

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