diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-01-18 11:33:23 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-01-18 11:39:26 +0100 |
commit | a39acb2518f272df8a601af72c13eabe2719dcb8 (patch) | |
tree | fb8bda9de5bea9d73553c3d54610eb211d7de6fb | |
parent | 3fb29fdda04ca86e04422d49b86cf646d53c4f9d (diff) | |
download | Shaarli-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
-rw-r--r-- | application/bookmark/BookmarkFileService.php | 9 | ||||
-rw-r--r-- | application/formatter/BookmarkDefaultFormatter.php | 2 | ||||
-rw-r--r-- | application/formatter/BookmarkFormatter.php | 35 | ||||
-rw-r--r-- | application/formatter/BookmarkMarkdownFormatter.php | 8 | ||||
-rw-r--r-- | application/formatter/FormatterFactory.php | 11 | ||||
-rw-r--r-- | index.php | 39 | ||||
-rw-r--r-- | tests/bookmark/BookmarkFileServiceTest.php | 41 | ||||
-rw-r--r-- | tests/feed/FeedBuilderTest.php | 2 | ||||
-rw-r--r-- | tests/formatter/BookmarkDefaultFormatterTest.php | 23 | ||||
-rw-r--r-- | tests/formatter/BookmarkMarkdownFormatterTest.php | 2 | ||||
-rw-r--r-- | tests/formatter/BookmarkRawFormatterTest.php | 2 | ||||
-rw-r--r-- | tests/formatter/FormatterFactoryTest.php | 2 | ||||
-rw-r--r-- | tests/netscape/BookmarkExportTest.php | 2 |
13 files changed, 145 insertions, 33 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; | |||
8 | use Shaarli\Bookmark\Exception\BookmarkNotFoundException; | 8 | use Shaarli\Bookmark\Exception\BookmarkNotFoundException; |
9 | use Shaarli\Bookmark\Exception\EmptyDataStoreException; | 9 | use Shaarli\Bookmark\Exception\EmptyDataStoreException; |
10 | use Shaarli\Config\ConfigManager; | 10 | use Shaarli\Config\ConfigManager; |
11 | use Shaarli\Formatter\BookmarkMarkdownFormatter; | ||
11 | use Shaarli\History; | 12 | use Shaarli\History; |
12 | use Shaarli\Legacy\LegacyLinkDB; | 13 | use Shaarli\Legacy\LegacyLinkDB; |
13 | use Shaarli\Legacy\LegacyUpdater; | 14 | use 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 | } |
@@ -70,6 +70,7 @@ use Shaarli\Bookmark\BookmarkFileService; | |||
70 | use \Shaarli\Config\ConfigManager; | 70 | use \Shaarli\Config\ConfigManager; |
71 | use \Shaarli\Feed\CachedPage; | 71 | use \Shaarli\Feed\CachedPage; |
72 | use \Shaarli\Feed\FeedBuilder; | 72 | use \Shaarli\Feed\FeedBuilder; |
73 | use Shaarli\Formatter\BookmarkMarkdownFormatter; | ||
73 | use Shaarli\Formatter\FormatterFactory; | 74 | use Shaarli\Formatter\FormatterFactory; |
74 | use \Shaarli\History; | 75 | use \Shaarli\History; |
75 | use \Shaarli\Languages; | 76 | use \Shaarli\Languages; |
@@ -351,7 +352,7 @@ function showDailyRSS($bookmarkService, $conf, $loginManager) | |||
351 | echo '<language>en-en</language>'; | 352 | echo '<language>en-en</language>'; |
352 | echo '<copyright>'. $pageaddr .'</copyright>'. PHP_EOL; | 353 | echo '<copyright>'. $pageaddr .'</copyright>'. PHP_EOL; |
353 | 354 | ||
354 | $factory = new FormatterFactory($conf); | 355 | $factory = new FormatterFactory($conf, $loginManager->isLoggedIn()); |
355 | $formatter = $factory->getFormatter(); | 356 | $formatter = $factory->getFormatter(); |
356 | $formatter->addContextData('index_url', index_url($_SERVER)); | 357 | $formatter->addContextData('index_url', index_url($_SERVER)); |
357 | // For each day. | 358 | // For each day. |
@@ -441,7 +442,7 @@ function showDaily($pageBuilder, $bookmarkService, $conf, $pluginManager, $login | |||
441 | $linksToDisplay = []; | 442 | $linksToDisplay = []; |
442 | } | 443 | } |
443 | 444 | ||
444 | $factory = new FormatterFactory($conf); | 445 | $factory = new FormatterFactory($conf, $loginManager->isLoggedIn()); |
445 | $formatter = $factory->getFormatter(); | 446 | $formatter = $factory->getFormatter(); |
446 | // We pre-format some fields for proper output. | 447 | // We pre-format some fields for proper output. |
447 | foreach ($linksToDisplay as $key => $bookmark) { | 448 | foreach ($linksToDisplay as $key => $bookmark) { |
@@ -630,7 +631,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
630 | 631 | ||
631 | // Get only bookmarks which have a thumbnail. | 632 | // Get only bookmarks which have a thumbnail. |
632 | // Note: we do not retrieve thumbnails here, the request is too heavy. | 633 | // Note: we do not retrieve thumbnails here, the request is too heavy. |
633 | $factory = new FormatterFactory($conf); | 634 | $factory = new FormatterFactory($conf, $loginManager->isLoggedIn()); |
634 | $formatter = $factory->getFormatter(); | 635 | $formatter = $factory->getFormatter(); |
635 | foreach ($links as $key => $link) { | 636 | foreach ($links as $key => $link) { |
636 | if ($link->getThumbnail() !== false) { | 637 | if ($link->getThumbnail() !== false) { |
@@ -753,7 +754,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
753 | exit; | 754 | exit; |
754 | } | 755 | } |
755 | 756 | ||
756 | $factory = new FormatterFactory($conf); | 757 | $factory = new FormatterFactory($conf, $loginManager->isLoggedIn()); |
757 | // Generate data. | 758 | // Generate data. |
758 | $feedGenerator = new FeedBuilder( | 759 | $feedGenerator = new FeedBuilder( |
759 | $bookmarkService, | 760 | $bookmarkService, |
@@ -1183,7 +1184,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
1183 | $bookmarkService->addOrSet($bookmark, false); | 1184 | $bookmarkService->addOrSet($bookmark, false); |
1184 | 1185 | ||
1185 | // To preserve backward compatibility with 3rd parties, plugins still use arrays | 1186 | // To preserve backward compatibility with 3rd parties, plugins still use arrays |
1186 | $factory = new FormatterFactory($conf); | 1187 | $factory = new FormatterFactory($conf, $loginManager->isLoggedIn()); |
1187 | $formatter = $factory->getFormatter('raw'); | 1188 | $formatter = $factory->getFormatter('raw'); |
1188 | $data = $formatter->format($bookmark); | 1189 | $data = $formatter->format($bookmark); |
1189 | $pluginManager->executeHooks('save_link', $data); | 1190 | $pluginManager->executeHooks('save_link', $data); |
@@ -1230,7 +1231,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
1230 | if (!count($ids)) { | 1231 | if (!count($ids)) { |
1231 | die('no id provided'); | 1232 | die('no id provided'); |
1232 | } | 1233 | } |
1233 | $factory = new FormatterFactory($conf); | 1234 | $factory = new FormatterFactory($conf, $loginManager->isLoggedIn()); |
1234 | $formatter = $factory->getFormatter('raw'); | 1235 | $formatter = $factory->getFormatter('raw'); |
1235 | foreach ($ids as $id) { | 1236 | foreach ($ids as $id) { |
1236 | $id = (int) escape($id); | 1237 | $id = (int) escape($id); |
@@ -1286,7 +1287,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
1286 | } else { | 1287 | } else { |
1287 | $private = $_GET['newVisibility'] === 'private'; | 1288 | $private = $_GET['newVisibility'] === 'private'; |
1288 | } | 1289 | } |
1289 | $factory = new FormatterFactory($conf); | 1290 | $factory = new FormatterFactory($conf, $loginManager->isLoggedIn()); |
1290 | $formatter = $factory->getFormatter('raw'); | 1291 | $formatter = $factory->getFormatter('raw'); |
1291 | foreach ($ids as $id) { | 1292 | foreach ($ids as $id) { |
1292 | $id = (int) escape($id); | 1293 | $id = (int) escape($id); |
@@ -1324,14 +1325,18 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
1324 | exit; | 1325 | exit; |
1325 | } | 1326 | } |
1326 | 1327 | ||
1327 | $factory = new FormatterFactory($conf); | 1328 | $factory = new FormatterFactory($conf, $loginManager->isLoggedIn()); |
1328 | $formatter = $factory->getFormatter('raw'); | 1329 | $formatter = $factory->getFormatter('raw'); |
1329 | $formattedLink = $formatter->format($link); | 1330 | $formattedLink = $formatter->format($link); |
1331 | $tags = $bookmarkService->bookmarksCountPerTag(); | ||
1332 | if ($conf->get('formatter') === 'markdown') { | ||
1333 | $tags[BookmarkMarkdownFormatter::NO_MD_TAG] = 1; | ||
1334 | } | ||
1330 | $data = array( | 1335 | $data = array( |
1331 | 'link' => $formattedLink, | 1336 | 'link' => $formattedLink, |
1332 | 'link_is_new' => false, | 1337 | 'link_is_new' => false, |
1333 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), | 1338 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), |
1334 | 'tags' => $bookmarkService->bookmarksCountPerTag(), | 1339 | 'tags' => $tags, |
1335 | ); | 1340 | ); |
1336 | $pluginManager->executeHooks('render_editlink', $data); | 1341 | $pluginManager->executeHooks('render_editlink', $data); |
1337 | 1342 | ||
@@ -1391,17 +1396,21 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
1391 | 'private' => $private, | 1396 | 'private' => $private, |
1392 | ]; | 1397 | ]; |
1393 | } else { | 1398 | } else { |
1394 | $factory = new FormatterFactory($conf); | 1399 | $factory = new FormatterFactory($conf, $loginManager->isLoggedIn()); |
1395 | $formatter = $factory->getFormatter('raw'); | 1400 | $formatter = $factory->getFormatter('raw'); |
1396 | $link = $formatter->format($bookmark); | 1401 | $link = $formatter->format($bookmark); |
1397 | } | 1402 | } |
1398 | 1403 | ||
1404 | $tags = $bookmarkService->bookmarksCountPerTag(); | ||
1405 | if ($conf->get('formatter') === 'markdown') { | ||
1406 | $tags[BookmarkMarkdownFormatter::NO_MD_TAG] = 1; | ||
1407 | } | ||
1399 | $data = [ | 1408 | $data = [ |
1400 | 'link' => $link, | 1409 | 'link' => $link, |
1401 | 'link_is_new' => $link_is_new, | 1410 | 'link_is_new' => $link_is_new, |
1402 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), | 1411 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), |
1403 | 'source' => (isset($_GET['source']) ? $_GET['source'] : ''), | 1412 | 'source' => (isset($_GET['source']) ? $_GET['source'] : ''), |
1404 | 'tags' => $bookmarkService->bookmarksCountPerTag(), | 1413 | 'tags' => $tags, |
1405 | 'default_private_links' => $conf->get('privacy.default_private_links', false), | 1414 | 'default_private_links' => $conf->get('privacy.default_private_links', false), |
1406 | ]; | 1415 | ]; |
1407 | $pluginManager->executeHooks('render_editlink', $data); | 1416 | $pluginManager->executeHooks('render_editlink', $data); |
@@ -1451,7 +1460,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
1451 | } | 1460 | } |
1452 | 1461 | ||
1453 | try { | 1462 | try { |
1454 | $factory = new FormatterFactory($conf); | 1463 | $factory = new FormatterFactory($conf, $loginManager->isLoggedIn()); |
1455 | $formatter = $factory->getFormatter('raw'); | 1464 | $formatter = $factory->getFormatter('raw'); |
1456 | $PAGE->assign( | 1465 | $PAGE->assign( |
1457 | 'links', | 1466 | 'links', |
@@ -1633,7 +1642,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
1633 | $bookmark->setThumbnail($thumbnailer->get($bookmark->getUrl())); | 1642 | $bookmark->setThumbnail($thumbnailer->get($bookmark->getUrl())); |
1634 | $bookmarkService->set($bookmark); | 1643 | $bookmarkService->set($bookmark); |
1635 | 1644 | ||
1636 | $factory = new FormatterFactory($conf); | 1645 | $factory = new FormatterFactory($conf, $loginManager->isLoggedIn()); |
1637 | echo json_encode($factory->getFormatter('raw')->format($bookmark)); | 1646 | echo json_encode($factory->getFormatter('raw')->format($bookmark)); |
1638 | exit; | 1647 | exit; |
1639 | } | 1648 | } |
@@ -1655,7 +1664,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
1655 | */ | 1664 | */ |
1656 | function buildLinkList($PAGE, $linkDb, $conf, $pluginManager, $loginManager) | 1665 | function buildLinkList($PAGE, $linkDb, $conf, $pluginManager, $loginManager) |
1657 | { | 1666 | { |
1658 | $factory = new FormatterFactory($conf); | 1667 | $factory = new FormatterFactory($conf, $loginManager->isLoggedIn()); |
1659 | $formatter = $factory->getFormatter(); | 1668 | $formatter = $factory->getFormatter(); |
1660 | 1669 | ||
1661 | // Used in templates | 1670 | // Used in templates |
diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index 1b438a7f..4900d41d 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php | |||
@@ -12,6 +12,7 @@ use ReflectionClass; | |||
12 | use Shaarli; | 12 | use Shaarli; |
13 | use Shaarli\Bookmark\Exception\BookmarkNotFoundException; | 13 | use Shaarli\Bookmark\Exception\BookmarkNotFoundException; |
14 | use Shaarli\Config\ConfigManager; | 14 | use Shaarli\Config\ConfigManager; |
15 | use Shaarli\Formatter\BookmarkMarkdownFormatter; | ||
15 | use Shaarli\History; | 16 | use Shaarli\History; |
16 | 17 | ||
17 | /** | 18 | /** |
@@ -1026,6 +1027,46 @@ class BookmarkFileServiceTest extends TestCase | |||
1026 | } | 1027 | } |
1027 | 1028 | ||
1028 | /** | 1029 | /** |
1030 | * Test linksCountPerTag public tags with filter. | ||
1031 | * Equal occurrences should be sorted alphabetically. | ||
1032 | */ | ||
1033 | public function testCountTagsNoMarkdown() | ||
1034 | { | ||
1035 | $expected = [ | ||
1036 | 'cartoon' => 3, | ||
1037 | 'dev' => 2, | ||
1038 | 'tag1' => 1, | ||
1039 | 'tag2' => 1, | ||
1040 | 'tag3' => 1, | ||
1041 | 'tag4' => 1, | ||
1042 | 'web' => 4, | ||
1043 | 'gnu' => 2, | ||
1044 | 'hashtag' => 2, | ||
1045 | 'sTuff' => 2, | ||
1046 | '-exclude' => 1, | ||
1047 | '.hidden' => 1, | ||
1048 | 'Mercurial' => 1, | ||
1049 | 'css' => 1, | ||
1050 | 'free' => 1, | ||
1051 | 'html' => 1, | ||
1052 | 'media' => 1, | ||
1053 | 'newTagToCount' => 1, | ||
1054 | 'samba' => 1, | ||
1055 | 'software' => 1, | ||
1056 | 'stallman' => 1, | ||
1057 | 'ut' => 1, | ||
1058 | 'w3c' => 1, | ||
1059 | ]; | ||
1060 | $bookmark = new Bookmark(); | ||
1061 | $bookmark->setTags(['newTagToCount', BookmarkMarkdownFormatter::NO_MD_TAG]); | ||
1062 | $this->privateLinkDB->add($bookmark); | ||
1063 | |||
1064 | $tags = $this->privateLinkDB->bookmarksCountPerTag(); | ||
1065 | |||
1066 | $this->assertEquals($expected, $tags, var_export($tags, true)); | ||
1067 | } | ||
1068 | |||
1069 | /** | ||
1029 | * Allows to test LinkDB's private methods | 1070 | * Allows to test LinkDB's private methods |
1030 | * | 1071 | * |
1031 | * @see | 1072 | * @see |
diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php index a43ff672..54671891 100644 --- a/tests/feed/FeedBuilderTest.php +++ b/tests/feed/FeedBuilderTest.php | |||
@@ -51,7 +51,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase | |||
51 | $refLinkDB = new \ReferenceLinkDB(); | 51 | $refLinkDB = new \ReferenceLinkDB(); |
52 | $refLinkDB->write(self::$testDatastore); | 52 | $refLinkDB->write(self::$testDatastore); |
53 | $history = new History('sandbox/history.php'); | 53 | $history = new History('sandbox/history.php'); |
54 | $factory = new FormatterFactory($conf); | 54 | $factory = new FormatterFactory($conf, true); |
55 | self::$formatter = $factory->getFormatter(); | 55 | self::$formatter = $factory->getFormatter(); |
56 | self::$bookmarkService = new BookmarkFileService($conf, $history, true); | 56 | self::$bookmarkService = new BookmarkFileService($conf, $history, true); |
57 | 57 | ||
diff --git a/tests/formatter/BookmarkDefaultFormatterTest.php b/tests/formatter/BookmarkDefaultFormatterTest.php index fe42a208..382a560e 100644 --- a/tests/formatter/BookmarkDefaultFormatterTest.php +++ b/tests/formatter/BookmarkDefaultFormatterTest.php | |||
@@ -29,7 +29,7 @@ class BookmarkDefaultFormatterTest extends TestCase | |||
29 | { | 29 | { |
30 | copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); | 30 | copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); |
31 | $this->conf = new ConfigManager(self::$testConf); | 31 | $this->conf = new ConfigManager(self::$testConf); |
32 | $this->formatter = new BookmarkDefaultFormatter($this->conf); | 32 | $this->formatter = new BookmarkDefaultFormatter($this->conf, true); |
33 | } | 33 | } |
34 | 34 | ||
35 | /** | 35 | /** |
@@ -153,4 +153,25 @@ class BookmarkDefaultFormatterTest extends TestCase | |||
153 | $link['description'] | 153 | $link['description'] |
154 | ); | 154 | ); |
155 | } | 155 | } |
156 | |||
157 | /** | ||
158 | * Make sure that private tags are properly filtered out when the user is logged out. | ||
159 | */ | ||
160 | public function testFormatTagListRemovePrivate(): void | ||
161 | { | ||
162 | $this->formatter = new BookmarkDefaultFormatter($this->conf, false); | ||
163 | |||
164 | $bookmark = new Bookmark(); | ||
165 | $bookmark->setId($id = 11); | ||
166 | $bookmark->setTags($tags = ['bookmark', '.private', 'othertag']); | ||
167 | |||
168 | $link = $this->formatter->format($bookmark); | ||
169 | |||
170 | unset($tags[1]); | ||
171 | $tags = array_values($tags); | ||
172 | |||
173 | $this->assertSame(11, $link['id']); | ||
174 | $this->assertSame($tags, $link['taglist']); | ||
175 | $this->assertSame(implode(' ', $tags), $link['tags']); | ||
176 | } | ||
156 | } | 177 | } |
diff --git a/tests/formatter/BookmarkMarkdownFormatterTest.php b/tests/formatter/BookmarkMarkdownFormatterTest.php index 0ca7f802..f1f12c04 100644 --- a/tests/formatter/BookmarkMarkdownFormatterTest.php +++ b/tests/formatter/BookmarkMarkdownFormatterTest.php | |||
@@ -29,7 +29,7 @@ class BookmarkMarkdownFormatterTest extends TestCase | |||
29 | { | 29 | { |
30 | copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); | 30 | copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); |
31 | $this->conf = new ConfigManager(self::$testConf); | 31 | $this->conf = new ConfigManager(self::$testConf); |
32 | $this->formatter = new BookmarkMarkdownFormatter($this->conf); | 32 | $this->formatter = new BookmarkMarkdownFormatter($this->conf, true); |
33 | } | 33 | } |
34 | 34 | ||
35 | /** | 35 | /** |
diff --git a/tests/formatter/BookmarkRawFormatterTest.php b/tests/formatter/BookmarkRawFormatterTest.php index ceb6fb73..4491b035 100644 --- a/tests/formatter/BookmarkRawFormatterTest.php +++ b/tests/formatter/BookmarkRawFormatterTest.php | |||
@@ -29,7 +29,7 @@ class BookmarkRawFormatterTest extends TestCase | |||
29 | { | 29 | { |
30 | copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); | 30 | copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); |
31 | $this->conf = new ConfigManager(self::$testConf); | 31 | $this->conf = new ConfigManager(self::$testConf); |
32 | $this->formatter = new BookmarkRawFormatter($this->conf); | 32 | $this->formatter = new BookmarkRawFormatter($this->conf, true); |
33 | } | 33 | } |
34 | 34 | ||
35 | /** | 35 | /** |
diff --git a/tests/formatter/FormatterFactoryTest.php b/tests/formatter/FormatterFactoryTest.php index 317c0b2d..5adf3ffd 100644 --- a/tests/formatter/FormatterFactoryTest.php +++ b/tests/formatter/FormatterFactoryTest.php | |||
@@ -28,7 +28,7 @@ class FormatterFactoryTest extends TestCase | |||
28 | { | 28 | { |
29 | copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); | 29 | copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); |
30 | $this->conf = new ConfigManager(self::$testConf); | 30 | $this->conf = new ConfigManager(self::$testConf); |
31 | $this->factory = new FormatterFactory($this->conf); | 31 | $this->factory = new FormatterFactory($this->conf, true); |
32 | } | 32 | } |
33 | 33 | ||
34 | /** | 34 | /** |
diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php index 011d19ac..6c948bba 100644 --- a/tests/netscape/BookmarkExportTest.php +++ b/tests/netscape/BookmarkExportTest.php | |||
@@ -46,7 +46,7 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase | |||
46 | self::$refDb->write(self::$testDatastore); | 46 | self::$refDb->write(self::$testDatastore); |
47 | $history = new History('sandbox/history.php'); | 47 | $history = new History('sandbox/history.php'); |
48 | self::$bookmarkService = new BookmarkFileService($conf, $history, true); | 48 | self::$bookmarkService = new BookmarkFileService($conf, $history, true); |
49 | $factory = new FormatterFactory($conf); | 49 | $factory = new FormatterFactory($conf, true); |
50 | self::$formatter = $factory->getFormatter('raw'); | 50 | self::$formatter = $factory->getFormatter('raw'); |
51 | } | 51 | } |
52 | 52 | ||