untag.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Remove photo tag action
  4. */
  5. $annotation = elgg_get_annotation_from_id(get_input('annotation_id'));
  6. if (!$annotation instanceof ElggAnnotation || $annotation->name != 'phototag') {
  7. register_error(elgg_echo("tidypics:phototagging:delete:error"));
  8. forward(REFERER);
  9. }
  10. if (!$annotation->canEdit()) {
  11. register_error(elgg_echo("tidypics:phototagging:delete:error"));
  12. forward(REFERER);
  13. }
  14. $entity_guid = $annotation->entity_guid;
  15. $image = get_entity($entity_guid);
  16. if (!$image) {
  17. register_error(elgg_echo("tidypics:phototagging:error"));
  18. forward(REFERER);
  19. }
  20. $value = $annotation->value;
  21. if ($annotation->delete()) {
  22. // KJ - now remove any user tag relationship
  23. $tag = unserialize($value);
  24. if ($tag->type == 'user') {
  25. remove_entity_relationship($tag->value, 'phototag', $entity_guid);
  26. } else if ($tag->type == 'word') {
  27. $obsolete_tags = string_to_tag_array($tag->value);
  28. // delete normal tags if they exists
  29. if (is_array($image->tags)) {
  30. $tagarray = array();
  31. $removed_tags = array();
  32. foreach($image->tags as $image_tag) {
  33. if((!in_array($image_tag, $obsolete_tags)) || (in_array($image_tag, $removed_tags))) {
  34. $tagarray[] = $image_tag;
  35. } else {
  36. $removed_tags[] = $image_tag;
  37. }
  38. }
  39. $image->deleteMetadata('tags');
  40. if (sizeof($tagarray) > 0) {
  41. $image->tags = $tagarray;
  42. }
  43. } else {
  44. if ($tag->value === $image->tags) {
  45. $image->deleteMetadata('tags');
  46. }
  47. }
  48. }
  49. system_message(elgg_echo("tidypics:phototagging:delete:success"));
  50. } else {
  51. system_message(elgg_echo("tidypics:phototagging:delete:error"));
  52. }
  53. forward(REFERER);