save.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Save album action
  4. *
  5. * @author Cash Costello
  6. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
  7. */
  8. // Get input data
  9. $title = get_input('title');
  10. $description = get_input('description');
  11. $tags = get_input('tags');
  12. $access_id = get_input('access_id');
  13. $container_guid = get_input('container_guid', elgg_get_logged_in_user_guid());
  14. $guid = get_input('guid');
  15. elgg_make_sticky_form('tidypics');
  16. if (empty($title)) {
  17. register_error(elgg_echo("album:blank"));
  18. forward(REFERER);
  19. }
  20. if ($guid) {
  21. $album = get_entity($guid);
  22. if ($album->access_id != $access_id) {
  23. $options = array('type' => 'object', 'subtype' => 'image', 'container_guid' => $album->guid, 'limit' => false);
  24. $images = new ElggBatch('elgg_get_entities', $options);
  25. foreach($images as $image) {
  26. $image->access_id = $access_id;
  27. $image->save();
  28. }
  29. $options = array('type' => 'object', 'subtype' => 'tidypics_batch', 'container_guid' => $album->guid, 'limit' => false);
  30. $batches = new ElggBatch('elgg_get_entities', $options);
  31. foreach($batches as $batch) {
  32. $batch->access_id = $access_id;
  33. $batch->save();
  34. }
  35. }
  36. } else {
  37. $album = new TidypicsAlbum();
  38. }
  39. $album->container_guid = $container_guid;
  40. $album->owner_guid = elgg_get_logged_in_user_guid();
  41. $album->access_id = $access_id;
  42. $album->title = $title;
  43. $album->description = $description;
  44. if($tags) {
  45. $album->tags = string_to_tag_array($tags);
  46. } else {
  47. $album->deleteMetadata('tags');
  48. }
  49. if (!$album->save()) {
  50. register_error(elgg_echo("album:error"));
  51. forward(REFERER);
  52. }
  53. elgg_clear_sticky_form('tidypics');
  54. system_message(elgg_echo("album:created"));
  55. forward($album->getURL());