aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper/DownloadImages.php
diff options
context:
space:
mode:
authornicofrand <mail@nicofrand.eu>2019-05-10 23:01:07 +0200
committernicofrand <mail@nicofrand.eu>2019-05-21 20:38:22 +0200
commit423efadefc2459c7b4a2eabc32edaed918e1075d (patch)
treea30cddc2fa567c7b9ca10c515eccd965d8d4ae03 /src/Wallabag/CoreBundle/Helper/DownloadImages.php
parenta2b5d67560341011e791b678422578ab8d6b1e3f (diff)
downloadwallabag-423efadefc2459c7b4a2eabc32edaed918e1075d.tar.gz
wallabag-423efadefc2459c7b4a2eabc32edaed918e1075d.tar.zst
wallabag-423efadefc2459c7b4a2eabc32edaed918e1075d.zip
Set first picture as preview picture
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/DownloadImages.php')
-rw-r--r--src/Wallabag/CoreBundle/Helper/DownloadImages.php29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/DownloadImages.php b/src/Wallabag/CoreBundle/Helper/DownloadImages.php
index 9a7e9828..c1645e45 100644
--- a/src/Wallabag/CoreBundle/Helper/DownloadImages.php
+++ b/src/Wallabag/CoreBundle/Helper/DownloadImages.php
@@ -31,23 +31,36 @@ class DownloadImages
31 } 31 }
32 32
33 /** 33 /**
34 * Process the html and extract image from it, save them to local and return the updated html. 34 * Process the html and extract images URLs from it.
35 * 35 *
36 * @param int $entryId ID of the entry
37 * @param string $html 36 * @param string $html
38 * @param string $url Used as a base path for relative image and folder
39 * 37 *
40 * @return string 38 * @return string[]
41 */ 39 */
42 public function processHtml($entryId, $html, $url) 40 public static function extractImagesUrlsFromHtml($html)
43 { 41 {
44 $crawler = new Crawler($html); 42 $crawler = new Crawler($html);
45 $imagesCrawler = $crawler 43 $imagesCrawler = $crawler
46 ->filterXpath('//img'); 44 ->filterXpath('//img');
47 $imagesUrls = $imagesCrawler 45 $imagesUrls = $imagesCrawler
48 ->extract(['src']); 46 ->extract(['src']);
49 $imagesSrcsetUrls = $this->getSrcsetUrls($imagesCrawler); 47 $imagesSrcsetUrls = self::getSrcsetUrls($imagesCrawler);
50 $imagesUrls = array_unique(array_merge($imagesUrls, $imagesSrcsetUrls)); 48
49 return array_unique(array_merge($imagesUrls, $imagesSrcsetUrls));
50 }
51
52 /**
53 * Process the html and extract image from it, save them to local and return the updated html.
54 *
55 * @param int $entryId ID of the entry
56 * @param string $html
57 * @param string $url Used as a base path for relative image and folder
58 *
59 * @return string
60 */
61 public function processHtml($entryId, $html, $url)
62 {
63 $imagesUrls = self::extractImagesUrlsFromHtml($html);
51 64
52 $relativePath = $this->getRelativePath($entryId); 65 $relativePath = $this->getRelativePath($entryId);
53 66
@@ -199,7 +212,7 @@ class DownloadImages
199 * 212 *
200 * @return array An array of urls 213 * @return array An array of urls
201 */ 214 */
202 private function getSrcsetUrls(Crawler $imagesCrawler) 215 private static function getSrcsetUrls(Crawler $imagesCrawler)
203 { 216 {
204 $urls = []; 217 $urls = [];
205 $iterator = $imagesCrawler 218 $iterator = $imagesCrawler