aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-01-18 17:59:37 +0100
committerGitHub <noreply@github.com>2020-01-18 17:59:37 +0100
commit1001cc108fec759b076c9f6e12b71dea5d49fe9b (patch)
treed7b57a982129b2006d388c2f9d25d29eceee891a /application
parent12523aea3458504be91854ce2f37d4f5991ccea2 (diff)
parenta39acb2518f272df8a601af72c13eabe2719dcb8 (diff)
downloadShaarli-1001cc108fec759b076c9f6e12b71dea5d49fe9b.tar.gz
Shaarli-1001cc108fec759b076c9f6e12b71dea5d49fe9b.tar.zst
Shaarli-1001cc108fec759b076c9f6e12b71dea5d49fe9b.zip
Fix an issue with private tags and fix nomarkdown tag (#1399)
Fix an issue with private tags and fix nomarkdown tag
Diffstat (limited to 'application')
-rw-r--r--application/bookmark/BookmarkFileService.php9
-rw-r--r--application/formatter/BookmarkDefaultFormatter.php2
-rw-r--r--application/formatter/BookmarkFormatter.php35
-rw-r--r--application/formatter/BookmarkMarkdownFormatter.php8
-rw-r--r--application/formatter/FormatterFactory.php11
5 files changed, 53 insertions, 12 deletions
diff --git a/application/bookmark/BookmarkFileService.php b/application/bookmark/BookmarkFileService.php
index a56cc92b..9c59e139 100644
--- a/application/bookmark/BookmarkFileService.php
+++ b/application/bookmark/BookmarkFileService.php
@@ -8,6 +8,7 @@ use Exception;
8use Shaarli\Bookmark\Exception\BookmarkNotFoundException; 8use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
9use Shaarli\Bookmark\Exception\EmptyDataStoreException; 9use Shaarli\Bookmark\Exception\EmptyDataStoreException;
10use Shaarli\Config\ConfigManager; 10use Shaarli\Config\ConfigManager;
11use Shaarli\Formatter\BookmarkMarkdownFormatter;
11use Shaarli\History; 12use Shaarli\History;
12use Shaarli\Legacy\LegacyLinkDB; 13use Shaarli\Legacy\LegacyLinkDB;
13use Shaarli\Legacy\LegacyUpdater; 14use Shaarli\Legacy\LegacyUpdater;
@@ -130,7 +131,7 @@ class BookmarkFileService implements BookmarkServiceInterface
130 } 131 }
131 132
132 if ($visibility === null) { 133 if ($visibility === null) {
133 $visibility = $this->isLoggedIn ? 'all' : 'public'; 134 $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC;
134 } 135 }
135 136
136 $bookmark = $this->bookmarks[$id]; 137 $bookmark = $this->bookmarks[$id];
@@ -287,9 +288,13 @@ class BookmarkFileService implements BookmarkServiceInterface
287 $caseMapping = []; 288 $caseMapping = [];
288 foreach ($bookmarks as $bookmark) { 289 foreach ($bookmarks as $bookmark) {
289 foreach ($bookmark->getTags() as $tag) { 290 foreach ($bookmark->getTags() as $tag) {
290 if (empty($tag) || (! $this->isLoggedIn && startsWith($tag, '.'))) { 291 if (empty($tag)
292 || (! $this->isLoggedIn && startsWith($tag, '.'))
293 || $tag === BookmarkMarkdownFormatter::NO_MD_TAG
294 ) {
291 continue; 295 continue;
292 } 296 }
297
293 // The first case found will be displayed. 298 // The first case found will be displayed.
294 if (!isset($caseMapping[strtolower($tag)])) { 299 if (!isset($caseMapping[strtolower($tag)])) {
295 $caseMapping[strtolower($tag)] = $tag; 300 $caseMapping[strtolower($tag)] = $tag;
diff --git a/application/formatter/BookmarkDefaultFormatter.php b/application/formatter/BookmarkDefaultFormatter.php
index 7550c556..c6c59064 100644
--- a/application/formatter/BookmarkDefaultFormatter.php
+++ b/application/formatter/BookmarkDefaultFormatter.php
@@ -34,7 +34,7 @@ class BookmarkDefaultFormatter extends BookmarkFormatter
34 */ 34 */
35 protected function formatTagList($bookmark) 35 protected function formatTagList($bookmark)
36 { 36 {
37 return escape($bookmark->getTags()); 37 return escape(parent::formatTagList($bookmark));
38 } 38 }
39 39
40 /** 40 /**
diff --git a/application/formatter/BookmarkFormatter.php b/application/formatter/BookmarkFormatter.php
index c82c3452..a80d83fc 100644
--- a/application/formatter/BookmarkFormatter.php
+++ b/application/formatter/BookmarkFormatter.php
@@ -20,6 +20,9 @@ abstract class BookmarkFormatter
20 */ 20 */
21 protected $conf; 21 protected $conf;
22 22
23 /** @var bool */
24 protected $isLoggedIn;
25
23 /** 26 /**
24 * @var array Additional parameters than can be used for specific formatting 27 * @var array Additional parameters than can be used for specific formatting
25 * e.g. index_url for Feed formatting 28 * e.g. index_url for Feed formatting
@@ -30,9 +33,10 @@ abstract class BookmarkFormatter
30 * LinkDefaultFormatter constructor. 33 * LinkDefaultFormatter constructor.
31 * @param ConfigManager $conf 34 * @param ConfigManager $conf
32 */ 35 */
33 public function __construct(ConfigManager $conf) 36 public function __construct(ConfigManager $conf, bool $isLoggedIn)
34 { 37 {
35 $this->conf = $conf; 38 $this->conf = $conf;
39 $this->isLoggedIn = $isLoggedIn;
36 } 40 }
37 41
38 /** 42 /**
@@ -172,7 +176,7 @@ abstract class BookmarkFormatter
172 */ 176 */
173 protected function formatTagList($bookmark) 177 protected function formatTagList($bookmark)
174 { 178 {
175 return $bookmark->getTags(); 179 return $this->filterTagList($bookmark->getTags());
176 } 180 }
177 181
178 /** 182 /**
@@ -184,7 +188,7 @@ abstract class BookmarkFormatter
184 */ 188 */
185 protected function formatTagString($bookmark) 189 protected function formatTagString($bookmark)
186 { 190 {
187 return implode(' ', $bookmark->getTags()); 191 return implode(' ', $this->formatTagList($bookmark));
188 } 192 }
189 193
190 /** 194 /**
@@ -253,4 +257,29 @@ abstract class BookmarkFormatter
253 } 257 }
254 return 0; 258 return 0;
255 } 259 }
260
261 /**
262 * Format tag list, e.g. remove private tags if the user is not logged in.
263 *
264 * @param array $tags
265 *
266 * @return array
267 */
268 protected function filterTagList(array $tags): array
269 {
270 if ($this->isLoggedIn === true) {
271 return $tags;
272 }
273
274 $out = [];
275 foreach ($tags as $tag) {
276 if (strpos($tag, '.') === 0) {
277 continue;
278 }
279
280 $out[] = $tag;
281 }
282
283 return $out;
284 }
256} 285}
diff --git a/application/formatter/BookmarkMarkdownFormatter.php b/application/formatter/BookmarkMarkdownFormatter.php
index 7797bfbf..077e5312 100644
--- a/application/formatter/BookmarkMarkdownFormatter.php
+++ b/application/formatter/BookmarkMarkdownFormatter.php
@@ -36,10 +36,12 @@ class BookmarkMarkdownFormatter extends BookmarkDefaultFormatter
36 * LinkMarkdownFormatter constructor. 36 * LinkMarkdownFormatter constructor.
37 * 37 *
38 * @param ConfigManager $conf instance 38 * @param ConfigManager $conf instance
39 * @param bool $isLoggedIn
39 */ 40 */
40 public function __construct(ConfigManager $conf) 41 public function __construct(ConfigManager $conf, bool $isLoggedIn)
41 { 42 {
42 parent::__construct($conf); 43 parent::__construct($conf, $isLoggedIn);
44
43 $this->parsedown = new \Parsedown(); 45 $this->parsedown = new \Parsedown();
44 $this->escape = $conf->get('security.markdown_escape', true); 46 $this->escape = $conf->get('security.markdown_escape', true);
45 $this->allowedProtocols = $conf->get('security.allowed_protocols', []); 47 $this->allowedProtocols = $conf->get('security.allowed_protocols', []);
@@ -79,7 +81,7 @@ class BookmarkMarkdownFormatter extends BookmarkDefaultFormatter
79 protected function formatTagList($bookmark) 81 protected function formatTagList($bookmark)
80 { 82 {
81 $out = parent::formatTagList($bookmark); 83 $out = parent::formatTagList($bookmark);
82 if (($pos = array_search(self::NO_MD_TAG, $out)) !== false) { 84 if ($this->isLoggedIn === false && ($pos = array_search(self::NO_MD_TAG, $out)) !== false) {
83 unset($out[$pos]); 85 unset($out[$pos]);
84 return array_values($out); 86 return array_values($out);
85 } 87 }
diff --git a/application/formatter/FormatterFactory.php b/application/formatter/FormatterFactory.php
index 0d2c0466..5f282f68 100644
--- a/application/formatter/FormatterFactory.php
+++ b/application/formatter/FormatterFactory.php
@@ -16,14 +16,19 @@ class FormatterFactory
16 /** @var ConfigManager instance */ 16 /** @var ConfigManager instance */
17 protected $conf; 17 protected $conf;
18 18
19 /** @var bool */
20 protected $isLoggedIn;
21
19 /** 22 /**
20 * FormatterFactory constructor. 23 * FormatterFactory constructor.
21 * 24 *
22 * @param ConfigManager $conf 25 * @param ConfigManager $conf
26 * @param bool $isLoggedIn
23 */ 27 */
24 public function __construct(ConfigManager $conf) 28 public function __construct(ConfigManager $conf, bool $isLoggedIn)
25 { 29 {
26 $this->conf = $conf; 30 $this->conf = $conf;
31 $this->isLoggedIn = $isLoggedIn;
27 } 32 }
28 33
29 /** 34 /**
@@ -33,7 +38,7 @@ class FormatterFactory
33 * 38 *
34 * @return BookmarkFormatter instance. 39 * @return BookmarkFormatter instance.
35 */ 40 */
36 public function getFormatter($type = null) 41 public function getFormatter(string $type = null)
37 { 42 {
38 $type = $type ? $type : $this->conf->get('formatter', 'default'); 43 $type = $type ? $type : $this->conf->get('formatter', 'default');
39 $className = '\\Shaarli\\Formatter\\Bookmark'. ucfirst($type) .'Formatter'; 44 $className = '\\Shaarli\\Formatter\\Bookmark'. ucfirst($type) .'Formatter';
@@ -41,6 +46,6 @@ class FormatterFactory
41 $className = '\\Shaarli\\Formatter\\BookmarkDefaultFormatter'; 46 $className = '\\Shaarli\\Formatter\\BookmarkDefaultFormatter';
42 } 47 }
43 48
44 return new $className($this->conf); 49 return new $className($this->conf, $this->isLoggedIn);
45 } 50 }
46} 51}