ajax_upload_complete.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * A batch is complete so check if this is first upload to album
  4. *
  5. */
  6. $batch = get_input('batch');
  7. $album_guid = (int) get_input('album_guid');
  8. $img_river_view = elgg_get_plugin_setting('img_river_view', 'tidypics');
  9. $album = get_entity($album_guid);
  10. if (!elgg_instanceof($album, 'object', 'album')) {
  11. exit;
  12. }
  13. $params = array(
  14. 'type' => 'object',
  15. 'subtype' => 'image',
  16. 'metadata_names' => 'batch',
  17. 'metadata_values' => $batch,
  18. 'limit' => 0
  19. );
  20. $images = elgg_get_entities_from_metadata($params);
  21. if ($images) {
  22. // Create a new batch object to contain these photos
  23. $batch = new TidypicsBatch();
  24. $batch->access_id = $album->access_id;
  25. $batch->container_guid = $album->guid;
  26. if ($batch->save()) {
  27. foreach ($images as $image) {
  28. add_entity_relationship($image->guid, "belongs_to_batch", $batch->getGUID());
  29. }
  30. }
  31. } else {
  32. // @todo some sort of message to edit them manually.
  33. exit;
  34. }
  35. // "added images to album" river
  36. if ($img_river_view == "batch" && $album->new_album == false) {
  37. elgg_create_river_item(array('view' => 'river/object/tidypics_batch/create',
  38. 'action_type' => 'create',
  39. 'subject_guid' => $batch->getOwnerGUID(),
  40. 'object_guid' => $batch->getGUID()));
  41. } else if ($img_river_view == "1" && $album->new_album == false) {
  42. elgg_create_river_item(array('view' => 'river/object/tidypics_batch/create_single_image',
  43. 'action_type' => 'create',
  44. 'subject_guid' => $batch->getOwnerGUID(),
  45. 'object_guid' => $batch->getGUID()));
  46. }
  47. // "created album" river
  48. if ($album->new_album) {
  49. $album->new_album = false;
  50. $album->first_upload = true;
  51. $album_river_view = elgg_get_plugin_setting('album_river_view', 'tidypics');
  52. if ($album_river_view != "none") {
  53. elgg_create_river_item(array('view' => 'river/object/album/create',
  54. 'action_type' => 'create',
  55. 'subject_guid' => $album->getOwnerGUID(),
  56. 'object_guid' => $album->getGUID()));
  57. }
  58. // "created album" notifications
  59. // we throw the notification manually here so users are not told about the new album until
  60. // there are at least a few photos in it
  61. if ($album->shouldNotify()) {
  62. elgg_trigger_event('album_first', 'album', $album);
  63. $album->last_notified = time();
  64. }
  65. } else {
  66. // "added image to album" notifications
  67. if ($album->first_upload) {
  68. $album->first_upload = false;
  69. }
  70. if ($album->shouldNotify()) {
  71. elgg_trigger_event('album_more', 'album', $album);
  72. $album->last_notified = time();
  73. }
  74. }
  75. echo json_encode(array('batch_guid' => $batch->getGUID()));
  76. exit;