From a8e7da01146455f13ef06b151a7dafedd3acf769 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 9 Feb 2019 14:13:08 +0100 Subject: Do not try to retrieve thumbnails for internal link Also adds a helper function to determine if a link is a note and apply it across multiple files. --- application/api/ApiUtils.php | 2 +- application/bookmark/LinkUtils.php | 13 +++++++++++++ application/feed/FeedBuilder.php | 4 ++-- application/netscape/NetscapeBookmarkUtils.php | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) (limited to 'application') 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 { $out['id'] = $link['id']; // Not an internal link - if ($link['url'][0] != '?') { + if (! is_note($link['url'])) { $out['url'] = $link['url']; } else { $out['url'] = $indexUrl . $link['url']; diff --git a/application/bookmark/LinkUtils.php b/application/bookmark/LinkUtils.php index de5b61cb..9e9d4f0a 100644 --- a/application/bookmark/LinkUtils.php +++ b/application/bookmark/LinkUtils.php @@ -220,3 +220,16 @@ function link_small_hash($date, $id) { return smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id); } + +/** + * Returns whether or not the link is an internal note. + * Its URL starts by `?` because it's actually a permalink. + * + * @param string $linkUrl + * + * @return bool true if internal note, false otherwise. + */ +function is_note($linkUrl) +{ + return isset($linkUrl[0]) && $linkUrl[0] === '?'; +} diff --git a/application/feed/FeedBuilder.php b/application/feed/FeedBuilder.php index b66f2f91..fec0452b 100644 --- a/application/feed/FeedBuilder.php +++ b/application/feed/FeedBuilder.php @@ -147,8 +147,8 @@ class FeedBuilder protected function buildItem($link, $pageaddr) { $link['guid'] = $pageaddr . '?' . $link['shorturl']; - // Check for both signs of a note: starting with ? and 7 chars long. - if ($link['url'][0] === '?' && strlen($link['url']) === 7) { + // Prepend the root URL for notes + if (is_note($link['url'])) { $link['url'] = $pageaddr . $link['url']; } 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 $link['timestamp'] = $date->getTimestamp(); $link['taglist'] = str_replace(' ', ',', $link['tags']); - if (startsWith($link['url'], '?') && $prependNoteUrl) { + if (is_note($link['url']) && $prependNoteUrl) { $link['url'] = $indexUrl . $link['url']; } -- cgit v1.2.3