diff options
-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 | ||||
-rw-r--r-- | classes/TidypicsAlbum.php | 2 | ||||
-rw-r--r-- | classes/TidypicsImage.php | 124 | ||||
-rw-r--r-- | pages/edit_multiple.php | 52 | ||||
-rw-r--r-- | pages/photos/batch/edit.php | 44 | ||||
-rw-r--r-- | pages/photos/image/thumbnail.php | 34 | ||||
-rw-r--r-- | pages/photos/image/upload.php | 61 | ||||
-rw-r--r-- | pages/thumbnail.php | 78 | ||||
-rw-r--r-- | start.php | 67 | ||||
-rw-r--r-- | views/default/forms/photos/basic_upload.php | 103 | ||||
-rw-r--r-- | views/default/forms/photos/batch/edit.php | 32 | ||||
-rw-r--r-- | views/default/forms/photos/batch/edit/image.php | 39 | ||||
-rw-r--r-- | views/default/object/album/full.php | 5 | ||||
-rw-r--r-- | views/default/tidypics/forms/edit_multi.php | 59 |
19 files changed, 570 insertions, 671 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)); diff --git a/classes/TidypicsAlbum.php b/classes/TidypicsAlbum.php index 75a018410..18fa556e3 100644 --- a/classes/TidypicsAlbum.php +++ b/classes/TidypicsAlbum.php @@ -3,6 +3,8 @@ * Tidypics Album class * * @package TidypicsAlbum + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 */ diff --git a/classes/TidypicsImage.php b/classes/TidypicsImage.php index 652cc9e9b..c604d869e 100644 --- a/classes/TidypicsImage.php +++ b/classes/TidypicsImage.php @@ -3,6 +3,8 @@ * Tidypics Image class * * @package TidypicsImage + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 */ @@ -18,6 +20,29 @@ class TidypicsImage extends ElggFile { } /** + * + * @warning container_guid must be set first + * + * @param array $data + * @return bool + */ + public function save($data = null) { + + if (!parent::save()) { + return false; + } + + if ($data) { + // new image + $this->simpletype = "image"; + $this->saveImageFile($data); + $this->saveThumbnails(); + } + + return true; + } + + /** * Get the title of the image * * @return string @@ -26,8 +51,13 @@ class TidypicsImage extends ElggFile { return $this->title; } - public function getSrcUrl() { - return "pg/photos/thumbnail/$this->guid/small/"; + /** + * Get the src URL for the image + * + * @return string + */ + public function getSrcUrl($size = 'small') { + return "photos/thumbnail/$this->guid/$size/"; } /** @@ -73,10 +103,8 @@ class TidypicsImage extends ElggFile { /** * Set the internal filenames - * - * @warning container needs to be set first */ - public function setOriginalFilename($originalName) { + protected function setOriginalFilename($originalName) { $prefix = "image/" . $this->container_guid . "/"; $filestorename = elgg_strtolower(time() . $originalName); $this->setFilename($prefix . $filestorename); @@ -85,24 +113,23 @@ class TidypicsImage extends ElggFile { /** * Save the uploaded image - * - * @warning filename needs to be set first * - * @param string $uploadedFilename name of the uploaded file - * @param int $size + * @param array $data */ - public function saveImageFile($uploadedFilename, $size) { + protected function saveImageFile($data) { + $this->checkUploadErrors($data); // we need to make sure the directory for the album exists // @note for group albums, the photos are distributed among the users - $dir = tp_get_img_dir() . $this->getContainer(); + $dir = tp_get_img_dir() . $this->getContainerGUID(); if (!file_exists($dir)) { mkdir($dir, 0755, true); } + // move the uploaded file into album directory + $this->setOriginalFilename($data['name']); $filename = $this->getFilenameOnFilestore(); - - $result = move_uploaded_file($uploadedFilename, $filename); + $result = move_uploaded_file($data['tmp_name'], $filename); if (!$result) { return false; } @@ -113,15 +140,42 @@ class TidypicsImage extends ElggFile { return true; } + protected function checkUploadErrors($data) { + // check for upload errors + if ($data['error']) { + if ($data['error'] == 1) { + trigger_error('Tidypics warning: image exceeded server php upload limit', E_USER_WARNING); + throw new Exception(elgg_echo('tidypics:image_mem')); + } else { + throw new Exception(elgg_echo('tidypics:unk_error')); + } + } + + // must be an image + if (!tp_upload_check_format($data['type'])) { + throw new Exception(elgg_echo('tidypics:not_image')); + } + + // make sure file does not exceed memory limit + if (!tp_upload_check_max_size($data['size'])) { + throw new Exception(elgg_echo('tidypics:image_mem')); + } + + // make sure the in memory image size does not exceed memory available + $imginfo = getimagesize($data['tmp_name']); + if (!tp_upload_memory_check($image_lib, $imginfo[0] * $imginfo[1])) { + trigger_error('Tidypics warning: image memory size too large for resizing so rejecting', E_USER_WARNING); + throw new Exception(elgg_echo('tidypics:image_pixels')); + } + } + /** * Save the image thumbnails - * - * @warning container guid and filename must be set - * - * @param string $imageLib */ - public function saveThumbnails($imageLib) { - include_once dirname(dirname(__FILE__)) . "/lib/resize.php"; + protected function saveThumbnails() { + elgg_load_library('tidypics:resize'); + + $imageLib = elgg_get_plugin_setting('image_lib', 'tidypics'); $prefix = "image/" . $this->container_guid . "/"; $filename = $this->getFilename(); @@ -145,6 +199,38 @@ class TidypicsImage extends ElggFile { } /** + * Get the image data of a thumbnail + * + * @param string $size + * @return string + */ + public function getThumbnail($size) { + switch ($size) { + case 'thumb': + $thumb = $this->thumbnail; + break; + case 'small': + $thumb = $this->smallthumb; + break; + case 'large': + $thumb = $this->largethumb; + break; + default: + return ''; + break; + } + + if (!$thumb) { + return ''; + } + + $file = new ElggFile(); + $file->owner_guid = $this->getObjectOwnerGUID(); + $file->setFilename($thumb); + return $file->grabFile(); + } + + /** * Extract EXIF Data from image * * @warning image file must be saved first diff --git a/pages/edit_multiple.php b/pages/edit_multiple.php deleted file mode 100644 index 7c7b989cf..000000000 --- a/pages/edit_multiple.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php -/** - * Tidypics: Edit the properties of multiple images - * - * Called after upload only - */ - -include_once dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php"; - -gatekeeper(); -set_context('photos'); - -set_page_owner(get_loggedin_userid()); - - -$batch = get_input('batch'); -if ($batch) { - $images = elgg_get_entities_from_metadata(array( - 'metadata_name' => 'batch', - 'metadata_value' => $batch, - 'type' => 'object', - 'subtype' => 'image', - 'owner_guid' => get_loggedin_userid(), - 'limit' => ELGG_ENTITIES_NO_VALUE, - )); -} else { - // parse out photo guids - $file_string = get_input('files'); - $file_array_sent = explode('-', $file_string); - - $images = array(); - foreach ($file_array_sent as $file_guid) { - if ($entity = get_entity($file_guid)) { - if ($entity->canEdit()) { - array_push($images, $entity); - } - } - } -} - -if (!$images) { - forward($_SERVER['HTTP_REFERER']); -} - - -$title = elgg_echo('tidypics:editprops'); - -$content .= elgg_view_title($title); -$content .= elgg_view("tidypics/forms/edit_multi", array('images' => $images)); - -$body = elgg_view_layout('two_column_left_sidebar', '', $content); -page_draw($title, $body); diff --git a/pages/photos/batch/edit.php b/pages/photos/batch/edit.php new file mode 100644 index 000000000..b96ddf408 --- /dev/null +++ b/pages/photos/batch/edit.php @@ -0,0 +1,44 @@ +<?php +/** + * Edit the image information for a batch of images + * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 + */ + +gatekeeper(); + +$guid = (int) get_input('guid'); + +if (!$batch = get_entity($guid)) { + // @todo either deleted or do not have access + forward('photos/all'); +} + +if (!$batch->canEdit()) { + // @todo cannot change it + forward('photos/all'); +} + +$album = $batch->getContainerEntity(); + +elgg_set_page_owner_guid($batch->getContainerEntity()->getContainerGUID()); +$owner = elgg_get_page_owner_entity(); + +$title = elgg_echo('tidypics:editprops'); + +elgg_push_breadcrumb(elgg_echo('photos'), "photos/all"); +elgg_push_breadcrumb($owner->name, "photos/owner/$owner->username"); +elgg_push_breadcrumb($album->title, $album->getURL()); +elgg_push_breadcrumb($title); + +$content = elgg_view_form('photos/batch/edit', array(), array('batch' => $batch)); + +$body = elgg_view_layout('content', array( + 'filter' => false, + 'content' => $content, + 'title' => elgg_echo('tidypics:editprops'), + 'sidebar' => elgg_view('tidypics/sidebar', array('page' => 'album')), +)); + +echo elgg_view_page($title, $body); diff --git a/pages/photos/image/thumbnail.php b/pages/photos/image/thumbnail.php new file mode 100644 index 000000000..ae07f2706 --- /dev/null +++ b/pages/photos/image/thumbnail.php @@ -0,0 +1,34 @@ +<?php +/** + * Image thumbnail view + * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 + */ + +$guid = (int) get_input('guid'); +$size = get_input('size'); +$image = get_entity($guid); +if (!$image) { + // @todo +} + +$contents = $image->getThumbnail($size); +if (!$contents) { + forward("mod/tidypics/graphics/image_error_$size"); +} + +// expires every 14 days +$expires = 14 * 60*60*24; + +// overwrite header caused by php session code so images can be cached +$mime = $image->getMimeType(); +header("Content-Type: $mime"); +header("Content-Length: " . strlen($contents)); +header("Cache-Control: public", true); +header("Pragma: public", true); +header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT', true); + +// Return the thumbnail and exit +echo $contents; +exit; diff --git a/pages/photos/image/upload.php b/pages/photos/image/upload.php index 6580c6f52..526972a35 100644 --- a/pages/photos/image/upload.php +++ b/pages/photos/image/upload.php @@ -1,62 +1,59 @@ <?php /** - * Tidypics Upload Images Page + * Upload images * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 */ -include_once dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php"; - -global $CONFIG; - -// must be logged in to upload images gatekeeper(); -$album_guid = (int) get_input('album_guid'); +$album_guid = (int) get_input('guid'); if (!$album_guid) { + // @todo forward(); } -if (get_plugin_setting('uploader', 'tidypics') != "disabled") { +if (elgg_get_plugin_setting('uploader', 'tidypics') != "disabled") { $uploader = get_input('uploader', 'ajax'); } else { $uploader = 'basic'; } - $album = get_entity($album_guid); - -//if album does not exist or user does not have access if (!$album || !$album->canEdit()) { + // @todo // throw warning and forward to previous page - forward($_SERVER['HTTP_REFERER']); + forward(REFERER); +} + +if (!$album->canEdit()) { + // @todo have to be able to edit album to upload photos } // set page owner based on container (user or group) -set_page_owner($album->container_guid); +elgg_set_page_owner_guid($album->getContainerGUID()); +$owner = elgg_get_page_owner_entity(); -$page_owner = page_owner_entity(); -if ($page_owner instanceof ElggGroup) { - add_submenu_item( sprintf(elgg_echo('album:group'),$page_owner->name), - $CONFIG->wwwroot . "pg/photos/owned/" . $page_owner->username); -} +$title = elgg_echo('album:addpix'); -set_context('photos'); -$title = elgg_echo('album:addpix') . ': ' . $album->title; -$area2 .= elgg_view_title($title); +// set up breadcrumbs +elgg_push_breadcrumb(elgg_echo('photos'), "photos/all"); +elgg_push_breadcrumb($owner->name, "photos/owner/$owner->username"); +elgg_push_breadcrumb($album->getTitle(), $album->getURL()); +elgg_push_breadcrumb(elgg_echo('album:addpix')); -if ($uploader == 'basic') { - $area2 .= elgg_view('input/form', array( - 'action' => "{$CONFIG->wwwroot}action/tidypics/upload", - 'body' => elgg_view('forms/tidypics/basic_upload', array('album' => $album)), - 'internalid' => 'tidypicsUpload', - 'enctype' => 'multipart/form-data', - 'method' => 'post', - )); +if ($uploader == 'basic') { + $content = elgg_view('forms/photos/basic_upload', array('entity' => $album)); } else { - $area2 .= elgg_view("forms/tidypics/ajax_upload", array('album' => $album)); + $content = elgg_view('forms/photos/ajax_upload', array('entity' => $album)); } -$body = elgg_view_layout('two_column_left_sidebar', '', $area2); +$body = elgg_view_layout('content', array( + 'content' => $content, + 'title' => $title, + 'filter' => '', +)); -page_draw($title, $body); +echo elgg_view_page($title, $body); diff --git a/pages/thumbnail.php b/pages/thumbnail.php deleted file mode 100644 index 9daa2f9c0..000000000 --- a/pages/thumbnail.php +++ /dev/null @@ -1,78 +0,0 @@ -<?php - -/** - * Tidypics Thumbnail - * - */ - -// Get file GUID -$file_guid = (int) get_input('file_guid'); - -// Get file thumbnail size -$size = get_input('size'); -// only 3 possibilities -if ($size != 'small' && $size != 'thumb') { - $size = 'large'; -} - -$error_image = ''; -switch ($size) { - case 'thumb': - $error_image = "image_error_thumb.png"; - break; - case 'small': - $error_image = "image_error_small.png"; - break; - case 'large': - $error_image = "image_error_large.png"; - break; -} - -// Get file entity -$file = get_entity($file_guid); -if (!$file) { - forward('mod/tidypics/graphics/' . $error_image); -} - -if ($file->getSubtype() != "image") { - forward('mod/tidypics/graphics/' . $error_image); -} - -// Get filename -if ($size == "thumb") { - $thumbfile = $file->thumbnail; -} else if ($size == "small") { - $thumbfile = $file->smallthumb; -} else { - $thumbfile = $file->largethumb; -} - -if (!$thumbfile) { - forward('mod/tidypics/graphics/' . $error_image); -} - -// create Elgg File object -$readfile = new ElggFile(); -$readfile->owner_guid = $file->owner_guid; -$readfile->setFilename($thumbfile); -$contents = $readfile->grabFile(); - -// send error image if file could not be read -if (!$contents) { - forward('mod/tidypics/graphics/' . $error_image); -} - -// expires every 14 days -$expires = 14 * 60*60*24; - -// overwrite header caused by php session code so images can be cached -$mime = $file->getMimeType(); -header("Content-Type: $mime"); -header("Content-Length: " . strlen($contents)); -header("Cache-Control: public", true); -header("Pragma: public", true); -header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT', true); - -// Return the thumbnail and exit -echo $contents; -exit; @@ -6,16 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 */ -// set some simple defines -define('TP_OLD_ALBUM', 0); -define('TP_NEW_ALBUM', 1); - -// include core libraries -require dirname(__FILE__) . "/lib/tidypics.php"; - - -// Make sure tidypics_init is called on initialization -register_elgg_event_handler('init', 'system', 'tidypics_init'); +elgg_register_event_handler('init', 'system', 'tidypics_init'); /** * Tidypics plugin initialization @@ -23,6 +14,9 @@ register_elgg_event_handler('init', 'system', 'tidypics_init'); function tidypics_init() { global $CONFIG; + // include core libraries + require dirname(__FILE__) . "/lib/tidypics.php"; + // Set up site menu elgg_register_menu_item('site', array( 'name' => 'photos', @@ -85,18 +79,21 @@ function tidypics_init() { // Register actions $base_dir = $CONFIG->pluginspath . "tidypics/actions/photos"; elgg_register_action("photos/album/save", "$base_dir/album/save.php"); - register_action("tidypics/upload", false, "$base_dir/upload.php"); + elgg_register_action("photos/delete", "$base_dir/delete.php"); + elgg_register_action("photos/image/upload", "$base_dir/image/upload.php"); + elgg_register_action("photos/batch/edit", "$base_dir/batch/edit.php"); register_action("tidypics/ajax_upload", true, "$base_dir/ajax_upload.php"); register_action("tidypics/ajax_upload_complete", true, "$base_dir/ajax_upload_complete.php"); register_action("tidypics/sortalbum", false, "$base_dir/sortalbum.php"); register_action("tidypics/edit", false, "$base_dir/edit.php"); - register_action("tidypics/delete", false, "$base_dir/delete.php"); - register_action("tidypics/edit_multi", false, "$base_dir/edit_multi.php"); register_action("tidypics/addtag", false, "$base_dir/addtag.php"); register_action("tidypics/deletetag", false, "$base_dir/deletetag.php"); register_action("tidypics/admin/settings", false, "$base_dir/admin/settings.php", true); register_action("tidypics/admin/upgrade", false, "$base_dir/admin/upgrade.php", true); + + elgg_register_library('tidypics:upload', $CONFIG->pluginspath . 'tidypics/lib/upload.php'); + elgg_register_library('tidypics:resize', $CONFIG->pluginspath . 'tidypics/lib/resize.php'); } /** @@ -301,9 +298,10 @@ function tidypics_page_handler($page) { case 'album': require "$base/album/edit.php"; break; + case 'tidypics_batch': + require "$base/batch/edit.php"; + break; default: - echo 'not album'; - exit; return false; } break; @@ -315,21 +313,22 @@ function tidypics_page_handler($page) { include($CONFIG->pluginspath . "tidypics/pages/sortalbum.php"); break; - case "view": //view an image individually - if (isset($page[1])) { - set_input('guid', $page[1]); - } - include($CONFIG->pluginspath . "tidypics/pages/viewimage.php"); + case "image": //view an image + case "view": + set_input('guid', $page[1]); + require "$base/image/view.php"; break; - - case "upload": //upload images to album - if (isset($page[1])) { - set_input('album_guid', $page[1]); - } - if (isset($page[2])) { - set_input('uploader', 'basic'); - } - include($CONFIG->pluginspath . "tidypics/pages/photos/image/upload.php"); + + case "thumbnail": // tidypics thumbnail + set_input('guid', $page[1]); + set_input('size', elgg_extract(2, $page, 'small')); + require "$base/image/thumbnail.php"; + break; + + case "upload": // upload images to album + set_input('guid', $page[1]); + set_input('uploader', elgg_extract(2, $page, 'basic')); + require "$base/image/upload.php"; break; case "batch": //update titles and descriptions @@ -349,16 +348,6 @@ function tidypics_page_handler($page) { include($CONFIG->pluginspath . "tidypics/pages/download.php"); break; - case "thumbnail": // tidypics thumbnail - if (isset($page[1])) { - set_input('file_guid', $page[1]); - } - if (isset($page[2])) { - set_input('size', $page[2]); - } - include($CONFIG->pluginspath . "tidypics/pages/thumbnail.php"); - break; - case "tagged": // all photos tagged with user if (isset($page[1])) { set_input('guid', $page[1]); diff --git a/views/default/forms/photos/basic_upload.php b/views/default/forms/photos/basic_upload.php index 55ab854a4..e4535814b 100644 --- a/views/default/forms/photos/basic_upload.php +++ b/views/default/forms/photos/basic_upload.php @@ -1,24 +1,22 @@ <?php /** - * Tidypics basic uploader form + * Basic uploader form * * This only handled uploading the images. Editing the titles and descriptions * are handled with the edit forms. * - * @uses $vars['album'] + * @uses $vars['entity'] + * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 */ -global $CONFIG; - -$album = $vars['album']; +$album = $vars['entity']; $access_id = $album->access_id; -$maxfilesize = (float) get_plugin_setting('maxfilesize','tidypics'); -if (!$maxfilesize) { - $maxfilesize = 5; -} - -$quota = get_plugin_setting('quota','tidypics'); +$maxfilesize = (float) elgg_get_plugin_setting('maxfilesize', 'tidypics'); +$quota = elgg_get_plugin_setting('quota', 'tidypics'); +/* if ($quota) { $image_repo_size_md = get_metadata_byname($album->container_guid, "image_repo_size"); $image_repo_size = (int)$image_repo_size_md->value; @@ -34,16 +32,6 @@ if ($quota) { $image_repo_size = $quota; } } - -?> -<div id="tidypics_ref"></div> -<div class="contentWrapper"> - <?php - ob_start(); - ?> - <p style="line-height:1.6em;"> - <label><?php echo elgg_echo("tidypics:uploader:upload"); ?></label><br /> - <i><?php echo sprintf(elgg_echo('tidypics:uploader:basic'), $maxfilesize); ?></i><br /> <?php if ($quota) { ?> @@ -51,54 +39,37 @@ if ($quota) { <?php } ?> - <div class="tidypics_popup"> - <?php echo elgg_echo("tidypics:uploading:images"); ?><br /> - <div style="margin:20px 0px 20px 80px;"><img id="progress" alt="..." border="0" src="<?php echo $vars['url'].'mod/tidypics/graphics/loader.gif' ?>" /></div> - </div> - <ol id="tidypics_image_upload_list"> - <?php - for ($x = 0; $x < 10; $x++) { - echo '<li>' . elgg_view("input/file",array('internalname' => "upload_$x")) . '</li>'; - } - ?> - </ol> -</p> -<p> - <?php - if ($album) { - echo '<input type="hidden" name="album_guid" value="' . $album->guid . '" />'; - } - if ($access_id) { - echo '<input type="hidden" name="access_id" value="' . $access_id . '" />'; - } - ?> - <input type="submit" value="<?php echo elgg_echo("save"); ?>" onclick="displayProgress();" /> -</p> -<?php -$form_body = ob_get_clean(); -echo $form_body; -?> -</div> -<script type="text/javascript"> + * +*/ - function displayProgress() - { - offsetY = 60; - offsetX = 120; +$instructions = elgg_echo("tidypics:uploader:upload"); +$max = elgg_echo('tidypics:uploader:basic', array($maxfilesize)); - divWidth = $('#tidypics_ref').width(); - imgOffset = $('#tidypics_ref').offset(); - imgWidth = $('#tidypics_ref').width(); +$list = ''; +for ($x = 0; $x < 10; $x++) { + $list .= '<li>' . elgg_view('input/file', array('name' => 'images[]')) . '</li>'; +} - _top = imgOffset.top + offsetY; - _left = imgOffset.left + offsetX; +$foot = elgg_view('input/hidden', array('name' => 'guid', 'value' => $album->getGUID())); +$foot .= elgg_view('input/submit', array('value' => elgg_echo("save"))); - $('.tidypics_popup').show().css({ - "top": _top + "px", - "left": _left + "px" - }); +$form_body = <<<HTML +<div> + $max +</div> +<div> + <ol> + $list + </ol> +</div> +<div class='elgg-foot'> + $foot +</div> +HTML; - setTimeout('document.images["progress"].src = "<?php echo $vars['url'].'mod/tidypics/graphics/loader.gif' ?>"', 200); - } -</script>
\ No newline at end of file +echo elgg_view('input/form', array( + 'body' => $form_body, + 'action' => 'action/photos/image/upload', + 'enctype' => 'multipart/form-data', +)); diff --git a/views/default/forms/photos/batch/edit.php b/views/default/forms/photos/batch/edit.php new file mode 100644 index 000000000..fa017ac96 --- /dev/null +++ b/views/default/forms/photos/batch/edit.php @@ -0,0 +1,32 @@ +<?php +/** + * Edit properties on a batch of images + * + * @uses $vars['batch'] ElggObject + * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 + */ + +$batch = $vars['batch']; +$album = $batch->getContainerEntity(); + +$images = elgg_get_entities_from_relationship(array( + 'type' => 'object', + 'subtype' => 'image', + 'relationship' => 'belongs_to_batch', + 'relationship_guid' => $batch->getGUID(), + 'inverse_relationship' => true, +)); + +echo '<ul>'; +foreach ($images as $image) { + echo '<li>'; + echo elgg_view('forms/photos/batch/edit/image', array('entity' => $image)); + echo '</li>'; +} +echo '</ul>'; + +echo '<div class="elgg-foot">'; +echo elgg_view('input/submit', array('value' => elgg_echo('save'))); +echo '</div>'; diff --git a/views/default/forms/photos/batch/edit/image.php b/views/default/forms/photos/batch/edit/image.php new file mode 100644 index 000000000..bf982ed84 --- /dev/null +++ b/views/default/forms/photos/batch/edit/image.php @@ -0,0 +1,39 @@ +<?php +/** + * Form component for editing a single image + * + * @uses $vars['entity'] + * + * @author Cash Costello + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 + */ + +$image = $vars['entity']; + +echo '<div class="elgg-image-block">'; + +echo '<div class="elgg-image">'; +echo elgg_view('output/img', array( + 'src' => $image->getSrcURL(), + 'alt' => $image->getTitle(), + 'class' => 'elgg-photo', +)); +echo '</div>'; + +echo '<div class="elgg-body"><fieldset class="mlm">'; +echo '<div><label>' . elgg_echo('album:title') . '</label>'; +echo elgg_view('input/text', array('name' => 'title[]', 'value' => $title,)); +echo '</div>'; + +echo '<div><label>' . elgg_echo('caption') . '</label>'; +echo elgg_view('input/longtext', array('name' => 'caption[]')); +echo '</div>'; + +echo '<div><label>' . elgg_echo("tags") . '</label>'; +echo elgg_view('input/tags', array('name' => 'tags[]')); +echo '</div>'; + +echo elgg_view('input/hidden', array('name' => 'guid[]', 'value' => $image->getGUID())); +echo '<fieldset></div>'; + +echo '</div>'; diff --git a/views/default/object/album/full.php b/views/default/object/album/full.php index 7484a48f3..4d2d8c88b 100644 --- a/views/default/object/album/full.php +++ b/views/default/object/album/full.php @@ -41,7 +41,10 @@ $params = array( $params = $params + $vars; $summary = elgg_view('object/elements/summary', $params); -$body = elgg_list_entities(array( +$body = elgg_view('output/longtext', array( + 'value' => $album->description, +)); +$body .= elgg_list_entities(array( 'type' => 'object', 'subtype' => 'image', 'container_guid' => $album->getGUID(), diff --git a/views/default/tidypics/forms/edit_multi.php b/views/default/tidypics/forms/edit_multi.php deleted file mode 100644 index aba6fd324..000000000 --- a/views/default/tidypics/forms/edit_multi.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php -/** - * form for mass editing all uploaded images - */ - -$images = $vars['images']; -$album = get_entity($images[0]->container_guid); - -?> -<div class="contentWrapper"> -<form action="<?php echo $vars['url']; ?>action/tidypics/edit_multi" method="post"> -<?php - - // make sure one of the images becomes the cover if there isn't one already - if (!$album->getCoverImageGuid()) { - $no_cover = true; - } - - foreach ($images as $key => $image) { - $guid = $image->guid; - $body = $image->description; - $title = $image->title; - $tags = $image->tags; - - // first one is default cover if there isn't one already - if ($no_cover) { - $val = $guid; - $no_cover = false; - } - - echo '<div class="tidypics_edit_image_container">'; - echo '<img src="' . $vars['url'] . 'mod/tidypics/thumbnail.php?file_guid=' . $guid . '&size=small" class="tidypics_edit_images" alt="' . $title . '"/>'; - echo '<div class="tidypics_image_info">'; - echo '<p><label>' . elgg_echo('album:title') . '</label>'; - echo elgg_view("input/text", array("internalname" => "title[$key]", "value" => $title,)) . "\n"; - echo '</p>'; - echo '<p><label>' . elgg_echo('caption') . "</label>"; - echo elgg_view("input/longtext",array("internalname" => "caption[$key]", "value" => $body, "class" => 'tidypics_caption_input',)) . "\n"; - echo "</p>"; - echo '<p><label>' . elgg_echo("tags") . "</label>\n"; - echo elgg_view("input/tags", array( "internalname" => "tags[$key]","value" => $tags)) . "\n"; - echo '</p>'; - echo '<input type="hidden" name="image_guid[' .$key. ']" value="'. $guid .'">' . "\n"; - echo elgg_view('input/securitytoken'); - - echo elgg_view("input/radio", array("internalname" => "cover", - "value" => $val, - 'options' => array( elgg_echo('album:cover') => $guid, - ), - )); - echo '</div>'; - echo '</div>'; - } - -?> -<input type="hidden" name="container_guid" value="<?php echo $album->guid; ?>" /> -<p><input type="submit" name="submit" value="<?php echo elgg_echo('save'); ?>" /></p> -</form> -</div>
\ No newline at end of file |