]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #3271 from wallabag/store-resolved-url
authorJérémy Benoist <j0k3r@users.noreply.github.com>
Wed, 5 Jun 2019 09:38:00 +0000 (11:38 +0200)
committerGitHub <noreply@github.com>
Wed, 5 Jun 2019 09:38:00 +0000 (11:38 +0200)
Add `given_url` in Entry table to check if a redirected url has already added

composer.json
composer.lock
src/Wallabag/ApiBundle/Controller/EntryRestController.php
src/Wallabag/ApiBundle/Controller/UserRestController.php
src/Wallabag/ApiBundle/Controller/WallabagRestController.php
src/Wallabag/CoreBundle/Entity/Entry.php
src/Wallabag/CoreBundle/Helper/DownloadImages.php
src/Wallabag/CoreBundle/Repository/EntryRepository.php

index 55e7f7651bbf1309714c0feda5fa5a600445622d..b0c17385ab70f2b201b8b7372cc1f04b292086e5 100644 (file)
@@ -63,7 +63,6 @@
         "nelmio/api-doc-bundle": "^2.13.2",
         "mgargano/simplehtmldom": "~1.5",
         "wallabag/tcpdf": "^6.2.26",
-        "simplepie/simplepie": "~1.5",
         "willdurand/hateoas-bundle": "~1.3",
         "liip/theme-bundle": "^1.4.6",
         "lexik/form-filter-bundle": "^5.0.4",
index cbb9265d063b011b558e6a68c153c0dd9d5dd169..a2a48c1eed5a9db33cca2d68bbf854f516ae767a 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "883f44eda34a48c8ddabc3294498d996",
+    "content-hash": "c42e1b50f4a2b8a59ca06c5ccb24e6a3",
     "packages": [
         {
             "name": "bdunogier/guzzle-site-authenticator",
index aaacdcdc9206cf9baeddbad79059eb7c9f78a99a..9f933adb7cef298ef90f43ccabfc09f1471ddaef 100644 (file)
@@ -564,7 +564,7 @@ class EntryRestController extends WallabagRestController
         }
 
         // if refreshing entry failed, don't save it
-        if ($this->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) {
+        if ($this->container->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) {
             return new JsonResponse([], 304);
         }
 
index 3a4dafcd083887e92923e0e23f30adef50292834..1b10a076da87f56d24163154d3b979e4595bbfb2 100644 (file)
@@ -45,7 +45,7 @@ class UserRestController extends WallabagRestController
      */
     public function putUserAction(Request $request)
     {
-        if (!$this->getParameter('fosuser_registration') || !$this->get('craue_config')->get('api_user_registration')) {
+        if (!$this->container->getParameter('fosuser_registration') || !$this->get('craue_config')->get('api_user_registration')) {
             $json = $this->get('jms_serializer')->serialize(['error' => "Server doesn't allow registrations"], 'json');
 
             return (new JsonResponse())
index f18b0910d9d05120b5eeee9ec108ed41190ac5a3..44fd968354120ced54c33ae4dd2e4a5d470df35f 100644 (file)
@@ -2,13 +2,13 @@
 
 namespace Wallabag\ApiBundle\Controller;
 
-use FOS\RestBundle\Controller\FOSRestController;
+use FOS\RestBundle\Controller\AbstractFOSRestController;
 use JMS\Serializer\SerializationContext;
 use Nelmio\ApiDocBundle\Annotation\ApiDoc;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\Security\Core\Exception\AccessDeniedException;
 
-class WallabagRestController extends FOSRestController
+class WallabagRestController extends AbstractFOSRestController
 {
     /**
      * Retrieve version number.
index 4a9cb8d8162d11d28a760bbfa199290543c18444..4d5e6fc9463894ad4538b734b75ea792a04f2c7d 100644 (file)
@@ -794,7 +794,7 @@ class Entry
     }
 
     /**
-     * @return string
+     * @return string|null
      */
     public function getUid()
     {
index 7a39a2e4a6d9cbf62e329822e9a806a328863356..1d361d6daeaa3a6da615a6cc52400d63256981ee 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace Wallabag\CoreBundle\Helper;
 
+use GuzzleHttp\Psr7\Uri;
+use GuzzleHttp\Psr7\UriResolver;
 use Http\Client\Common\HttpMethodsClient;
 use Http\Client\Common\Plugin\ErrorPlugin;
 use Http\Client\Common\PluginClient;
@@ -45,10 +47,8 @@ class DownloadImages
     public static function extractImagesUrlsFromHtml($html)
     {
         $crawler = new Crawler($html);
-        $imagesCrawler = $crawler
-            ->filterXpath('//img');
-        $imagesUrls = $imagesCrawler
-            ->extract(['src']);
+        $imagesCrawler = $crawler->filterXpath('//img');
+        $imagesUrls = $imagesCrawler->extract(['src']);
         $imagesSrcsetUrls = self::getSrcsetUrls($imagesCrawler);
 
         return array_unique(array_merge($imagesUrls, $imagesSrcsetUrls));
@@ -220,22 +220,25 @@ class DownloadImages
     private static function getSrcsetUrls(Crawler $imagesCrawler)
     {
         $urls = [];
-        $iterator = $imagesCrawler
-            ->getIterator();
+        $iterator = $imagesCrawler->getIterator();
+
         while ($iterator->valid()) {
             $srcsetAttribute = $iterator->current()->getAttribute('srcset');
+
             if ('' !== $srcsetAttribute) {
                 // Couldn't start with " OR ' OR a white space
                 // Could be one or more white space
                 // Must be one or more digits followed by w OR x
                 $pattern = "/(?:[^\"'\s]+\s*(?:\d+[wx])+)/";
                 preg_match_all($pattern, $srcsetAttribute, $matches);
+
                 $srcset = \call_user_func_array('array_merge', $matches);
                 $srcsetUrls = array_map(function ($src) {
                     return trim(explode(' ', $src, 2)[0]);
                 }, $srcset);
                 $urls = array_merge($srcsetUrls, $urls);
             }
+
             $iterator->next();
         }
 
@@ -292,20 +295,16 @@ class DownloadImages
             return $url;
         }
 
-        $base = new \SimplePie_IRI($base);
+        $base = new Uri($base);
 
-        // remove '//' in URL path (causes URLs not to resolve properly)
-        if (isset($base->ipath)) {
-            $base->ipath = preg_replace('!//+!', '/', $base->ipath);
-        }
+        // in case the url has no scheme & host
+        if ('' === $base->getAuthority() || '' === $base->getScheme()) {
+            $this->logger->error('DownloadImages: Can not make an absolute link', ['base' => $base, 'url' => $url]);
 
-        if ($absolute = \SimplePie_IRI::absolutize($base, $url)) {
-            return $absolute->get_uri();
+            return false;
         }
 
-        $this->logger->error('DownloadImages: Can not make an absolute link', ['base' => $base, 'url' => $url]);
-
-        return false;
+        return (string) UriResolver::resolve($base, new Uri($url));
     }
 
     /**
index 7772e0b78a7c29387278ddcfd138a003187d408e..16c448851f444e73f3652313e1baffaa09ea9e40 100644 (file)
@@ -345,7 +345,7 @@ class EntryRepository extends EntityRepository
      * @param string $url
      * @param int    $userId
      *
-     * @return Entry|bool
+     * @return Entry|false
      */
     public function findByUrlAndUserId($url, $userId)
     {
@@ -362,7 +362,7 @@ class EntryRepository extends EntityRepository
      * @param string $hashedUrl Url hashed using sha1
      * @param int    $userId
      *
-     * @return Entry|bool
+     * @return Entry|false
      */
     public function findByHashedUrlAndUserId($hashedUrl, $userId)
     {