diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-05-31 18:24:21 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2017-05-31 18:24:21 +0200 |
commit | 4c970f099f2210ac91cccdca1d0c3564a8f79c1a (patch) | |
tree | 866b1a8a21dfda3084c4b5d52c2f23ffeaf60339 /index.php | |
parent | 5c6fac0bfc9583e6e372643facf6ddc50a6a1b1d (diff) | |
download | Shaarli-4c970f099f2210ac91cccdca1d0c3564a8f79c1a.tar.gz Shaarli-4c970f099f2210ac91cccdca1d0c3564a8f79c1a.tar.zst Shaarli-4c970f099f2210ac91cccdca1d0c3564a8f79c1a.zip |
Make sure that the tag exists before altering/removing it
Fixes #886
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 27 |
1 files changed, 17 insertions, 10 deletions
@@ -1176,6 +1176,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
1176 | die('Wrong token.'); | 1176 | die('Wrong token.'); |
1177 | } | 1177 | } |
1178 | 1178 | ||
1179 | $count = 0; | ||
1179 | // Delete a tag: | 1180 | // Delete a tag: |
1180 | if (isset($_POST['deletetag']) && !empty($_POST['fromtag'])) { | 1181 | if (isset($_POST['deletetag']) && !empty($_POST['fromtag'])) { |
1181 | $needle = trim($_POST['fromtag']); | 1182 | $needle = trim($_POST['fromtag']); |
@@ -1184,13 +1185,16 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
1184 | foreach($linksToAlter as $key=>$value) | 1185 | foreach($linksToAlter as $key=>$value) |
1185 | { | 1186 | { |
1186 | $tags = explode(' ',trim($value['tags'])); | 1187 | $tags = explode(' ',trim($value['tags'])); |
1187 | unset($tags[array_search($needle,$tags)]); // Remove tag. | 1188 | if (($pos = array_search($needle,$tags)) !== false) { |
1188 | $value['tags']=trim(implode(' ',$tags)); | 1189 | unset($tags[$pos]); // Remove tag. |
1189 | $LINKSDB[$key]=$value; | 1190 | $value['tags']=trim(implode(' ',$tags)); |
1190 | $history->updateLink($LINKSDB[$key]); | 1191 | $LINKSDB[$key]=$value; |
1192 | $history->updateLink($LINKSDB[$key]); | ||
1193 | ++$count; | ||
1194 | } | ||
1191 | } | 1195 | } |
1192 | $LINKSDB->save($conf->get('resource.page_cache')); | 1196 | $LINKSDB->save($conf->get('resource.page_cache')); |
1193 | echo '<script>alert("Tag was removed from '.count($linksToAlter).' links.");document.location=\'?do=changetag\';</script>'; | 1197 | echo '<script>alert("Tag was removed from '.$count.' links.");document.location=\'?do=changetag\';</script>'; |
1194 | exit; | 1198 | exit; |
1195 | } | 1199 | } |
1196 | 1200 | ||
@@ -1202,13 +1206,16 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
1202 | foreach($linksToAlter as $key=>$value) { | 1206 | foreach($linksToAlter as $key=>$value) { |
1203 | $tags = preg_split('/\s+/', trim($value['tags'])); | 1207 | $tags = preg_split('/\s+/', trim($value['tags'])); |
1204 | // Replace tags value. | 1208 | // Replace tags value. |
1205 | $tags[array_search($needle, $tags)] = trim($_POST['totag']); | 1209 | if (($pos = array_search($needle,$tags)) !== false) { |
1206 | $value['tags'] = implode(' ', array_unique($tags)); | 1210 | $tags[$pos] = trim($_POST['totag']); |
1207 | $LINKSDB[$key] = $value; | 1211 | $value['tags'] = implode(' ', array_unique($tags)); |
1208 | $history->updateLink($LINKSDB[$key]); | 1212 | $LINKSDB[$key] = $value; |
1213 | $history->updateLink($LINKSDB[$key]); | ||
1214 | ++$count; | ||
1215 | } | ||
1209 | } | 1216 | } |
1210 | $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk. | 1217 | $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk. |
1211 | echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode(escape($_POST['totag'])).'\';</script>'; | 1218 | echo '<script>alert("Tag was renamed in '.$count.' links.");document.location=\'?searchtags='.urlencode(escape($_POST['totag'])).'\';</script>'; |
1212 | exit; | 1219 | exit; |
1213 | } | 1220 | } |
1214 | } | 1221 | } |