]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Integrate graby
authorJeremy Benoist <jeremy.benoist@gmail.com>
Mon, 24 Aug 2015 10:27:17 +0000 (12:27 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Mon, 24 Aug 2015 10:27:17 +0000 (12:27 +0200)
composer.json
src/Wallabag/ApiBundle/Controller/WallabagRestController.php
src/Wallabag/ApiBundle/Resources/config/services.yml
src/Wallabag/CoreBundle/Controller/EntryController.php
src/Wallabag/CoreBundle/Entity/Entry.php
src/Wallabag/CoreBundle/Helper/Content.php [deleted file]
src/Wallabag/CoreBundle/Helper/Url.php [deleted file]
src/Wallabag/CoreBundle/Resources/config/services.yml
src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig
src/Wallabag/CoreBundle/Service/Extractor.php [deleted file]

index 2c5111fdecc87e601a88899946a1fd11243814f0..6644c2a3aec537e35c7740dfdc5b3138ae301093 100644 (file)
         "email": "hello@wallabag.org",
         "issues": "https://github.com/wallabag/wallabag/issues"
     },
-    "repositories": [
-        {
-            "type": "vcs",
-            "url": "https://github.com/wallabag/php-readability"
-        },
-        {
-            "type": "vcs",
-            "url": "https://github.com/wallabag/Fivefilters_Libraries"
-        }
-    ],
     "require": {
         "php": ">=5.3.3",
         "symfony/symfony": "~2.7.0",
-        "doctrine/orm": "~2.2,>=2.2.3",
+        "doctrine/orm": "~2.3",
         "doctrine/doctrine-bundle": "~1.2",
         "twig/extensions": "~1.0",
         "symfony/assetic-bundle": "~2.3",
         "willdurand/hateoas-bundle": "~0.5.0",
         "htmlawed/htmlawed": "~1.1.19",
         "liip/theme-bundle": "~1.1.3",
-        "wallabag/php-readability": "~1.0.0",
-        "wallabag/Fivefilters_Libraries": "~1.0",
         "pagerfanta/pagerfanta": "~1.0.3",
-        "lexik/form-filter-bundle": "~4.0"
+        "lexik/form-filter-bundle": "~4.0",
+        "j0k3r/graby": "dev-master"
     },
     "require-dev": {
         "doctrine/doctrine-fixtures-bundle": "~2.2.0",
index 02a6de64c9297d69809bdb4b71f32bee62f6fb25..d5579de4e18c4cb8fc06de4546898a67f29b96f9 100644 (file)
@@ -147,11 +147,16 @@ class WallabagRestController extends Controller
     {
         $url = $request->request->get('url');
 
-        $content = Extractor::extract($url);
+        $content = $this->get('wallabag_core.graby')->fetchContent($url);
+
         $entry = new Entry($this->getUser());
         $entry->setUrl($url);
-        $entry->setTitle($request->request->get('title') ?: $content->getTitle());
-        $entry->setContent($content->getBody());
+        $entry->setTitle($request->request->get('title') ?: $content['title']);
+        $entry->setContent($content['html']);
+        $entry->setMimetype($content['content_type']);
+        if (isset($content['open_graph']['og_image'])) {
+            $entry->setPreviewPicture($content['open_graph']['og_image']);
+        }
 
         $tags = $request->request->get('tags', '');
         if (!empty($tags)) {
index 6854a444cc549c6be2d2ee2c1299228959e53f9c..9ab4f3d1e2574aadf6e0dcdaf00372e8f350b597 100644 (file)
@@ -10,3 +10,6 @@ services:
         tags:
             - { name: monolog.logger, channel: wsse }
         arguments: ['@security.context', '@security.authentication.manager', '@logger']
+
+    wallabag_core.graby:
+        class: Graby\Graby
index a77489e250cf0c6b2a9f9bd1d68e291cf6b110e0..bd87c6f4431ff88a702d58e3cedbdade7c866adb 100644 (file)
@@ -31,10 +31,14 @@ class EntryController extends Controller
         $form->handleRequest($request);
 
         if ($form->isValid()) {
-            $content = Extractor::extract($entry->getUrl());
-
-            $entry->setTitle($content->getTitle());
-            $entry->setContent($content->getBody());
+            $content = $this->get('wallabag_core.graby')->fetchContent($entry->getUrl());
+
+            $entry->setTitle($content['title']);
+            $entry->setContent($content['html']);
+            $entry->setMimetype($content['content_type']);
+            if (isset($content['open_graph']['og_image'])) {
+                $entry->setPreviewPicture($content['open_graph']['og_image']);
+            }
 
             $em = $this->getDoctrine()->getManager();
             $em->persist($entry);
index f88d189d3f6e376f08fec5851999d478c0dede8d..5e3f9a37a6bc89f4604de1d623f039a927993877 100644 (file)
@@ -108,6 +108,13 @@ class Entry
      */
     private $domainName;
 
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="preview_picture", type="text", nullable=true)
+     */
+    private $previewPicture;
+
     /**
      * @var bool
      *
@@ -419,4 +426,29 @@ class Entry
     {
         $this->tags->removeElement($tag);
     }
+
+    /**
+     * Set previewPicture
+     *
+     * @param string $previewPicture
+     *
+     * @return Entry
+     */
+    public function setPreviewPicture($previewPicture)
+    {
+        $this->previewPicture = $previewPicture;
+
+        return $this;
+    }
+
+    /**
+     * Get previewPicture
+     *
+     * @return string
+     */
+    public function getPreviewPicture()
+    {
+        return $this->previewPicture;
+    }
+
 }
diff --git a/src/Wallabag/CoreBundle/Helper/Content.php b/src/Wallabag/CoreBundle/Helper/Content.php
deleted file mode 100644 (file)
index 1cc5e4c..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-
-namespace Wallabag\CoreBundle\Helper;
-
-class Content
-{
-    private $title;
-
-    private $body;
-
-    public function __constructor()
-    {
-    }
-
-    public function getTitle()
-    {
-        return $this->title;
-    }
-
-    public function setTitle($title)
-    {
-        $this->title = $title;
-    }
-
-    public function getBody()
-    {
-        return $this->body;
-    }
-
-    public function setBody($body)
-    {
-        $this->body = $body;
-    }
-}
diff --git a/src/Wallabag/CoreBundle/Helper/Url.php b/src/Wallabag/CoreBundle/Helper/Url.php
deleted file mode 100644 (file)
index 35eb260..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-
-namespace Wallabag\CoreBundle\Helper;
-
-class Url
-{
-    public $url;
-
-    public function __construct($url)
-    {
-        $this->url = base64_decode($url);
-    }
-
-    public function getUrl()
-    {
-        return $this->url;
-    }
-
-    public function setUrl($url)
-    {
-        $this->url = $url;
-    }
-
-    public function isCorrect()
-    {
-        return filter_var($this->url, FILTER_VALIDATE_URL) !== false;
-    }
-}
index 08eae32748f7cd27bb6c6456973c622d7cb02d21..6b8774f204f8b11f93e407e07672eb35c247c9e8 100644 (file)
@@ -30,3 +30,6 @@ services:
     wallabag_core.doctrine.prefixed_naming_strategy:
         class: Wallabag\CoreBundle\Doctrine\Mapping\PrefixedNamingStrategy
         arguments: [%database_table_prefix%]
+
+    wallabag_core.graby:
+        class: Graby\Graby
index 47ca661aa83d56506bbf3da31b728f0577a01744..75ac2a6bd4fc5d189b85ae83646883eb226413d0 100644 (file)
@@ -10,7 +10,7 @@
         <div class="nav-wrapper cyan darken-1">
             <ul>
                 <li>
-                    <a class="waves-effect" href="/">
+                    <a class="waves-effect" href="{{ path('homepage') }}">
                         <i class="mdi-action-exit-to-app"></i>
                     </a>
                 </li>
@@ -36,7 +36,7 @@
     </nav>
     <ul id="slide-out" class="collapsible side-nav fixed reader-mode" data-collapsible="accordion">
         <li class="bold border-bottom hide-on-med-and-down">
-            <a class="waves-effect collapsible-header" href="/">
+            <a class="waves-effect collapsible-header" href="{{ path('homepage') }}">
                 <i class="mdi-action-exit-to-app small"></i>
                 <span>{% trans %}back{% endtrans %}</span>
             </a>
diff --git a/src/Wallabag/CoreBundle/Service/Extractor.php b/src/Wallabag/CoreBundle/Service/Extractor.php
deleted file mode 100644 (file)
index 4c067d3..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-<?php
-
-namespace Wallabag\CoreBundle\Service;
-
-use Wallabag\CoreBundle\Helper\Content;
-use Wallabag\CoreBundle\Helper\Url;
-
-final class Extractor
-{
-    public static function extract($url)
-    {
-        $pageContent = self::getPageContent(new Url(base64_encode($url)));
-        $title = $pageContent['rss']['channel']['item']['title'] ?: parse_url($url, PHP_URL_HOST);
-        $body = $pageContent['rss']['channel']['item']['description'];
-
-        $content = new Content();
-        $content->setTitle($title);
-        $content->setBody($body);
-
-        return $content;
-    }
-
-    /**
-     * Get the content for a given URL (by a call to FullTextFeed).
-     *
-     * @param Url $url
-     *
-     * @return mixed
-     */
-    public static function getPageContent(Url $url)
-    {
-        // Saving and clearing context
-        $REAL = array();
-        foreach ($GLOBALS as $key => $value) {
-            if ($key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS') {
-                $GLOBALS[$key] = array();
-                $REAL[$key] = $value;
-            }
-        }
-        // Saving and clearing session
-        if (isset($_SESSION)) {
-            $REAL_SESSION = array();
-            foreach ($_SESSION as $key => $value) {
-                $REAL_SESSION[$key] = $value;
-                unset($_SESSION[$key]);
-            }
-        }
-
-        // Running code in different context
-        $scope = function () {
-            extract(func_get_arg(1));
-            $_GET = $_REQUEST = array(
-                'url' => $url->getUrl(),
-                'max' => 5,
-                'links' => 'preserve',
-                'exc' => '',
-                'format' => 'json',
-                'submit' => 'Create Feed',
-            );
-            ob_start();
-            require func_get_arg(0);
-            $json = ob_get_contents();
-            ob_end_clean();
-
-            return $json;
-        };
-
-        // Silence $scope function to avoid
-        // issues with FTRSS when error_reporting is to high
-        // FTRSS generates PHP warnings which break output
-        $json = @$scope(__DIR__.'/../../../../vendor/wallabag/Fivefilters_Libraries/makefulltextfeed.php', array('url' => $url));
-
-        // Clearing and restoring context
-        foreach ($GLOBALS as $key => $value) {
-            if ($key != 'GLOBALS' && $key != '_SESSION') {
-                unset($GLOBALS[$key]);
-            }
-        }
-        foreach ($REAL as $key => $value) {
-            $GLOBALS[$key] = $value;
-        }
-
-        // Clearing and restoring session
-        if (isset($REAL_SESSION)) {
-            foreach ($_SESSION as $key => $value) {
-                unset($_SESSION[$key]);
-            }
-
-            foreach ($REAL_SESSION as $key => $value) {
-                $_SESSION[$key] = $value;
-            }
-        }
-
-        return json_decode($json, true);
-    }
-}