aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php2
-rw-r--r--src/Wallabag/ApiBundle/Controller/UserRestController.php2
-rw-r--r--src/Wallabag/ApiBundle/Controller/WallabagRestController.php4
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php2
-rw-r--r--src/Wallabag/CoreBundle/Helper/DownloadImages.php31
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php4
6 files changed, 22 insertions, 23 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index aaacdcdc..9f933adb 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -564,7 +564,7 @@ class EntryRestController extends WallabagRestController
564 } 564 }
565 565
566 // if refreshing entry failed, don't save it 566 // if refreshing entry failed, don't save it
567 if ($this->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) { 567 if ($this->container->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) {
568 return new JsonResponse([], 304); 568 return new JsonResponse([], 304);
569 } 569 }
570 570
diff --git a/src/Wallabag/ApiBundle/Controller/UserRestController.php b/src/Wallabag/ApiBundle/Controller/UserRestController.php
index 3a4dafcd..1b10a076 100644
--- a/src/Wallabag/ApiBundle/Controller/UserRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/UserRestController.php
@@ -45,7 +45,7 @@ class UserRestController extends WallabagRestController
45 */ 45 */
46 public function putUserAction(Request $request) 46 public function putUserAction(Request $request)
47 { 47 {
48 if (!$this->getParameter('fosuser_registration') || !$this->get('craue_config')->get('api_user_registration')) { 48 if (!$this->container->getParameter('fosuser_registration') || !$this->get('craue_config')->get('api_user_registration')) {
49 $json = $this->get('jms_serializer')->serialize(['error' => "Server doesn't allow registrations"], 'json'); 49 $json = $this->get('jms_serializer')->serialize(['error' => "Server doesn't allow registrations"], 'json');
50 50
51 return (new JsonResponse()) 51 return (new JsonResponse())
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
index f18b0910..44fd9683 100644
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
@@ -2,13 +2,13 @@
2 2
3namespace Wallabag\ApiBundle\Controller; 3namespace Wallabag\ApiBundle\Controller;
4 4
5use FOS\RestBundle\Controller\FOSRestController; 5use FOS\RestBundle\Controller\AbstractFOSRestController;
6use JMS\Serializer\SerializationContext; 6use JMS\Serializer\SerializationContext;
7use Nelmio\ApiDocBundle\Annotation\ApiDoc; 7use Nelmio\ApiDocBundle\Annotation\ApiDoc;
8use Symfony\Component\HttpFoundation\JsonResponse; 8use Symfony\Component\HttpFoundation\JsonResponse;
9use Symfony\Component\Security\Core\Exception\AccessDeniedException; 9use Symfony\Component\Security\Core\Exception\AccessDeniedException;
10 10
11class WallabagRestController extends FOSRestController 11class WallabagRestController extends AbstractFOSRestController
12{ 12{
13 /** 13 /**
14 * Retrieve version number. 14 * Retrieve version number.
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 4a9cb8d8..4d5e6fc9 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -794,7 +794,7 @@ class Entry
794 } 794 }
795 795
796 /** 796 /**
797 * @return string 797 * @return string|null
798 */ 798 */
799 public function getUid() 799 public function getUid()
800 { 800 {
diff --git a/src/Wallabag/CoreBundle/Helper/DownloadImages.php b/src/Wallabag/CoreBundle/Helper/DownloadImages.php
index 7a39a2e4..1d361d6d 100644
--- a/src/Wallabag/CoreBundle/Helper/DownloadImages.php
+++ b/src/Wallabag/CoreBundle/Helper/DownloadImages.php
@@ -2,6 +2,8 @@
2 2
3namespace Wallabag\CoreBundle\Helper; 3namespace Wallabag\CoreBundle\Helper;
4 4
5use GuzzleHttp\Psr7\Uri;
6use GuzzleHttp\Psr7\UriResolver;
5use Http\Client\Common\HttpMethodsClient; 7use Http\Client\Common\HttpMethodsClient;
6use Http\Client\Common\Plugin\ErrorPlugin; 8use Http\Client\Common\Plugin\ErrorPlugin;
7use Http\Client\Common\PluginClient; 9use Http\Client\Common\PluginClient;
@@ -45,10 +47,8 @@ class DownloadImages
45 public static function extractImagesUrlsFromHtml($html) 47 public static function extractImagesUrlsFromHtml($html)
46 { 48 {
47 $crawler = new Crawler($html); 49 $crawler = new Crawler($html);
48 $imagesCrawler = $crawler 50 $imagesCrawler = $crawler->filterXpath('//img');
49 ->filterXpath('//img'); 51 $imagesUrls = $imagesCrawler->extract(['src']);
50 $imagesUrls = $imagesCrawler
51 ->extract(['src']);
52 $imagesSrcsetUrls = self::getSrcsetUrls($imagesCrawler); 52 $imagesSrcsetUrls = self::getSrcsetUrls($imagesCrawler);
53 53
54 return array_unique(array_merge($imagesUrls, $imagesSrcsetUrls)); 54 return array_unique(array_merge($imagesUrls, $imagesSrcsetUrls));
@@ -220,22 +220,25 @@ class DownloadImages
220 private static function getSrcsetUrls(Crawler $imagesCrawler) 220 private static function getSrcsetUrls(Crawler $imagesCrawler)
221 { 221 {
222 $urls = []; 222 $urls = [];
223 $iterator = $imagesCrawler 223 $iterator = $imagesCrawler->getIterator();
224 ->getIterator(); 224
225 while ($iterator->valid()) { 225 while ($iterator->valid()) {
226 $srcsetAttribute = $iterator->current()->getAttribute('srcset'); 226 $srcsetAttribute = $iterator->current()->getAttribute('srcset');
227
227 if ('' !== $srcsetAttribute) { 228 if ('' !== $srcsetAttribute) {
228 // Couldn't start with " OR ' OR a white space 229 // Couldn't start with " OR ' OR a white space
229 // Could be one or more white space 230 // Could be one or more white space
230 // Must be one or more digits followed by w OR x 231 // Must be one or more digits followed by w OR x
231 $pattern = "/(?:[^\"'\s]+\s*(?:\d+[wx])+)/"; 232 $pattern = "/(?:[^\"'\s]+\s*(?:\d+[wx])+)/";
232 preg_match_all($pattern, $srcsetAttribute, $matches); 233 preg_match_all($pattern, $srcsetAttribute, $matches);
234
233 $srcset = \call_user_func_array('array_merge', $matches); 235 $srcset = \call_user_func_array('array_merge', $matches);
234 $srcsetUrls = array_map(function ($src) { 236 $srcsetUrls = array_map(function ($src) {
235 return trim(explode(' ', $src, 2)[0]); 237 return trim(explode(' ', $src, 2)[0]);
236 }, $srcset); 238 }, $srcset);
237 $urls = array_merge($srcsetUrls, $urls); 239 $urls = array_merge($srcsetUrls, $urls);
238 } 240 }
241
239 $iterator->next(); 242 $iterator->next();
240 } 243 }
241 244
@@ -292,20 +295,16 @@ class DownloadImages
292 return $url; 295 return $url;
293 } 296 }
294 297
295 $base = new \SimplePie_IRI($base); 298 $base = new Uri($base);
296 299
297 // remove '//' in URL path (causes URLs not to resolve properly) 300 // in case the url has no scheme & host
298 if (isset($base->ipath)) { 301 if ('' === $base->getAuthority() || '' === $base->getScheme()) {
299 $base->ipath = preg_replace('!//+!', '/', $base->ipath); 302 $this->logger->error('DownloadImages: Can not make an absolute link', ['base' => $base, 'url' => $url]);
300 }
301 303
302 if ($absolute = \SimplePie_IRI::absolutize($base, $url)) { 304 return false;
303 return $absolute->get_uri();
304 } 305 }
305 306
306 $this->logger->error('DownloadImages: Can not make an absolute link', ['base' => $base, 'url' => $url]); 307 return (string) UriResolver::resolve($base, new Uri($url));
307
308 return false;
309 } 308 }
310 309
311 /** 310 /**
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 7772e0b7..16c44885 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -345,7 +345,7 @@ class EntryRepository extends EntityRepository
345 * @param string $url 345 * @param string $url
346 * @param int $userId 346 * @param int $userId
347 * 347 *
348 * @return Entry|bool 348 * @return Entry|false
349 */ 349 */
350 public function findByUrlAndUserId($url, $userId) 350 public function findByUrlAndUserId($url, $userId)
351 { 351 {
@@ -362,7 +362,7 @@ class EntryRepository extends EntityRepository
362 * @param string $hashedUrl Url hashed using sha1 362 * @param string $hashedUrl Url hashed using sha1
363 * @param int $userId 363 * @param int $userId
364 * 364 *
365 * @return Entry|bool 365 * @return Entry|false
366 */ 366 */
367 public function findByHashedUrlAndUserId($hashedUrl, $userId) 367 public function findByHashedUrlAndUserId($hashedUrl, $userId)
368 { 368 {