aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/formatter/BookmarkFormatter.php
diff options
context:
space:
mode:
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}