diff options
Diffstat (limited to 'actions')
-rw-r--r-- | actions/delete.php | 58 | ||||
-rw-r--r-- | actions/edit_multi.php | 65 | ||||
-rw-r--r-- | actions/photos/batch/edit.php | 42 | ||||
-rw-r--r-- | actions/photos/delete.php | 48 | ||||
-rw-r--r-- | actions/photos/image/upload.php | 126 | ||||
-rw-r--r-- | actions/upload.php | 202 |
6 files changed, 216 insertions, 325 deletions
diff --git a/actions/delete.php b/actions/delete.php deleted file mode 100644 index dfe910666..000000000 --- a/actions/delete.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php - -/** - * Tidypics Delete Action for Images and Albums - * - */ - -// must be logged in -gatekeeper(); - -$forward_url = 'pg/photos/world'; // by default forward to world photos - -$guid = (int) get_input('guid'); - -$entity = get_entity($guid); -if (!$entity) { - // unable to get Elgg entity - register_error(elgg_echo("tidypics:deletefailed")); - forward($forward_url); -} - -if (!$entity->canEdit()) { - // user doesn't have permissions - register_error(elgg_echo("tidypics:deletefailed")); - forward($forward_url); -} - -$subtype = $entity->getSubtype(); -$container = get_entity($entity->container_guid); - -if ($subtype != 'image' && $subtype != 'album') { - // how did we even get here? - register_error(elgg_echo("tidypics:deletefailed")); - forward($forward_url); -} - -if ($subtype == 'image') { - //forward back to album after deleting pictures - $forward_url = $container->getURL(); - - // plugins can register to be told when a Tidypics image has been deleted - trigger_elgg_event('delete', 'tp_image', $entity); -} else { - // forward to this person's albums - $forward_url = 'pg/photos/owned/' . $container->username; - - // plugins can register to be told when a Tidypics album has been deleted - trigger_elgg_event('delete', 'tp_album', $entity); -} - - -if ($entity->delete()) { - system_message(elgg_echo("tidypics:deleted")); -} else { - register_error(elgg_echo("tidypics:deletefailed")); -} - -forward($forward_url); diff --git a/actions/edit_multi.php b/actions/edit_multi.php deleted file mode 100644 index 1d0e537b0..000000000 --- a/actions/edit_multi.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php -/** - * Elgg album: multi image edit action - * - * This is called when uploading images - */ - -// Make sure we're logged in -gatekeeper(); - -// Get input data -$title_array = get_input('title'); -$caption_array = get_input('caption'); -$tags_array = get_input('tags'); -$image_guid_array = get_input('image_guid'); -$container_guid = get_input('container_guid'); -$album_entity = get_entity($container_guid); -$cover = get_input('cover'); -$not_updated = array(); - -foreach($image_guid_array as $key => $im) { - $image = get_entity($im); - - if ($image->canEdit()) { - - // Convert string of tags into a preformatted array - $tagarray = string_to_tag_array($tags_array[$key]); - - //set title appropriately - if ($title_array[$key]) { - $image->title = $title_array[$key]; - } else { - $image->title = substr($image->originalfilename, 0, strrpos($image->originalfilename, '.')); - } - - //set description appropriately - $image->description = $caption_array[$key]; - - // Before we can set metadata, we need to save the image - if (!$image->save()) { - array_push($not_updated, $image->guid); - } - - // Now let's add tags. We can pass an array directly to the object property! Easy. - $image->clearMetadata('tags'); - if (is_array($tagarray)) { - $image->tags = $tagarray; - } - - //if cover meta is sent from image save as metadata - if ($cover == $im) { - $album_entity->setCoverImageGuid($im); - } - } -} - -// Success message -if (count($not_updated) > 0) { - register_error(elgg_echo("images:notedited")); -} else { - system_message(elgg_echo("images:edited")); -} - -// Forward to the main album page -forward($album_entity->getURL()); diff --git a/actions/photos/batch/edit.php b/actions/photos/batch/edit.php new file mode 100644 index 000000000..6d376a9db --- /dev/null +++ b/actions/photos/batch/edit.php @@ -0,0 +1,42 @@ +<?php +/** + * Edit the images in a batch + * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 + */ + +$guids = get_input('guid'); +$titles = get_input('title'); +$captions = get_input('caption'); +$tags = get_input('tags'); + +$not_updated = array(); +foreach ($guids as $key => $guid) { + $image = get_entity($guid); + + if ($image->canEdit()) { + + // set title appropriately + if ($titles[$key]) { + $image->title = $titles[$key]; + } else { + $image->title = substr($image->originalfilename, 0, strrpos($image->originalfilename, '.')); + } + + // set description appropriately + $image->description = $captions[$key]; + $image->tags = string_to_tag_array($tags[$key]); + + if (!$image->save()) { + array_push($not_updated, $image->getGUID()); + } + } +} + +if (count($not_updated) > 0) { + register_error(elgg_echo("images:notedited")); +} else { + system_message(elgg_echo("images:edited")); +} +forward($image->getContainerEntity()->getURL()); diff --git a/actions/photos/delete.php b/actions/photos/delete.php new file mode 100644 index 000000000..f8d194e55 --- /dev/null +++ b/actions/photos/delete.php @@ -0,0 +1,48 @@ +<?php +/** + * Delete album or image + * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 + */ + +$guid = (int) get_input('guid'); +$entity = get_entity($guid); +if (!$entity) { + // unable to get Elgg entity + register_error(elgg_echo("tidypics:deletefailed")); + forward(REFERER); +} + +if (!$entity->canEdit()) { + // user doesn't have permissions + register_error(elgg_echo("tidypics:deletefailed")); + forward(REFERER); +} + +$container = $entity->getContainerEntity(); + +$subtype = $entity->getSubtype(); +switch ($subtype) { + case 'album': + if (elgg_instanceof($container, 'user')) { + $forward_url = "photos/owner/$container->username"; + } else { + $forward_url = "photos/group/$container->guid/all"; + } + break; + case 'image': + $forward_url = $container->getURL(); + break; + default: + forward(REFERER); + break; +} + +if ($entity->delete()) { + system_message(elgg_echo("tidypics:deleted")); +} else { + register_error(elgg_echo("tidypics:deletefailed")); +} + +forward($forward_url); 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 @@ +<?php +/** + * Multi-image uploader action + * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 + */ + +elgg_load_library('tidypics:upload'); + +$img_river_view = elgg_get_plugin_setting('img_river_view', 'tidypics'); + +$guid = (int) get_input('guid'); +$album = get_entity($guid); +if (!$album) { + register_error(elgg_echo('tidypics:baduploadform')); + forward(REFERER); +} + +// post limit exceeded +if (count($_FILES) == 0) { + trigger_error('Tidypics warning: user exceeded post limit on image upload', E_USER_WARNING); + register_error(elgg_echo('tidypics:exceedpostlimit')); + forward(REFERER); +} + +// test to make sure at least 1 image was selected by user +$num_images = 0; +foreach($_FILES['images']['name'] as $name) { + if (!empty($name)) { + $num_images++; + } +} +if ($num_images == 0) { + // have user try again + register_error(elgg_echo('tidypics:noimages')); + forward(REFERER); +} + +// 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; + } + + $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)) . '<br />'; + } else { + $error = elgg_echo("tidypics:completeuploadfailure") . '<br />'; + } + + $num_failures = count($not_uploaded); + for ($i = 0; $i < $num_failures; $i++) { + $error .= "{$not_uploaded[$i]}: {$error_msgs[$i]} <br />"; + } + 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"); diff --git a/actions/upload.php b/actions/upload.php deleted file mode 100644 index 3bbd97e60..000000000 --- a/actions/upload.php +++ /dev/null @@ -1,202 +0,0 @@ -<?php -/** - * Elgg multi-image uploader action - * - * This will upload up to 10 images at at time to an album - */ - -include_once dirname(dirname(__FILE__)) . "/lib/upload.php"; - -// Get common variables -$access_id = (int) get_input("access_id"); -$album_guid = (int) get_input('album_guid', 0); -$album = get_entity($album_guid); -if (!$album) { - register_error(elgg_echo('tidypics:baduploadform')); - forward($_SERVER['HTTP_REFERER']); -} - -$image_lib = get_plugin_setting('image_lib', 'tidypics'); -if (!$image_lib) { - $image_lib = "GD"; -} - -$img_river_view = get_plugin_setting('img_river_view', 'tidypics'); - -if ($album->new_album == TP_NEW_ALBUM) { - $new_album = true; -} else { - $new_album = false; -} - - -// post limit exceeded -if (count($_FILES) == 0) { - trigger_error('Tidypics warning: user exceeded post limit on image upload', E_USER_WARNING); - register_error(elgg_echo('tidypics:exceedpostlimit')); - forward($_SERVER['HTTP_REFERER']); -} - -// test to make sure at least 1 image was selected by user -$num_images = 0; -foreach($_FILES as $key => $sent_file) { - if (!empty($sent_file['name'])) { - $num_images++; - } -} -if ($num_images == 0) { - // have user try again - register_error(elgg_echo('tidypics:noimages')); - forward($_SERVER['HTTP_REFERER']); -} - -$uploaded_images = array(); -$not_uploaded = array(); -$error_msgs = array(); - -foreach($_FILES as $key => $sent_file) { - - // skip empty entries - if (empty($sent_file['name'])) { - continue; - } - - $name = $sent_file['name']; - $mime = $sent_file['type']; - - if ($sent_file['error']) { - array_push($not_uploaded, $sent_file['name']); - if ($sent_file['error'] == 1) { - trigger_error('Tidypics warning: image exceeded server php upload limit', E_USER_WARNING); - array_push($error_msgs, elgg_echo('tidypics:image_mem')); - } else { - array_push($error_msgs, elgg_echo('tidypics:unk_error')); - } - continue; - } - - // must be an image - if (!tp_upload_check_format($mime)) { - array_push($not_uploaded, $sent_file['name']); - array_push($error_msgs, elgg_echo('tidypics:not_image')); - continue; - } - - // check quota - if (!tp_upload_check_quota($sent_file['size'], get_loggedin_userid())) { - array_push($not_uploaded, $sent_file['name']); - array_push($error_msgs, elgg_echo('tidypics:exceed_quota')); - continue; - } - - // make sure file does not exceed memory limit - if (!tp_upload_check_max_size($sent_file['size'])) { - array_push($not_uploaded, $sent_file['name']); - array_push($error_msgs, elgg_echo('tidypics:image_mem')); - continue; - } - - // make sure the in memory image size does not exceed memory available - $imginfo = getimagesize($sent_file['tmp_name']); - if (!tp_upload_memory_check($image_lib, $imginfo[0] * $imginfo[1])) { - array_push($not_uploaded, $sent_file['name']); - array_push($error_msgs, elgg_echo('tidypics:image_pixels')); - trigger_error('Tidypics warning: image memory size too large for resizing so rejecting', E_USER_WARNING); - continue; - } - - //this will save to user's folder in /image/ and organize by photo album - $file = new TidypicsImage(); - $file->container_guid = $album_guid; - $file->setMimeType($mime); - $file->simpletype = "image"; - $file->access_id = $access_id; - //$file->title = substr($name, 0, strrpos($name, '.')); - - $result = $file->save(); - - if (!$result) { - array_push($not_uploaded, $sent_file['name']); - array_push($error_msgs, elgg_echo('tidypics:save_error')); - continue; - } - - $file->setOriginalFilename($name); - $file->saveImageFile($sent_file['tmp_name'], $sent_file['size']); - $file->extractExifData(); - $file->saveThumbnails($image_lib); - - array_push($uploaded_images, $file->guid); - - // plugins can register to be told when a new image has been uploaded - trigger_elgg_event('upload', 'tp_image', $file); - - // successful upload so check if this is a new album and throw river event/notification if so - if ($album->new_album == TP_NEW_ALBUM) { - $album->new_album = TP_OLD_ALBUM; - - // 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); - - add_to_river('river/object/album/create', 'create', $album->owner_guid, $album->guid); - } - - if ($img_river_view == "all") { - add_to_river('river/object/image/create', 'create', $file->getObjectOwnerGUID(), $file->getGUID()); - } - unset($file); // may not be needed but there seems to be a memory leak - -} //end of for loop - -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)) . '<br />'; - } else { - $error = elgg_echo("tidypics:completeuploadfailure") . '<br />'; - } - - $num_failures = count($not_uploaded); - for ($i = 0; $i < $num_failures; $i++) { - $error .= "{$not_uploaded[$i]}: {$error_msgs[$i]} <br />"; - } - register_error($error); - - if (count($uploaded_images) == 0) { - //upload failed, so forward to previous page - forward($_SERVER['HTTP_REFERER']); - } else { - // some images did upload so we fall through - } -} else { - system_message(elgg_echo('tidypics:upl_success')); -} - -if (count($uploaded_images)) { - // Create a new batch object to contain these photos - $batch = new ElggObject(); - $batch->subtype = "tidypics_batch"; - $batch->access_id = $access_id; - $batch->container_guid = $album_guid; - - if ($batch->save()) { - foreach ($uploaded_images as $uploaded_guid) { - add_entity_relationship($uploaded_guid, "belongs_to_batch", $batch->getGUID()); - } - if ($img_river_view == "batch" && $new_album == false) { - add_to_river('river/object/tidypics_batch/create', 'create', $batch->getObjectOwnerGUID(), $batch->getGUID()); - } - } -} - - -if (count($uploaded_images) > 0) { - $album->prependImageList($uploaded_images); -} - -// plugins can register to be told when a Tidypics album has had images added -trigger_elgg_event('upload', 'tp_album', $album); - - -//forward to multi-image edit page -forward($CONFIG->wwwroot . 'mod/tidypics/pages/edit_multiple.php?files=' . implode('-', $uploaded_images)); |