$value) {
$data = array();
foreach ($_FILES['images'] as $key => $values) {
$data[$key] = $values[$index];
}
if (empty($data['name'])) {
continue;
}
$name = htmlspecialchars($data['name'], ENT_QUOTES, 'UTF-8', false);
$mime = tp_upload_get_mimetype($name);
$image = new TidypicsImage();
$image->title = $name;
$image->container_guid = $album->getGUID();
$image->setMimeType($mime);
$image->access_id = $album->access_id;
try {
$result = $image->save($data);
} catch (Exception $e) {
$image->delete();
$result = false;
array_push($not_uploaded, $name);
array_push($error_msgs, $e->getMessage());
}
if ($result) {
array_push($uploaded_images, $image->getGUID());
if ($img_river_view == "all") {
elgg_create_river_item(array('view' => 'river/object/image/create',
'action_type' => 'create',
'subject_guid' => $image->getOwnerGUID(),
'object_guid' => $image->getGUID()));
}
}
}
if (count($uploaded_images)) {
// Create a new batch object to contain these photos
$batch = new TidypicsBatch();
$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);
// "added images to album" river
if ($img_river_view == "batch" && $album->new_album == false) {
elgg_create_river_item(array('view' => 'river/object/tidypics_batch/create',
'action_type' => 'create',
'subject_guid' => $batch->getOwnerGUID(),
'object_guid' => $batch->getGUID()));
} else if ($img_river_view == "1" && $album->new_album == false) {
elgg_create_river_item(array('view' => 'river/object/tidypics_batch/create_single_image',
'action_type' => 'create',
'subject_guid' => $batch->getOwnerGUID(),
'object_guid' => $batch->getGUID()));
}
// "created album" river
if ($album->new_album) {
$album->new_album = false;
$album->first_upload = true;
$album_river_view = elgg_get_plugin_setting('album_river_view', 'tidypics');
if ($album_river_view != "none") {
elgg_create_river_item(array('view' => 'river/object/album/create',
'action_type' => 'create',
'subject_guid' => $album->getOwnerGUID(),
'object_guid' => $album->getGUID()));
}
// "created album" notifications
// we throw the notification manually here so users are not told about the new album until
// there are at least a few photos in it
if ($album->shouldNotify()) {
elgg_trigger_event('album_first', 'album', $album);
$album->last_notified = time();
}
} else {
// "added image to album" notifications
if ($album->first_upload) {
$album->first_upload = false;
}
if ($album->shouldNotify()) {
elgg_trigger_event('album_more', 'album', $album);
$album->last_notified = time();
}
}
}
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");