aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php58
1 files changed, 18 insertions, 40 deletions
diff --git a/index.php b/index.php
index 5c292b04..9025df58 100644
--- a/index.php
+++ b/index.php
@@ -686,6 +686,7 @@ function showLinkList($PAGE, $LINKSDB, $conf, $pluginManager) {
686 * @param ConfigManager $conf Configuration Manager instance. 686 * @param ConfigManager $conf Configuration Manager instance.
687 * @param PluginManager $pluginManager Plugin Manager instance, 687 * @param PluginManager $pluginManager Plugin Manager instance,
688 * @param LinkDB $LINKSDB 688 * @param LinkDB $LINKSDB
689 * @param History $history instance
689 */ 690 */
690function renderPage($conf, $pluginManager, $LINKSDB, $history) 691function renderPage($conf, $pluginManager, $LINKSDB, $history)
691{ 692{
@@ -1198,41 +1199,18 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
1198 die('Wrong token.'); 1199 die('Wrong token.');
1199 } 1200 }
1200 1201
1201 // Delete a tag: 1202 $alteredLinks = $LINKSDB->renameTag(escape($_POST['fromtag']), escape($_POST['totag']));
1202 if (isset($_POST['deletetag']) && !empty($_POST['fromtag'])) { 1203 $LINKSDB->save($conf->get('resource.page_cache'));
1203 $needle = trim($_POST['fromtag']); 1204 foreach ($alteredLinks as $link) {
1204 // True for case-sensitive tag search. 1205 $history->updateLink($link);
1205 $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true);
1206 foreach($linksToAlter as $key=>$value)
1207 {
1208 $tags = explode(' ',trim($value['tags']));
1209 unset($tags[array_search($needle,$tags)]); // Remove tag.
1210 $value['tags']=trim(implode(' ',$tags));
1211 $LINKSDB[$key]=$value;
1212 $history->updateLink($LINKSDB[$key]);
1213 }
1214 $LINKSDB->save($conf->get('resource.page_cache'));
1215 echo '<script>alert("Tag was removed from '.count($linksToAlter).' links.");document.location=\'?do=changetag\';</script>';
1216 exit;
1217 }
1218
1219 // Rename a tag:
1220 if (isset($_POST['renametag']) && !empty($_POST['fromtag']) && !empty($_POST['totag'])) {
1221 $needle = trim($_POST['fromtag']);
1222 // True for case-sensitive tag search.
1223 $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true);
1224 foreach($linksToAlter as $key=>$value) {
1225 $tags = preg_split('/\s+/', trim($value['tags']));
1226 // Replace tags value.
1227 $tags[array_search($needle, $tags)] = trim($_POST['totag']);
1228 $value['tags'] = implode(' ', array_unique($tags));
1229 $LINKSDB[$key] = $value;
1230 $history->updateLink($LINKSDB[$key]);
1231 }
1232 $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk.
1233 echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode(escape($_POST['totag'])).'\';</script>';
1234 exit;
1235 } 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;
1236 } 1214 }
1237 1215
1238 // -------- 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.
@@ -2259,6 +2237,12 @@ if (!isset($_SESSION['LINKS_PER_PAGE'])) {
2259 $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20); 2237 $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20);
2260} 2238}
2261 2239
2240try {
2241 $history = new History($conf->get('resource.history'));
2242} catch(Exception $e) {
2243 die($e->getMessage());
2244}
2245
2262$linkDb = new LinkDB( 2246$linkDb = new LinkDB(
2263 $conf->get('resource.datastore'), 2247 $conf->get('resource.datastore'),
2264 isLoggedIn(), 2248 isLoggedIn(),
@@ -2267,12 +2251,6 @@ $linkDb = new LinkDB(
2267 $conf->get('redirector.encode_url') 2251 $conf->get('redirector.encode_url')
2268); 2252);
2269 2253
2270try {
2271 $history = new History($conf->get('resource.history'));
2272} catch(Exception $e) {
2273 die($e->getMessage());
2274}
2275
2276$container = new \Slim\Container(); 2254$container = new \Slim\Container();
2277$container['conf'] = $conf; 2255$container['conf'] = $conf;
2278$container['plugins'] = $pluginManager; 2256$container['plugins'] = $pluginManager;