X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=76526bd54717efeaf2d56eed8f83ed6a6970e67d;hb=f32ec5fb3c2139546caec5d26bff3eb5b7d37255;hp=85486eb50d72ea16be69fe59e261612356e2a435;hpb=d5d22a6d07917865c44148ad76f43c65a929a890;p=github%2Fshaarli%2FShaarli.git diff --git a/index.php b/index.php index 85486eb5..76526bd5 100644 --- a/index.php +++ b/index.php @@ -287,6 +287,7 @@ function logout() { unset($_SESSION['ip']); unset($_SESSION['username']); unset($_SESSION['privateonly']); + unset($_SESSION['untaggedonly']); } setcookie('shaarli_staySignedIn', FALSE, 0, WEB_PATH); } @@ -685,6 +686,7 @@ function showLinkList($PAGE, $LINKSDB, $conf, $pluginManager) { * @param ConfigManager $conf Configuration Manager instance. * @param PluginManager $pluginManager Plugin Manager instance, * @param LinkDB $LINKSDB + * @param History $history instance */ function renderPage($conf, $pluginManager, $LINKSDB, $history) { @@ -801,7 +803,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) $maxcount = max($maxcount, $value); } - alphabetical_sort($tags, true, true); + alphabetical_sort($tags, false, true); $tagList = array(); foreach($tags as $key => $value) { @@ -1017,6 +1019,19 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) exit; } + // -------- User wants to see only untagged links (toggle) + if (isset($_GET['untaggedonly'])) { + $_SESSION['untaggedonly'] = empty($_SESSION['untaggedonly']); + + if (! empty($_SERVER['HTTP_REFERER'])) { + $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('untaggedonly')); + } else { + $location = '?'; + } + header('Location: '. $location); + exit; + } + // -------- Handle other actions allowed for non-logged in users: if (!isLoggedIn()) { @@ -1184,41 +1199,18 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) die('Wrong token.'); } - // Delete a tag: - if (isset($_POST['deletetag']) && !empty($_POST['fromtag'])) { - $needle = trim($_POST['fromtag']); - // True for case-sensitive tag search. - $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true); - foreach($linksToAlter as $key=>$value) - { - $tags = explode(' ',trim($value['tags'])); - unset($tags[array_search($needle,$tags)]); // Remove tag. - $value['tags']=trim(implode(' ',$tags)); - $LINKSDB[$key]=$value; - $history->updateLink($LINKSDB[$key]); - } - $LINKSDB->save($conf->get('resource.page_cache')); - echo ''; - exit; - } - - // Rename a tag: - if (isset($_POST['renametag']) && !empty($_POST['fromtag']) && !empty($_POST['totag'])) { - $needle = trim($_POST['fromtag']); - // True for case-sensitive tag search. - $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true); - foreach($linksToAlter as $key=>$value) { - $tags = preg_split('/\s+/', trim($value['tags'])); - // Replace tags value. - $tags[array_search($needle, $tags)] = trim($_POST['totag']); - $value['tags'] = implode(' ', array_unique($tags)); - $LINKSDB[$key] = $value; - $history->updateLink($LINKSDB[$key]); - } - $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk. - echo ''; - exit; + $alteredLinks = $LINKSDB->renameTag(escape($_POST['fromtag']), escape($_POST['totag'])); + $LINKSDB->save($conf->get('resource.page_cache')); + foreach ($alteredLinks as $link) { + $history->updateLink($link); } + $delete = empty($_POST['totag']); + $redirect = $delete ? 'do=changetag' : 'searchtags='. urlencode(escape($_POST['totag'])); + $alert = $delete + ? sprintf(t('The tag was removed from %d links.'), count($alteredLinks)) + : sprintf(t('The tag was renamed in %d links.'), count($alteredLinks)); + echo ''; + exit; } // -------- User wants to add a link without using the bookmarklet: Show form. @@ -1651,7 +1643,7 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) 'searchtags' => $searchtags, 'searchterm' => $searchterm, ]; - $linksToDisplay = $LINKSDB->filterSearch($request, false, $visibility); + $linksToDisplay = $LINKSDB->filterSearch($request, false, $visibility, !empty($_SESSION['untaggedonly'])); } // ---- Handle paging. @@ -2245,6 +2237,12 @@ if (!isset($_SESSION['LINKS_PER_PAGE'])) { $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20); } +try { + $history = new History($conf->get('resource.history')); +} catch(Exception $e) { + die($e->getMessage()); +} + $linkDb = new LinkDB( $conf->get('resource.datastore'), isLoggedIn(), @@ -2253,12 +2251,6 @@ $linkDb = new LinkDB( $conf->get('redirector.encode_url') ); -try { - $history = new History($conf->get('resource.history')); -} catch(Exception $e) { - die($e->getMessage()); -} - $container = new \Slim\Container(); $container['conf'] = $conf; $container['plugins'] = $pluginManager;