@@ -51,7 +51,7 @@ |
||
51 | 51 | new \RecursiveDirectoryIterator( |
52 | 52 | $path, |
53 | 53 | \FilesystemIterator::SKIP_DOTS | |
54 | - \FilesystemIterator::UNIX_PATHS |
|
54 | + \FilesystemIterator::UNIX_PATHS |
|
55 | 55 | ), |
56 | 56 | \RecursiveIteratorIterator::CHILD_FIRST |
57 | 57 | ) as $value) { |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public static function generateThumbnail($imageStr, $target, $maxWidth, $maxHeight, $crop = false) |
34 | 34 | { |
35 | - if (! touch($target)) { |
|
35 | + if (!touch($target)) { |
|
36 | 36 | throw new ImageConvertException('Target file is not writable.'); |
37 | 37 | } |
38 | 38 | |
39 | - if ($crop && ($maxWidth == 0 || $maxHeight == 0)) { |
|
39 | + if ($crop && ($maxWidth == 0 || $maxHeight == 0)) { |
|
40 | 40 | throw new ImageConvertException('Both width and height must be provided for cropping'); |
41 | 41 | } |
42 | 42 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | throw new ImageConvertException('Could not generate the thumbnail from source image.'); |
68 | 68 | } |
69 | 69 | |
70 | - if (! imagecopyresized( |
|
70 | + if (!imagecopyresized( |
|
71 | 71 | $targetImg, |
72 | 72 | $sourceImg, |
73 | 73 | 0, |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $diffHeight = !empty($maxHeight) ? $originalHeight - $maxHeight : false; |
109 | 109 | |
110 | 110 | if (($diffHeight === false && $diffWidth !== false) |
111 | - || ($diffWidth > $diffHeight && ! $crop) |
|
111 | + || ($diffWidth > $diffHeight && !$crop) |
|
112 | 112 | || ($diffWidth < $diffHeight && $crop) |
113 | 113 | ) { |
114 | 114 | $finalWidth = $maxWidth; |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | try { |
34 | 34 | list($domain, $finder, $rules, $options) = self::getThumbnailMeta($domain, $url); |
35 | 35 | |
36 | - $className = '\\WebThumbnailer\\Finder\\' . $finder . 'Finder'; |
|
36 | + $className = '\\WebThumbnailer\\Finder\\'.$finder.'Finder'; |
|
37 | 37 | if (!class_exists($className)) { |
38 | 38 | throw new Exception\UnsupportedDomainException(); |
39 | 39 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $jsonFiles = ConfigManager::get('settings.rules_filename', ['rules.json']); |
64 | 64 | $allRules = []; |
65 | 65 | foreach ($jsonFiles as $file) { |
66 | - $allRules = array_merge($allRules, DataUtils::loadJson(FileUtils::RESOURCES_PATH . $file)); |
|
66 | + $allRules = array_merge($allRules, DataUtils::loadJson(FileUtils::RESOURCES_PATH.$file)); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | $domain = null; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | protected function replaceOption($thumbnailUrl, $option) |
59 | 59 | { |
60 | 60 | $chosenOption = $this->getOptionValue($option); |
61 | - return str_replace('${'. $option .'}', $chosenOption, $thumbnailUrl); |
|
61 | + return str_replace('${'.$option.'}', $chosenOption, $thumbnailUrl); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | protected function getOptionValue($option) |
73 | 73 | { |
74 | 74 | // If the provided option is not defined in the Finder rules. |
75 | - if (empty($this->finderOptions) || ! in_array($option, array_keys($this->finderOptions))) { |
|
76 | - throw new BadRulesException('Unknown option "'. $option .'" for the finder "'. $this->getName() .'"'); |
|
75 | + if (empty($this->finderOptions) || !in_array($option, array_keys($this->finderOptions))) { |
|
76 | + throw new BadRulesException('Unknown option "'.$option.'" for the finder "'.$this->getName().'"'); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | // User option is defined. |
80 | 80 | // Any defined option must provide a replacement value in rules under the `param` key. |
81 | - if (! empty($this->userOptions[$option]) |
|
81 | + if (!empty($this->userOptions[$option]) |
|
82 | 82 | && is_string($this->userOptions[$option]) |
83 | 83 | && isset($this->finderOptions[$option][$this->userOptions[$option]]['param']) |
84 | 84 | ) { |
@@ -86,15 +86,15 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | // If no user option has been found, and no default value is provided: error. |
89 | - if (! isset($this->finderOptions[$option]['default'])) { |
|
90 | - $error = 'No default set for option "'. $option .'" for the finder "'. $this->getName() .'"'; |
|
89 | + if (!isset($this->finderOptions[$option]['default'])) { |
|
90 | + $error = 'No default set for option "'.$option.'" for the finder "'.$this->getName().'"'; |
|
91 | 91 | throw new BadRulesException($error); |
92 | 92 | } |
93 | 93 | |
94 | 94 | // Use default option replacement. |
95 | 95 | $default = $this->finderOptions[$option]['default']; |
96 | 96 | if (!isset($this->finderOptions[$option][$default]['param'])) { |
97 | - $error = 'No default parameter set for option "'. $option .'" for the finder "'. $this->getName() .'"'; |
|
97 | + $error = 'No default parameter set for option "'.$option.'" for the finder "'.$this->getName().'"'; |
|
98 | 98 | throw new BadRulesException($error); |
99 | 99 | } |
100 | 100 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function isHotlinkAllowed() |
108 | 108 | { |
109 | - if (! isset($this->finderOptions['hotlink_allowed']) |
|
109 | + if (!isset($this->finderOptions['hotlink_allowed']) |
|
110 | 110 | || $this->finderOptions['hotlink_allowed'] === true |
111 | 111 | ) { |
112 | 112 | return true; |
@@ -62,16 +62,16 @@ discard block |
||
62 | 62 | return $this->url; |
63 | 63 | } |
64 | 64 | |
65 | - if (empty($thumbnail) && ! empty($headers) && strpos($headers[0], '200') === false) { |
|
65 | + if (empty($thumbnail) && !empty($headers) && strpos($headers[0], '200') === false) { |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | 69 | // With curl, the thumb is extracted during the download |
70 | - if ($this->webAccess instanceof WebAccessCUrl && ! empty($thumbnail)) { |
|
70 | + if ($this->webAccess instanceof WebAccessCUrl && !empty($thumbnail)) { |
|
71 | 71 | return $thumbnail; |
72 | 72 | } |
73 | 73 | |
74 | - return ! empty($content) ? self::extractMetaTag($content) : false; |
|
74 | + return !empty($content) ? self::extractMetaTag($content) : false; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return int|bool length of $data or false if we need to stop the download |
101 | 101 | */ |
102 | - return function (&$ch, $data) use ($url, &$content, &$thumbnail) { |
|
102 | + return function(&$ch, $data) use ($url, &$content, &$thumbnail) { |
|
103 | 103 | $content .= $data; |
104 | 104 | $responseCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); |
105 | 105 | if (!empty($responseCode) && $responseCode != 200) { |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | $propertiesKey = ['property', 'name', 'itemprop']; |
146 | 146 | $properties = implode('|', $propertiesKey); |
147 | 147 | // Try to retrieve OpenGraph image. |
148 | - $ogRegex = '#<meta[^>]+(?:'. $properties .')=["\']?og:image["\'\s][^>]*content=["\']?(.*?)["\'\s>]#'; |
|
148 | + $ogRegex = '#<meta[^>]+(?:'.$properties.')=["\']?og:image["\'\s][^>]*content=["\']?(.*?)["\'\s>]#'; |
|
149 | 149 | // If the attributes are not in the order property => content (e.g. Github) |
150 | 150 | // New regex to keep this readable... more or less. |
151 | - $ogRegexReverse = '#<meta[^>]+content=["\']?([^"\'\s]+)[^>]+(?:'. $properties .')=["\']?og:image["\'\s/>]#'; |
|
151 | + $ogRegexReverse = '#<meta[^>]+content=["\']?([^"\'\s]+)[^>]+(?:'.$properties.')=["\']?og:image["\'\s/>]#'; |
|
152 | 152 | |
153 | 153 | if (preg_match($ogRegex, $content, $matches) > 0 |
154 | 154 | || preg_match($ogRegexReverse, $content, $matches) > 0 |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | // With curl, the thumb is extracted during the download |
91 | - if ($this->webAccess instanceof WebAccessCUrl && ! empty($thumbnail)) { |
|
91 | + if ($this->webAccess instanceof WebAccessCUrl && !empty($thumbnail)) { |
|
92 | 92 | return $thumbnail; |
93 | 93 | } |
94 | 94 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return int|bool length of $data or false if we need to stop the download |
121 | 121 | */ |
122 | - return function (&$ch, $data) use (&$content, &$thumbnail) { |
|
122 | + return function(&$ch, $data) use (&$content, &$thumbnail) { |
|
123 | 123 | $content .= $data; |
124 | 124 | $responseCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); |
125 | 125 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | if (preg_match($this->urlRegex, $content, $matches) !== 0) { |
154 | 154 | $total = count($matches); |
155 | 155 | for ($i = 1; $i < $total; $i++) { |
156 | - $thumbnailUrl = str_replace('${'. $i . '}', $matches[$i], $thumbnailUrl); |
|
156 | + $thumbnailUrl = str_replace('${'.$i.'}', $matches[$i], $thumbnailUrl); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | // Match only options (not ${number}) |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | */ |
173 | 173 | public function checkRules($rules) |
174 | 174 | { |
175 | - if (! FinderUtils::checkMandatoryRules($rules, [ |
|
175 | + if (!FinderUtils::checkMandatoryRules($rules, [ |
|
176 | 176 | 'image_regex', |
177 | 177 | 'thumbnail_url' |
178 | 178 | ])) { |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * Thumbnails image cache. |
27 | 27 | */ |
28 | - const TYPE_THUMB = 'thumb'; |
|
28 | + const TYPE_THUMB = 'thumb'; |
|
29 | 29 | /** |
30 | 30 | * Finder cache. |
31 | 31 | */ |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | self::rebuildCacheFolders(); |
56 | 56 | return self::getCachePath($type, true); |
57 | 57 | } elseif (!$path) { |
58 | - throw new IOException('Cache folders are not writable: '. $cache); |
|
58 | + throw new IOException('Cache folders are not writable: '.$cache); |
|
59 | 59 | } |
60 | 60 | return $path; |
61 | 61 | } |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | self::createDomainThumbCacheFolder($domain, $type); |
78 | 78 | $domainFolder = FileUtils::getPath(self::getCachePath($type), $domain); |
79 | 79 | if ($type === self::TYPE_THUMB) { |
80 | - $suffix = $width . $height . ($crop ? '1' : '0') .'.png'; |
|
80 | + $suffix = $width.$height.($crop ? '1' : '0').'.png'; |
|
81 | 81 | } else { |
82 | - $suffix = $width . $height; |
|
82 | + $suffix = $width.$height; |
|
83 | 83 | } |
84 | - return $domainFolder . self::getThumbFilename($url) . $suffix; |
|
84 | + return $domainFolder.self::getThumbFilename($url).$suffix; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | public static function isCacheValid($cacheFile, $domain, $type) |
100 | 100 | { |
101 | 101 | $out = false; |
102 | - $cacheDuration = ConfigManager::get('settings.cache_duration', 3600*24*31); |
|
102 | + $cacheDuration = ConfigManager::get('settings.cache_duration', 3600 * 24 * 31); |
|
103 | 103 | |
104 | 104 | if (is_readable($cacheFile) |
105 | 105 | && ($cacheDuration < 0 || (time() - filemtime($cacheFile)) < $cacheDuration) |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | */ |
121 | 121 | protected static function createDomainThumbCacheFolder($domain, $type) |
122 | 122 | { |
123 | - $domainFolder = self::getCachePath($type) . $domain; |
|
123 | + $domainFolder = self::getCachePath($type).$domain; |
|
124 | 124 | if (!file_exists($domainFolder)) { |
125 | 125 | mkdir($domainFolder, 0775, false); |
126 | - touch($domainFolder . '/' . self::$CLEAN_FILE); |
|
126 | + touch($domainFolder.'/'.self::$CLEAN_FILE); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | protected static function checkCacheType($type) |
151 | 151 | { |
152 | 152 | if ($type != self::TYPE_THUMB && $type != self::TYPE_FINDER) { |
153 | - throw new CacheException('Unknown cache type '. $type); |
|
153 | + throw new CacheException('Unknown cache type '.$type); |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
@@ -160,19 +160,19 @@ discard block |
||
160 | 160 | protected static function rebuildCacheFolders() |
161 | 161 | { |
162 | 162 | $mainFolder = ConfigManager::get('settings.path.cache', 'cache/'); |
163 | - if (! is_dir($mainFolder)) { |
|
163 | + if (!is_dir($mainFolder)) { |
|
164 | 164 | mkdir($mainFolder, 0755); |
165 | 165 | } |
166 | - if (! is_dir($mainFolder.self::TYPE_THUMB)) { |
|
166 | + if (!is_dir($mainFolder.self::TYPE_THUMB)) { |
|
167 | 167 | mkdir($mainFolder.self::TYPE_THUMB, 0755); |
168 | 168 | } |
169 | - if (! is_readable($mainFolder . self::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep')) { |
|
170 | - touch($mainFolder . self::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep'); |
|
169 | + if (!is_readable($mainFolder.self::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep')) { |
|
170 | + touch($mainFolder.self::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep'); |
|
171 | 171 | } |
172 | - if (! is_dir($mainFolder.self::TYPE_FINDER)) { |
|
173 | - mkdir($mainFolder . self::TYPE_FINDER, 0755); |
|
172 | + if (!is_dir($mainFolder.self::TYPE_FINDER)) { |
|
173 | + mkdir($mainFolder.self::TYPE_FINDER, 0755); |
|
174 | 174 | } |
175 | - if (! is_readable($mainFolder . self::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep')) { |
|
175 | + if (!is_readable($mainFolder.self::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep')) { |
|
176 | 176 | touch($mainFolder.self::TYPE_FINDER.DIRECTORY_SEPARATOR.'.gitkeep'); |
177 | 177 | } |
178 | 178 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @var array List of JSON configuration file path. |
24 | 24 | */ |
25 | 25 | public static $configFiles = [ |
26 | - FileUtils::RESOURCES_PATH . 'settings.json', |
|
26 | + FileUtils::RESOURCES_PATH.'settings.json', |
|
27 | 27 | ]; |
28 | 28 | |
29 | 29 | /** |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected static function getConfig($settings, $config) |
104 | 104 | { |
105 | - if (! is_array($settings) || count($settings) == 0) { |
|
105 | + if (!is_array($settings) || count($settings) == 0) { |
|
106 | 106 | return self::$NOT_FOUND; |
107 | 107 | } |
108 | 108 |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | $maxBytes = ConfigManager::get('settings.default.max_img_dl', 16777216); |
60 | 60 | } |
61 | 61 | |
62 | - $cookie = ConfigManager::get('settings.path.cache') . '/cookie.txt'; |
|
62 | + $cookie = ConfigManager::get('settings.path.cache').'/cookie.txt'; |
|
63 | 63 | $userAgent = |
64 | 64 | 'Mozilla/5.0 (X11; Linux x86_64; rv:45.0; WebThumbnailer)' |
65 | 65 | . ' Gecko/20100101 Firefox/45.0'; |
66 | 66 | $acceptLanguage = |
67 | - substr(setlocale(LC_COLLATE, 0), 0, 2) . ',en-US;q=0.7,en;q=0.3'; |
|
67 | + substr(setlocale(LC_COLLATE, 0), 0, 2).',en-US;q=0.7,en;q=0.3'; |
|
68 | 68 | $maxRedirs = 6; |
69 | 69 | |
70 | 70 | $ch = curl_init($url); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | curl_setopt( |
80 | 80 | $ch, |
81 | 81 | CURLOPT_HTTPHEADER, |
82 | - ['Accept-Language: ' . $acceptLanguage] |
|
82 | + ['Accept-Language: '.$acceptLanguage] |
|
83 | 83 | ); |
84 | 84 | curl_setopt($ch, CURLOPT_MAXREDIRS, $maxRedirs); |
85 | 85 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); |
92 | 92 | |
93 | 93 | // Max download size management |
94 | - curl_setopt($ch, CURLOPT_BUFFERSIZE, 1024*16); |
|
94 | + curl_setopt($ch, CURLOPT_BUFFERSIZE, 1024 * 16); |
|
95 | 95 | curl_setopt($ch, CURLOPT_NOPROGRESS, false); |
96 | 96 | curl_setopt( |
97 | 97 | $ch, |
98 | 98 | CURLOPT_PROGRESSFUNCTION, |
99 | - function ($arg0, $arg1, $arg2, $arg3, $arg4 = 0) use ($maxBytes) { |
|
99 | + function($arg0, $arg1, $arg2, $arg3, $arg4 = 0) use ($maxBytes) { |
|
100 | 100 | $downloaded = $arg2; |
101 | 101 | // Non-zero return stops downloading |
102 | 102 | return ($downloaded > $maxBytes) ? 1 : 0; |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | curl_close($ch); |
118 | 118 | |
119 | 119 | if ($response === false) { |
120 | - return [[0 => 'curl_exec() error #'. $errorNo .': ' . $errorStr], false]; |
|
120 | + return [[0 => 'curl_exec() error #'.$errorNo.': '.$errorStr], false]; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | // Formatting output like the fallback method |