@@ -54,7 +54,7 @@ |
||
54 | 54 | if (preg_match($this->urlRegex, $this->url, $matches) !== 0) { |
55 | 55 | $total = count($matches); |
56 | 56 | for ($i = 1; $i < $total; $i++) { |
57 | - $this->thumbnailUrl = str_replace('${' . $i . '}', $matches[$i], $this->thumbnailUrl); |
|
57 | + $this->thumbnailUrl = str_replace('${'.$i.'}', $matches[$i], $this->thumbnailUrl); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Match only options (not ${number}) |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | $chosenOption = $this->getOptionValue($option); |
48 | 48 | |
49 | - return str_replace('${' . $option . '}', $chosenOption, $thumbnailUrl); |
|
49 | + return str_replace('${'.$option.'}', $chosenOption, $thumbnailUrl); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -59,14 +59,14 @@ discard block |
||
59 | 59 | protected function getOptionValue(string $option) |
60 | 60 | { |
61 | 61 | // If the provided option is not defined in the Finder rules. |
62 | - if (empty($this->finderOptions) || ! in_array($option, array_keys($this->finderOptions))) { |
|
63 | - throw new BadRulesException('Unknown option "' . $option . '" for the finder "' . $this->getName() . '"'); |
|
62 | + if (empty($this->finderOptions) || !in_array($option, array_keys($this->finderOptions))) { |
|
63 | + throw new BadRulesException('Unknown option "'.$option.'" for the finder "'.$this->getName().'"'); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // User option is defined. |
67 | 67 | // Any defined option must provide a replacement value in rules under the `param` key. |
68 | 68 | if ( |
69 | - ! empty($this->userOptions[$option]) |
|
69 | + !empty($this->userOptions[$option]) |
|
70 | 70 | && is_string($this->userOptions[$option]) |
71 | 71 | && isset($this->finderOptions[$option][$this->userOptions[$option]]['param']) |
72 | 72 | ) { |
@@ -74,15 +74,15 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | // If no user option has been found, and no default value is provided: error. |
77 | - if (! isset($this->finderOptions[$option]['default'])) { |
|
78 | - $error = 'No default set for option "' . $option . '" for the finder "' . $this->getName() . '"'; |
|
77 | + if (!isset($this->finderOptions[$option]['default'])) { |
|
78 | + $error = 'No default set for option "'.$option.'" for the finder "'.$this->getName().'"'; |
|
79 | 79 | throw new BadRulesException($error); |
80 | 80 | } |
81 | 81 | |
82 | 82 | // Use default option replacement. |
83 | 83 | $default = $this->finderOptions[$option]['default']; |
84 | 84 | if (!isset($this->finderOptions[$option][$default]['param'])) { |
85 | - $error = 'No default parameter set for option "' . $option . '" for the finder "' . $this->getName() . '"'; |
|
85 | + $error = 'No default parameter set for option "'.$option.'" for the finder "'.$this->getName().'"'; |
|
86 | 86 | throw new BadRulesException($error); |
87 | 87 | } |
88 | 88 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | /** @inheritdoc */ |
93 | 93 | public function isHotlinkAllowed(): bool |
94 | 94 | { |
95 | - if (! isset($this->finderOptions['hotlink_allowed']) || $this->finderOptions['hotlink_allowed'] === true) { |
|
95 | + if (!isset($this->finderOptions['hotlink_allowed']) || $this->finderOptions['hotlink_allowed'] === true) { |
|
96 | 96 | return true; |
97 | 97 | } |
98 | 98 |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | try { |
35 | 35 | list($domain, $finder, $rules, $options) = static::getThumbnailMeta($domain, $url); |
36 | 36 | |
37 | - $className = '\\WebThumbnailer\\Finder\\' . $finder . 'Finder'; |
|
37 | + $className = '\\WebThumbnailer\\Finder\\'.$finder.'Finder'; |
|
38 | 38 | if (!class_exists($className)) { |
39 | 39 | throw new UnsupportedDomainException(); |
40 | 40 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $jsonFiles = ConfigManager::get('settings.rules_filename', ['rules.json']); |
66 | 66 | $allRules = []; |
67 | 67 | foreach ($jsonFiles as $file) { |
68 | - $allRules = array_merge($allRules, DataUtils::loadJson(FileUtils::RESOURCES_PATH . $file)); |
|
68 | + $allRules = array_merge($allRules, DataUtils::loadJson(FileUtils::RESOURCES_PATH.$file)); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $domain = null; |
@@ -28,8 +28,8 @@ |
||
28 | 28 | |
29 | 29 | $size = $this->getOptionValue('size'); |
30 | 30 | // One size is actually no suffix... |
31 | - $size = ! empty($size) ? '_' . $size : ''; |
|
32 | - $thumb = preg_replace('#(.*)_\w(\.\w+)$#i', '$1' . $size . '$2', $thumb); |
|
31 | + $size = !empty($size) ? '_'.$size : ''; |
|
32 | + $thumb = preg_replace('#(.*)_\w(\.\w+)$#i', '$1'.$size.'$2', $thumb); |
|
33 | 33 | |
34 | 34 | return $thumb; |
35 | 35 | } |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | return $this->url; |
61 | 61 | } |
62 | 62 | |
63 | - if (empty($thumbnail) && ! empty($headers) && strpos($headers[0], '200') === false) { |
|
63 | + if (empty($thumbnail) && !empty($headers) && strpos($headers[0], '200') === false) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 | |
67 | 67 | // With curl, the thumb is extracted during the download |
68 | - if ($this->webAccess instanceof WebAccessCUrl && ! empty($thumbnail)) { |
|
68 | + if ($this->webAccess instanceof WebAccessCUrl && !empty($thumbnail)) { |
|
69 | 69 | return $thumbnail; |
70 | 70 | } |
71 | 71 | |
72 | - return ! empty($content) ? static::extractMetaTag($content) : false; |
|
72 | + return !empty($content) ? static::extractMetaTag($content) : false; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return int|false length of $data or false if we need to stop the download |
101 | 101 | */ |
102 | - return function (&$ch, $data) use ($url, &$content, &$thumbnail, &$isRedirected) { |
|
102 | + return function(&$ch, $data) use ($url, &$content, &$thumbnail, &$isRedirected) { |
|
103 | 103 | $content .= $data; |
104 | 104 | $responseCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); |
105 | 105 | if (!empty($responseCode) && in_array($responseCode, [301, 302])) { |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | } |
112 | 112 | // After a redirection, the content type will keep the previous request value |
113 | 113 | // until it finds the next content-type header. |
114 | - if (! $isRedirected || strpos(strtolower($data), 'content-type') !== false) { |
|
114 | + if (!$isRedirected || strpos(strtolower($data), 'content-type') !== false) { |
|
115 | 115 | $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); |
116 | 116 | } |
117 | 117 | // we look for image, and ignore application/octet-stream, |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | $propertiesKey = ['property', 'name', 'itemprop']; |
156 | 156 | $properties = implode('|', $propertiesKey); |
157 | 157 | // Try to retrieve OpenGraph image. |
158 | - $ogRegex = '#<meta[^>]+(?:' . $properties . ')=["\']?og:image["\'\s][^>]*content=["\']?(.*?)["\'\s>]#'; |
|
158 | + $ogRegex = '#<meta[^>]+(?:'.$properties.')=["\']?og:image["\'\s][^>]*content=["\']?(.*?)["\'\s>]#'; |
|
159 | 159 | // If the attributes are not in the order property => content (e.g. Github) |
160 | 160 | // New regex to keep this readable... more or less. |
161 | - $ogRegexReverse = '#<meta[^>]+content=["\']?([^"\'\s]+)[^>]+(?:' . $properties . ')=["\']?og:image["\'\s/>]#'; |
|
161 | + $ogRegexReverse = '#<meta[^>]+content=["\']?([^"\'\s]+)[^>]+(?:'.$properties.')=["\']?og:image["\'\s/>]#'; |
|
162 | 162 | |
163 | 163 | if ( |
164 | 164 | preg_match($ogRegex, $content, $matches) > 0 |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | // With curl, the thumb is extracted during the download |
86 | - if ($this->webAccess instanceof WebAccessCUrl && ! empty($thumbnail)) { |
|
86 | + if ($this->webAccess instanceof WebAccessCUrl && !empty($thumbnail)) { |
|
87 | 87 | return $thumbnail; |
88 | 88 | } |
89 | 89 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @return int|false length of $data or false if we need to stop the download |
118 | 118 | */ |
119 | - return function (&$ch, $data) use (&$content, &$thumbnail, &$isRedirected) { |
|
119 | + return function(&$ch, $data) use (&$content, &$thumbnail, &$isRedirected) { |
|
120 | 120 | $content .= $data; |
121 | 121 | $responseCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); |
122 | 122 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | } |
130 | 130 | // After a redirection, the content type will keep the previous request value |
131 | 131 | // until it finds the next content-type header. |
132 | - if (! $isRedirected || strpos(strtolower($data), 'content-type') !== false) { |
|
132 | + if (!$isRedirected || strpos(strtolower($data), 'content-type') !== false) { |
|
133 | 133 | $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); |
134 | 134 | } |
135 | 135 | if (!empty($contentType) && strpos($contentType, 'text/html') === false) { |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | if (preg_match($this->urlRegex, $content, $matches) !== 0) { |
161 | 161 | $total = count($matches); |
162 | 162 | for ($i = 1; $i < $total; $i++) { |
163 | - $thumbnailUrl = str_replace('${' . $i . '}', $matches[$i], $thumbnailUrl); |
|
163 | + $thumbnailUrl = str_replace('${'.$i.'}', $matches[$i], $thumbnailUrl); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | // Match only options (not ${number}) |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | $maxBytes = ConfigManager::get('settings.default.max_img_dl', 16777216); |
64 | 64 | } |
65 | 65 | |
66 | - $cookie = ConfigManager::get('settings.path.cache') . '/cookie.txt'; |
|
66 | + $cookie = ConfigManager::get('settings.path.cache').'/cookie.txt'; |
|
67 | 67 | $userAgent = |
68 | 68 | 'Mozilla/5.0 (X11; Linux x86_64; rv:45.0; WebThumbnailer)' |
69 | 69 | . ' Gecko/20100101 Firefox/45.0'; |
70 | 70 | $acceptLanguage = |
71 | - substr(setlocale(LC_COLLATE, 0), 0, 2) . ',en-US;q=0.7,en;q=0.3'; |
|
71 | + substr(setlocale(LC_COLLATE, 0), 0, 2).',en-US;q=0.7,en;q=0.3'; |
|
72 | 72 | $maxRedirs = 6; |
73 | 73 | |
74 | 74 | $ch = curl_init($url); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | curl_setopt( |
84 | 84 | $ch, |
85 | 85 | CURLOPT_HTTPHEADER, |
86 | - ['Accept-Language: ' . $acceptLanguage] |
|
86 | + ['Accept-Language: '.$acceptLanguage] |
|
87 | 87 | ); |
88 | 88 | curl_setopt($ch, CURLOPT_MAXREDIRS, $maxRedirs); |
89 | 89 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | curl_setopt( |
101 | 101 | $ch, |
102 | 102 | CURLOPT_PROGRESSFUNCTION, |
103 | - function ($arg0, $arg1, $arg2) use ($maxBytes) { |
|
103 | + function($arg0, $arg1, $arg2) use ($maxBytes) { |
|
104 | 104 | $downloaded = $arg2; |
105 | 105 | // Non-zero return stops downloading |
106 | 106 | return ($downloaded > $maxBytes) ? 1 : 0; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | curl_close($ch); |
122 | 122 | |
123 | 123 | if (!is_string($response)) { |
124 | - return [[0 => 'curl_exec() error #' . $errorNo . ': ' . $errorStr], false]; |
|
124 | + return [[0 => 'curl_exec() error #'.$errorNo.': '.$errorStr], false]; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | // Formatting output like the fallback method |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | static::rebuildCacheFolders(); |
52 | 52 | return static::getCachePath($type, true); |
53 | 53 | } elseif (!$path) { |
54 | - throw new IOException('Cache folders are not writable: ' . $cache); |
|
54 | + throw new IOException('Cache folders are not writable: '.$cache); |
|
55 | 55 | } |
56 | 56 | return $path; |
57 | 57 | } |
@@ -94,12 +94,12 @@ discard block |
||
94 | 94 | } |
95 | 95 | |
96 | 96 | if ($type === static::TYPE_THUMB) { |
97 | - $suffix = $width . $height . ($crop ? '1' : '0') . '.jpg'; |
|
97 | + $suffix = $width.$height.($crop ? '1' : '0').'.jpg'; |
|
98 | 98 | } else { |
99 | - $suffix = $width . $height; |
|
99 | + $suffix = $width.$height; |
|
100 | 100 | } |
101 | 101 | |
102 | - return $domainFolder . static::getThumbFilename($url) . $suffix; |
|
102 | + return $domainFolder.static::getThumbFilename($url).$suffix; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | protected static function createDomainThumbCacheFolder(string $domain, string $type): void |
149 | 149 | { |
150 | 150 | $cachePath = static::getCachePath($type); |
151 | - $domainFolder = $cachePath . $domain; |
|
151 | + $domainFolder = $cachePath.$domain; |
|
152 | 152 | if (!file_exists($domainFolder)) { |
153 | 153 | mkdir($domainFolder, 0775, false); |
154 | - touch($domainFolder . '/' . static::$CLEAN_FILE); |
|
154 | + touch($domainFolder.'/'.static::$CLEAN_FILE); |
|
155 | 155 | } |
156 | 156 | static::createHtaccessFile($cachePath, $type === static::TYPE_THUMB); |
157 | 157 | } |
@@ -169,13 +169,13 @@ discard block |
||
169 | 169 | protected static function createHtaccessFile(string $path, bool $allowed = false): void |
170 | 170 | { |
171 | 171 | $apacheVersion = ConfigManager::get('settings.apache_version', ''); |
172 | - $htaccessFile = $path . '.htaccess'; |
|
172 | + $htaccessFile = $path.'.htaccess'; |
|
173 | 173 | if (file_exists($htaccessFile)) { |
174 | 174 | return; |
175 | 175 | } |
176 | - $templateFile = file_exists(FileUtils::RESOURCES_PATH . 'htaccess' . $apacheVersion . '_template') |
|
177 | - ? FileUtils::RESOURCES_PATH . 'htaccess' . $apacheVersion . '_template' |
|
178 | - : FileUtils::RESOURCES_PATH . 'htaccess_template'; |
|
176 | + $templateFile = file_exists(FileUtils::RESOURCES_PATH.'htaccess'.$apacheVersion.'_template') |
|
177 | + ? FileUtils::RESOURCES_PATH.'htaccess'.$apacheVersion.'_template' |
|
178 | + : FileUtils::RESOURCES_PATH.'htaccess_template'; |
|
179 | 179 | $template = new \Text_Template($templateFile); |
180 | 180 | $template->setVar([ |
181 | 181 | 'new_all' => $allowed ? 'granted' : 'denied', |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | protected static function checkCacheType(string $type): bool |
211 | 211 | { |
212 | 212 | if ($type != static::TYPE_THUMB && $type != static::TYPE_FINDER) { |
213 | - throw new CacheException('Unknown cache type ' . $type); |
|
213 | + throw new CacheException('Unknown cache type '.$type); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | return true; |
@@ -225,20 +225,20 @@ discard block |
||
225 | 225 | protected static function rebuildCacheFolders(): void |
226 | 226 | { |
227 | 227 | $mainFolder = ConfigManager::get('settings.path.cache', 'cache/'); |
228 | - if (! is_dir($mainFolder)) { |
|
228 | + if (!is_dir($mainFolder)) { |
|
229 | 229 | mkdir($mainFolder, 0755); |
230 | 230 | } |
231 | - if (! is_dir($mainFolder . static::TYPE_THUMB)) { |
|
232 | - mkdir($mainFolder . static::TYPE_THUMB, 0755); |
|
231 | + if (!is_dir($mainFolder.static::TYPE_THUMB)) { |
|
232 | + mkdir($mainFolder.static::TYPE_THUMB, 0755); |
|
233 | 233 | } |
234 | - if (! is_readable($mainFolder . static::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep')) { |
|
235 | - touch($mainFolder . static::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep'); |
|
234 | + if (!is_readable($mainFolder.static::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep')) { |
|
235 | + touch($mainFolder.static::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep'); |
|
236 | 236 | } |
237 | - if (! is_dir($mainFolder . static::TYPE_FINDER)) { |
|
238 | - mkdir($mainFolder . static::TYPE_FINDER, 0755); |
|
237 | + if (!is_dir($mainFolder.static::TYPE_FINDER)) { |
|
238 | + mkdir($mainFolder.static::TYPE_FINDER, 0755); |
|
239 | 239 | } |
240 | - if (! is_readable($mainFolder . static::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep')) { |
|
241 | - touch($mainFolder . static::TYPE_FINDER . DIRECTORY_SEPARATOR . '.gitkeep'); |
|
240 | + if (!is_readable($mainFolder.static::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep')) { |
|
241 | + touch($mainFolder.static::TYPE_FINDER.DIRECTORY_SEPARATOR.'.gitkeep'); |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 |