} 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(), 'target_guid' => $album->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(), 'target_guid' => $album->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(), 'target_guid' => $album->getGUID())); } } // "created album" river if ($album->new_album) { $album->new_album = false; $album->first_upload = true;
$img_river_view = elgg_get_plugin_setting('img_river_view', 'tidypics'); $album = get_entity($album_guid); if (!elgg_instanceof($album, 'object', 'album')) { exit; } $params = array('type' => 'object', 'subtype' => 'image', 'metadata_names' => 'batch', 'metadata_values' => $batch, 'limit' => 0); $images = elgg_get_entities_from_metadata($params); if ($images) { // Create a new batch object to contain these photos $batch = new TidypicsBatch(); $batch->access_id = $album->access_id; $batch->container_guid = $album->guid; try { if ($batch->save()) { foreach ($images as $image) { add_entity_relationship($image->guid, "belongs_to_batch", $batch->getGUID()); } } else { elgg_log("ZHError , tidypics, error calling batch->save, album_id {$album_guid}, user_id " . elgg_get_logged_in_user_guid(), "ERROR"); } } catch (Exception $e) { if ($e->getMessage() == elgg_echo('tidypics:cannot_upload_exceeds_quota')) { register_error(elgg_echo('tidypics:cannot_upload_exceeds_quota')); } register_error(elgg_echo("zhaohu:wrong") . elgg_echo("zhaohu:sorry")); elgg_log("ZHError , tidypics, Exception calling batch->save, album_id {$album_guid}, user_id " . elgg_get_logged_in_user_guid() . "Exception " . $e->getMessage(), "ERROR"); } } else { // @todo some sort of message to edit them manually. elgg_log("ZHError , tidypics, error calling elgg_get_entities_from_metadata, album_id {$album_guid}, user_id " . elgg_get_logged_in_user_guid(), "ERROR"); exit;
/** * Created by PhpStorm. * Date: 12/4/2015 * Time: 11:38 PM * @param int $access * @param $album_guid * @param $username * @param $title * @param $caption * @return * @throws InvalidParameterException */ function image_save_post($access = ACCESS_FRIENDS, $album_guid, $username, $title, $caption) { if (!$username) { $user = elgg_get_logged_in_user_entity(); } else { $user = get_user_by_username($username); if (!$user) { throw new InvalidParameterException('registration:usernamenotvalid'); } } $path = elgg_get_plugins_path(); include_once $path . 'tidypics/lib/upload.php'; $file = $_FILES["Image"]; $imageMime = getimagesize($file['tmp_name']); // get temporary file REAL info $file['type'] = $imageMime['mime']; if ($album_guid == 0) { $album_guid = album_getid($user->username); } if (empty($file)) { $response['status'] = 1; $response['result'] = elgg_echo("image:blank"); return $response; } if ($access == 'ACCESS_FRIENDS') { $access_id = -2; } elseif ($access == 'ACCESS_PRIVATE') { $access_id = 0; } elseif ($access == 'ACCESS_LOGGED_IN') { $access_id = 1; } elseif ($access == 'ACCESS_PUBLIC') { $access_id = 2; } else { $access_id = -2; } $batch_id = time(); $album = get_entity($album_guid); if (!$album) { $response['status'] = 1; $response['result'] = "Album not found"; return $response; } $image = new TidypicsImage(); $image->container_guid = $album_guid; $image->setMimeType($file['type']); $image->access_id = $access_id; $image->batch = $batch_id; $image->owner_guid = $user->guid; $image->description = $caption; $image->title = $title; try { $result = $image->save($file); } catch (Exception $e) { // remove the bits that were saved if ($image_entity = get_entity($image->getGUID())) { $recursive = true; if ($image_entity->delete($recursive)) { $result = false; } } echo $e->getMessage(); $response['status'] = 1; $response['result'] = $e->getMessage(); return $response; exit; } set_input('tidypics_action_name', 'tidypics_photo_upload'); if ($result) { $album->prependImageList(array($image->guid)); $img_river_view = elgg_get_plugin_setting('img_river_view', 'tidypics'); $batch = new TidypicsBatch(); $batch->access_id = $album->access_id; $batch->container_guid = $album->guid; $batch->owner_guid = $user->guid; $batch->description = $caption; if ($batch->save()) { add_entity_relationship($image->guid, "belongs_to_batch", $batch->getGUID()); //foreach ($images as $image) { // add_entity_relationship($image->guid, "belongs_to_batch", $batch->getGUID()); //} } $img_river_view = elgg_get_plugin_setting('img_river_view', 'tidypics'); // "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(), 'target_guid' => $album->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(), 'target_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_services()->events->trigger('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_services()->events->trigger('album_more', 'album', $album); $album->last_notified = time(); } } $response['status'] = 0; $response['result'] = $image->guid; return $response; } }
} if ($result) { array_push($uploaded_images, $image->getGUID()); if ($img_river_view == "all") { add_to_river('river/object/image/create', 'create', $image->getOwnerGUID(), $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) { add_to_river('river/object/tidypics_batch/create', 'create', $batch->getOwnerGUID(), $batch->getGUID()); } else { if ($img_river_view == "1" && $album->new_album == false) { add_to_river('river/object/tidypics_batch/create_single_image', 'create', $batch->getOwnerGUID(), $batch->getGUID()); } } // "created album" river if ($album->new_album) { $album->new_album = false; $album->first_upload = true;
$album_guid = (int) get_input('album_guid'); $img_river_view = elgg_get_plugin_setting('img_river_view', 'tidypics'); $album = get_entity($album_guid); if (!elgg_instanceof($album, 'object', 'album')) { exit; } $params = array('type' => 'object', 'subtype' => 'image', 'metadata_names' => 'batch', 'metadata_values' => $batch, 'limit' => 0); $images = elgg_get_entities_from_metadata($params); if ($images) { // Create a new batch object to contain these photos $batch = new TidypicsBatch(); $batch->access_id = $album->access_id; $batch->container_guid = $album->guid; if ($batch->save()) { foreach ($images as $image) { add_entity_relationship($image->guid, "belongs_to_batch", $batch->getGUID()); } } } else { // @todo some sort of message to edit them manually. exit; } // "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