diff options
author | ArthurHoaro <arthur@hoa.ro> | 2019-03-02 10:54:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-02 10:54:06 +0100 |
commit | cc69aad4a903dc603f47cfa87aeb1865b03c8950 (patch) | |
tree | ffc04dac709b2a4cc732ce10f98fb40a562863c7 | |
parent | 5bb384cd2742ff4f982cbe914cee551b74ab4bad (diff) | |
parent | a8e7da01146455f13ef06b151a7dafedd3acf769 (diff) | |
download | Shaarli-cc69aad4a903dc603f47cfa87aeb1865b03c8950.tar.gz Shaarli-cc69aad4a903dc603f47cfa87aeb1865b03c8950.tar.zst Shaarli-cc69aad4a903dc603f47cfa87aeb1865b03c8950.zip |
Merge pull request #1271 from ArthurHoaro/hotfix/thumb-note-retrieve
Do not try to retrieve thumbnails for internal link
-rw-r--r-- | application/api/ApiUtils.php | 2 | ||||
-rw-r--r-- | application/bookmark/LinkUtils.php | 13 | ||||
-rw-r--r-- | application/feed/FeedBuilder.php | 4 | ||||
-rw-r--r-- | application/netscape/NetscapeBookmarkUtils.php | 2 | ||||
-rw-r--r-- | index.php | 8 | ||||
-rw-r--r-- | tests/bookmark/LinkUtilsTest.php | 20 |
6 files changed, 42 insertions, 7 deletions
diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php index 1824b5d0..1e3ac02e 100644 --- a/application/api/ApiUtils.php +++ b/application/api/ApiUtils.php | |||
@@ -59,7 +59,7 @@ class ApiUtils | |||
59 | { | 59 | { |
60 | $out['id'] = $link['id']; | 60 | $out['id'] = $link['id']; |
61 | // Not an internal link | 61 | // Not an internal link |
62 | if ($link['url'][0] != '?') { | 62 | if (! is_note($link['url'])) { |
63 | $out['url'] = $link['url']; | 63 | $out['url'] = $link['url']; |
64 | } else { | 64 | } else { |
65 | $out['url'] = $indexUrl . $link['url']; | 65 | $out['url'] = $indexUrl . $link['url']; |
diff --git a/application/bookmark/LinkUtils.php b/application/bookmark/LinkUtils.php index 988970bd..35a5b290 100644 --- a/application/bookmark/LinkUtils.php +++ b/application/bookmark/LinkUtils.php | |||
@@ -204,3 +204,16 @@ function link_small_hash($date, $id) | |||
204 | { | 204 | { |
205 | return smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id); | 205 | return smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id); |
206 | } | 206 | } |
207 | |||
208 | /** | ||
209 | * Returns whether or not the link is an internal note. | ||
210 | * Its URL starts by `?` because it's actually a permalink. | ||
211 | * | ||
212 | * @param string $linkUrl | ||
213 | * | ||
214 | * @return bool true if internal note, false otherwise. | ||
215 | */ | ||
216 | function is_note($linkUrl) | ||
217 | { | ||
218 | return isset($linkUrl[0]) && $linkUrl[0] === '?'; | ||
219 | } | ||
diff --git a/application/feed/FeedBuilder.php b/application/feed/FeedBuilder.php index e23b3452..7c859474 100644 --- a/application/feed/FeedBuilder.php +++ b/application/feed/FeedBuilder.php | |||
@@ -147,8 +147,8 @@ class FeedBuilder | |||
147 | protected function buildItem($link, $pageaddr) | 147 | protected function buildItem($link, $pageaddr) |
148 | { | 148 | { |
149 | $link['guid'] = $pageaddr . '?' . $link['shorturl']; | 149 | $link['guid'] = $pageaddr . '?' . $link['shorturl']; |
150 | // Check for both signs of a note: starting with ? and 7 chars long. | 150 | // Prepend the root URL for notes |
151 | if ($link['url'][0] === '?' && strlen($link['url']) === 7) { | 151 | if (is_note($link['url'])) { |
152 | $link['url'] = $pageaddr . $link['url']; | 152 | $link['url'] = $pageaddr . $link['url']; |
153 | } | 153 | } |
154 | if ($this->usePermalinks === true) { | 154 | if ($this->usePermalinks === true) { |
diff --git a/application/netscape/NetscapeBookmarkUtils.php b/application/netscape/NetscapeBookmarkUtils.php index 2fb1a4a6..28665941 100644 --- a/application/netscape/NetscapeBookmarkUtils.php +++ b/application/netscape/NetscapeBookmarkUtils.php | |||
@@ -54,7 +54,7 @@ class NetscapeBookmarkUtils | |||
54 | $link['timestamp'] = $date->getTimestamp(); | 54 | $link['timestamp'] = $date->getTimestamp(); |
55 | $link['taglist'] = str_replace(' ', ',', $link['tags']); | 55 | $link['taglist'] = str_replace(' ', ',', $link['tags']); |
56 | 56 | ||
57 | if (startsWith($link['url'], '?') && $prependNoteUrl) { | 57 | if (is_note($link['url']) && $prependNoteUrl) { |
58 | $link['url'] = $indexUrl . $link['url']; | 58 | $link['url'] = $indexUrl . $link['url']; |
59 | } | 59 | } |
60 | 60 | ||
@@ -356,7 +356,7 @@ function showDailyRSS($conf, $loginManager) | |||
356 | foreach ($links as &$link) { | 356 | foreach ($links as &$link) { |
357 | $link['formatedDescription'] = format_description($link['description']); | 357 | $link['formatedDescription'] = format_description($link['description']); |
358 | $link['timestamp'] = $link['created']->getTimestamp(); | 358 | $link['timestamp'] = $link['created']->getTimestamp(); |
359 | if (startsWith($link['url'], '?')) { | 359 | if (is_note($link['url'])) { |
360 | $link['url'] = index_url($_SERVER) . $link['url']; // make permalink URL absolute | 360 | $link['url'] = index_url($_SERVER) . $link['url']; // make permalink URL absolute |
361 | } | 361 | } |
362 | } | 362 | } |
@@ -1166,7 +1166,9 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, | |||
1166 | $link['title'] = $link['url']; | 1166 | $link['title'] = $link['url']; |
1167 | } | 1167 | } |
1168 | 1168 | ||
1169 | if ($conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE) { | 1169 | if ($conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE |
1170 | && ! is_note($link['url']) | ||
1171 | ) { | ||
1170 | $thumbnailer = new Thumbnailer($conf); | 1172 | $thumbnailer = new Thumbnailer($conf); |
1171 | $link['thumbnail'] = $thumbnailer->get($url); | 1173 | $link['thumbnail'] = $thumbnailer->get($url); |
1172 | } | 1174 | } |
@@ -1550,7 +1552,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, | |||
1550 | $ids = []; | 1552 | $ids = []; |
1551 | foreach ($LINKSDB as $link) { | 1553 | foreach ($LINKSDB as $link) { |
1552 | // A note or not HTTP(S) | 1554 | // A note or not HTTP(S) |
1553 | if ($link['url'][0] === '?' || ! startsWith(strtolower($link['url']), 'http')) { | 1555 | if (is_note($link['url']) || ! startsWith(strtolower($link['url']), 'http')) { |
1554 | continue; | 1556 | continue; |
1555 | } | 1557 | } |
1556 | $ids[] = $link['id']; | 1558 | $ids[] = $link['id']; |
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php index bd08f036..25fb3043 100644 --- a/tests/bookmark/LinkUtilsTest.php +++ b/tests/bookmark/LinkUtilsTest.php | |||
@@ -289,6 +289,26 @@ class LinkUtilsTest extends \PHPUnit\Framework\TestCase | |||
289 | } | 289 | } |
290 | 290 | ||
291 | /** | 291 | /** |
292 | * Test is_note with note URLs. | ||
293 | */ | ||
294 | public function testIsNote() | ||
295 | { | ||
296 | $this->assertTrue(is_note('?')); | ||
297 | $this->assertTrue(is_note('?abcDEf')); | ||
298 | $this->assertTrue(is_note('?_abcDEf#123')); | ||
299 | } | ||
300 | |||
301 | /** | ||
302 | * Test is_note with non note URLs. | ||
303 | */ | ||
304 | public function testIsNotNote() | ||
305 | { | ||
306 | $this->assertFalse(is_note('')); | ||
307 | $this->assertFalse(is_note('nope')); | ||
308 | $this->assertFalse(is_note('https://github.com/shaarli/Shaarli/?hi')); | ||
309 | } | ||
310 | |||
311 | /** | ||
292 | * Util function to build an hashtag link. | 312 | * Util function to build an hashtag link. |
293 | * | 313 | * |
294 | * @param string $hashtag Hashtag name. | 314 | * @param string $hashtag Hashtag name. |