diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-07-28 20:46:11 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-28 20:46:11 +0200 |
commit | 301c7ab1a079d937ab41c6f52b8804e5731008e6 (patch) | |
tree | da6a5ed2a436fea87a3fe83fe72483c3f07c5826 /application | |
parent | b725eb047d233d6c7a505f160b57ebc399a24d45 (diff) | |
download | Shaarli-301c7ab1a079d937ab41c6f52b8804e5731008e6.tar.gz Shaarli-301c7ab1a079d937ab41c6f52b8804e5731008e6.tar.zst Shaarli-301c7ab1a079d937ab41c6f52b8804e5731008e6.zip |
Better support for notes permalink
Diffstat (limited to 'application')
-rw-r--r-- | application/api/ApiUtils.php | 2 | ||||
-rw-r--r-- | application/bookmark/Bookmark.php | 4 | ||||
-rw-r--r-- | application/container/ContainerBuilder.php | 5 | ||||
-rw-r--r-- | application/feed/FeedBuilder.php | 2 | ||||
-rw-r--r-- | application/formatter/BookmarkDefaultFormatter.php | 22 | ||||
-rw-r--r-- | application/formatter/BookmarkFormatter.php | 6 | ||||
-rw-r--r-- | application/formatter/FormatterFactory.php | 2 | ||||
-rw-r--r-- | application/front/controller/visitor/BookmarkListController.php | 6 | ||||
-rw-r--r-- | application/front/controller/visitor/DailyController.php | 1 | ||||
-rw-r--r-- | application/netscape/NetscapeBookmarkUtils.php | 2 |
10 files changed, 34 insertions, 18 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 @@ | |||
3 | namespace Shaarli\Formatter; | 3 | namespace Shaarli\Formatter; |
4 | 4 | ||
5 | use DateTime; | 5 | use DateTime; |
6 | use Shaarli\Config\ConfigManager; | ||
7 | use Shaarli\Bookmark\Bookmark; | 6 | use Shaarli\Bookmark\Bookmark; |
7 | use 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; |