diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 74 |
1 files changed, 33 insertions, 41 deletions
@@ -287,6 +287,7 @@ function logout() { | |||
287 | unset($_SESSION['ip']); | 287 | unset($_SESSION['ip']); |
288 | unset($_SESSION['username']); | 288 | unset($_SESSION['username']); |
289 | unset($_SESSION['privateonly']); | 289 | unset($_SESSION['privateonly']); |
290 | unset($_SESSION['untaggedonly']); | ||
290 | } | 291 | } |
291 | setcookie('shaarli_staySignedIn', FALSE, 0, WEB_PATH); | 292 | setcookie('shaarli_staySignedIn', FALSE, 0, WEB_PATH); |
292 | } | 293 | } |
@@ -685,6 +686,7 @@ function showLinkList($PAGE, $LINKSDB, $conf, $pluginManager) { | |||
685 | * @param ConfigManager $conf Configuration Manager instance. | 686 | * @param ConfigManager $conf Configuration Manager instance. |
686 | * @param PluginManager $pluginManager Plugin Manager instance, | 687 | * @param PluginManager $pluginManager Plugin Manager instance, |
687 | * @param LinkDB $LINKSDB | 688 | * @param LinkDB $LINKSDB |
689 | * @param History $history instance | ||
688 | */ | 690 | */ |
689 | function renderPage($conf, $pluginManager, $LINKSDB, $history) | 691 | function renderPage($conf, $pluginManager, $LINKSDB, $history) |
690 | { | 692 | { |
@@ -1017,6 +1019,19 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
1017 | exit; | 1019 | exit; |
1018 | } | 1020 | } |
1019 | 1021 | ||
1022 | // -------- User wants to see only untagged links (toggle) | ||
1023 | if (isset($_GET['untaggedonly'])) { | ||
1024 | $_SESSION['untaggedonly'] = !$_SESSION['untaggedonly']; | ||
1025 | |||
1026 | if (! empty($_SERVER['HTTP_REFERER'])) { | ||
1027 | $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('untaggedonly')); | ||
1028 | } else { | ||
1029 | $location = '?'; | ||
1030 | } | ||
1031 | header('Location: '. $location); | ||
1032 | exit; | ||
1033 | } | ||
1034 | |||
1020 | // -------- Handle other actions allowed for non-logged in users: | 1035 | // -------- Handle other actions allowed for non-logged in users: |
1021 | if (!isLoggedIn()) | 1036 | if (!isLoggedIn()) |
1022 | { | 1037 | { |
@@ -1184,41 +1199,18 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
1184 | die('Wrong token.'); | 1199 | die('Wrong token.'); |
1185 | } | 1200 | } |
1186 | 1201 | ||
1187 | // Delete a tag: | 1202 | $alteredLinks = $LINKSDB->renameTag(escape($_POST['fromtag']), escape($_POST['totag'])); |
1188 | if (isset($_POST['deletetag']) && !empty($_POST['fromtag'])) { | 1203 | $LINKSDB->save($conf->get('resource.page_cache')); |
1189 | $needle = trim($_POST['fromtag']); | 1204 | foreach ($alteredLinks as $link) { |
1190 | // True for case-sensitive tag search. | 1205 | $history->updateLink($link); |
1191 | $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true); | ||
1192 | foreach($linksToAlter as $key=>$value) | ||
1193 | { | ||
1194 | $tags = explode(' ',trim($value['tags'])); | ||
1195 | unset($tags[array_search($needle,$tags)]); // Remove tag. | ||
1196 | $value['tags']=trim(implode(' ',$tags)); | ||
1197 | $LINKSDB[$key]=$value; | ||
1198 | $history->updateLink($LINKSDB[$key]); | ||
1199 | } | ||
1200 | $LINKSDB->save($conf->get('resource.page_cache')); | ||
1201 | echo '<script>alert("Tag was removed from '.count($linksToAlter).' links.");document.location=\'?do=changetag\';</script>'; | ||
1202 | exit; | ||
1203 | } | ||
1204 | |||
1205 | // Rename a tag: | ||
1206 | if (isset($_POST['renametag']) && !empty($_POST['fromtag']) && !empty($_POST['totag'])) { | ||
1207 | $needle = trim($_POST['fromtag']); | ||
1208 | // True for case-sensitive tag search. | ||
1209 | $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true); | ||
1210 | foreach($linksToAlter as $key=>$value) { | ||
1211 | $tags = preg_split('/\s+/', trim($value['tags'])); | ||
1212 | // Replace tags value. | ||
1213 | $tags[array_search($needle, $tags)] = trim($_POST['totag']); | ||
1214 | $value['tags'] = implode(' ', array_unique($tags)); | ||
1215 | $LINKSDB[$key] = $value; | ||
1216 | $history->updateLink($LINKSDB[$key]); | ||
1217 | } | ||
1218 | $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk. | ||
1219 | echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode(escape($_POST['totag'])).'\';</script>'; | ||
1220 | exit; | ||
1221 | } | 1206 | } |
1207 | $delete = empty($_POST['totag']); | ||
1208 | $redirect = $delete ? 'do=changetag' : 'searchtags='. urlencode(escape($_POST['totag'])); | ||
1209 | $alert = $delete | ||
1210 | ? sprintf(t('The tag was removed from %d links.'), count($alteredLinks)) | ||
1211 | : sprintf(t('The tag was renamed in %d links.'), count($alteredLinks)); | ||
1212 | echo '<script>alert("'. $alert .'");document.location=\'?'. $redirect .'\';</script>'; | ||
1213 | exit; | ||
1222 | } | 1214 | } |
1223 | 1215 | ||
1224 | // -------- User wants to add a link without using the bookmarklet: Show form. | 1216 | // -------- User wants to add a link without using the bookmarklet: Show form. |
@@ -1651,7 +1643,7 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) | |||
1651 | 'searchtags' => $searchtags, | 1643 | 'searchtags' => $searchtags, |
1652 | 'searchterm' => $searchterm, | 1644 | 'searchterm' => $searchterm, |
1653 | ]; | 1645 | ]; |
1654 | $linksToDisplay = $LINKSDB->filterSearch($request, false, $visibility); | 1646 | $linksToDisplay = $LINKSDB->filterSearch($request, false, $visibility, !empty($_SESSION['untaggedonly'])); |
1655 | } | 1647 | } |
1656 | 1648 | ||
1657 | // ---- Handle paging. | 1649 | // ---- Handle paging. |
@@ -2245,6 +2237,12 @@ if (!isset($_SESSION['LINKS_PER_PAGE'])) { | |||
2245 | $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20); | 2237 | $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20); |
2246 | } | 2238 | } |
2247 | 2239 | ||
2240 | try { | ||
2241 | $history = new History($conf->get('resource.history')); | ||
2242 | } catch(Exception $e) { | ||
2243 | die($e->getMessage()); | ||
2244 | } | ||
2245 | |||
2248 | $linkDb = new LinkDB( | 2246 | $linkDb = new LinkDB( |
2249 | $conf->get('resource.datastore'), | 2247 | $conf->get('resource.datastore'), |
2250 | isLoggedIn(), | 2248 | isLoggedIn(), |
@@ -2253,12 +2251,6 @@ $linkDb = new LinkDB( | |||
2253 | $conf->get('redirector.encode_url') | 2251 | $conf->get('redirector.encode_url') |
2254 | ); | 2252 | ); |
2255 | 2253 | ||
2256 | try { | ||
2257 | $history = new History($conf->get('resource.history')); | ||
2258 | } catch(Exception $e) { | ||
2259 | die($e->getMessage()); | ||
2260 | } | ||
2261 | |||
2262 | $container = new \Slim\Container(); | 2254 | $container = new \Slim\Container(); |
2263 | $container['conf'] = $conf; | 2255 | $container['conf'] = $conf; |
2264 | $container['plugins'] = $pluginManager; | 2256 | $container['plugins'] = $pluginManager; |