aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/api/ApiUtils.php2
-rw-r--r--application/bookmark/Bookmark.php4
-rw-r--r--application/container/ContainerBuilder.php5
-rw-r--r--application/feed/FeedBuilder.php2
-rw-r--r--application/formatter/BookmarkDefaultFormatter.php22
-rw-r--r--application/formatter/BookmarkFormatter.php6
-rw-r--r--application/formatter/FormatterFactory.php2
-rw-r--r--application/front/controller/visitor/BookmarkListController.php6
-rw-r--r--application/front/controller/visitor/DailyController.php1
-rw-r--r--application/netscape/NetscapeBookmarkUtils.php2
-rw-r--r--assets/default/js/base.js8
-rw-r--r--tests/api/controllers/links/PostLinkTest.php4
-rw-r--r--tests/api/controllers/links/PutLinkTest.php4
-rw-r--r--tests/bookmark/BookmarkFileServiceTest.php4
-rw-r--r--tests/bookmark/BookmarkTest.php4
-rw-r--r--tpl/default/daily.html2
16 files changed, 49 insertions, 29 deletions
diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php
index 5156a5f7..faebb8f5 100644
--- a/application/api/ApiUtils.php
+++ b/application/api/ApiUtils.php
@@ -67,7 +67,7 @@ class ApiUtils
67 if (! $bookmark->isNote()) { 67 if (! $bookmark->isNote()) {
68 $out['url'] = $bookmark->getUrl(); 68 $out['url'] = $bookmark->getUrl();
69 } else { 69 } else {
70 $out['url'] = $indexUrl . $bookmark->getUrl(); 70 $out['url'] = rtrim($indexUrl, '/') . '/' . ltrim($bookmark->getUrl(), '/');
71 } 71 }
72 $out['shorturl'] = $bookmark->getShortUrl(); 72 $out['shorturl'] = $bookmark->getShortUrl();
73 $out['title'] = $bookmark->getTitle(); 73 $out['title'] = $bookmark->getTitle();
diff --git a/application/bookmark/Bookmark.php b/application/bookmark/Bookmark.php
index 90ff5b16..c6f2c515 100644
--- a/application/bookmark/Bookmark.php
+++ b/application/bookmark/Bookmark.php
@@ -106,7 +106,7 @@ class Bookmark
106 throw new InvalidBookmarkException($this); 106 throw new InvalidBookmarkException($this);
107 } 107 }
108 if (empty($this->url)) { 108 if (empty($this->url)) {
109 $this->url = '?'. $this->shortUrl; 109 $this->url = '/shaare/'. $this->shortUrl;
110 } 110 }
111 if (empty($this->title)) { 111 if (empty($this->title)) {
112 $this->title = $this->url; 112 $this->title = $this->url;
@@ -406,7 +406,7 @@ class Bookmark
406 public function isNote() 406 public function isNote()
407 { 407 {
408 // We check empty value to get a valid result if the link has not been saved yet 408 // We check empty value to get a valid result if the link has not been saved yet
409 return empty($this->url) || $this->url[0] === '?'; 409 return empty($this->url) || startsWith($this->url, '/shaare/') || $this->url[0] === '?';
410 } 410 }
411 411
412 /** 412 /**
diff --git a/application/container/ContainerBuilder.php b/application/container/ContainerBuilder.php
index bfe93501..2e8c1ee3 100644
--- a/application/container/ContainerBuilder.php
+++ b/application/container/ContainerBuilder.php
@@ -105,7 +105,10 @@ class ContainerBuilder
105 }; 105 };
106 106
107 $container['formatterFactory'] = function (ShaarliContainer $container): FormatterFactory { 107 $container['formatterFactory'] = function (ShaarliContainer $container): FormatterFactory {
108 return new FormatterFactory($container->conf, $container->loginManager->isLoggedIn()); 108 return new FormatterFactory(
109 $container->conf,
110 $container->loginManager->isLoggedIn()
111 );
109 }; 112 };
110 113
111 $container['pageCacheManager'] = function (ShaarliContainer $container): PageCacheManager { 114 $container['pageCacheManager'] = function (ShaarliContainer $container): PageCacheManager {
diff --git a/application/feed/FeedBuilder.php b/application/feed/FeedBuilder.php
index c97ae1ea..269ad877 100644
--- a/application/feed/FeedBuilder.php
+++ b/application/feed/FeedBuilder.php
@@ -174,7 +174,7 @@ class FeedBuilder
174 protected function buildItem(string $feedType, $link, $pageaddr) 174 protected function buildItem(string $feedType, $link, $pageaddr)
175 { 175 {
176 $data = $this->formatter->format($link); 176 $data = $this->formatter->format($link);
177 $data['guid'] = $pageaddr . '?' . $data['shorturl']; 177 $data['guid'] = rtrim($pageaddr, '/') . '/shaare/' . $data['shorturl'];
178 if ($this->usePermalinks === true) { 178 if ($this->usePermalinks === true) {
179 $permalink = '<a href="'. $data['url'] .'" title="'. t('Direct link') .'">'. t('Direct link') .'</a>'; 179 $permalink = '<a href="'. $data['url'] .'" title="'. t('Direct link') .'">'. t('Direct link') .'</a>';
180 } else { 180 } else {
diff --git a/application/formatter/BookmarkDefaultFormatter.php b/application/formatter/BookmarkDefaultFormatter.php
index c6c59064..08e710eb 100644
--- a/application/formatter/BookmarkDefaultFormatter.php
+++ b/application/formatter/BookmarkDefaultFormatter.php
@@ -50,11 +50,10 @@ class BookmarkDefaultFormatter extends BookmarkFormatter
50 */ 50 */
51 public function formatUrl($bookmark) 51 public function formatUrl($bookmark)
52 { 52 {
53 if (! empty($this->contextData['index_url']) && ( 53 if ($bookmark->isNote() && !empty($this->contextData['index_url'])) {
54 startsWith($bookmark->getUrl(), '?') || startsWith($bookmark->getUrl(), '/') 54 return rtrim($this->contextData['index_url'], '/') . '/' . escape(ltrim($bookmark->getUrl(), '/'));
55 )) {
56 return $this->contextData['index_url'] . escape($bookmark->getUrl());
57 } 55 }
56
58 return escape($bookmark->getUrl()); 57 return escape($bookmark->getUrl());
59 } 58 }
60 59
@@ -63,11 +62,18 @@ class BookmarkDefaultFormatter extends BookmarkFormatter
63 */ 62 */
64 protected function formatRealUrl($bookmark) 63 protected function formatRealUrl($bookmark)
65 { 64 {
66 if (! empty($this->contextData['index_url']) && ( 65 if ($bookmark->isNote()) {
67 startsWith($bookmark->getUrl(), '?') || startsWith($bookmark->getUrl(), '/') 66 if (!empty($this->contextData['index_url'])) {
68 )) { 67 $prefix = rtrim($this->contextData['index_url'], '/') . '/';
69 return $this->contextData['index_url'] . escape($bookmark->getUrl()); 68 }
69
70 if (!empty($this->contextData['base_path'])) {
71 $prefix = rtrim($this->contextData['base_path'], '/') . '/';
72 }
73
74 return escape($prefix ?? '') . escape(ltrim($bookmark->getUrl(), '/'));
70 } 75 }
76
71 return escape($bookmark->getUrl()); 77 return escape($bookmark->getUrl());
72 } 78 }
73 79
diff --git a/application/formatter/BookmarkFormatter.php b/application/formatter/BookmarkFormatter.php
index a80d83fc..22ba7aae 100644
--- a/application/formatter/BookmarkFormatter.php
+++ b/application/formatter/BookmarkFormatter.php
@@ -3,8 +3,8 @@
3namespace Shaarli\Formatter; 3namespace Shaarli\Formatter;
4 4
5use DateTime; 5use DateTime;
6use Shaarli\Config\ConfigManager;
7use Shaarli\Bookmark\Bookmark; 6use Shaarli\Bookmark\Bookmark;
7use Shaarli\Config\ConfigManager;
8 8
9/** 9/**
10 * Class BookmarkFormatter 10 * Class BookmarkFormatter
@@ -80,6 +80,8 @@ abstract class BookmarkFormatter
80 public function addContextData($key, $value) 80 public function addContextData($key, $value)
81 { 81 {
82 $this->contextData[$key] = $value; 82 $this->contextData[$key] = $value;
83
84 return $this;
83 } 85 }
84 86
85 /** 87 /**
@@ -128,7 +130,7 @@ abstract class BookmarkFormatter
128 */ 130 */
129 protected function formatRealUrl($bookmark) 131 protected function formatRealUrl($bookmark)
130 { 132 {
131 return $bookmark->getUrl(); 133 return $this->formatUrl($bookmark);
132 } 134 }
133 135
134 /** 136 /**
diff --git a/application/formatter/FormatterFactory.php b/application/formatter/FormatterFactory.php
index 5f282f68..a029579f 100644
--- a/application/formatter/FormatterFactory.php
+++ b/application/formatter/FormatterFactory.php
@@ -38,7 +38,7 @@ class FormatterFactory
38 * 38 *
39 * @return BookmarkFormatter instance. 39 * @return BookmarkFormatter instance.
40 */ 40 */
41 public function getFormatter(string $type = null) 41 public function getFormatter(string $type = null): BookmarkFormatter
42 { 42 {
43 $type = $type ? $type : $this->conf->get('formatter', 'default'); 43 $type = $type ? $type : $this->conf->get('formatter', 'default');
44 $className = '\\Shaarli\\Formatter\\Bookmark'. ucfirst($type) .'Formatter'; 44 $className = '\\Shaarli\\Formatter\\Bookmark'. ucfirst($type) .'Formatter';
diff --git a/application/front/controller/visitor/BookmarkListController.php b/application/front/controller/visitor/BookmarkListController.php
index 23c4fbae..2988bee6 100644
--- a/application/front/controller/visitor/BookmarkListController.php
+++ b/application/front/controller/visitor/BookmarkListController.php
@@ -32,6 +32,7 @@ class BookmarkListController extends ShaarliVisitorController
32 } 32 }
33 33
34 $formatter = $this->container->formatterFactory->getFormatter(); 34 $formatter = $this->container->formatterFactory->getFormatter();
35 $formatter->addContextData('base_path', $this->container->basePath);
35 36
36 $searchTags = escape(normalize_spaces($request->getParam('searchtags') ?? '')); 37 $searchTags = escape(normalize_spaces($request->getParam('searchtags') ?? ''));
37 $searchTerm = escape(normalize_spaces($request->getParam('searchterm') ?? ''));; 38 $searchTerm = escape(normalize_spaces($request->getParam('searchterm') ?? ''));;
@@ -145,11 +146,14 @@ class BookmarkListController extends ShaarliVisitorController
145 146
146 $this->updateThumbnail($bookmark); 147 $this->updateThumbnail($bookmark);
147 148
149 $formatter = $this->container->formatterFactory->getFormatter();
150 $formatter->addContextData('base_path', $this->container->basePath);
151
148 $data = array_merge( 152 $data = array_merge(
149 $this->initializeTemplateVars(), 153 $this->initializeTemplateVars(),
150 [ 154 [
151 'pagetitle' => $bookmark->getTitle() .' - '. $this->container->conf->get('general.title', 'Shaarli'), 155 'pagetitle' => $bookmark->getTitle() .' - '. $this->container->conf->get('general.title', 'Shaarli'),
152 'links' => [$this->container->formatterFactory->getFormatter()->format($bookmark)], 156 'links' => [$formatter->format($bookmark)],
153 ] 157 ]
154 ); 158 );
155 159
diff --git a/application/front/controller/visitor/DailyController.php b/application/front/controller/visitor/DailyController.php
index 808ca5f7..54a4778f 100644
--- a/application/front/controller/visitor/DailyController.php
+++ b/application/front/controller/visitor/DailyController.php
@@ -54,6 +54,7 @@ class DailyController extends ShaarliVisitorController
54 } 54 }
55 55
56 $formatter = $this->container->formatterFactory->getFormatter(); 56 $formatter = $this->container->formatterFactory->getFormatter();
57 $formatter->addContextData('base_path', $this->container->basePath);
57 // We pre-format some fields for proper output. 58 // We pre-format some fields for proper output.
58 foreach ($linksToDisplay as $key => $bookmark) { 59 foreach ($linksToDisplay as $key => $bookmark) {
59 $linksToDisplay[$key] = $formatter->format($bookmark); 60 $linksToDisplay[$key] = $formatter->format($bookmark);
diff --git a/application/netscape/NetscapeBookmarkUtils.php b/application/netscape/NetscapeBookmarkUtils.php
index b150f649..b83f16f8 100644
--- a/application/netscape/NetscapeBookmarkUtils.php
+++ b/application/netscape/NetscapeBookmarkUtils.php
@@ -68,7 +68,7 @@ class NetscapeBookmarkUtils
68 $link = $formatter->format($bookmark); 68 $link = $formatter->format($bookmark);
69 $link['taglist'] = implode(',', $bookmark->getTags()); 69 $link['taglist'] = implode(',', $bookmark->getTags());
70 if ($bookmark->isNote() && $prependNoteUrl) { 70 if ($bookmark->isNote() && $prependNoteUrl) {
71 $link['url'] = $indexUrl . $link['url']; 71 $link['url'] = rtrim($indexUrl, '/') . '/' . ltrim($link['url'], '/');
72 } 72 }
73 73
74 $bookmarkLinks[] = $link; 74 $bookmarkLinks[] = $link;
diff --git a/assets/default/js/base.js b/assets/default/js/base.js
index 76e4fe2a..0f29799d 100644
--- a/assets/default/js/base.js
+++ b/assets/default/js/base.js
@@ -26,11 +26,15 @@ function findParent(element, tagName, attributes) {
26 * Ajax request to refresh the CSRF token. 26 * Ajax request to refresh the CSRF token.
27 */ 27 */
28function refreshToken(basePath) { 28function refreshToken(basePath) {
29 console.log('refresh');
29 const xhr = new XMLHttpRequest(); 30 const xhr = new XMLHttpRequest();
30 xhr.open('GET', `${basePath}/admin/token`); 31 xhr.open('GET', `${basePath}/admin/token`);
31 xhr.onload = () => { 32 xhr.onload = () => {
32 const token = document.getElementById('token'); 33 const elements = document.querySelectorAll('input[name="token"]');
33 token.setAttribute('value', xhr.responseText); 34 [...elements].forEach((element) => {
35 console.log(element);
36 element.setAttribute('value', xhr.responseText);
37 });
34 }; 38 };
35 xhr.send(); 39 xhr.send();
36} 40}
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php
index b2dd09eb..4e791a04 100644
--- a/tests/api/controllers/links/PostLinkTest.php
+++ b/tests/api/controllers/links/PostLinkTest.php
@@ -131,8 +131,8 @@ class PostLinkTest extends TestCase
131 $this->assertEquals(self::NB_FIELDS_LINK, count($data)); 131 $this->assertEquals(self::NB_FIELDS_LINK, count($data));
132 $this->assertEquals(43, $data['id']); 132 $this->assertEquals(43, $data['id']);
133 $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']); 133 $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']);
134 $this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']); 134 $this->assertEquals('http://domain.tld/shaare/' . $data['shorturl'], $data['url']);
135 $this->assertEquals('?' . $data['shorturl'], $data['title']); 135 $this->assertEquals('/shaare/' . $data['shorturl'], $data['title']);
136 $this->assertEquals('', $data['description']); 136 $this->assertEquals('', $data['description']);
137 $this->assertEquals([], $data['tags']); 137 $this->assertEquals([], $data['tags']);
138 $this->assertEquals(true, $data['private']); 138 $this->assertEquals(true, $data['private']);
diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php
index cb63742e..302cac0f 100644
--- a/tests/api/controllers/links/PutLinkTest.php
+++ b/tests/api/controllers/links/PutLinkTest.php
@@ -114,8 +114,8 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase
114 $this->assertEquals(self::NB_FIELDS_LINK, count($data)); 114 $this->assertEquals(self::NB_FIELDS_LINK, count($data));
115 $this->assertEquals($id, $data['id']); 115 $this->assertEquals($id, $data['id']);
116 $this->assertEquals('WDWyig', $data['shorturl']); 116 $this->assertEquals('WDWyig', $data['shorturl']);
117 $this->assertEquals('http://domain.tld/?WDWyig', $data['url']); 117 $this->assertEquals('http://domain.tld/shaare/WDWyig', $data['url']);
118 $this->assertEquals('?WDWyig', $data['title']); 118 $this->assertEquals('/shaare/WDWyig', $data['title']);
119 $this->assertEquals('', $data['description']); 119 $this->assertEquals('', $data['description']);
120 $this->assertEquals([], $data['tags']); 120 $this->assertEquals([], $data['tags']);
121 $this->assertEquals(true, $data['private']); 121 $this->assertEquals(true, $data['private']);
diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php
index b19c8250..a8bf47cb 100644
--- a/tests/bookmark/BookmarkFileServiceTest.php
+++ b/tests/bookmark/BookmarkFileServiceTest.php
@@ -200,7 +200,7 @@ class BookmarkFileServiceTest extends TestCase
200 200
201 $bookmark = $this->privateLinkDB->get(43); 201 $bookmark = $this->privateLinkDB->get(43);
202 $this->assertEquals(43, $bookmark->getId()); 202 $this->assertEquals(43, $bookmark->getId());
203 $this->assertRegExp('/\?[\w\-]{6}/', $bookmark->getUrl()); 203 $this->assertRegExp('#/shaare/[\w\-]{6}#', $bookmark->getUrl());
204 $this->assertRegExp('/[\w\-]{6}/', $bookmark->getShortUrl()); 204 $this->assertRegExp('/[\w\-]{6}/', $bookmark->getShortUrl());
205 $this->assertEquals($bookmark->getUrl(), $bookmark->getTitle()); 205 $this->assertEquals($bookmark->getUrl(), $bookmark->getTitle());
206 $this->assertEmpty($bookmark->getDescription()); 206 $this->assertEmpty($bookmark->getDescription());
@@ -216,7 +216,7 @@ class BookmarkFileServiceTest extends TestCase
216 216
217 $bookmark = $this->privateLinkDB->get(43); 217 $bookmark = $this->privateLinkDB->get(43);
218 $this->assertEquals(43, $bookmark->getId()); 218 $this->assertEquals(43, $bookmark->getId());
219 $this->assertRegExp('/\?[\w\-]{6}/', $bookmark->getUrl()); 219 $this->assertRegExp('#/shaare/[\w\-]{6}#', $bookmark->getUrl());
220 $this->assertRegExp('/[\w\-]{6}/', $bookmark->getShortUrl()); 220 $this->assertRegExp('/[\w\-]{6}/', $bookmark->getShortUrl());
221 $this->assertEquals($bookmark->getUrl(), $bookmark->getTitle()); 221 $this->assertEquals($bookmark->getUrl(), $bookmark->getTitle());
222 $this->assertEmpty($bookmark->getDescription()); 222 $this->assertEmpty($bookmark->getDescription());
diff --git a/tests/bookmark/BookmarkTest.php b/tests/bookmark/BookmarkTest.php
index 9a3bbbfc..4b6a3c07 100644
--- a/tests/bookmark/BookmarkTest.php
+++ b/tests/bookmark/BookmarkTest.php
@@ -124,8 +124,8 @@ class BookmarkTest extends TestCase
124 $this->assertEquals(1, $bookmark->getId()); 124 $this->assertEquals(1, $bookmark->getId());
125 $this->assertEquals('abc', $bookmark->getShortUrl()); 125 $this->assertEquals('abc', $bookmark->getShortUrl());
126 $this->assertEquals($date, $bookmark->getCreated()); 126 $this->assertEquals($date, $bookmark->getCreated());
127 $this->assertEquals('?abc', $bookmark->getUrl()); 127 $this->assertEquals('/shaare/abc', $bookmark->getUrl());
128 $this->assertEquals('?abc', $bookmark->getTitle()); 128 $this->assertEquals('/shaare/abc', $bookmark->getTitle());
129 $this->assertEquals('', $bookmark->getDescription()); 129 $this->assertEquals('', $bookmark->getDescription());
130 $this->assertEquals([], $bookmark->getTags()); 130 $this->assertEquals([], $bookmark->getTags());
131 $this->assertEquals('', $bookmark->getTagsString()); 131 $this->assertEquals('', $bookmark->getTagsString());
diff --git a/tpl/default/daily.html b/tpl/default/daily.html
index aa34bd1c..3ab8053f 100644
--- a/tpl/default/daily.html
+++ b/tpl/default/daily.html
@@ -85,7 +85,7 @@
85 {if="$link.tags"} 85 {if="$link.tags"}
86 <div class="daily-entry-tags center"> 86 <div class="daily-entry-tags center">
87 {loop="link.taglist"} 87 {loop="link.taglist"}
88 <span class="label label-tag" title="Add tag"> 88 <span class="label label-tag">
89 {$value} 89 {$value}
90 </span> 90 </span>
91 {/loop} 91 {/loop}