aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/ApiBundle/Controller/WallabagRestController.php11
-rw-r--r--src/Wallabag/ApiBundle/Resources/config/services.yml3
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php12
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php32
-rw-r--r--src/Wallabag/CoreBundle/Helper/Content.php34
-rw-r--r--src/Wallabag/CoreBundle/Helper/Url.php28
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml3
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig4
-rw-r--r--src/Wallabag/CoreBundle/Service/Extractor.php96
9 files changed, 56 insertions, 167 deletions
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
147 { 147 {
148 $url = $request->request->get('url'); 148 $url = $request->request->get('url');
149 149
150 $content = Extractor::extract($url); 150 $content = $this->get('wallabag_core.graby')->fetchContent($url);
151
151 $entry = new Entry($this->getUser()); 152 $entry = new Entry($this->getUser());
152 $entry->setUrl($url); 153 $entry->setUrl($url);
153 $entry->setTitle($request->request->get('title') ?: $content->getTitle()); 154 $entry->setTitle($request->request->get('title') ?: $content['title']);
154 $entry->setContent($content->getBody()); 155 $entry->setContent($content['html']);
156 $entry->setMimetype($content['content_type']);
157 if (isset($content['open_graph']['og_image'])) {
158 $entry->setPreviewPicture($content['open_graph']['og_image']);
159 }
155 160
156 $tags = $request->request->get('tags', ''); 161 $tags = $request->request->get('tags', '');
157 if (!empty($tags)) { 162 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:
10 tags: 10 tags:
11 - { name: monolog.logger, channel: wsse } 11 - { name: monolog.logger, channel: wsse }
12 arguments: ['@security.context', '@security.authentication.manager', '@logger'] 12 arguments: ['@security.context', '@security.authentication.manager', '@logger']
13
14 wallabag_core.graby:
15 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
31 $form->handleRequest($request); 31 $form->handleRequest($request);
32 32
33 if ($form->isValid()) { 33 if ($form->isValid()) {
34 $content = Extractor::extract($entry->getUrl()); 34 $content = $this->get('wallabag_core.graby')->fetchContent($entry->getUrl());
35 35
36 $entry->setTitle($content->getTitle()); 36 $entry->setTitle($content['title']);
37 $entry->setContent($content->getBody()); 37 $entry->setContent($content['html']);
38 $entry->setMimetype($content['content_type']);
39 if (isset($content['open_graph']['og_image'])) {
40 $entry->setPreviewPicture($content['open_graph']['og_image']);
41 }
38 42
39 $em = $this->getDoctrine()->getManager(); 43 $em = $this->getDoctrine()->getManager();
40 $em->persist($entry); 44 $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
@@ -109,6 +109,13 @@ class Entry
109 private $domainName; 109 private $domainName;
110 110
111 /** 111 /**
112 * @var string
113 *
114 * @ORM\Column(name="preview_picture", type="text", nullable=true)
115 */
116 private $previewPicture;
117
118 /**
112 * @var bool 119 * @var bool
113 * 120 *
114 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false}) 121 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
@@ -419,4 +426,29 @@ class Entry
419 { 426 {
420 $this->tags->removeElement($tag); 427 $this->tags->removeElement($tag);
421 } 428 }
429
430 /**
431 * Set previewPicture
432 *
433 * @param string $previewPicture
434 *
435 * @return Entry
436 */
437 public function setPreviewPicture($previewPicture)
438 {
439 $this->previewPicture = $previewPicture;
440
441 return $this;
442 }
443
444 /**
445 * Get previewPicture
446 *
447 * @return string
448 */
449 public function getPreviewPicture()
450 {
451 return $this->previewPicture;
452 }
453
422} 454}
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 @@
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5class Content
6{
7 private $title;
8
9 private $body;
10
11 public function __constructor()
12 {
13 }
14
15 public function getTitle()
16 {
17 return $this->title;
18 }
19
20 public function setTitle($title)
21 {
22 $this->title = $title;
23 }
24
25 public function getBody()
26 {
27 return $this->body;
28 }
29
30 public function setBody($body)
31 {
32 $this->body = $body;
33 }
34}
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 @@
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5class Url
6{
7 public $url;
8
9 public function __construct($url)
10 {
11 $this->url = base64_decode($url);
12 }
13
14 public function getUrl()
15 {
16 return $this->url;
17 }
18
19 public function setUrl($url)
20 {
21 $this->url = $url;
22 }
23
24 public function isCorrect()
25 {
26 return filter_var($this->url, FILTER_VALIDATE_URL) !== false;
27 }
28}
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:
30 wallabag_core.doctrine.prefixed_naming_strategy: 30 wallabag_core.doctrine.prefixed_naming_strategy:
31 class: Wallabag\CoreBundle\Doctrine\Mapping\PrefixedNamingStrategy 31 class: Wallabag\CoreBundle\Doctrine\Mapping\PrefixedNamingStrategy
32 arguments: [%database_table_prefix%] 32 arguments: [%database_table_prefix%]
33
34 wallabag_core.graby:
35 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 @@
10 <div class="nav-wrapper cyan darken-1"> 10 <div class="nav-wrapper cyan darken-1">
11 <ul> 11 <ul>
12 <li> 12 <li>
13 <a class="waves-effect" href="/"> 13 <a class="waves-effect" href="{{ path('homepage') }}">
14 <i class="mdi-action-exit-to-app"></i> 14 <i class="mdi-action-exit-to-app"></i>
15 </a> 15 </a>
16 </li> 16 </li>
@@ -36,7 +36,7 @@
36 </nav> 36 </nav>
37 <ul id="slide-out" class="collapsible side-nav fixed reader-mode" data-collapsible="accordion"> 37 <ul id="slide-out" class="collapsible side-nav fixed reader-mode" data-collapsible="accordion">
38 <li class="bold border-bottom hide-on-med-and-down"> 38 <li class="bold border-bottom hide-on-med-and-down">
39 <a class="waves-effect collapsible-header" href="/"> 39 <a class="waves-effect collapsible-header" href="{{ path('homepage') }}">
40 <i class="mdi-action-exit-to-app small"></i> 40 <i class="mdi-action-exit-to-app small"></i>
41 <span>{% trans %}back{% endtrans %}</span> 41 <span>{% trans %}back{% endtrans %}</span>
42 </a> 42 </a>
diff --git a/src/Wallabag/CoreBundle/Service/Extractor.php b/src/Wallabag/CoreBundle/Service/Extractor.php
deleted file mode 100644
index 4c067d3a..00000000
--- a/src/Wallabag/CoreBundle/Service/Extractor.php
+++ /dev/null
@@ -1,96 +0,0 @@
1<?php
2
3namespace Wallabag\CoreBundle\Service;
4
5use Wallabag\CoreBundle\Helper\Content;
6use Wallabag\CoreBundle\Helper\Url;
7
8final class Extractor
9{
10 public static function extract($url)
11 {
12 $pageContent = self::getPageContent(new Url(base64_encode($url)));
13 $title = $pageContent['rss']['channel']['item']['title'] ?: parse_url($url, PHP_URL_HOST);
14 $body = $pageContent['rss']['channel']['item']['description'];
15
16 $content = new Content();
17 $content->setTitle($title);
18 $content->setBody($body);
19
20 return $content;
21 }
22
23 /**
24 * Get the content for a given URL (by a call to FullTextFeed).
25 *
26 * @param Url $url
27 *
28 * @return mixed
29 */
30 public static function getPageContent(Url $url)
31 {
32 // Saving and clearing context
33 $REAL = array();
34 foreach ($GLOBALS as $key => $value) {
35 if ($key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS') {
36 $GLOBALS[$key] = array();
37 $REAL[$key] = $value;
38 }
39 }
40 // Saving and clearing session
41 if (isset($_SESSION)) {
42 $REAL_SESSION = array();
43 foreach ($_SESSION as $key => $value) {
44 $REAL_SESSION[$key] = $value;
45 unset($_SESSION[$key]);
46 }
47 }
48
49 // Running code in different context
50 $scope = function () {
51 extract(func_get_arg(1));
52 $_GET = $_REQUEST = array(
53 'url' => $url->getUrl(),
54 'max' => 5,
55 'links' => 'preserve',
56 'exc' => '',
57 'format' => 'json',
58 'submit' => 'Create Feed',
59 );
60 ob_start();
61 require func_get_arg(0);
62 $json = ob_get_contents();
63 ob_end_clean();
64
65 return $json;
66 };
67
68 // Silence $scope function to avoid
69 // issues with FTRSS when error_reporting is to high
70 // FTRSS generates PHP warnings which break output
71 $json = @$scope(__DIR__.'/../../../../vendor/wallabag/Fivefilters_Libraries/makefulltextfeed.php', array('url' => $url));
72
73 // Clearing and restoring context
74 foreach ($GLOBALS as $key => $value) {
75 if ($key != 'GLOBALS' && $key != '_SESSION') {
76 unset($GLOBALS[$key]);
77 }
78 }
79 foreach ($REAL as $key => $value) {
80 $GLOBALS[$key] = $value;
81 }
82
83 // Clearing and restoring session
84 if (isset($REAL_SESSION)) {
85 foreach ($_SESSION as $key => $value) {
86 unset($_SESSION[$key]);
87 }
88
89 foreach ($REAL_SESSION as $key => $value) {
90 $_SESSION[$key] = $value;
91 }
92 }
93
94 return json_decode($json, true);
95 }
96}