aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/api/ApiUtils.php2
-rw-r--r--application/bookmark/LinkUtils.php13
-rw-r--r--application/feed/FeedBuilder.php4
-rw-r--r--application/netscape/NetscapeBookmarkUtils.php2
-rw-r--r--index.php8
-rw-r--r--tests/bookmark/LinkUtilsTest.php20
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 de5b61cb..9e9d4f0a 100644
--- a/application/bookmark/LinkUtils.php
+++ b/application/bookmark/LinkUtils.php
@@ -220,3 +220,16 @@ function link_small_hash($date, $id)
220{ 220{
221 return smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id); 221 return smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id);
222} 222}
223
224/**
225 * Returns whether or not the link is an internal note.
226 * Its URL starts by `?` because it's actually a permalink.
227 *
228 * @param string $linkUrl
229 *
230 * @return bool true if internal note, false otherwise.
231 */
232function is_note($linkUrl)
233{
234 return isset($linkUrl[0]) && $linkUrl[0] === '?';
235}
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
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
diff --git a/index.php b/index.php
index 633ab89e..7b54f98f 100644
--- a/index.php
+++ b/index.php
@@ -362,7 +362,7 @@ function showDailyRSS($conf, $loginManager)
362 $conf->get('redirector.encode_url') 362 $conf->get('redirector.encode_url')
363 ); 363 );
364 $link['timestamp'] = $link['created']->getTimestamp(); 364 $link['timestamp'] = $link['created']->getTimestamp();
365 if (startsWith($link['url'], '?')) { 365 if (is_note($link['url'])) {
366 $link['url'] = index_url($_SERVER) . $link['url']; // make permalink URL absolute 366 $link['url'] = index_url($_SERVER) . $link['url']; // make permalink URL absolute
367 } 367 }
368 } 368 }
@@ -1176,7 +1176,9 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1176 $link['title'] = $link['url']; 1176 $link['title'] = $link['url'];
1177 } 1177 }
1178 1178
1179 if ($conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE) { 1179 if ($conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE
1180 && ! is_note($link['url'])
1181 ) {
1180 $thumbnailer = new Thumbnailer($conf); 1182 $thumbnailer = new Thumbnailer($conf);
1181 $link['thumbnail'] = $thumbnailer->get($url); 1183 $link['thumbnail'] = $thumbnailer->get($url);
1182 } 1184 }
@@ -1558,7 +1560,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1558 $ids = []; 1560 $ids = [];
1559 foreach ($LINKSDB as $link) { 1561 foreach ($LINKSDB as $link) {
1560 // A note or not HTTP(S) 1562 // A note or not HTTP(S)
1561 if ($link['url'][0] === '?' || ! startsWith(strtolower($link['url']), 'http')) { 1563 if (is_note($link['url']) || ! startsWith(strtolower($link['url']), 'http')) {
1562 continue; 1564 continue;
1563 } 1565 }
1564 $ids[] = $link['id']; 1566 $ids[] = $link['id'];
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php
index 1b8688e6..5b31115b 100644
--- a/tests/bookmark/LinkUtilsTest.php
+++ b/tests/bookmark/LinkUtilsTest.php
@@ -318,6 +318,26 @@ class LinkUtilsTest extends \PHPUnit\Framework\TestCase
318 } 318 }
319 319
320 /** 320 /**
321 * Test is_note with note URLs.
322 */
323 public function testIsNote()
324 {
325 $this->assertTrue(is_note('?'));
326 $this->assertTrue(is_note('?abcDEf'));
327 $this->assertTrue(is_note('?_abcDEf#123'));
328 }
329
330 /**
331 * Test is_note with non note URLs.
332 */
333 public function testIsNotNote()
334 {
335 $this->assertFalse(is_note(''));
336 $this->assertFalse(is_note('nope'));
337 $this->assertFalse(is_note('https://github.com/shaarli/Shaarli/?hi'));
338 }
339
340 /**
321 * Util function to build an hashtag link. 341 * Util function to build an hashtag link.
322 * 342 *
323 * @param string $hashtag Hashtag name. 343 * @param string $hashtag Hashtag name.