diff options
Diffstat (limited to 'src/Wallabag/CoreBundle')
6 files changed, 37 insertions, 25 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index fb6a720b..736eb1dc 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -70,7 +70,7 @@ class TagController extends Controller | |||
70 | $em->flush(); | 70 | $em->flush(); |
71 | } | 71 | } |
72 | 72 | ||
73 | $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer')); | 73 | $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true); |
74 | 74 | ||
75 | return $this->redirect($redirectUrl); | 75 | return $this->redirect($redirectUrl); |
76 | } | 76 | } |
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 08a67c34..9a7dd4e7 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -550,7 +550,7 @@ class Entry | |||
550 | } | 550 | } |
551 | 551 | ||
552 | /** | 552 | /** |
553 | * @return ArrayCollection<Tag> | 553 | * @return ArrayCollection |
554 | */ | 554 | */ |
555 | public function getTags() | 555 | public function getTags() |
556 | { | 556 | { |
@@ -685,7 +685,7 @@ class Entry | |||
685 | } | 685 | } |
686 | 686 | ||
687 | /** | 687 | /** |
688 | * @return int | 688 | * @return string |
689 | */ | 689 | */ |
690 | public function getHttpStatus() | 690 | public function getHttpStatus() |
691 | { | 691 | { |
@@ -693,7 +693,7 @@ class Entry | |||
693 | } | 693 | } |
694 | 694 | ||
695 | /** | 695 | /** |
696 | * @param int $httpStatus | 696 | * @param string $httpStatus |
697 | * | 697 | * |
698 | * @return Entry | 698 | * @return Entry |
699 | */ | 699 | */ |
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php index c712bb26..1c56fa9f 100644 --- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php +++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php | |||
@@ -5,7 +5,6 @@ namespace Wallabag\CoreBundle\GuzzleSiteAuthenticator; | |||
5 | use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; | 5 | use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; |
6 | use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder; | 6 | use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder; |
7 | use Graby\SiteConfig\ConfigBuilder; | 7 | use Graby\SiteConfig\ConfigBuilder; |
8 | use OutOfRangeException; | ||
9 | use Psr\Log\LoggerInterface; | 8 | use Psr\Log\LoggerInterface; |
10 | 9 | ||
11 | class GrabySiteConfigBuilder implements SiteConfigBuilder | 10 | class GrabySiteConfigBuilder implements SiteConfigBuilder |
@@ -38,13 +37,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder | |||
38 | } | 37 | } |
39 | 38 | ||
40 | /** | 39 | /** |
41 | * Builds the SiteConfig for a host. | 40 | * {@inheritdoc} |
42 | * | ||
43 | * @param string $host The "www." prefix is ignored | ||
44 | * | ||
45 | * @return SiteConfig | ||
46 | * | ||
47 | * @throws OutOfRangeException If there is no config for $host | ||
48 | */ | 41 | */ |
49 | public function buildForHost($host) | 42 | public function buildForHost($host) |
50 | { | 43 | { |
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 4b3e6fbb..8ba77ca9 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php | |||
@@ -31,7 +31,7 @@ class ContentProxy | |||
31 | } | 31 | } |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * Fetch content using graby and hydrate given entry with results information. | 34 | * Fetch content using graby and hydrate given $entry with results information. |
35 | * In case we couldn't find content, we'll try to use Open Graph data. | 35 | * In case we couldn't find content, we'll try to use Open Graph data. |
36 | * | 36 | * |
37 | * We can also force the content, in case of an import from the v1 for example, so the function won't | 37 | * We can also force the content, in case of an import from the v1 for example, so the function won't |
@@ -39,12 +39,17 @@ class ContentProxy | |||
39 | * | 39 | * |
40 | * @param Entry $entry Entry to update | 40 | * @param Entry $entry Entry to update |
41 | * @param string $url Url to grab content for | 41 | * @param string $url Url to grab content for |
42 | * @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url | 42 | * @param array $content An array with AT LEAST keys title, html, url to skip the fetchContent from the url |
43 | * | 43 | * |
44 | * @return Entry | 44 | * @return Entry |
45 | */ | 45 | */ |
46 | public function updateEntry(Entry $entry, $url, array $content = []) | 46 | public function updateEntry(Entry $entry, $url, array $content = []) |
47 | { | 47 | { |
48 | // ensure content is a bit cleaned up | ||
49 | if (!empty($content['html'])) { | ||
50 | $content['html'] = $this->graby->cleanupHtml($content['html'], $url); | ||
51 | } | ||
52 | |||
48 | // do we have to fetch the content or the provided one is ok? | 53 | // do we have to fetch the content or the provided one is ok? |
49 | if (empty($content) || false === $this->validateContent($content)) { | 54 | if (empty($content) || false === $this->validateContent($content)) { |
50 | $fetchedContent = $this->graby->fetchContent($url); | 55 | $fetchedContent = $this->graby->fetchContent($url); |
@@ -57,7 +62,7 @@ class ContentProxy | |||
57 | } | 62 | } |
58 | 63 | ||
59 | $title = $content['title']; | 64 | $title = $content['title']; |
60 | if (!$title && isset($content['open_graph']['og_title'])) { | 65 | if (!$title && !empty($content['open_graph']['og_title'])) { |
61 | $title = $content['open_graph']['og_title']; | 66 | $title = $content['open_graph']['og_title']; |
62 | } | 67 | } |
63 | 68 | ||
@@ -65,7 +70,7 @@ class ContentProxy | |||
65 | if (false === $html) { | 70 | if (false === $html) { |
66 | $html = $this->fetchingErrorMessage; | 71 | $html = $this->fetchingErrorMessage; |
67 | 72 | ||
68 | if (isset($content['open_graph']['og_description'])) { | 73 | if (!empty($content['open_graph']['og_description'])) { |
69 | $html .= '<p><i>But we found a short description: </i></p>'; | 74 | $html .= '<p><i>But we found a short description: </i></p>'; |
70 | $html .= $content['open_graph']['og_description']; | 75 | $html .= $content['open_graph']['og_description']; |
71 | } | 76 | } |
@@ -76,8 +81,19 @@ class ContentProxy | |||
76 | $entry->setContent($html); | 81 | $entry->setContent($html); |
77 | $entry->setHttpStatus(isset($content['status']) ? $content['status'] : ''); | 82 | $entry->setHttpStatus(isset($content['status']) ? $content['status'] : ''); |
78 | 83 | ||
79 | if (isset($content['date']) && null !== $content['date'] && '' !== $content['date']) { | 84 | if (!empty($content['date'])) { |
80 | $entry->setPublishedAt(new \DateTime($content['date'])); | 85 | $date = $content['date']; |
86 | |||
87 | // is it a timestamp? | ||
88 | if (filter_var($date, FILTER_VALIDATE_INT) !== false) { | ||
89 | $date = '@'.$content['date']; | ||
90 | } | ||
91 | |||
92 | try { | ||
93 | $entry->setPublishedAt(new \DateTime($date)); | ||
94 | } catch (\Exception $e) { | ||
95 | $this->logger->warning('Error while defining date', ['e' => $e, 'url' => $url, 'date' => $content['date']]); | ||
96 | } | ||
81 | } | 97 | } |
82 | 98 | ||
83 | if (!empty($content['authors'])) { | 99 | if (!empty($content['authors'])) { |
@@ -97,12 +113,12 @@ class ContentProxy | |||
97 | $entry->setDomainName($domainName); | 113 | $entry->setDomainName($domainName); |
98 | } | 114 | } |
99 | 115 | ||
100 | if (isset($content['open_graph']['og_image']) && $content['open_graph']['og_image']) { | 116 | if (!empty($content['open_graph']['og_image'])) { |
101 | $entry->setPreviewPicture($content['open_graph']['og_image']); | 117 | $entry->setPreviewPicture($content['open_graph']['og_image']); |
102 | } | 118 | } |
103 | 119 | ||
104 | // if content is an image define as a preview too | 120 | // if content is an image define as a preview too |
105 | if (isset($content['content_type']) && in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) { | 121 | if (!empty($content['content_type']) && in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) { |
106 | $entry->setPreviewPicture($content['url']); | 122 | $entry->setPreviewPicture($content['url']); |
107 | } | 123 | } |
108 | 124 | ||
@@ -128,6 +144,6 @@ class ContentProxy | |||
128 | */ | 144 | */ |
129 | private function validateContent(array $content) | 145 | private function validateContent(array $content) |
130 | { | 146 | { |
131 | return isset($content['title']) && isset($content['html']) && isset($content['url']) && isset($content['language']) && isset($content['content_type']); | 147 | return !empty($content['title']) && !empty($content['html']) && !empty($content['url']); |
132 | } | 148 | } |
133 | } | 149 | } |
diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php index f78b7fe0..abc84d08 100644 --- a/src/Wallabag/CoreBundle/Helper/Redirect.php +++ b/src/Wallabag/CoreBundle/Helper/Redirect.php | |||
@@ -21,12 +21,13 @@ class Redirect | |||
21 | } | 21 | } |
22 | 22 | ||
23 | /** | 23 | /** |
24 | * @param string $url URL to redirect | 24 | * @param string $url URL to redirect |
25 | * @param string $fallback Fallback URL if $url is null | 25 | * @param string $fallback Fallback URL if $url is null |
26 | * @param bool $ignoreActionMarkAsRead Ignore configured action when mark as read | ||
26 | * | 27 | * |
27 | * @return string | 28 | * @return string |
28 | */ | 29 | */ |
29 | public function to($url, $fallback = '') | 30 | public function to($url, $fallback = '', $ignoreActionMarkAsRead = false) |
30 | { | 31 | { |
31 | $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; | 32 | $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; |
32 | 33 | ||
@@ -34,7 +35,8 @@ class Redirect | |||
34 | return $url; | 35 | return $url; |
35 | } | 36 | } |
36 | 37 | ||
37 | if (Config::REDIRECT_TO_HOMEPAGE === $user->getConfig()->getActionMarkAsRead()) { | 38 | if (!$ignoreActionMarkAsRead && |
39 | Config::REDIRECT_TO_HOMEPAGE === $user->getConfig()->getActionMarkAsRead()) { | ||
38 | return $this->router->generate('homepage'); | 40 | return $this->router->generate('homepage'); |
39 | } | 41 | } |
40 | 42 | ||
diff --git a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php index add27db2..509d0dec 100644 --- a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php +++ b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php | |||
@@ -15,6 +15,7 @@ class RuleBasedTagger | |||
15 | private $rulerz; | 15 | private $rulerz; |
16 | private $tagRepository; | 16 | private $tagRepository; |
17 | private $entryRepository; | 17 | private $entryRepository; |
18 | private $logger; | ||
18 | 19 | ||
19 | public function __construct(RulerZ $rulerz, TagRepository $tagRepository, EntryRepository $entryRepository, LoggerInterface $logger) | 20 | public function __construct(RulerZ $rulerz, TagRepository $tagRepository, EntryRepository $entryRepository, LoggerInterface $logger) |
20 | { | 21 | { |