diff options
Diffstat (limited to 'application/Thumbnailer.php')
-rw-r--r-- | application/Thumbnailer.php | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/application/Thumbnailer.php b/application/Thumbnailer.php index d2284e79..7d0d9c33 100644 --- a/application/Thumbnailer.php +++ b/application/Thumbnailer.php | |||
@@ -14,6 +14,27 @@ use WebThumbnailer\Application\ConfigManager as WTConfigManager; | |||
14 | */ | 14 | */ |
15 | class Thumbnailer | 15 | class Thumbnailer |
16 | { | 16 | { |
17 | const COMMON_MEDIA_DOMAINS = [ | ||
18 | 'imgur.com', | ||
19 | 'flickr.com', | ||
20 | 'youtube.com', | ||
21 | 'wikimedia.org', | ||
22 | 'redd.it', | ||
23 | 'gfycat.com', | ||
24 | 'media.giphy.com', | ||
25 | 'twitter.com', | ||
26 | 'twimg.com', | ||
27 | 'instagram.com', | ||
28 | 'pinterest.com', | ||
29 | 'pinterest.fr', | ||
30 | 'tumblr.com', | ||
31 | 'deviantart.com', | ||
32 | ]; | ||
33 | |||
34 | const MODE_ALL = 'all'; | ||
35 | const MODE_COMMON = 'common'; | ||
36 | const MODE_NONE = 'none'; | ||
37 | |||
17 | /** | 38 | /** |
18 | * @var WebThumbnailer instance. | 39 | * @var WebThumbnailer instance. |
19 | */ | 40 | */ |
@@ -57,13 +78,42 @@ class Thumbnailer | |||
57 | */ | 78 | */ |
58 | public function get($url) | 79 | public function get($url) |
59 | { | 80 | { |
81 | if ($this->conf->get('thumbnails.mode') === self::MODE_COMMON | ||
82 | && ! $this->isCommonMediaOrImage($url) | ||
83 | ) { | ||
84 | return false; | ||
85 | } | ||
86 | |||
60 | try { | 87 | try { |
61 | return $this->wt->thumbnail($url); | 88 | return $this->wt->thumbnail($url); |
62 | } catch (WebThumbnailerException $e) { | 89 | } catch (WebThumbnailerException $e) { |
63 | // Exceptions are only thrown in debug mode. | 90 | // Exceptions are only thrown in debug mode. |
64 | error_log(get_class($e) .': '. $e->getMessage()); | 91 | error_log(get_class($e) . ': ' . $e->getMessage()); |
65 | return false; | ||
66 | } | 92 | } |
93 | return false; | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * We check weather the given URL is from a common media domain, | ||
98 | * or if the file extension is an image. | ||
99 | * | ||
100 | * @param string $url to check | ||
101 | * | ||
102 | * @return bool true if it's an image or from a common media domain, false otherwise. | ||
103 | */ | ||
104 | public function isCommonMediaOrImage($url) | ||
105 | { | ||
106 | foreach (self::COMMON_MEDIA_DOMAINS as $domain) { | ||
107 | if (strpos($url, $domain) !== false) { | ||
108 | return true; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | if (endsWith($url, '.jpg') || endsWith($url, '.png') || endsWith($url, '.jpeg')) { | ||
113 | return true; | ||
114 | } | ||
115 | |||
116 | return false; | ||
67 | } | 117 | } |
68 | 118 | ||
69 | /** | 119 | /** |