@@ -56,19 +56,19 @@ discard block |
||
56 | 56 | protected function replaceOption($thumbnailUrl, $option) |
57 | 57 | { |
58 | 58 | $chosenOption = $this->getOptionValue($option); |
59 | - return str_replace('${'. $option .'}', $chosenOption, $thumbnailUrl); |
|
59 | + return str_replace('${'.$option.'}', $chosenOption, $thumbnailUrl); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | protected function getOptionValue($option) |
63 | 63 | { |
64 | 64 | // If the provided option is not defined in the Finder rules. |
65 | - if (empty($this->finderOptions) || ! in_array($option, array_keys($this->finderOptions))) { |
|
66 | - throw new BadRulesException('Unknown option "'. $option .'" for the finder "'. $this->getName() .'"'); |
|
65 | + if (empty($this->finderOptions) || !in_array($option, array_keys($this->finderOptions))) { |
|
66 | + throw new BadRulesException('Unknown option "'.$option.'" for the finder "'.$this->getName().'"'); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | // User option is defined. |
70 | 70 | // Any defined option must provide a replacement value in rules under the `param` key. |
71 | - if (! empty($this->userOptions[$option]) |
|
71 | + if (!empty($this->userOptions[$option]) |
|
72 | 72 | && is_string($this->userOptions[$option]) |
73 | 73 | && isset($this->finderOptions[$option][$this->userOptions[$option]]['param']) |
74 | 74 | ) { |
@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | } |
78 | 78 | |
79 | 79 | // If no user option has been found, and no default value is provided: error. |
80 | - if (! isset($this->finderOptions[$option]['default'])) { |
|
81 | - $error = 'No default set for option "'. $option .'" for the finder "'. $this->getName() .'"'; |
|
80 | + if (!isset($this->finderOptions[$option]['default'])) { |
|
81 | + $error = 'No default set for option "'.$option.'" for the finder "'.$this->getName().'"'; |
|
82 | 82 | throw new BadRulesException($error); |
83 | 83 | } |
84 | 84 | |
85 | 85 | // Use default option replacement. |
86 | 86 | $default = $this->finderOptions[$option]['default']; |
87 | 87 | if (!isset($this->finderOptions[$option][$default]['param'])) { |
88 | - $error = 'No default parameter set for option "'. $option .'" for the finder "'. $this->getName() .'"'; |
|
88 | + $error = 'No default parameter set for option "'.$option.'" for the finder "'.$this->getName().'"'; |
|
89 | 89 | throw new BadRulesException($error); |
90 | 90 | } |
91 | 91 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | public function isHotlinkAllowed() |
99 | 99 | { |
100 | 100 | if ( |
101 | - ! isset($this->finderOptions['hotlink_allowed']) |
|
101 | + !isset($this->finderOptions['hotlink_allowed']) |
|
102 | 102 | || $this->finderOptions['hotlink_allowed'] === true |
103 | 103 | ) { |
104 | 104 | return true; |
@@ -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 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | $thumbnailUrl = $this->thumbnailUrlFormat; |
78 | 78 | if (preg_match($this->urlRegex, $this->content, $matches) != false) { |
79 | 79 | for ($i = 1; $i < count($matches); $i++) { |
80 | - $thumbnailUrl = str_replace('${'. $i . '}', $matches[$i], $thumbnailUrl); |
|
80 | + $thumbnailUrl = str_replace('${'.$i.'}', $matches[$i], $thumbnailUrl); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Match only options (not ${number}) |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function checkRules($rules) |
98 | 98 | { |
99 | - if (! FinderUtils::checkMandatoryRules($rules, [ |
|
99 | + if (!FinderUtils::checkMandatoryRules($rules, [ |
|
100 | 100 | 'image_regex', |
101 | 101 | 'thumbnail_url' |
102 | 102 | ])) { |
@@ -57,10 +57,10 @@ |
||
57 | 57 | |
58 | 58 | $propertiesKey = ['property', 'name', 'itemprop']; |
59 | 59 | // Try to retrieve OpenGraph image. |
60 | - $ogRegex = '#<meta[^>]+(?:'. implode('|', $propertiesKey) .')=["\']?og:image["\'\s][^>]*content=["\']?(.*?)["\'\s>]#'; |
|
60 | + $ogRegex = '#<meta[^>]+(?:'.implode('|', $propertiesKey).')=["\']?og:image["\'\s][^>]*content=["\']?(.*?)["\'\s>]#'; |
|
61 | 61 | // If the attributes are not in the order property => content (e.g. Github) |
62 | 62 | // New regex to keep this readable... more or less. |
63 | - $ogRegexReverse = '#<meta[^>]+content=["\']?([^"\'\s]+)[^>]+(?:'. implode('|', $propertiesKey) .')=["\']?og:image["\'\s/>]#'; |
|
63 | + $ogRegexReverse = '#<meta[^>]+content=["\']?([^"\'\s]+)[^>]+(?:'.implode('|', $propertiesKey).')=["\']?og:image["\'\s/>]#'; |
|
64 | 64 | |
65 | 65 | if (preg_match($ogRegex, $content, $matches) > 0 |
66 | 66 | || preg_match($ogRegexReverse, $content, $matches) > 0 |
@@ -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 | } |
@@ -39,8 +39,8 @@ |
||
39 | 39 | protected $webAccess; |
40 | 40 | |
41 | 41 | /** |
42 | - * @var string thumbnail_url rule. |
|
43 | - */ |
|
42 | + * @var string thumbnail_url rule. |
|
43 | + */ |
|
44 | 44 | protected $thumbnailUrlFormat; |
45 | 45 | |
46 | 46 | /** |
@@ -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 | ])) { |
@@ -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 | } |