]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #1271 from ArthurHoaro/hotfix/thumb-note-retrieve
authorArthurHoaro <arthur@hoa.ro>
Sat, 2 Mar 2019 09:54:06 +0000 (10:54 +0100)
committerGitHub <noreply@github.com>
Sat, 2 Mar 2019 09:54:06 +0000 (10:54 +0100)
Do not try to retrieve thumbnails for internal link

application/api/ApiUtils.php
application/bookmark/LinkUtils.php
application/feed/FeedBuilder.php
application/netscape/NetscapeBookmarkUtils.php
index.php
tests/bookmark/LinkUtilsTest.php

index 1824b5d08171f19c27ebb28d3831eacbfc040538..1e3ac02e110bdb137d7f52a2ce521d079ef13875 100644 (file)
@@ -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'];
index 988970bdf924854ba06fa352a61a1d3c62da94bd..35a5b290454b32870464c6457fea73059d613f4c 100644 (file)
@@ -204,3 +204,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] === '?';
+}
index e23b34525b02f6e0920777e51e8cc42ee5d0dca4..7c859474de414773052c0c5e79dd1583dfcd046f 100644 (file)
@@ -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) {
index 2fb1a4a6943674c557188e28bb5df206867f3857..28665941507366a364930f4adcdde702cf983a25 100644 (file)
@@ -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'];
             }
 
index 3700504b8a9e86422b1570a315b76c207daa35b8..a43063b041a43ea2e323782ca798a6977a558e9a 100644 (file)
--- a/index.php
+++ b/index.php
@@ -356,7 +356,7 @@ function showDailyRSS($conf, $loginManager)
         foreach ($links as &$link) {
             $link['formatedDescription'] = format_description($link['description']);
             $link['timestamp'] = $link['created']->getTimestamp();
-            if (startsWith($link['url'], '?')) {
+            if (is_note($link['url'])) {
                 $link['url'] = index_url($_SERVER) . $link['url'];  // make permalink URL absolute
             }
         }
@@ -1166,7 +1166,9 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
             $link['title'] = $link['url'];
         }
 
-        if ($conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE) {
+        if ($conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE
+            && ! is_note($link['url'])
+        ) {
             $thumbnailer = new Thumbnailer($conf);
             $link['thumbnail'] = $thumbnailer->get($url);
         }
@@ -1550,7 +1552,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
         $ids = [];
         foreach ($LINKSDB as $link) {
             // A note or not HTTP(S)
-            if ($link['url'][0] === '?' || ! startsWith(strtolower($link['url']), 'http')) {
+            if (is_note($link['url']) || ! startsWith(strtolower($link['url']), 'http')) {
                 continue;
             }
             $ids[] = $link['id'];
index bd08f03670a68cba16bea8895a906b35c5b953ec..25fb30435c8ef09c91623f6b416c1b6300ff459e 100644 (file)
@@ -288,6 +288,26 @@ class LinkUtilsTest extends \PHPUnit\Framework\TestCase
         $this->assertNotContains('>#nothashtag', $autolinkedDescription);
     }
 
+    /**
+     * Test is_note with note URLs.
+     */
+    public function testIsNote()
+    {
+        $this->assertTrue(is_note('?'));
+        $this->assertTrue(is_note('?abcDEf'));
+        $this->assertTrue(is_note('?_abcDEf#123'));
+    }
+
+    /**
+     * Test is_note with non note URLs.
+     */
+    public function testIsNotNote()
+    {
+        $this->assertFalse(is_note(''));
+        $this->assertFalse(is_note('nope'));
+        $this->assertFalse(is_note('https://github.com/shaarli/Shaarli/?hi'));
+    }
+
     /**
      * Util function to build an hashtag link.
      *