From fad316151c282b2383fae751f7ca45373f1f26ed Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 24 Aug 2015 12:27:17 +0200 Subject: [PATCH] Integrate graby --- composer.json | 17 +--- .../Controller/WallabagRestController.php | 11 ++- .../ApiBundle/Resources/config/services.yml | 3 + .../CoreBundle/Controller/EntryController.php | 12 ++- src/Wallabag/CoreBundle/Entity/Entry.php | 32 +++++++ src/Wallabag/CoreBundle/Helper/Content.php | 34 ------- src/Wallabag/CoreBundle/Helper/Url.php | 28 ------ .../CoreBundle/Resources/config/services.yml | 3 + .../themes/material/Entry/entry.html.twig | 4 +- src/Wallabag/CoreBundle/Service/Extractor.php | 96 ------------------- 10 files changed, 59 insertions(+), 181 deletions(-) delete mode 100644 src/Wallabag/CoreBundle/Helper/Content.php delete mode 100644 src/Wallabag/CoreBundle/Helper/Url.php delete mode 100644 src/Wallabag/CoreBundle/Service/Extractor.php diff --git a/composer.json b/composer.json index 2c5111fd..6644c2a3 100644 --- a/composer.json +++ b/composer.json @@ -27,20 +27,10 @@ "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", @@ -60,10 +50,9 @@ "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", diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 02a6de64..d5579de4 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -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)) { diff --git a/src/Wallabag/ApiBundle/Resources/config/services.yml b/src/Wallabag/ApiBundle/Resources/config/services.yml index 6854a444..9ab4f3d1 100644 --- a/src/Wallabag/ApiBundle/Resources/config/services.yml +++ b/src/Wallabag/ApiBundle/Resources/config/services.yml @@ -10,3 +10,6 @@ services: tags: - { name: monolog.logger, channel: wsse } arguments: ['@security.context', '@security.authentication.manager', '@logger'] + + wallabag_core.graby: + class: Graby\Graby diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index a77489e2..bd87c6f4 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -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); diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index f88d189d..5e3f9a37 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -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 index 1cc5e4cf..00000000 --- a/src/Wallabag/CoreBundle/Helper/Content.php +++ /dev/null @@ -1,34 +0,0 @@ -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 index 35eb260d..00000000 --- a/src/Wallabag/CoreBundle/Helper/Url.php +++ /dev/null @@ -1,28 +0,0 @@ -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; - } -} diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 08eae327..6b8774f2 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -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 diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig index 47ca661a..75ac2a6b 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig @@ -10,7 +10,7 @@