Better parsing for tags
This commit is contained in:
parent
ad082076df
commit
9cd3f050cd
@ -316,16 +316,8 @@ photo = {
|
|||||||
|
|
||||||
tags = $(".message input.text").val();
|
tags = $(".message input.text").val();
|
||||||
|
|
||||||
if (tags.length<800) {
|
if (tags.length<800) photo.setTags(photoIDs, tags)
|
||||||
|
else loadingBar.show("error", "Description too long. Please try again!");
|
||||||
if (visible.photo()) {
|
|
||||||
photo.json.tags = tags;
|
|
||||||
view.photo.tags();
|
|
||||||
}
|
|
||||||
|
|
||||||
photo.setTags(photoIDs, tags)
|
|
||||||
|
|
||||||
} else loadingBar.show("error", "Description too long. Please try again!");
|
|
||||||
|
|
||||||
}],
|
}],
|
||||||
["Cancel", function() {}]
|
["Cancel", function() {}]
|
||||||
@ -341,6 +333,15 @@ photo = {
|
|||||||
if (!photoIDs) return false;
|
if (!photoIDs) return false;
|
||||||
if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
|
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;
|
params = "setTags&photoIDs=" + photoIDs + "&tags=" + tags;
|
||||||
lychee.api(params, function(data) {
|
lychee.api(params, function(data) {
|
||||||
|
|
||||||
@ -360,7 +361,6 @@ photo = {
|
|||||||
|
|
||||||
// Save
|
// Save
|
||||||
photo.json.tags = tags.toString();
|
photo.json.tags = tags.toString();
|
||||||
view.photo.tags();
|
|
||||||
photo.setTags([photoID], photo.json.tags);
|
photo.setTags([photoID], photo.json.tags);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@ -23,12 +23,10 @@ function getTags($photoID) {
|
|||||||
function setTags($photoIDs, $tags) {
|
function setTags($photoIDs, $tags) {
|
||||||
|
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
if (substr($tags, strlen($tags)-1)===',') $tags = substr($tags, 0, strlen($tags)-1);
|
// Parse tags
|
||||||
$tags = str_replace(' , ', ',', $tags);
|
$tags = preg_replace('/(\ ,\ )|(\ ,)|(,\ )|(,{1,}\ {0,})|(,$|^,)/', ',', $tags);
|
||||||
$tags = str_replace(', ', ',', $tags);
|
$tags = preg_replace('/,$|^,/', ',', $tags);
|
||||||
$tags = str_replace(' ,', ',', $tags);
|
|
||||||
$tags = str_replace(',,', ',', $tags);
|
|
||||||
|
|
||||||
$result = $database->query("UPDATE lychee_photos SET tags = '$tags' WHERE id IN ($photoIDs);");
|
$result = $database->query("UPDATE lychee_photos SET tags = '$tags' WHERE id IN ($photoIDs);");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user