diff --git a/assets/js/modules/photo.js b/assets/js/modules/photo.js index 22a1dc0..8673f38 100644 --- a/assets/js/modules/photo.js +++ b/assets/js/modules/photo.js @@ -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); }, diff --git a/php/modules/tags.php b/php/modules/tags.php index f0faf9f..d5887ed 100644 --- a/php/modules/tags.php +++ b/php/modules/tags.php @@ -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);");