delete.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Delete album or image
  4. *
  5. * @author Cash Costello
  6. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
  7. */
  8. $guid = (int) get_input('guid');
  9. $entity = get_entity($guid);
  10. if (!$entity) {
  11. // unable to get Elgg entity
  12. register_error(elgg_echo("tidypics:deletefailed"));
  13. forward(REFERER);
  14. }
  15. if (!$entity->canEdit()) {
  16. // user doesn't have permissions
  17. register_error(elgg_echo("tidypics:deletefailed"));
  18. forward(REFERER);
  19. }
  20. $container = $entity->getContainerEntity();
  21. $subtype = $entity->getSubtype();
  22. switch ($subtype) {
  23. case 'album':
  24. if (elgg_instanceof($container, 'user')) {
  25. $forward_url = "photos/owner/$container->username";
  26. } else {
  27. $forward_url = "photos/group/$container->guid/all";
  28. }
  29. break;
  30. case 'image':
  31. $forward_url = $container->getURL();
  32. break;
  33. default:
  34. forward(REFERER);
  35. break;
  36. }
  37. if ($entity->delete()) {
  38. system_message(elgg_echo("tidypics:deleted"));
  39. } else {
  40. register_error(elgg_echo("tidypics:deletefailed"));
  41. }
  42. forward($forward_url);