/** * Pull EXIF data from image file * * @param TidypicsImage $file */ function td_get_exif($file) { // catch for those who don't have exif module loaded if (!is_callable('exif_read_data')) { return; } $mime = $file->mimetype; if ($mime != 'image/jpeg' && $mime != 'image/pjpeg') { return; } $filename = $file->getFilenameOnFilestore(); $exif = exif_read_data($filename); create_metadata($file->getGUID(), "tp_exif", serialize($exif), "text", $file->getOwnerGUID(), ACCESS_PUBLIC); }
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)) { // 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()); }
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())); } } exit;
$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(), '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()); } }
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]; $mime = tp_upload_get_mimetype($file['name']); if ($mime == 'unknown') { echo 'Not an image'; exit; } // we have to override the mime type because uploadify sends everything as application/octet-string $file['type'] = $mime; $image = new TidypicsImage(); $image->container_guid = $album->getGUID(); $image->setMimeType($mime); $image->access_id = $album->access_id; $image->batch = $batch; try { $image->save($file); $album->prependImageList(array($image->guid)); if (elgg_get_plugin_setting('img_river_view', 'tidypics') === "all") { add_to_river('river/object/image/create', 'create', $image->getOwnerGUID(), $image->getGUID()); } echo elgg_echo('success'); } catch (Exception $e) { // remove the bits that were saved $image->delete(); echo $e->getMessage(); } 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; } }