@@ -32,8 +32,8 @@ |
||
| 32 | 32 | protected $webAccess; |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | - * @var string thumbnail_url rule. |
|
| 36 | - */ |
|
| 35 | + * @var string thumbnail_url rule. |
|
| 36 | + */ |
|
| 37 | 37 | protected $thumbnailUrlFormat; |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -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 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | $thumbnailUrl = $this->thumbnailUrlFormat; |
| 154 | 154 | if (preg_match($this->urlRegex, $content, $matches) != false) { |
| 155 | 155 | for ($i = 1; $i < count($matches); $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 | ])) { |
@@ -33,11 +33,11 @@ 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 | } |
| 40 | - } catch(Exception\UnsupportedDomainException $e) { |
|
| 40 | + } catch (Exception\UnsupportedDomainException $e) { |
|
| 41 | 41 | $className = '\\WebThumbnailer\\Finder\\DefaultFinder'; |
| 42 | 42 | $rules = []; |
| 43 | 43 | $options = []; |
@@ -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 | foreach ($allRules as $value) { |
@@ -81,16 +81,16 @@ discard block |
||
| 81 | 81 | continue; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if(!empty($value['url_exclude'])) { |
|
| 84 | + if (!empty($value['url_exclude'])) { |
|
| 85 | 85 | preg_match(FinderUtils::buildRegex($value['url_exclude'], 'i'), $url, $match); |
| 86 | - if(!empty($match)) { |
|
| 86 | + if (!empty($match)) { |
|
| 87 | 87 | continue; |
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if(!empty($value['url_require'])) { |
|
| 91 | + if (!empty($value['url_require'])) { |
|
| 92 | 92 | preg_match(FinderUtils::buildRegex($value['url_require'], 'i'), $url, $match); |
| 93 | - if(empty($match)) { |
|
| 93 | + if (empty($match)) { |
|
| 94 | 94 | continue; |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -103,7 +103,7 @@ |
||
| 103 | 103 | */ |
| 104 | 104 | public function checkRules($rules) |
| 105 | 105 | { |
| 106 | - if (! FinderUtils::checkMandatoryRules($rules, [ |
|
| 106 | + if (!FinderUtils::checkMandatoryRules($rules, [ |
|
| 107 | 107 | 'image_xpath', |
| 108 | 108 | 'thumbnail_url' |
| 109 | 109 | ])) { |
@@ -32,8 +32,8 @@ |
||
| 32 | 32 | protected $webAccess; |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | - * @var string thumbnail_url rule. |
|
| 36 | - */ |
|
| 35 | + * @var string thumbnail_url rule. |
|
| 36 | + */ |
|
| 37 | 37 | protected $thumbnailUrlFormat; |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -30,8 +30,8 @@ |
||
| 30 | 30 | |
| 31 | 31 | $size = $this->getOptionValue('size'); |
| 32 | 32 | // One size is actually no suffix... |
| 33 | - $size = ! empty($size) ? '_'. $size : ''; |
|
| 34 | - $thumb = preg_replace('#(.*)_\w(\.\w+)$#i', '$1'. $size .'$2', $thumb); |
|
| 33 | + $size = !empty($size) ? '_'.$size : ''; |
|
| 34 | + $thumb = preg_replace('#(.*)_\w(\.\w+)$#i', '$1'.$size.'$2', $thumb); |
|
| 35 | 35 | return $thumb; |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | $this->thumbnailUrl = $this->thumbnailUrlFormat; |
| 58 | 58 | if (preg_match($this->urlRegex, $this->url, $matches) != false) { |
| 59 | 59 | for ($i = 1; $i < count($matches); $i++) { |
| 60 | - $this->thumbnailUrl = str_replace('${'. $i . '}', $matches[$i], $this->thumbnailUrl); |
|
| 60 | + $this->thumbnailUrl = str_replace('${'.$i.'}', $matches[$i], $this->thumbnailUrl); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // Match only options (not ${number}) |
@@ -104,7 +104,7 @@ |
||
| 104 | 104 | try { |
| 105 | 105 | $downloader = new Thumbnailer($url, $options, $_SERVER); |
| 106 | 106 | return $downloader->getThumbnail(); |
| 107 | - } catch(MissingRequirementException $e) { |
|
| 107 | + } catch (MissingRequirementException $e) { |
|
| 108 | 108 | throw $e; |
| 109 | 109 | } catch (WebThumbnailerException $e) { |
| 110 | 110 | if (isset($options[self::DEBUG]) && $options[self::DEBUG] === true) { |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | if (empty($thumburl)) { |
| 107 | - $error = 'No thumbnail could be found using '. $this->finder->getName() .' finder: '. $this->url; |
|
| 107 | + $error = 'No thumbnail could be found using '.$this->finder->getName().' finder: '.$this->url; |
|
| 108 | 108 | throw new ThumbnailNotFoundException($error); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | protected function thumbnailStrictHotlink($thumburl) |
| 136 | 136 | { |
| 137 | - if (! $this->finder->isHotlinkAllowed()) { |
|
| 137 | + if (!$this->finder->isHotlinkAllowed()) { |
|
| 138 | 138 | throw new ThumbnailNotFoundException('Hotlink is not supported for this URL.'); |
| 139 | 139 | } |
| 140 | 140 | return $thumburl; |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | protected function thumbnailHotlink($thumburl) |
| 151 | 151 | { |
| 152 | - if (! $this->finder->isHotlinkAllowed()) { |
|
| 152 | + if (!$this->finder->isHotlinkAllowed()) { |
|
| 153 | 153 | return $this->thumbnailDownload($thumburl); |
| 154 | 154 | } |
| 155 | 155 | return $thumburl; |
@@ -199,13 +199,13 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | if (strpos($headers[0], '200') === false) { |
| 201 | 201 | throw new DownloadException( |
| 202 | - 'Unreachable thumbnail URL. HTTP '. $headers[0] .'.'. PHP_EOL . |
|
| 203 | - ' - thumbnail URL: '. $thumburl |
|
| 202 | + 'Unreachable thumbnail URL. HTTP '.$headers[0].'.'.PHP_EOL. |
|
| 203 | + ' - thumbnail URL: '.$thumburl |
|
| 204 | 204 | ); |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | if (empty($data)) { |
| 208 | - throw new DownloadException('Couldn\'t download the thumbnail at '. $thumburl); |
|
| 208 | + throw new DownloadException('Couldn\'t download the thumbnail at '.$thumburl); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | // Resize and save it locally. |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | $this->options[WebThumbnailer::CROP] |
| 218 | 218 | ); |
| 219 | 219 | |
| 220 | - if (! is_file($thumbPath)) { |
|
| 220 | + if (!is_file($thumbPath)) { |
|
| 221 | 221 | throw new ImageConvertException('Thumbnail was not generated.'); |
| 222 | 222 | } |
| 223 | 223 | |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | protected function setSizeOptions($options) { |
| 295 | 295 | // Width |
| 296 | 296 | $width = 0; |
| 297 | - if (! empty($options[WebThumbnailer::MAX_WIDTH])) { |
|
| 297 | + if (!empty($options[WebThumbnailer::MAX_WIDTH])) { |
|
| 298 | 298 | if (SizeUtils::isMetaSize($options[WebThumbnailer::MAX_WIDTH])) { |
| 299 | 299 | $width = SizeUtils::getMetaSize($options[WebThumbnailer::MAX_WIDTH]); |
| 300 | 300 | } else if (is_int($options[WebThumbnailer::MAX_WIDTH]) |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | if (count(array_intersect($incompatibleFlags, $options)) > 1) { |
| 345 | 345 | $error = 'Only one of these flags can be set between: '; |
| 346 | 346 | foreach ($incompatibleFlags as $flag) { |
| 347 | - $error .= $flag .' '; |
|
| 347 | + $error .= $flag.' '; |
|
| 348 | 348 | } |
| 349 | 349 | throw new BadRulesException($error); |
| 350 | 350 | } |
@@ -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 | /** |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | protected static function initialize() |
| 48 | 48 | { |
| 49 | 49 | self::$loadedConfig = []; |
| 50 | - foreach(self::$configFiles as $configFile) { |
|
| 50 | + foreach (self::$configFiles as $configFile) { |
|
| 51 | 51 | self::$loadedConfig = array_replace_recursive(self::$loadedConfig, DataUtils::loadJson($configFile)); |
| 52 | 52 | } |
| 53 | 53 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | protected static function getConfig($settings, $config) |
| 102 | 102 | { |
| 103 | - if (! is_array($settings) || count($settings) == 0) { |
|
| 103 | + if (!is_array($settings) || count($settings) == 0) { |
|
| 104 | 104 | return self::$NOT_FOUND; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -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); |
@@ -73,26 +73,26 @@ discard block |
||
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // General cURL settings |
| 76 | - curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
|
| 77 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
| 78 | - curl_setopt($ch, CURLOPT_HEADER, true); |
|
| 76 | + curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
|
| 77 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
| 78 | + curl_setopt($ch, CURLOPT_HEADER, true); |
|
| 79 | 79 | curl_setopt( |
| 80 | 80 | $ch, |
| 81 | 81 | CURLOPT_HTTPHEADER, |
| 82 | - ['Accept-Language: ' . $acceptLanguage] |
|
| 82 | + ['Accept-Language: '.$acceptLanguage] |
|
| 83 | 83 | ); |
| 84 | - curl_setopt($ch, CURLOPT_MAXREDIRS, $maxRedirs); |
|
| 85 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 86 | - curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 87 | - curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); |
|
| 84 | + curl_setopt($ch, CURLOPT_MAXREDIRS, $maxRedirs); |
|
| 85 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 86 | + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 87 | + curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); |
|
| 88 | 88 | |
| 89 | 89 | curl_setopt($ch, CURLOPT_COOKIESESSION, true); |
| 90 | - curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); |
|
| 91 | - curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); |
|
| 90 | + curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); |
|
| 91 | + curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); |
|
| 92 | 92 | |
| 93 | 93 | // Max download size management |
| 94 | - curl_setopt($ch, CURLOPT_BUFFERSIZE, 1024*16); |
|
| 95 | - curl_setopt($ch, CURLOPT_NOPROGRESS, false); |
|
| 94 | + curl_setopt($ch, CURLOPT_BUFFERSIZE, 1024 * 16); |
|
| 95 | + curl_setopt($ch, CURLOPT_NOPROGRESS, false); |
|
| 96 | 96 | curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, |
| 97 | 97 | function($arg0, $arg1, $arg2, $arg3, $arg4 = 0) use ($maxBytes) |
| 98 | 98 | { |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | curl_close($ch); |
| 111 | 111 | |
| 112 | 112 | if ($response === false) { |
| 113 | - return [[0 => 'curl_exec() error #'. $errorNo .': ' . $errorStr], false]; |
|
| 113 | + return [[0 => 'curl_exec() error #'.$errorNo.': '.$errorStr], false]; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Formatting output like the fallback method |