diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2018-09-07 13:46:30 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2018-09-07 13:46:30 +0200 |
commit | 7083c0a21d27e7e1bf45a9807a76844116d61fb8 (patch) | |
tree | b72b5a0516d9114aeeccd6ecdb055ee240bda66a /src/Wallabag/CoreBundle/Helper | |
parent | 44043ebe82a22470e2514d05efac324035ee809a (diff) | |
parent | 495f83c92539444bff7dfd6cd647b7d65a74f949 (diff) | |
download | wallabag-7083c0a21d27e7e1bf45a9807a76844116d61fb8.tar.gz wallabag-7083c0a21d27e7e1bf45a9807a76844116d61fb8.tar.zst wallabag-7083c0a21d27e7e1bf45a9807a76844116d61fb8.zip |
Merge remote-tracking branch 'origin/master' into 2.4
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper')
7 files changed, 24 insertions, 15 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index fe795d42..3fe31c2c 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php | |||
@@ -85,7 +85,7 @@ class ContentProxy | |||
85 | (new LocaleConstraint()) | 85 | (new LocaleConstraint()) |
86 | ); | 86 | ); |
87 | 87 | ||
88 | if (0 === count($errors)) { | 88 | if (0 === \count($errors)) { |
89 | $entry->setLanguage($value); | 89 | $entry->setLanguage($value); |
90 | 90 | ||
91 | return; | 91 | return; |
@@ -107,7 +107,7 @@ class ContentProxy | |||
107 | (new UrlConstraint()) | 107 | (new UrlConstraint()) |
108 | ); | 108 | ); |
109 | 109 | ||
110 | if (0 === count($errors)) { | 110 | if (0 === \count($errors)) { |
111 | $entry->setPreviewPicture($value); | 111 | $entry->setPreviewPicture($value); |
112 | 112 | ||
113 | return; | 113 | return; |
@@ -212,7 +212,7 @@ class ContentProxy | |||
212 | $entry->setHttpStatus($content['status']); | 212 | $entry->setHttpStatus($content['status']); |
213 | } | 213 | } |
214 | 214 | ||
215 | if (!empty($content['authors']) && is_array($content['authors'])) { | 215 | if (!empty($content['authors']) && \is_array($content['authors'])) { |
216 | $entry->setPublishedBy($content['authors']); | 216 | $entry->setPublishedBy($content['authors']); |
217 | } | 217 | } |
218 | 218 | ||
@@ -233,7 +233,7 @@ class ContentProxy | |||
233 | } | 233 | } |
234 | 234 | ||
235 | // if content is an image, define it as a preview too | 235 | // if content is an image, define it as a preview too |
236 | if (!empty($content['content_type']) && in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) { | 236 | if (!empty($content['content_type']) && \in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) { |
237 | $this->updatePreviewPicture($entry, $content['url']); | 237 | $this->updatePreviewPicture($entry, $content['url']); |
238 | } | 238 | } |
239 | 239 | ||
diff --git a/src/Wallabag/CoreBundle/Helper/CryptoProxy.php b/src/Wallabag/CoreBundle/Helper/CryptoProxy.php index 7d8c9888..67d73915 100644 --- a/src/Wallabag/CoreBundle/Helper/CryptoProxy.php +++ b/src/Wallabag/CoreBundle/Helper/CryptoProxy.php | |||
@@ -81,6 +81,6 @@ class CryptoProxy | |||
81 | */ | 81 | */ |
82 | private function mask($value) | 82 | private function mask($value) |
83 | { | 83 | { |
84 | return strlen($value) > 0 ? $value[0] . '*****' . $value[strlen($value) - 1] : 'Empty value'; | 84 | return \strlen($value) > 0 ? $value[0] . '*****' . $value[\strlen($value) - 1] : 'Empty value'; |
85 | } | 85 | } |
86 | } | 86 | } |
diff --git a/src/Wallabag/CoreBundle/Helper/DownloadImages.php b/src/Wallabag/CoreBundle/Helper/DownloadImages.php index 9c9452dd..cc3dcfce 100644 --- a/src/Wallabag/CoreBundle/Helper/DownloadImages.php +++ b/src/Wallabag/CoreBundle/Helper/DownloadImages.php | |||
@@ -85,6 +85,10 @@ class DownloadImages | |||
85 | */ | 85 | */ |
86 | public function processSingleImage($entryId, $imagePath, $url, $relativePath = null) | 86 | public function processSingleImage($entryId, $imagePath, $url, $relativePath = null) |
87 | { | 87 | { |
88 | if (null === $imagePath) { | ||
89 | return false; | ||
90 | } | ||
91 | |||
88 | if (null === $relativePath) { | 92 | if (null === $relativePath) { |
89 | $relativePath = $this->getRelativePath($entryId); | 93 | $relativePath = $this->getRelativePath($entryId); |
90 | } | 94 | } |
@@ -181,7 +185,7 @@ class DownloadImages | |||
181 | * | 185 | * |
182 | * @return array An array of urls | 186 | * @return array An array of urls |
183 | */ | 187 | */ |
184 | protected function getSrcsetUrls(Crawler $imagesCrawler) | 188 | private function getSrcsetUrls(Crawler $imagesCrawler) |
185 | { | 189 | { |
186 | $urls = []; | 190 | $urls = []; |
187 | $iterator = $imagesCrawler | 191 | $iterator = $imagesCrawler |
@@ -189,9 +193,14 @@ class DownloadImages | |||
189 | while ($iterator->valid()) { | 193 | while ($iterator->valid()) { |
190 | $srcsetAttribute = $iterator->current()->getAttribute('srcset'); | 194 | $srcsetAttribute = $iterator->current()->getAttribute('srcset'); |
191 | if ('' !== $srcsetAttribute) { | 195 | if ('' !== $srcsetAttribute) { |
192 | $srcset = array_map('trim', explode(',', $srcsetAttribute)); | 196 | // Couldn't start with " OR ' OR a white space |
197 | // Could be one or more white space | ||
198 | // Must be one or more digits followed by w OR x | ||
199 | $pattern = "/(?:[^\"'\s]+\s*(?:\d+[wx])+)/"; | ||
200 | preg_match_all($pattern, $srcsetAttribute, $matches); | ||
201 | $srcset = \call_user_func_array('array_merge', $matches); | ||
193 | $srcsetUrls = array_map(function ($src) { | 202 | $srcsetUrls = array_map(function ($src) { |
194 | return explode(' ', $src)[0]; | 203 | return trim(explode(' ', $src, 2)[0]); |
195 | }, $srcset); | 204 | }, $srcset); |
196 | $urls = array_merge($srcsetUrls, $urls); | 205 | $urls = array_merge($srcsetUrls, $urls); |
197 | } | 206 | } |
@@ -299,7 +308,7 @@ class DownloadImages | |||
299 | $this->logger->debug('DownloadImages: Checking extension (alternative)', ['ext' => $ext]); | 308 | $this->logger->debug('DownloadImages: Checking extension (alternative)', ['ext' => $ext]); |
300 | } | 309 | } |
301 | 310 | ||
302 | if (!in_array($ext, ['jpeg', 'jpg', 'gif', 'png'], true)) { | 311 | if (!\in_array($ext, ['jpeg', 'jpg', 'gif', 'png'], true)) { |
303 | $this->logger->error('DownloadImages: Processed image with not allowed extension. Skipping: ' . $imagePath); | 312 | $this->logger->error('DownloadImages: Processed image with not allowed extension. Skipping: ' . $imagePath); |
304 | 313 | ||
305 | return false; | 314 | return false; |
diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 136f66f5..cbf1037b 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php | |||
@@ -45,7 +45,7 @@ class EntriesExport | |||
45 | */ | 45 | */ |
46 | public function setEntries($entries) | 46 | public function setEntries($entries) |
47 | { | 47 | { |
48 | if (!is_array($entries)) { | 48 | if (!\is_array($entries)) { |
49 | $this->language = $entries->getLanguage(); | 49 | $this->language = $entries->getLanguage(); |
50 | $entries = [$entries]; | 50 | $entries = [$entries]; |
51 | } | 51 | } |
@@ -325,7 +325,7 @@ class EntriesExport | |||
325 | { | 325 | { |
326 | $delimiter = ';'; | 326 | $delimiter = ';'; |
327 | $enclosure = '"'; | 327 | $enclosure = '"'; |
328 | $handle = fopen('php://memory', 'rb+'); | 328 | $handle = fopen('php://memory', 'b+r'); |
329 | 329 | ||
330 | fputcsv($handle, ['Title', 'URL', 'Content', 'Tags', 'MIME Type', 'Language', 'Creation date'], $delimiter, $enclosure); | 330 | fputcsv($handle, ['Title', 'URL', 'Content', 'Tags', 'MIME Type', 'Language', 'Creation date'], $delimiter, $enclosure); |
331 | 331 | ||
diff --git a/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php b/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php index 49c1ea41..1c2c5093 100644 --- a/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php +++ b/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php | |||
@@ -31,7 +31,7 @@ class PreparePagerForEntries | |||
31 | $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; | 31 | $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; |
32 | } | 32 | } |
33 | 33 | ||
34 | if (null === $user || !is_object($user)) { | 34 | if (null === $user || !\is_object($user)) { |
35 | return; | 35 | return; |
36 | } | 36 | } |
37 | 37 | ||
diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php index abc84d08..9d1a6345 100644 --- a/src/Wallabag/CoreBundle/Helper/Redirect.php +++ b/src/Wallabag/CoreBundle/Helper/Redirect.php | |||
@@ -31,7 +31,7 @@ class Redirect | |||
31 | { | 31 | { |
32 | $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; | 32 | $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; |
33 | 33 | ||
34 | if (null === $user || !is_object($user)) { | 34 | if (null === $user || !\is_object($user)) { |
35 | return $url; | 35 | return $url; |
36 | } | 36 | } |
37 | 37 | ||
diff --git a/src/Wallabag/CoreBundle/Helper/TagsAssigner.php b/src/Wallabag/CoreBundle/Helper/TagsAssigner.php index 0bfe5c57..e6b4989f 100644 --- a/src/Wallabag/CoreBundle/Helper/TagsAssigner.php +++ b/src/Wallabag/CoreBundle/Helper/TagsAssigner.php | |||
@@ -32,7 +32,7 @@ class TagsAssigner | |||
32 | { | 32 | { |
33 | $tagsEntities = []; | 33 | $tagsEntities = []; |
34 | 34 | ||
35 | if (!is_array($tags)) { | 35 | if (!\is_array($tags)) { |
36 | $tags = explode(',', $tags); | 36 | $tags = explode(',', $tags); |
37 | } | 37 | } |
38 | 38 | ||
@@ -48,7 +48,7 @@ class TagsAssigner | |||
48 | $label = trim(mb_convert_case($label, MB_CASE_LOWER)); | 48 | $label = trim(mb_convert_case($label, MB_CASE_LOWER)); |
49 | 49 | ||
50 | // avoid empty tag | 50 | // avoid empty tag |
51 | if (0 === strlen($label)) { | 51 | if (0 === \strlen($label)) { |
52 | continue; | 52 | continue; |
53 | } | 53 | } |
54 | 54 | ||