$batch = get_input('batch'); $album = get_entity($album_guid); if (!$album) { echo elgg_echo('tidypics:baduploadform'); exit; } // probably POST limit exceeded if (empty($_FILES)) { trigger_error('Tidypics warning: user exceeded post limit on image upload', E_USER_WARNING); register_error(elgg_echo('tidypics:exceedpostlimit')); exit; } $file = $_FILES[$file_var_name]; $image = new TidypicsImage(); $image->container_guid = $album->getGUID(); $image->setMimeType($file['type']); $image->access_id = $album->access_id; $image->batch = $batch; try { $result = $image->save($file); } catch (Exception $e) { // remove the bits that were saved $image->delete(); $result = false; echo $e->getMessage(); } if ($result) { $album->prependImageList(array($image->guid)); if (elgg_get_plugin_setting('img_river_view', 'tidypics') === "all") { elgg_create_river_item(array('view' => 'river/object/image/create', 'action_type' => 'create', 'subject_guid' => $image->getOwnerGUID(), 'object_guid' => $image->getGUID())); }
// create the image object for each upload $uploaded_images = array(); $not_uploaded = array(); $error_msgs = array(); foreach ($_FILES['images']['name'] as $index => $value) { $data = array(); foreach ($_FILES['images'] as $key => $values) { $data[$key] = $values[$index]; } if (empty($data['name'])) { continue; } $mime = tp_upload_get_mimetype($data['name']); $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->getOwnerGUID(), $image->getGUID()); } } } if (count($uploaded_images)) {
/** * 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; } }