From c51b483f24936c8d04a54a6999412937ec21c49a Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 19 Nov 2011 23:13:26 -0500 Subject: uploading photos through the basic interface works now --- actions/delete.php | 58 ------- actions/edit_multi.php | 65 -------- actions/photos/batch/edit.php | 42 +++++ actions/photos/delete.php | 48 ++++++ actions/photos/image/upload.php | 126 +++++++++++++++ actions/upload.php | 202 ------------------------ classes/TidypicsAlbum.php | 2 + classes/TidypicsImage.php | 124 ++++++++++++--- pages/edit_multiple.php | 52 ------ pages/photos/batch/edit.php | 44 ++++++ pages/photos/image/thumbnail.php | 34 ++++ pages/photos/image/upload.php | 61 ++++--- pages/thumbnail.php | 78 --------- start.php | 67 ++++---- views/default/forms/photos/basic_upload.php | 103 +++++------- views/default/forms/photos/batch/edit.php | 32 ++++ views/default/forms/photos/batch/edit/image.php | 39 +++++ views/default/object/album/full.php | 5 +- views/default/tidypics/forms/edit_multi.php | 59 ------- 19 files changed, 570 insertions(+), 671 deletions(-) delete mode 100644 actions/delete.php delete mode 100644 actions/edit_multi.php create mode 100644 actions/photos/batch/edit.php create mode 100644 actions/photos/delete.php create mode 100644 actions/photos/image/upload.php delete mode 100644 actions/upload.php delete mode 100644 pages/edit_multiple.php create mode 100644 pages/photos/batch/edit.php create mode 100644 pages/photos/image/thumbnail.php delete mode 100644 pages/thumbnail.php create mode 100644 views/default/forms/photos/batch/edit.php create mode 100644 views/default/forms/photos/batch/edit/image.php delete mode 100644 views/default/tidypics/forms/edit_multi.php 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 @@ -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 @@ - $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 @@ + $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 @@ +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 @@ + $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)) . '
'; + } else { + $error = elgg_echo("tidypics:completeuploadfailure") . '
'; + } + + $num_failures = count($not_uploaded); + for ($i = 0; $i < $num_failures; $i++) { + $error .= "{$not_uploaded[$i]}: {$error_msgs[$i]}
"; + } + 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 @@ -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)) . '
'; - } else { - $error = elgg_echo("tidypics:completeuploadfailure") . '
'; - } - - $num_failures = count($not_uploaded); - for ($i = 0; $i < $num_failures; $i++) { - $error .= "{$not_uploaded[$i]}: {$error_msgs[$i]}
"; - } - 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 */ @@ -17,6 +19,29 @@ class TidypicsImage extends ElggFile { parent::__construct($guid); } + /** + * + * @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 * @@ -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(); @@ -144,6 +198,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 * 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 @@ - '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 @@ +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 @@ +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 @@ 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 @@ -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; diff --git a/start.php b/start.php index 953789924..fff4ebf8d 100644 --- a/start.php +++ b/start.php @@ -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 @@ 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; } } - -?> -
-
- -

-
-
@@ -51,54 +39,37 @@ if ($quota) { -

-
-
...
-
-
    - ' . elgg_view("input/file",array('internalname' => "upload_$x")) . ''; - } - ?> -
-

-

- guid . '" />'; - } - if ($access_id) { - echo ''; - } - ?> - " onclick="displayProgress();" /> -

- -
- \ 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 @@ +getContainerEntity(); + +$images = elgg_get_entities_from_relationship(array( + 'type' => 'object', + 'subtype' => 'image', + 'relationship' => 'belongs_to_batch', + 'relationship_guid' => $batch->getGUID(), + 'inverse_relationship' => true, +)); + +echo ''; + +echo '
'; +echo elgg_view('input/submit', array('value' => elgg_echo('save'))); +echo '
'; 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 @@ +'; + +echo '
'; +echo elgg_view('output/img', array( + 'src' => $image->getSrcURL(), + 'alt' => $image->getTitle(), + 'class' => 'elgg-photo', +)); +echo '
'; + +echo '
'; +echo '
'; +echo elgg_view('input/text', array('name' => 'title[]', 'value' => $title,)); +echo '
'; + +echo '
'; +echo elgg_view('input/longtext', array('name' => 'caption[]')); +echo '
'; + +echo '
'; +echo elgg_view('input/tags', array('name' => 'tags[]')); +echo '
'; + +echo elgg_view('input/hidden', array('name' => 'guid[]', 'value' => $image->getGUID())); +echo '
'; + +echo ''; 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 @@ -container_guid); - -?> -
-
-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 '
'; - echo '' . $title . ''; - echo '
'; - echo '

'; - echo elgg_view("input/text", array("internalname" => "title[$key]", "value" => $title,)) . "\n"; - echo '

'; - echo '

"; - echo elgg_view("input/longtext",array("internalname" => "caption[$key]", "value" => $body, "class" => 'tidypics_caption_input',)) . "\n"; - echo "

"; - echo '

\n"; - echo elgg_view("input/tags", array( "internalname" => "tags[$key]","value" => $tags)) . "\n"; - echo '

'; - echo '' . "\n"; - echo elgg_view('input/securitytoken'); - - echo elgg_view("input/radio", array("internalname" => "cover", - "value" => $val, - 'options' => array( elgg_echo('album:cover') => $guid, - ), - )); - echo '
'; - echo '
'; - } - -?> - -

-
-
\ No newline at end of file -- cgit v1.2.3