move.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. $file_guid = (int) get_input("file_guid", 0);
  3. $folder_guid = (int) get_input("folder_guid", 0);
  4. if (!empty($file_guid)) {
  5. if ($file = get_entity($file_guid)) {
  6. $container_entity = $file->getContainerEntity();
  7. if (($file->canEdit() || (elgg_instanceof($container_entity, "group") && $container_entity->isMember()))) {
  8. if (elgg_instanceof($file, "object", "file")) {
  9. // check if a given guid is a folder
  10. if (!empty($folder_guid)) {
  11. if (!($folder = get_entity($folder_guid)) || !elgg_instanceof($folder, "object", FILE_TOOLS_SUBTYPE)) {
  12. unset($folder_guid);
  13. }
  14. }
  15. // remove old relationships
  16. remove_entity_relationships($file->getGUID(), FILE_TOOLS_RELATIONSHIP, true);
  17. if (!empty($folder_guid)) {
  18. add_entity_relationship($folder_guid, FILE_TOOLS_RELATIONSHIP, $file_guid);
  19. }
  20. system_message(elgg_echo("file_tools:action:move:success:file"));
  21. } elseif (elgg_instanceof($file, "object", FILE_TOOLS_SUBTYPE)) {
  22. $file->parent_guid = $folder_guid;
  23. system_message(elgg_echo("file_tools:action:move:success:folder"));
  24. }
  25. } else {
  26. register_error(elgg_echo("InvalidParameterException:NoEntityFound"));
  27. }
  28. } else {
  29. register_error(elgg_echo("InvalidParameterException:NoEntityFound"));
  30. }
  31. } else {
  32. register_error(elgg_echo("InvalidParameterException:MissingParameter"));
  33. }
  34. forward(REFERER);