aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper/ContentProxy.php
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2017-11-26 23:20:23 +0100
committerKevin Decherf <kevin@kdecherf.com>2017-12-13 22:44:31 +0100
commitaf29e1bf07aabaa6a4e4653c1a3b5c10ce831bb6 (patch)
treeb4e0a8e01717f3d8d96138033bf8ce1696a127a7 /src/Wallabag/CoreBundle/Helper/ContentProxy.php
parent70265817aee257e7e635eda79ce3e037e3b4a242 (diff)
downloadwallabag-af29e1bf07aabaa6a4e4653c1a3b5c10ce831bb6.tar.gz
wallabag-af29e1bf07aabaa6a4e4653c1a3b5c10ce831bb6.tar.zst
wallabag-af29e1bf07aabaa6a4e4653c1a3b5c10ce831bb6.zip
Fix empty title and domain_name when exception is thrown during fetch
Add a new helper to set a default title when it's empty: 1/ use basename part of entry's path, if any 2/ or use domain name Fixes #2053 Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/ContentProxy.php')
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index 4cc20c9c..fe795d42 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -145,6 +145,38 @@ class ContentProxy
145 } 145 }
146 146
147 /** 147 /**
148 * Helper to extract and save host from entry url.
149 *
150 * @param Entry $entry
151 */
152 public function setEntryDomainName(Entry $entry)
153 {
154 $domainName = parse_url($entry->getUrl(), PHP_URL_HOST);
155 if (false !== $domainName) {
156 $entry->setDomainName($domainName);
157 }
158 }
159
160 /**
161 * Helper to set a default title using:
162 * - url basename, if applicable
163 * - hostname.
164 *
165 * @param Entry $entry
166 */
167 public function setDefaultEntryTitle(Entry $entry)
168 {
169 $url = parse_url($entry->getUrl());
170 $path = pathinfo($url['path'], PATHINFO_BASENAME);
171
172 if (empty($path)) {
173 $path = $url['host'];
174 }
175
176 $entry->setTitle($path);
177 }
178
179 /**
148 * Stock entry with fetched or imported content. 180 * Stock entry with fetched or imported content.
149 * Will fall back to OpenGraph data if available. 181 * Will fall back to OpenGraph data if available.
150 * 182 *
@@ -155,10 +187,7 @@ class ContentProxy
155 { 187 {
156 $entry->setUrl($content['url']); 188 $entry->setUrl($content['url']);
157 189
158 $domainName = parse_url($entry->getUrl(), PHP_URL_HOST); 190 $this->setEntryDomainName($entry);
159 if (false !== $domainName) {
160 $entry->setDomainName($domainName);
161 }
162 191
163 if (!empty($content['title'])) { 192 if (!empty($content['title'])) {
164 $entry->setTitle($content['title']); 193 $entry->setTitle($content['title']);