@@ -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; |
@@ -19,7 +19,7 @@ |
||
19 | 19 | public static function getDomain(string $url): string |
20 | 20 | { |
21 | 21 | if (!parse_url($url, PHP_URL_SCHEME)) { |
22 | - $url = 'http://' . $url; |
|
22 | + $url = 'http://'.$url; |
|
23 | 23 | } |
24 | 24 | return strtolower(parse_url($url, PHP_URL_HOST) ?: ''); |
25 | 25 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | $error = json_last_error(); |
34 | 34 | $msg = json_last_error_msg(); |
35 | 35 | throw new BadRulesException( |
36 | - 'An error occured while parsing JSON file: error code #' . $error . ': ' . $msg |
|
36 | + 'An error occured while parsing JSON file: error code #'.$error.': '.$msg |
|
37 | 37 | ); |
38 | 38 | } |
39 | 39 |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | $locale = setlocale(LC_COLLATE, '0'); |
67 | - $cookie = ConfigManager::get('settings.path.cache') . '/cookie.txt'; |
|
67 | + $cookie = ConfigManager::get('settings.path.cache').'/cookie.txt'; |
|
68 | 68 | $userAgent = |
69 | 69 | 'Mozilla/5.0 (X11; Linux x86_64; rv:45.0; WebThumbnailer)' |
70 | 70 | . ' Gecko/20100101 Firefox/45.0'; |
71 | 71 | $acceptLanguage = |
72 | - substr($locale ?: 'en', 0, 2) . ',en-US;q=0.7,en;q=0.3'; |
|
72 | + substr($locale ?: 'en', 0, 2).',en-US;q=0.7,en;q=0.3'; |
|
73 | 73 | $maxRedirs = 6; |
74 | 74 | |
75 | 75 | $ch = curl_init($url); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | curl_setopt( |
85 | 85 | $ch, |
86 | 86 | CURLOPT_HTTPHEADER, |
87 | - ['Accept-Language: ' . $acceptLanguage] |
|
87 | + ['Accept-Language: '.$acceptLanguage] |
|
88 | 88 | ); |
89 | 89 | curl_setopt($ch, CURLOPT_MAXREDIRS, $maxRedirs); |
90 | 90 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | curl_setopt( |
102 | 102 | $ch, |
103 | 103 | CURLOPT_PROGRESSFUNCTION, |
104 | - function ($arg0, $arg1, $arg2) use ($maxBytes) { |
|
104 | + function($arg0, $arg1, $arg2) use ($maxBytes) { |
|
105 | 105 | $downloaded = $arg2; |
106 | 106 | // Non-zero return stops downloading |
107 | 107 | return ($downloaded > $maxBytes) ? 1 : 0; |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | curl_close($ch); |
123 | 123 | |
124 | 124 | if (!is_string($response)) { |
125 | - return [[0 => 'curl_exec() error #' . $errorNo . ': ' . $errorStr], false]; |
|
125 | + return [[0 => 'curl_exec() error #'.$errorNo.': '.$errorStr], false]; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | // Formatting output like the fallback method |
@@ -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 ?? false; |
35 | 35 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | static::rebuildCacheFolders(); |
53 | 53 | return static::getCachePath($type, true); |
54 | 54 | } elseif (!$path) { |
55 | - throw new IOException('Cache folders are not writable: ' . $cache); |
|
55 | + throw new IOException('Cache folders are not writable: '.$cache); |
|
56 | 56 | } |
57 | 57 | return $path; |
58 | 58 | } |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | } |
96 | 96 | |
97 | 97 | if ($type === static::TYPE_THUMB) { |
98 | - $suffix = $width . $height . ($crop ? '1' : '0') . '.jpg'; |
|
98 | + $suffix = $width.$height.($crop ? '1' : '0').'.jpg'; |
|
99 | 99 | } else { |
100 | - $suffix = $width . $height; |
|
100 | + $suffix = $width.$height; |
|
101 | 101 | } |
102 | 102 | |
103 | - return $domainFolder . static::getThumbFilename($url) . $suffix; |
|
103 | + return $domainFolder.static::getThumbFilename($url).$suffix; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -149,10 +149,10 @@ discard block |
||
149 | 149 | protected static function createDomainThumbCacheFolder(string $domain, string $type): void |
150 | 150 | { |
151 | 151 | $cachePath = static::getCachePath($type); |
152 | - $domainFolder = $cachePath . $domain; |
|
152 | + $domainFolder = $cachePath.$domain; |
|
153 | 153 | if (!file_exists($domainFolder)) { |
154 | 154 | mkdir($domainFolder, 0775, false); |
155 | - touch($domainFolder . '/' . static::$CLEAN_FILE); |
|
155 | + touch($domainFolder.'/'.static::$CLEAN_FILE); |
|
156 | 156 | } |
157 | 157 | static::createHtaccessFile($cachePath, $type === static::TYPE_THUMB); |
158 | 158 | } |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | protected static function createHtaccessFile(string $path, bool $allowed = false): void |
171 | 171 | { |
172 | 172 | $apacheVersion = ConfigManager::get('settings.apache_version', ''); |
173 | - $htaccessFile = $path . '.htaccess'; |
|
173 | + $htaccessFile = $path.'.htaccess'; |
|
174 | 174 | if (file_exists($htaccessFile)) { |
175 | 175 | return; |
176 | 176 | } |
177 | - $templateFile = file_exists(FileUtils::RESOURCES_PATH . 'htaccess' . $apacheVersion . '_template') |
|
178 | - ? FileUtils::RESOURCES_PATH . 'htaccess' . $apacheVersion . '_template' |
|
179 | - : FileUtils::RESOURCES_PATH . 'htaccess_template'; |
|
177 | + $templateFile = file_exists(FileUtils::RESOURCES_PATH.'htaccess'.$apacheVersion.'_template') |
|
178 | + ? FileUtils::RESOURCES_PATH.'htaccess'.$apacheVersion.'_template' |
|
179 | + : FileUtils::RESOURCES_PATH.'htaccess_template'; |
|
180 | 180 | $template = TemplatePolyfill::get($templateFile); |
181 | 181 | $template->setVar([ |
182 | 182 | 'new_all' => $allowed ? 'granted' : 'denied', |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | protected static function checkCacheType(string $type): bool |
212 | 212 | { |
213 | 213 | if ($type != static::TYPE_THUMB && $type != static::TYPE_FINDER) { |
214 | - throw new CacheException('Unknown cache type ' . $type); |
|
214 | + throw new CacheException('Unknown cache type '.$type); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | return true; |
@@ -226,20 +226,20 @@ discard block |
||
226 | 226 | protected static function rebuildCacheFolders(): void |
227 | 227 | { |
228 | 228 | $mainFolder = ConfigManager::get('settings.path.cache', 'cache/'); |
229 | - if (! is_dir($mainFolder)) { |
|
229 | + if (!is_dir($mainFolder)) { |
|
230 | 230 | mkdir($mainFolder, 0755); |
231 | 231 | } |
232 | - if (! is_dir($mainFolder . static::TYPE_THUMB)) { |
|
233 | - mkdir($mainFolder . static::TYPE_THUMB, 0755); |
|
232 | + if (!is_dir($mainFolder.static::TYPE_THUMB)) { |
|
233 | + mkdir($mainFolder.static::TYPE_THUMB, 0755); |
|
234 | 234 | } |
235 | - if (! is_readable($mainFolder . static::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep')) { |
|
236 | - touch($mainFolder . static::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep'); |
|
235 | + if (!is_readable($mainFolder.static::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep')) { |
|
236 | + touch($mainFolder.static::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep'); |
|
237 | 237 | } |
238 | - if (! is_dir($mainFolder . static::TYPE_FINDER)) { |
|
239 | - mkdir($mainFolder . static::TYPE_FINDER, 0755); |
|
238 | + if (!is_dir($mainFolder.static::TYPE_FINDER)) { |
|
239 | + mkdir($mainFolder.static::TYPE_FINDER, 0755); |
|
240 | 240 | } |
241 | - if (! is_readable($mainFolder . static::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep')) { |
|
242 | - touch($mainFolder . static::TYPE_FINDER . DIRECTORY_SEPARATOR . '.gitkeep'); |
|
241 | + if (!is_readable($mainFolder.static::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep')) { |
|
242 | + touch($mainFolder.static::TYPE_FINDER.DIRECTORY_SEPARATOR.'.gitkeep'); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 |
@@ -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}) |