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 /index.php | |
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
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 39 |
1 files changed, 24 insertions, 15 deletions
@@ -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 |