diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 93 |
1 files changed, 67 insertions, 26 deletions
@@ -790,7 +790,9 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
790 | // -------- Tag cloud | 790 | // -------- Tag cloud |
791 | if ($targetPage == Router::$PAGE_TAGCLOUD) | 791 | if ($targetPage == Router::$PAGE_TAGCLOUD) |
792 | { | 792 | { |
793 | $tags= $LINKSDB->allTags(); | 793 | $visibility = ! empty($_SESSION['privateonly']) ? 'private' : 'all'; |
794 | $filteringTags = isset($_GET['searchtags']) ? explode(' ', $_GET['searchtags']) : []; | ||
795 | $tags = $LINKSDB->linksCountPerTag($filteringTags, $visibility); | ||
794 | 796 | ||
795 | // We sort tags alphabetically, then choose a font size according to count. | 797 | // We sort tags alphabetically, then choose a font size according to count. |
796 | // First, find max value. | 798 | // First, find max value. |
@@ -799,17 +801,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
799 | $maxcount = max($maxcount, $value); | 801 | $maxcount = max($maxcount, $value); |
800 | } | 802 | } |
801 | 803 | ||
802 | // Sort tags alphabetically: case insensitive, support locale if available. | 804 | alphabetical_sort($tags, true, true); |
803 | uksort($tags, function($a, $b) { | ||
804 | // Collator is part of PHP intl. | ||
805 | if (class_exists('Collator')) { | ||
806 | $c = new Collator(setlocale(LC_COLLATE, 0)); | ||
807 | if (!intl_is_failure(intl_get_error_code())) { | ||
808 | return $c->compare($a, $b); | ||
809 | } | ||
810 | } | ||
811 | return strcasecmp($a, $b); | ||
812 | }); | ||
813 | 805 | ||
814 | $tagList = array(); | 806 | $tagList = array(); |
815 | foreach($tags as $key => $value) { | 807 | foreach($tags as $key => $value) { |
@@ -824,6 +816,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
824 | } | 816 | } |
825 | 817 | ||
826 | $data = array( | 818 | $data = array( |
819 | 'search_tags' => implode(' ', $filteringTags), | ||
827 | 'tags' => $tagList, | 820 | 'tags' => $tagList, |
828 | ); | 821 | ); |
829 | $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn())); | 822 | $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn())); |
@@ -832,7 +825,32 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
832 | $PAGE->assign($key, $value); | 825 | $PAGE->assign($key, $value); |
833 | } | 826 | } |
834 | 827 | ||
835 | $PAGE->renderPage('tagcloud'); | 828 | $PAGE->renderPage('tag.cloud'); |
829 | exit; | ||
830 | } | ||
831 | |||
832 | // -------- Tag cloud | ||
833 | if ($targetPage == Router::$PAGE_TAGLIST) | ||
834 | { | ||
835 | $visibility = ! empty($_SESSION['privateonly']) ? 'private' : 'all'; | ||
836 | $filteringTags = isset($_GET['searchtags']) ? explode(' ', $_GET['searchtags']) : []; | ||
837 | $tags = $LINKSDB->linksCountPerTag($filteringTags, $visibility); | ||
838 | |||
839 | if (! empty($_GET['sort']) && $_GET['sort'] === 'alpha') { | ||
840 | alphabetical_sort($tags, false, true); | ||
841 | } | ||
842 | |||
843 | $data = [ | ||
844 | 'search_tags' => implode(' ', $filteringTags), | ||
845 | 'tags' => $tags, | ||
846 | ]; | ||
847 | $pluginManager->executeHooks('render_taglist', $data, ['loggedin' => isLoggedIn()]); | ||
848 | |||
849 | foreach ($data as $key => $value) { | ||
850 | $PAGE->assign($key, $value); | ||
851 | } | ||
852 | |||
853 | $PAGE->renderPage('tag.list'); | ||
836 | exit; | 854 | exit; |
837 | } | 855 | } |
838 | 856 | ||
@@ -1149,6 +1167,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
1149 | if ($targetPage == Router::$PAGE_CHANGETAG) | 1167 | if ($targetPage == Router::$PAGE_CHANGETAG) |
1150 | { | 1168 | { |
1151 | if (empty($_POST['fromtag']) || (empty($_POST['totag']) && isset($_POST['renametag']))) { | 1169 | if (empty($_POST['fromtag']) || (empty($_POST['totag']) && isset($_POST['renametag']))) { |
1170 | $PAGE->assign('fromtag', ! empty($_GET['fromtag']) ? escape($_GET['fromtag']) : ''); | ||
1152 | $PAGE->renderPage('changetag'); | 1171 | $PAGE->renderPage('changetag'); |
1153 | exit; | 1172 | exit; |
1154 | } | 1173 | } |
@@ -1302,18 +1321,21 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
1302 | // -------- User clicked the "Delete" button when editing a link: Delete link from database. | 1321 | // -------- User clicked the "Delete" button when editing a link: Delete link from database. |
1303 | if ($targetPage == Router::$PAGE_DELETELINK) | 1322 | if ($targetPage == Router::$PAGE_DELETELINK) |
1304 | { | 1323 | { |
1305 | // We do not need to ask for confirmation: | ||
1306 | // - confirmation is handled by JavaScript | ||
1307 | // - we are protected from XSRF by the token. | ||
1308 | |||
1309 | if (! tokenOk($_GET['token'])) { | 1324 | if (! tokenOk($_GET['token'])) { |
1310 | die('Wrong token.'); | 1325 | die('Wrong token.'); |
1311 | } | 1326 | } |
1312 | 1327 | ||
1313 | $id = intval(escape($_GET['lf_linkdate'])); | 1328 | if (strpos($_GET['lf_linkdate'], ' ') !== false) { |
1314 | $link = $LINKSDB[$id]; | 1329 | $ids = array_values(array_filter(preg_split('/\s+/', escape($_GET['lf_linkdate'])))); |
1315 | $pluginManager->executeHooks('delete_link', $link); | 1330 | } else { |
1316 | unset($LINKSDB[$id]); | 1331 | $ids = [$_GET['lf_linkdate']]; |
1332 | } | ||
1333 | foreach ($ids as $id) { | ||
1334 | $id = (int) escape($id); | ||
1335 | $link = $LINKSDB[$id]; | ||
1336 | $pluginManager->executeHooks('delete_link', $link); | ||
1337 | unset($LINKSDB[$id]); | ||
1338 | } | ||
1317 | $LINKSDB->save($conf->get('resource.page_cache')); // save to disk | 1339 | $LINKSDB->save($conf->get('resource.page_cache')); // save to disk |
1318 | $history->deleteLink($link); | 1340 | $history->deleteLink($link); |
1319 | 1341 | ||
@@ -1345,7 +1367,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
1345 | 'link' => $link, | 1367 | 'link' => $link, |
1346 | 'link_is_new' => false, | 1368 | 'link_is_new' => false, |
1347 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), | 1369 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), |
1348 | 'tags' => $LINKSDB->allTags(), | 1370 | 'tags' => $LINKSDB->linksCountPerTag(), |
1349 | ); | 1371 | ); |
1350 | $pluginManager->executeHooks('render_editlink', $data); | 1372 | $pluginManager->executeHooks('render_editlink', $data); |
1351 | 1373 | ||
@@ -1414,7 +1436,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
1414 | 'link_is_new' => $link_is_new, | 1436 | 'link_is_new' => $link_is_new, |
1415 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), | 1437 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), |
1416 | 'source' => (isset($_GET['source']) ? $_GET['source'] : ''), | 1438 | 'source' => (isset($_GET['source']) ? $_GET['source'] : ''), |
1417 | 'tags' => $LINKSDB->allTags(), | 1439 | 'tags' => $LINKSDB->linksCountPerTag(), |
1418 | 'default_private_links' => $conf->get('privacy.default_private_links', false), | 1440 | 'default_private_links' => $conf->get('privacy.default_private_links', false), |
1419 | ); | 1441 | ); |
1420 | $pluginManager->executeHooks('render_editlink', $data); | 1442 | $pluginManager->executeHooks('render_editlink', $data); |
@@ -1570,6 +1592,13 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
1570 | exit; | 1592 | exit; |
1571 | } | 1593 | } |
1572 | 1594 | ||
1595 | // Get a fresh token | ||
1596 | if ($targetPage == Router::$GET_TOKEN) { | ||
1597 | header('Content-Type:text/plain'); | ||
1598 | echo getToken($conf); | ||
1599 | exit; | ||
1600 | } | ||
1601 | |||
1573 | // -------- Otherwise, simply display search form and links: | 1602 | // -------- Otherwise, simply display search form and links: |
1574 | showLinkList($PAGE, $LINKSDB, $conf, $pluginManager); | 1603 | showLinkList($PAGE, $LINKSDB, $conf, $pluginManager); |
1575 | exit; | 1604 | exit; |
@@ -1587,7 +1616,15 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
1587 | function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) | 1616 | function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) |
1588 | { | 1617 | { |
1589 | // Used in templates | 1618 | // Used in templates |
1590 | $searchtags = !empty($_GET['searchtags']) ? escape(normalize_spaces($_GET['searchtags'])) : ''; | 1619 | if (isset($_GET['searchtags'])) { |
1620 | if (! empty($_GET['searchtags'])) { | ||
1621 | $searchtags = escape(normalize_spaces($_GET['searchtags'])); | ||
1622 | } else { | ||
1623 | $searchtags = false; | ||
1624 | } | ||
1625 | } else { | ||
1626 | $searchtags = ''; | ||
1627 | } | ||
1591 | $searchterm = !empty($_GET['searchterm']) ? escape(normalize_spaces($_GET['searchterm'])) : ''; | 1628 | $searchterm = !empty($_GET['searchterm']) ? escape(normalize_spaces($_GET['searchterm'])) : ''; |
1592 | 1629 | ||
1593 | // Smallhash filter | 1630 | // Smallhash filter |
@@ -1602,7 +1639,11 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) | |||
1602 | } else { | 1639 | } else { |
1603 | // Filter links according search parameters. | 1640 | // Filter links according search parameters. |
1604 | $visibility = ! empty($_SESSION['privateonly']) ? 'private' : 'all'; | 1641 | $visibility = ! empty($_SESSION['privateonly']) ? 'private' : 'all'; |
1605 | $linksToDisplay = $LINKSDB->filterSearch($_GET, false, $visibility); | 1642 | $request = [ |
1643 | 'searchtags' => $searchtags, | ||
1644 | 'searchterm' => $searchterm, | ||
1645 | ]; | ||
1646 | $linksToDisplay = $LINKSDB->filterSearch($request, false, $visibility); | ||
1606 | } | 1647 | } |
1607 | 1648 | ||
1608 | // ---- Handle paging. | 1649 | // ---- Handle paging. |
@@ -1649,7 +1690,7 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) | |||
1649 | } | 1690 | } |
1650 | 1691 | ||
1651 | // Compute paging navigation | 1692 | // Compute paging navigation |
1652 | $searchtagsUrl = empty($searchtags) ? '' : '&searchtags=' . urlencode($searchtags); | 1693 | $searchtagsUrl = $searchtags === '' ? '' : '&searchtags=' . urlencode($searchtags); |
1653 | $searchtermUrl = empty($searchterm) ? '' : '&searchterm=' . urlencode($searchterm); | 1694 | $searchtermUrl = empty($searchterm) ? '' : '&searchterm=' . urlencode($searchterm); |
1654 | $previous_page_url = ''; | 1695 | $previous_page_url = ''; |
1655 | if ($i != count($keys)) { | 1696 | if ($i != count($keys)) { |