Better parsing for tags

This commit is contained in:
Tobias Reich 2014-02-02 23:22:06 +01:00
parent ad082076df
commit 9cd3f050cd
2 changed files with 15 additions and 17 deletions

View File

@ -316,16 +316,8 @@ photo = {
tags = $(".message input.text").val();
if (tags.length<800) {
if (visible.photo()) {
photo.json.tags = tags;
view.photo.tags();
}
photo.setTags(photoIDs, tags)
} else loadingBar.show("error", "Description too long. Please try again!");
if (tags.length<800) photo.setTags(photoIDs, tags)
else loadingBar.show("error", "Description too long. Please try again!");
}],
["Cancel", function() {}]
@ -341,6 +333,15 @@ photo = {
if (!photoIDs) return false;
if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
// Parse tags
tags = tags.replace(/(\ ,\ )|(\ ,)|(,\ )|(,{1,}\ {0,})|(,$|^,)/g, ',');
tags = tags.replace(/,$|^,/g, '');
if (visible.photo()) {
photo.json.tags = tags;
view.photo.tags();
}
params = "setTags&photoIDs=" + photoIDs + "&tags=" + tags;
lychee.api(params, function(data) {
@ -360,7 +361,6 @@ photo = {
// Save
photo.json.tags = tags.toString();
view.photo.tags();
photo.setTags([photoID], photo.json.tags);
},

View File

@ -23,12 +23,10 @@ function getTags($photoID) {
function setTags($photoIDs, $tags) {
global $database;
if (substr($tags, strlen($tags)-1)===',') $tags = substr($tags, 0, strlen($tags)-1);
$tags = str_replace(' , ', ',', $tags);
$tags = str_replace(', ', ',', $tags);
$tags = str_replace(' ,', ',', $tags);
$tags = str_replace(',,', ',', $tags);
// Parse tags
$tags = preg_replace('/(\ ,\ )|(\ ,)|(,\ )|(,{1,}\ {0,})|(,$|^,)/', ',', $tags);
$tags = preg_replace('/,$|^,/', ',', $tags);
$result = $database->query("UPDATE lychee_photos SET tags = '$tags' WHERE id IN ($photoIDs);");