From c51b483f24936c8d04a54a6999412937ec21c49a Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 19 Nov 2011 23:13:26 -0500 Subject: uploading photos through the basic interface works now --- actions/photos/image/upload.php | 126 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 actions/photos/image/upload.php (limited to 'actions/photos/image/upload.php') diff --git a/actions/photos/image/upload.php b/actions/photos/image/upload.php new file mode 100644 index 000000000..3a1970367 --- /dev/null +++ b/actions/photos/image/upload.php @@ -0,0 +1,126 @@ + $value) { + $data = array(); + foreach ($_FILES['images'] as $key => $values) { + $data[$key] = $values[$index]; + } + + if (empty($data['name'])) { + continue; + } + + $image = new TidypicsImage(); + $image->container_guid = $album->getGUID(); + $image->setMimeType($mime); + $image->access_id = $album->access_id; + + try { + $result = $image->save($data); + } catch (Exception $e) { + array_push($not_uploaded, $data['name']); + array_push($error_msgs, $e->getMessage()); + } + + if ($result) { + array_push($uploaded_images, $image->getGUID()); + + if ($img_river_view == "all") { + add_to_river('river/object/image/create', 'create', $image->getObjectOwnerGUID(), $image->getGUID()); + } + } +} + +if (count($uploaded_images)) { + // Create a new batch object to contain these photos + $batch = new ElggObject(); + $batch->subtype = "tidypics_batch"; + $batch->access_id = $album->access_id; + $batch->container_guid = $album->getGUID(); + if ($batch->save()) { + foreach ($uploaded_images as $uploaded_guid) { + add_entity_relationship($uploaded_guid, "belongs_to_batch", $batch->getGUID()); + } + } + + $album->prependImageList($uploaded_images); + + if ($img_river_view == "batch" && $album->new_album == false) { + add_to_river('river/object/tidypics_batch/create', 'create', $batch->getObjectOwnerGUID(), $batch->getGUID()); + } + + if ($album->new_album) { + $album->new_album = false; + add_to_river('river/object/album/create', 'create', $album->getOwnerGUID(), $album->getGUID()); + + // we throw the notification manually here so users are not told about the new album until there + // is at least a few photos in it + object_notifications('create', 'object', $album); + } +} + +if (count($not_uploaded) > 0) { + if (count($uploaded_images) > 0) { + $error = sprintf(elgg_echo("tidypics:partialuploadfailure"), count($not_uploaded), count($not_uploaded) + count($uploaded_images)) . '
'; + } else { + $error = elgg_echo("tidypics:completeuploadfailure") . '
'; + } + + $num_failures = count($not_uploaded); + for ($i = 0; $i < $num_failures; $i++) { + $error .= "{$not_uploaded[$i]}: {$error_msgs[$i]}
"; + } + register_error($error); + + if (count($uploaded_images) == 0) { + //upload failed, so forward to previous page + forward(REFERER); + } else { + // some images did upload so we fall through + } +} else { + system_message(elgg_echo('tidypics:upl_success')); +} + +forward("photos/edit/$batch->guid"); -- cgit v1.2.3