aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/formatter/BookmarkFormatter.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-01-18 11:33:23 +0100
committerArthurHoaro <arthur@hoa.ro>2020-01-18 11:39:26 +0100
commita39acb2518f272df8a601af72c13eabe2719dcb8 (patch)
treefb8bda9de5bea9d73553c3d54610eb211d7de6fb /application/formatter/BookmarkFormatter.php
parent3fb29fdda04ca86e04422d49b86cf646d53c4f9d (diff)
downloadShaarli-a39acb2518f272df8a601af72c13eabe2719dcb8.tar.gz
Shaarli-a39acb2518f272df8a601af72c13eabe2719dcb8.tar.zst
Shaarli-a39acb2518f272df8a601af72c13eabe2719dcb8.zip
Fix an issue with private tags and fix nomarkdown tag
The new bookmark service wasn't handling private tags properly. nomarkdown tag is now shown only for logged in user in bookmarks, and hidden for everyone in tag clouds/lists. Fixes #726
Diffstat (limited to 'application/formatter/BookmarkFormatter.php')
-rw-r--r--application/formatter/BookmarkFormatter.php35
1 files changed, 32 insertions, 3 deletions
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}