diff options
Diffstat (limited to 'actions')
-rw-r--r-- | actions/addalbum.php | 146 | ||||
-rw-r--r-- | actions/addtag.php | 208 | ||||
-rw-r--r-- | actions/create_thumbnails.php | 122 | ||||
-rw-r--r-- | actions/delete.php | 240 | ||||
-rw-r--r-- | actions/deletetag.php | 114 | ||||
-rw-r--r-- | actions/edit.php | 162 | ||||
-rw-r--r-- | actions/edit_multi.php | 130 | ||||
-rw-r--r-- | actions/imtest.php | 38 | ||||
-rw-r--r-- | actions/settings.php | 140 | ||||
-rw-r--r-- | actions/upload.php | 510 |
10 files changed, 905 insertions, 905 deletions
diff --git a/actions/addalbum.php b/actions/addalbum.php index ffc7ec9c7..8df488a92 100644 --- a/actions/addalbum.php +++ b/actions/addalbum.php @@ -1,74 +1,74 @@ -<?php
- /**
- * Tidypics Add New Album Action
- *
- */
-
- // Make sure we're logged in
- gatekeeper();
-
- // Get input data
- $title = get_input('tidypicstitle');
- $body = get_input('tidypicsbody');
- $tags = get_input('tidypicstags');
- $access = get_input('access_id');
- $container_guid = get_input('container_guid', $_SESSION['user']->getGUID());
-
- // Cache to the session
- $_SESSION['tidypicstitle'] = $title;
- $_SESSION['tidypicsbody'] = $body;
- $_SESSION['tidypicstags'] = $tags;
-
- // Convert string of tags into a preformatted array
- $tagarray = string_to_tag_array($tags);
- // Make sure the title isn't blank
- if (empty($title)) {
- register_error(elgg_echo("album:blank"));
- forward($_SERVER['HTTP_REFERER']); //failed, so forward to previous page
- // Otherwise, save the album
- } else {
-
- // Initialise a new ElggObject
- $album = new ElggObject();
- // Tell the system it's an album
- $album->subtype = "album";
-
- // Set its owner to the current user
- $album->container_guid = $container_guid;
- $album->owner_guid = $_SESSION['user']->getGUID();
- $album->access_id = $access;
- // Set its title and description appropriately
- $album->title = $title;
- $album->description = $body;
-
- // we catch the adding images to new albums in the upload action and throw a river new album event
- $album->new_album = TP_NEW_ALBUM;
-
- // Before we can set metadata, we need to save the album
- if (!$album->save()) {
- register_error(elgg_echo("album:error"));
- forward(get_input('forward_url', $_SERVER['HTTP_REFERER'])); //failed, so forward to previous page
- }
-
- // Now let's add tags
- if (is_array($tagarray)) {
- $album->tags = $tagarray;
- }
-
-
-
- // Success message
- system_message(elgg_echo("album:created"));
-
- // Remove the album post cache
- unset($_SESSION['tidypicstitle']);
- unset($_SESSION['tidypicsbody']);
- unset($_SESSION['tidypicstags']);
-
- // plugins can register to be told when a new Tidypics album has been created
- trigger_elgg_event('add', 'tp_album', $album);
-
- forward("pg/photos/upload/" . $album->guid);
- }
-
+<?php + /** + * Tidypics Add New Album Action + * + */ + + // Make sure we're logged in + gatekeeper(); + + // Get input data + $title = get_input('tidypicstitle'); + $body = get_input('tidypicsbody'); + $tags = get_input('tidypicstags'); + $access = get_input('access_id'); + $container_guid = get_input('container_guid', $_SESSION['user']->getGUID()); + + // Cache to the session + $_SESSION['tidypicstitle'] = $title; + $_SESSION['tidypicsbody'] = $body; + $_SESSION['tidypicstags'] = $tags; + + // Convert string of tags into a preformatted array + $tagarray = string_to_tag_array($tags); + // Make sure the title isn't blank + if (empty($title)) { + register_error(elgg_echo("album:blank")); + forward($_SERVER['HTTP_REFERER']); //failed, so forward to previous page + // Otherwise, save the album + } else { + + // Initialise a new ElggObject + $album = new ElggObject(); + // Tell the system it's an album + $album->subtype = "album"; + + // Set its owner to the current user + $album->container_guid = $container_guid; + $album->owner_guid = $_SESSION['user']->getGUID(); + $album->access_id = $access; + // Set its title and description appropriately + $album->title = $title; + $album->description = $body; + + // we catch the adding images to new albums in the upload action and throw a river new album event + $album->new_album = TP_NEW_ALBUM; + + // Before we can set metadata, we need to save the album + if (!$album->save()) { + register_error(elgg_echo("album:error")); + forward(get_input('forward_url', $_SERVER['HTTP_REFERER'])); //failed, so forward to previous page + } + + // Now let's add tags + if (is_array($tagarray)) { + $album->tags = $tagarray; + } + + + + // Success message + system_message(elgg_echo("album:created")); + + // Remove the album post cache + unset($_SESSION['tidypicstitle']); + unset($_SESSION['tidypicsbody']); + unset($_SESSION['tidypicstags']); + + // plugins can register to be told when a new Tidypics album has been created + trigger_elgg_event('add', 'tp_album', $album); + + forward("pg/photos/upload/" . $album->guid); + } + ?>
\ No newline at end of file diff --git a/actions/addtag.php b/actions/addtag.php index 2c258db84..56268783e 100644 --- a/actions/addtag.php +++ b/actions/addtag.php @@ -1,104 +1,104 @@ -<?php
- /**
- * Tidypics Add Photo Tag
- *
- */
-
- gatekeeper();
- action_gatekeeper();
-
- $coordinates_str = get_input('coordinates');
-
- $user_id = get_input('user_id');
- $image_guid = get_input('image_guid');
- $word = get_input('word');
-
- if ($image_guid == 0) {
- register_error(elgg_echo("tidypics:phototagging:error"));
- forward($_SERVER['HTTP_REFERER']);
- }
-
- $image = get_entity($image_guid);
- if (!$image)
- {
- register_error(elgg_echo("tidypics:phototagging:error"));
- forward($_SERVER['HTTP_REFERER']);
- }
-
- // test for empty tag
- if ($user_id == 0 && empty($word)) {
- register_error(elgg_echo("tidypics:phototagging:error"));
- forward($_SERVER['HTTP_REFERER']);
- }
-
-
- $new_word_tag = false;
- if ($user_id != 0) {
- $relationships_type = 'user';
- $value = $user_id;
- } else {
- $relationships_type = 'word';
- $value = $word;
-
- // check to see if the photo has this tag and add if not
- if (!is_array($image->tags)) {
- if ($image->tags != $word) {
- $new_word_tag = true;
- $tagarray = $image->tags . ',' . $word;
- $tagarray = string_to_tag_array($tagarray);
- }
- } else {
- if (!in_array($word, $image->tags)) {
- $new_word_tag = true;
- $tagarray = $image->tags;
- $tagarray[] = $word;
- }
- }
- }
-
- // add new tag now so it is available in search
- if ($new_word_tag) {
- $image->clearMetadata('tags');
- $image->tags = $tagarray;
- }
-
- // create string for javascript tag object
- $tag->coords = $coordinates_str;
- $tag->type = $relationships_type;
- $tag->value = $value;
-
- $access_id = $image->getAccessID();
- $owner_id = get_loggedin_userid();
- $tagger = get_loggedin_user();
-
- //Save annotation
- if ($image->annotate('phototag', serialize($tag), $access_id, $owner_id)) {
- // if tag is a user id, add relationship for searching (find all images with user x)
- if ($relationships_type === 'user') {
- if (!check_entity_relationship($user_id, 'phototag', $image_guid)) {
- add_entity_relationship($user_id, 'phototag', $image_guid);
-
- // also add this to the river - subject is image, object is the tagged user
- if (function_exists('add_to_river'))
- add_to_river('river/object/image/tag', 'tag', $image_guid, $user_id, $access_id);
-
- // notify user of tagging as long as not self
- if ($owner_id != $user_id)
- notify_user($user_id, $owner_id, elgg_echo('tidypics:tag:subject'),
- sprintf(
- elgg_echo('tidypics:tag:body'),
- $image->title,
- $tagger->name,
- $image->getURL()
- )
- );
- }
- }
-
- system_message(elgg_echo("tidypics:phototagging:success"));
- }
-
-
- forward($_SERVER['HTTP_REFERER']);
-
-?>
+<?php + /** + * Tidypics Add Photo Tag + * + */ + + gatekeeper(); + action_gatekeeper(); + + $coordinates_str = get_input('coordinates'); + + $user_id = get_input('user_id'); + $image_guid = get_input('image_guid'); + $word = get_input('word'); + + if ($image_guid == 0) { + register_error(elgg_echo("tidypics:phototagging:error")); + forward($_SERVER['HTTP_REFERER']); + } + + $image = get_entity($image_guid); + if (!$image) + { + register_error(elgg_echo("tidypics:phototagging:error")); + forward($_SERVER['HTTP_REFERER']); + } + + // test for empty tag + if ($user_id == 0 && empty($word)) { + register_error(elgg_echo("tidypics:phototagging:error")); + forward($_SERVER['HTTP_REFERER']); + } + + + $new_word_tag = false; + if ($user_id != 0) { + $relationships_type = 'user'; + $value = $user_id; + } else { + $relationships_type = 'word'; + $value = $word; + + // check to see if the photo has this tag and add if not + if (!is_array($image->tags)) { + if ($image->tags != $word) { + $new_word_tag = true; + $tagarray = $image->tags . ',' . $word; + $tagarray = string_to_tag_array($tagarray); + } + } else { + if (!in_array($word, $image->tags)) { + $new_word_tag = true; + $tagarray = $image->tags; + $tagarray[] = $word; + } + } + } + + // add new tag now so it is available in search + if ($new_word_tag) { + $image->clearMetadata('tags'); + $image->tags = $tagarray; + } + + // create string for javascript tag object + $tag->coords = $coordinates_str; + $tag->type = $relationships_type; + $tag->value = $value; + + $access_id = $image->getAccessID(); + $owner_id = get_loggedin_userid(); + $tagger = get_loggedin_user(); + + //Save annotation + if ($image->annotate('phototag', serialize($tag), $access_id, $owner_id)) { + // if tag is a user id, add relationship for searching (find all images with user x) + if ($relationships_type === 'user') { + if (!check_entity_relationship($user_id, 'phototag', $image_guid)) { + add_entity_relationship($user_id, 'phototag', $image_guid); + + // also add this to the river - subject is image, object is the tagged user + if (function_exists('add_to_river')) + add_to_river('river/object/image/tag', 'tag', $image_guid, $user_id, $access_id); + + // notify user of tagging as long as not self + if ($owner_id != $user_id) + notify_user($user_id, $owner_id, elgg_echo('tidypics:tag:subject'), + sprintf( + elgg_echo('tidypics:tag:body'), + $image->title, + $tagger->name, + $image->getURL() + ) + ); + } + } + + system_message(elgg_echo("tidypics:phototagging:success")); + } + + + forward($_SERVER['HTTP_REFERER']); + +?> diff --git a/actions/create_thumbnails.php b/actions/create_thumbnails.php index 3869e2dcf..09743eef6 100644 --- a/actions/create_thumbnails.php +++ b/actions/create_thumbnails.php @@ -1,61 +1,61 @@ -<?php
- /**
- * Tidypics Thumbnail Creation Test
- *
- * Called through ajax
- */
-
- include_once dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php";
- include dirname(dirname(__FILE__)) . "/lib/resize.php";
-
- global $CONFIG;
-
- $guid = $_GET['guid'];
-
- $image = get_entity($guid);
- if (!$image || !($image instanceof TidypicsImage)) {
- echo "Unable to get original image";
- return;
- }
-
- $filename = $image->getFilename();
- $container_guid = $image->container_guid;
- if (!$filename || !$container_guid) {
- echo "Error retrieving information about the image";
- return;
- }
-
- $title = $image->title;
- $prefix = "image/" . $container_guid . "/";
- $filestorename = substr($filename, strlen($prefix));
-
- $image_lib = get_plugin_setting('image_lib', 'tidypics');
- if (!$image_lib)
- $image_lib = "GD";
-
- if ($image_lib == 'ImageMagick') { // ImageMagick command line
-
- if (tp_create_im_cmdline_thumbnails($image, $prefix, $filestorename) != true) {
- trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick command line', E_USER_WARNING);
- echo "Failed to create thumbnails";
- }
-
- } else if ($image_lib == 'ImageMagickPHP') { // imagick PHP extension
-
- if (tp_create_imagick_thumbnails($image, $prefix, $filestorename) != true) {
- trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick PHP', E_USER_WARNING);
- echo "Failed to create thumbnails";
- }
-
- } else {
-
- if (tp_create_gd_thumbnails($image, $prefix, $filestorename) != true) {
- trigger_error('Tidypics warning: failed to create thumbnails - GD', E_USER_WARNING);
- echo "Failed to create thumbnails";
- }
-
- } // end of image library selector
-
- echo "<img id=\"tidypics_image\" src=\"{$CONFIG->wwwroot}mod/tidypics/thumbnail.php?file_guid={$guid}&size=large\" alt=\"{$title}\" />";
-
-?>
+<?php + /** + * Tidypics Thumbnail Creation Test + * + * Called through ajax + */ + + include_once dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php"; + include dirname(dirname(__FILE__)) . "/lib/resize.php"; + + global $CONFIG; + + $guid = $_GET['guid']; + + $image = get_entity($guid); + if (!$image || !($image instanceof TidypicsImage)) { + echo "Unable to get original image"; + return; + } + + $filename = $image->getFilename(); + $container_guid = $image->container_guid; + if (!$filename || !$container_guid) { + echo "Error retrieving information about the image"; + return; + } + + $title = $image->title; + $prefix = "image/" . $container_guid . "/"; + $filestorename = substr($filename, strlen($prefix)); + + $image_lib = get_plugin_setting('image_lib', 'tidypics'); + if (!$image_lib) + $image_lib = "GD"; + + if ($image_lib == 'ImageMagick') { // ImageMagick command line + + if (tp_create_im_cmdline_thumbnails($image, $prefix, $filestorename) != true) { + trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick command line', E_USER_WARNING); + echo "Failed to create thumbnails"; + } + + } else if ($image_lib == 'ImageMagickPHP') { // imagick PHP extension + + if (tp_create_imagick_thumbnails($image, $prefix, $filestorename) != true) { + trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick PHP', E_USER_WARNING); + echo "Failed to create thumbnails"; + } + + } else { + + if (tp_create_gd_thumbnails($image, $prefix, $filestorename) != true) { + trigger_error('Tidypics warning: failed to create thumbnails - GD', E_USER_WARNING); + echo "Failed to create thumbnails"; + } + + } // end of image library selector + + echo "<img id=\"tidypics_image\" src=\"{$CONFIG->wwwroot}mod/tidypics/thumbnail.php?file_guid={$guid}&size=large\" alt=\"{$title}\" />"; + +?> diff --git a/actions/delete.php b/actions/delete.php index 1a518af9e..5506c2303 100644 --- a/actions/delete.php +++ b/actions/delete.php @@ -1,121 +1,121 @@ -<?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("file:deletefailed"));
- forward($forward_url);
- }
-
- if (!$entity->canEdit()) { // user doesn't have permissions
- register_error(elgg_echo("file: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("file:deletefailed"));
- forward($forward_url);
- }
-
- $owner_guid = 0; // group or user
- if ($subtype == 'image') { //deleting an image
- $album = get_entity($entity->container_guid);
- $owner_guid = $album->container_guid;
- $forward_url = $container->getURL(); //forward back to album after deleting pictures
- $images = array($entity);
- // plugins can register to be told when a Tidypics image has been deleted
- trigger_elgg_event('delete', 'tp_image', $entity);
- } else { //deleting an album
- $owner_guid = $entity->container_guid;
- $forward_url = 'pg/photos/owned/' . $container->username;
- //get all the images from this album as long as less than 999 images
- $images = get_entities("object", "image", $guid, '', 999);
- // plugins can register to be told when a Tidypics album has been deleted
- trigger_elgg_event('delete', 'tp_album', $entity);
- }
-
- // make sure we decrease the repo size for the size quota
- $image_repo_size_md = get_metadata_byname($owner_guid, "image_repo_size");
- $image_repo_size = (int)$image_repo_size_md->value;
-
- //loop through all images and delete them
- foreach($images as $im) {
- $thumbnail = $im->thumbnail;
- $smallthumb = $im->smallthumb;
- $largethumb = $im->largethumb;
-
- if ($thumbnail) { //delete standard thumbnail image
- $delfile = new ElggFile();
- $delfile->owner_guid = $im->getOwner();
- $delfile->setFilename($thumbnail);
- $delfile->delete();
- }
- if ($smallthumb) { //delete small thumbnail image
- $delfile = new ElggFile();
- $delfile->owner_guid = $im->getOwner();
- $delfile->setFilename($smallthumb);
- $delfile->delete();
- }
- if ($largethumb) { //delete large thumbnail image
- $delfile = new ElggFile();
- $delfile->owner_guid = $im->getOwner();
- $delfile->setFilename($largethumb);
- $delfile->delete();
- }
- if ($im) { //delete actual image file
- $delfile = new ElggFile($im->getGUID());
- $delfile->owner_guid = $im->getOwner();
- //$delfile->setFilename($im->originalfilename);
- $image_repo_size -= $delfile->size();
-
- if (!$delfile->delete()) {
- if ($subtype=='image') register_error(elgg_echo("file:deletefailed")); //unable to delete object
- } else {
- if ($subtype=='image') system_message(elgg_echo("file:deleted")); //successfully deleted object
- }
- } //end delete actual image file
- } //end looping through each image to delete it
-
- //now that all images have been deleted, delete the album
- if ($subtype == 'album') {
- //delete the album's directory manually; first create a temp file to get the directory path
- $tmpfile = new ElggFile();
- $tmpfile->setFilename('image/' . $guid . '/._tmp_del_tidypics_album_');
- $tmpfile->subtype = 'image';
- $tmpfile->container_guid = $guid;
- $tmpfile->open("write");
- $tmpfile->write('');
- $tmpfile->close();
- $tmpfile->save();
- $albumdir = eregi_replace('/._tmp_del_tidypics_album_', '', $tmpfile->getFilenameOnFilestore());
- $tmpfile->delete();
- if (is_dir($albumdir))
- rmdir($albumdir);
-
- //delete object from database
- if (!$entity->delete()) {
- register_error(elgg_echo("file:deletefailed")); //unable to delete object
- } else {
- system_message(elgg_echo("file:deleted")); //successfully deleted object
- }
- } //end of delete album
-
- create_metadata($owner_guid, "image_repo_size", $image_repo_size, 'integer', $owner_guid);
-
- forward($forward_url);
-
+<?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("file:deletefailed")); + forward($forward_url); + } + + if (!$entity->canEdit()) { // user doesn't have permissions + register_error(elgg_echo("file: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("file:deletefailed")); + forward($forward_url); + } + + $owner_guid = 0; // group or user + if ($subtype == 'image') { //deleting an image + $album = get_entity($entity->container_guid); + $owner_guid = $album->container_guid; + $forward_url = $container->getURL(); //forward back to album after deleting pictures + $images = array($entity); + // plugins can register to be told when a Tidypics image has been deleted + trigger_elgg_event('delete', 'tp_image', $entity); + } else { //deleting an album + $owner_guid = $entity->container_guid; + $forward_url = 'pg/photos/owned/' . $container->username; + //get all the images from this album as long as less than 999 images + $images = get_entities("object", "image", $guid, '', 999); + // plugins can register to be told when a Tidypics album has been deleted + trigger_elgg_event('delete', 'tp_album', $entity); + } + + // make sure we decrease the repo size for the size quota + $image_repo_size_md = get_metadata_byname($owner_guid, "image_repo_size"); + $image_repo_size = (int)$image_repo_size_md->value; + + //loop through all images and delete them + foreach($images as $im) { + $thumbnail = $im->thumbnail; + $smallthumb = $im->smallthumb; + $largethumb = $im->largethumb; + + if ($thumbnail) { //delete standard thumbnail image + $delfile = new ElggFile(); + $delfile->owner_guid = $im->getOwner(); + $delfile->setFilename($thumbnail); + $delfile->delete(); + } + if ($smallthumb) { //delete small thumbnail image + $delfile = new ElggFile(); + $delfile->owner_guid = $im->getOwner(); + $delfile->setFilename($smallthumb); + $delfile->delete(); + } + if ($largethumb) { //delete large thumbnail image + $delfile = new ElggFile(); + $delfile->owner_guid = $im->getOwner(); + $delfile->setFilename($largethumb); + $delfile->delete(); + } + if ($im) { //delete actual image file + $delfile = new ElggFile($im->getGUID()); + $delfile->owner_guid = $im->getOwner(); + //$delfile->setFilename($im->originalfilename); + $image_repo_size -= $delfile->size(); + + if (!$delfile->delete()) { + if ($subtype=='image') register_error(elgg_echo("file:deletefailed")); //unable to delete object + } else { + if ($subtype=='image') system_message(elgg_echo("file:deleted")); //successfully deleted object + } + } //end delete actual image file + } //end looping through each image to delete it + + //now that all images have been deleted, delete the album + if ($subtype == 'album') { + //delete the album's directory manually; first create a temp file to get the directory path + $tmpfile = new ElggFile(); + $tmpfile->setFilename('image/' . $guid . '/._tmp_del_tidypics_album_'); + $tmpfile->subtype = 'image'; + $tmpfile->container_guid = $guid; + $tmpfile->open("write"); + $tmpfile->write(''); + $tmpfile->close(); + $tmpfile->save(); + $albumdir = eregi_replace('/._tmp_del_tidypics_album_', '', $tmpfile->getFilenameOnFilestore()); + $tmpfile->delete(); + if (is_dir($albumdir)) + rmdir($albumdir); + + //delete object from database + if (!$entity->delete()) { + register_error(elgg_echo("file:deletefailed")); //unable to delete object + } else { + system_message(elgg_echo("file:deleted")); //successfully deleted object + } + } //end of delete album + + create_metadata($owner_guid, "image_repo_size", $image_repo_size, 'integer', $owner_guid); + + forward($forward_url); + ?>
\ No newline at end of file diff --git a/actions/deletetag.php b/actions/deletetag.php index 3a76f6e99..becf1fedb 100644 --- a/actions/deletetag.php +++ b/actions/deletetag.php @@ -1,57 +1,57 @@ -<?php
- /**
- * Tidypics Delete Photo Tag
- *
- */
-
- gatekeeper();
- action_gatekeeper();
-
- $image_guid = get_input('image_guid');
- $tags = get_input('tags');
-
-
- if ($image_guid == 0) {
- register_error(elgg_echo("tidypics:phototagging:error"));
- forward($_SERVER['HTTP_REFERER']);
- }
-
- $image = get_entity($image_guid);
- if (!$image)
- {
- register_error(elgg_echo("tidypics:phototagging:error"));
- forward($_SERVER['HTTP_REFERER']);
- }
-
- foreach ($tags as $id => $value) {
- // delete normal tag if it exists
- if (is_array($image->tags)) {
- $index = array_search($value, $image->tags);
- if ($index !== false) {
- $tagarray = $image->tags;
- unset($tagarray[$index]);
- $image->clearMetadata('tags');
- $image->tags = $tagarray;
- }
- } else {
- if ($value === $image->tags) {
- $image->clearMetadata('tags');
- }
- }
-
- // delete relationship if this tag is a user
- $annotation = get_annotation($id);
- $photo_tag = unserialize($annotation->value);
- if ($photo_tag->type == 'user') {
- remove_entity_relationship($photo_tag->value, 'phototag', $image_guid);
- }
-
- // delete the photo tag annotation
- delete_annotation($id);
- }
-
- system_message(elgg_echo("tidypics:deletetag:success"));
-
- forward($_SERVER['HTTP_REFERER']);
-
-?>
+<?php + /** + * Tidypics Delete Photo Tag + * + */ + + gatekeeper(); + action_gatekeeper(); + + $image_guid = get_input('image_guid'); + $tags = get_input('tags'); + + + if ($image_guid == 0) { + register_error(elgg_echo("tidypics:phototagging:error")); + forward($_SERVER['HTTP_REFERER']); + } + + $image = get_entity($image_guid); + if (!$image) + { + register_error(elgg_echo("tidypics:phototagging:error")); + forward($_SERVER['HTTP_REFERER']); + } + + foreach ($tags as $id => $value) { + // delete normal tag if it exists + if (is_array($image->tags)) { + $index = array_search($value, $image->tags); + if ($index !== false) { + $tagarray = $image->tags; + unset($tagarray[$index]); + $image->clearMetadata('tags'); + $image->tags = $tagarray; + } + } else { + if ($value === $image->tags) { + $image->clearMetadata('tags'); + } + } + + // delete relationship if this tag is a user + $annotation = get_annotation($id); + $photo_tag = unserialize($annotation->value); + if ($photo_tag->type == 'user') { + remove_entity_relationship($photo_tag->value, 'phototag', $image_guid); + } + + // delete the photo tag annotation + delete_annotation($id); + } + + system_message(elgg_echo("tidypics:deletetag:success")); + + forward($_SERVER['HTTP_REFERER']); + +?> diff --git a/actions/edit.php b/actions/edit.php index 91c465828..cdf9420b2 100644 --- a/actions/edit.php +++ b/actions/edit.php @@ -1,81 +1,81 @@ -<?php
-
- /**
- * Tidypics edit album/image action
- *
- */
-
- // Make sure we're logged in
- gatekeeper();
-
- // Get input data
- $guid = (int) get_input('guid'); // guid of image or album
- $title = get_input('tidypicstitle');
- $body = get_input('tidypicsbody');
- $access = get_input('access_id');
- $tags = get_input('tidypicstags');
- $subtype = get_input('subtype');
- $cover = get_input('cover');
- if (is_array($cover)) $cover = $cover[0];
-
- $container_guid = get_input('container_guid');
-
- // Make sure we actually have permission to edit
- $entity = get_entity($guid);
- if (!$entity->canEdit()) {
- forward();
- }
-
- // Get owning user/group
- $owner = get_entity($entity->getOwner());
-
- // change access only if access is different from current
- if ($subtype == 'album' && $entity->access_id != $access) {
- $entity->access_id = $access;
-
- //get images from album and update access on image entities
- $images = get_entities("object","image", $guid, '', 999, '', false);
- foreach ($images as $im) {
- $im->access_id = $access;
- $im->save();
- }
- }
-
-
- // Set its title and description appropriately
- $entity->title = $title;
- $entity->description = $body;
-
- // Before we can set metadata, we need to save the entity
- if (!$entity->save()) {
- register_error(elgg_echo("album:error"));
- $entity->delete();
- forward($_SERVER['HTTP_REFERER']); //failed, so forward to previous page
- }
-
- // Now let's add tags
- $tagarray = string_to_tag_array($tags);
- $entity->clearMetadata('tags');
- if (is_array($tagarray)) {
- $entity->tags = $tagarray;
- }
-
- //if cover meta is sent from image save as metadata
- if ($subtype == 'image' && $cover == elgg_echo('album:cover')) {
- $album = get_entity($container_guid);
- $album->cover = $entity->guid;
- }
-
- // Success message
- if ($subtype == 'album') {
- system_message(elgg_echo("album:edited"));
- // plugins can register to be told when a Tidypics album has been updated
- trigger_elgg_event('update', 'tp_album', $entity);
- } else {
- system_message(elgg_echo('images:edited'));
- // plugins can register to be told when a Tidypics image has been updated
- trigger_elgg_event('update', 'tp_image', $entity);
- }
-
- forward($entity->getURL());
-?>
+<?php + + /** + * Tidypics edit album/image action + * + */ + + // Make sure we're logged in + gatekeeper(); + + // Get input data + $guid = (int) get_input('guid'); // guid of image or album + $title = get_input('tidypicstitle'); + $body = get_input('tidypicsbody'); + $access = get_input('access_id'); + $tags = get_input('tidypicstags'); + $subtype = get_input('subtype'); + $cover = get_input('cover'); + if (is_array($cover)) $cover = $cover[0]; + + $container_guid = get_input('container_guid'); + + // Make sure we actually have permission to edit + $entity = get_entity($guid); + if (!$entity->canEdit()) { + forward(); + } + + // Get owning user/group + $owner = get_entity($entity->getOwner()); + + // change access only if access is different from current + if ($subtype == 'album' && $entity->access_id != $access) { + $entity->access_id = $access; + + //get images from album and update access on image entities + $images = get_entities("object","image", $guid, '', 999, '', false); + foreach ($images as $im) { + $im->access_id = $access; + $im->save(); + } + } + + + // Set its title and description appropriately + $entity->title = $title; + $entity->description = $body; + + // Before we can set metadata, we need to save the entity + if (!$entity->save()) { + register_error(elgg_echo("album:error")); + $entity->delete(); + forward($_SERVER['HTTP_REFERER']); //failed, so forward to previous page + } + + // Now let's add tags + $tagarray = string_to_tag_array($tags); + $entity->clearMetadata('tags'); + if (is_array($tagarray)) { + $entity->tags = $tagarray; + } + + //if cover meta is sent from image save as metadata + if ($subtype == 'image' && $cover == elgg_echo('album:cover')) { + $album = get_entity($container_guid); + $album->cover = $entity->guid; + } + + // Success message + if ($subtype == 'album') { + system_message(elgg_echo("album:edited")); + // plugins can register to be told when a Tidypics album has been updated + trigger_elgg_event('update', 'tp_album', $entity); + } else { + system_message(elgg_echo('images:edited')); + // plugins can register to be told when a Tidypics image has been updated + trigger_elgg_event('update', 'tp_image', $entity); + } + + forward($entity->getURL()); +?> diff --git a/actions/edit_multi.php b/actions/edit_multi.php index 92252b6dd..c7099e6db 100644 --- a/actions/edit_multi.php +++ b/actions/edit_multi.php @@ -1,66 +1,66 @@ -<?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->cover = $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());
-
+<?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->cover = $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()); + ?>
\ No newline at end of file diff --git a/actions/imtest.php b/actions/imtest.php index 8d5171785..cbe15a1c1 100644 --- a/actions/imtest.php +++ b/actions/imtest.php @@ -1,19 +1,19 @@ -<?php
- /**
- * Tidypics ImageMagick Location Test
- *
- * Called through ajax
- */
-
- $location = $_GET['location'];
-
- $command = $location . "convert -version";
-
- $result = system($command, $return_val);
-
- if ($return_val == 0) {
- echo $result;
- } else {
- echo "Unable to run ImageMagick. Please check the path.";
- }
-?>
+<?php + /** + * Tidypics ImageMagick Location Test + * + * Called through ajax + */ + + $location = $_GET['location']; + + $command = $location . "convert -version"; + + $result = system($command, $return_val); + + if ($return_val == 0) { + echo $result; + } else { + echo "Unable to run ImageMagick. Please check the path."; + } +?> diff --git a/actions/settings.php b/actions/settings.php index 6b115b049..e16e7960e 100644 --- a/actions/settings.php +++ b/actions/settings.php @@ -1,70 +1,70 @@ -<?php
- /**
- * Save settings of Tidypics
- *
- */
-
- global $CONFIG;
-
- admin_gatekeeper();
- action_gatekeeper();
-
-
- // Params array (text boxes and drop downs)
- $params = get_input('params');
- $result = false;
- foreach ($params as $k => $v) {
- if (!set_plugin_setting($k, $v, 'tidypics')) {
- register_error(sprintf(elgg_echo('plugins:settings:save:fail'), 'tidypics'));
- forward($_SERVER['HTTP_REFERER']);
- }
- }
-
- // check boxes
- if (is_array(get_input('download_link'))) // this can be done due to way Elgg uses checkboxes
- set_plugin_setting('download_link', 'enabled', 'tidypics');
- else
- set_plugin_setting('download_link', 'disabled', 'tidypics');
-
- if (is_array(get_input('tagging')))
- set_plugin_setting('tagging', 'enabled', 'tidypics');
- else
- set_plugin_setting('tagging', 'disabled', 'tidypics');
-
- if (is_array(get_input('photo_ratings')))
- set_plugin_setting('photo_ratings', 'enabled', 'tidypics');
- else
- set_plugin_setting('photo_ratings', 'disabled', 'tidypics');
-
- if (is_array(get_input('exif')))
- set_plugin_setting('exif', 'enabled', 'tidypics');
- else
- set_plugin_setting('exif', 'disabled', 'tidypics');
-
- if (is_array(get_input('view_count')))
- set_plugin_setting('view_count', 'enabled', 'tidypics');
- else
- set_plugin_setting('view_count', 'disabled', 'tidypics');
-
- if (is_array(get_input('grp_perm_override')))
- set_plugin_setting('grp_perm_override', 'enabled', 'tidypics');
- else
- set_plugin_setting('grp_perm_override', 'disabled', 'tidypics');
-
-
- // image sizes
- $image_sizes = array();
- $image_sizes['large_image_width'] = get_input('large_thumb_width');
- $image_sizes['large_image_height'] = get_input('large_thumb_height');
- $image_sizes['small_image_width'] = get_input('small_thumb_width');
- $image_sizes['small_image_height'] = get_input('small_thumb_height');
- $image_sizes['thumb_image_width'] = get_input('thumb_width');
- $image_sizes['thumb_image_height'] = get_input('thumb_height');
- set_plugin_setting('image_sizes', serialize($image_sizes), 'tidypics');
-
-
-
- system_message(elgg_echo('tidypics:settings:save:ok'));
-
- forward($_SERVER['HTTP_REFERER']);
-?>
+<?php + /** + * Save settings of Tidypics + * + */ + + global $CONFIG; + + admin_gatekeeper(); + action_gatekeeper(); + + + // Params array (text boxes and drop downs) + $params = get_input('params'); + $result = false; + foreach ($params as $k => $v) { + if (!set_plugin_setting($k, $v, 'tidypics')) { + register_error(sprintf(elgg_echo('plugins:settings:save:fail'), 'tidypics')); + forward($_SERVER['HTTP_REFERER']); + } + } + + // check boxes + if (is_array(get_input('download_link'))) // this can be done due to way Elgg uses checkboxes + set_plugin_setting('download_link', 'enabled', 'tidypics'); + else + set_plugin_setting('download_link', 'disabled', 'tidypics'); + + if (is_array(get_input('tagging'))) + set_plugin_setting('tagging', 'enabled', 'tidypics'); + else + set_plugin_setting('tagging', 'disabled', 'tidypics'); + + if (is_array(get_input('photo_ratings'))) + set_plugin_setting('photo_ratings', 'enabled', 'tidypics'); + else + set_plugin_setting('photo_ratings', 'disabled', 'tidypics'); + + if (is_array(get_input('exif'))) + set_plugin_setting('exif', 'enabled', 'tidypics'); + else + set_plugin_setting('exif', 'disabled', 'tidypics'); + + if (is_array(get_input('view_count'))) + set_plugin_setting('view_count', 'enabled', 'tidypics'); + else + set_plugin_setting('view_count', 'disabled', 'tidypics'); + + if (is_array(get_input('grp_perm_override'))) + set_plugin_setting('grp_perm_override', 'enabled', 'tidypics'); + else + set_plugin_setting('grp_perm_override', 'disabled', 'tidypics'); + + + // image sizes + $image_sizes = array(); + $image_sizes['large_image_width'] = get_input('large_thumb_width'); + $image_sizes['large_image_height'] = get_input('large_thumb_height'); + $image_sizes['small_image_width'] = get_input('small_thumb_width'); + $image_sizes['small_image_height'] = get_input('small_thumb_height'); + $image_sizes['thumb_image_width'] = get_input('thumb_width'); + $image_sizes['thumb_image_height'] = get_input('thumb_height'); + set_plugin_setting('image_sizes', serialize($image_sizes), 'tidypics'); + + + + system_message(elgg_echo('tidypics:settings:save:ok')); + + forward($_SERVER['HTTP_REFERER']); +?> diff --git a/actions/upload.php b/actions/upload.php index 3aa739414..0913ed937 100644 --- a/actions/upload.php +++ b/actions/upload.php @@ -1,255 +1,255 @@ -<?php
- /**
- * Elgg multi-image uploader action
- *
- * This will upload up to 10 images at at time to an album
- */
-
- global $CONFIG;
- include dirname(dirname(__FILE__)) . "/lib/resize.php";
- include dirname(dirname(__FILE__)) . "/lib/exif.php";
-
- // Make sure we're logged in
- gatekeeper();
-
- // Get common variables
- $access_id = (int) get_input("access_id");
- $container_guid = (int) get_input('container_guid', 0);
- if (!$container_guid)
- $container_guid == $_SESSION['user']->getGUID();
-
- $album = get_entity($container_guid);
-
- $maxfilesize = (float) get_plugin_setting('maxfilesize','tidypics');
- if (!$maxfilesize)
- $maxfilesize = 5; // default to 5 MB if not set
- $maxfilesize = 1024 * 1024 * $maxfilesize; // convert to bytes from MBs
-
- $quota = get_plugin_setting('quota','tidypics');
- $quota = 1024 * 1024 * $quota;
- $image_repo_size_md = get_metadata_byname($album->container_guid, "image_repo_size");
- $image_repo_size = (int)$image_repo_size_md->value;
-
- $image_lib = get_plugin_setting('image_lib', 'tidypics');
- if (!$image_lib)
- $image_lib = "GD";
-
- // 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(get_input('forward_url', $_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(get_input('forward_url', $_SERVER['HTTP_REFERER']));
- }
-
- $uploaded_images = array();
- $not_uploaded = array();
- $error_msgs = array();
-
- $img_river_view = get_plugin_setting('img_river_view', 'tidypics');
-
- $accepted_formats = array(
- 'image/jpeg',
- 'image/png',
- 'image/gif',
- 'image/pjpeg',
- 'image/x-png',
- );
-
-
- 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 exceed 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;
- }
-
- //make sure file is an image
- if (!in_array($mime, $accepted_formats)) {
- array_push($not_uploaded, $sent_file['name']);
- array_push($error_msgs, elgg_echo('tidypics:not_image'));
- continue;
- }
-
- // check quota
- if ($quota) {
- if ($image_repo_size + $sent_file['size'] > $quota) {
- 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 ($sent_file['size'] > $maxfilesize) {
- 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 - GD only
- $imginfo = getimagesize($sent_file['tmp_name']);
- $mem_avail = ini_get('memory_limit');
- $mem_avail = rtrim($mem_avail, 'M');
- $mem_avail = $mem_avail * 1024 * 1024;
- if ($image_lib == 'GD') {
- $mem_required = ceil(5.35 * $imginfo[0] * $imginfo[1]);
-
- $mem_used = memory_get_usage();
-
- $mem_avail = $mem_avail - $mem_used - 2097152; // 2 MB buffer
- if ($mem_required > $mem_avail) {
- 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;
- }
- } else if ($image_lib == 'ImageMagickPHP') {
- // haven't been able to determine a limit like there is for GD
- }
-
- //this will save to users folder in /image/ and organize by photo album
- $prefix = "image/" . $container_guid . "/";
- $file = new ElggFile();
- $filestorename = strtolower(time().$name);
- $file->setFilename($prefix.$filestorename);
- $file->setMimeType($mime);
- $file->originalfilename = $name;
- $file->subtype="image";
- $file->simpletype="image";
- $file->access_id = $access_id;
- if ($container_guid) {
- $file->container_guid = $container_guid;
- }
- $file->open("write");
- $file->write(get_uploaded_file($key));
- $file->close();
- $result = $file->save();
-
- if (!$result) {
- array_push($not_uploaded, $sent_file['name']);
- array_push($error_msgs, elgg_echo('tidypics:save_error'));
- continue;
- }
-
- //get and store the exif data
- td_get_exif($file);
-
-
- // resize photos to create thumbnails
- if ($image_lib == 'ImageMagick') { // ImageMagick command line
-
- if (tp_create_im_cmdline_thumbnails($file, $prefix, $filestorename) != true) {
- trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick command line', E_USER_WARNING);
- }
-
- } else if ($image_lib == 'ImageMagickPHP') { // imagick php extension
-
- if (tp_create_imagick_thumbnails($file, $prefix, $filestorename) != true) {
- trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick PHP', E_USER_WARNING);
- }
-
- } else {
-
- if (tp_create_gd_thumbnails($file, $prefix, $filestorename) != true) {
- trigger_error('Tidypics warning: failed to create thumbnails - GD', E_USER_WARNING);
- }
-
- } // end of image library selector
-
- //keep one file handy so we can add a notice to the river if single image option selected
- if(!$file_for_river) {
- $file_for_river = $file;
- }
-
- array_push($uploaded_images, $file->guid);
-
- // update user/group size for checking quota
- $image_repo_size += $sent_file['size'];
-
- // 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);
-
- if (function_exists('add_to_river'))
- 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)
- forward(get_input('forward_url', $_SERVER['HTTP_REFERER'])); //upload failed, so forward to previous page
- else {
- // some images did upload so we fall through
- }
- } else {
- system_message(elgg_echo('tidypics:upl_success'));
- }
-
-
- if (count($uploaded_images) && $img_river_view == "1") {
- if (function_exists('add_to_river')) {
- add_to_river('river/object/image/create', 'create', $file_for_river->getObjectOwnerGUID(), $file_for_river->getGUID());
- }
- }
-
- // update image repo size
- create_metadata($album->container_guid, "image_repo_size", $image_repo_size, 'integer', $album->container_guid);
-
- // 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));
-
-?>
+<?php + /** + * Elgg multi-image uploader action + * + * This will upload up to 10 images at at time to an album + */ + + global $CONFIG; + include dirname(dirname(__FILE__)) . "/lib/resize.php"; + include dirname(dirname(__FILE__)) . "/lib/exif.php"; + + // Make sure we're logged in + gatekeeper(); + + // Get common variables + $access_id = (int) get_input("access_id"); + $container_guid = (int) get_input('container_guid', 0); + if (!$container_guid) + $container_guid == $_SESSION['user']->getGUID(); + + $album = get_entity($container_guid); + + $maxfilesize = (float) get_plugin_setting('maxfilesize','tidypics'); + if (!$maxfilesize) + $maxfilesize = 5; // default to 5 MB if not set + $maxfilesize = 1024 * 1024 * $maxfilesize; // convert to bytes from MBs + + $quota = get_plugin_setting('quota','tidypics'); + $quota = 1024 * 1024 * $quota; + $image_repo_size_md = get_metadata_byname($album->container_guid, "image_repo_size"); + $image_repo_size = (int)$image_repo_size_md->value; + + $image_lib = get_plugin_setting('image_lib', 'tidypics'); + if (!$image_lib) + $image_lib = "GD"; + + // 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(get_input('forward_url', $_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(get_input('forward_url', $_SERVER['HTTP_REFERER'])); + } + + $uploaded_images = array(); + $not_uploaded = array(); + $error_msgs = array(); + + $img_river_view = get_plugin_setting('img_river_view', 'tidypics'); + + $accepted_formats = array( + 'image/jpeg', + 'image/png', + 'image/gif', + 'image/pjpeg', + 'image/x-png', + ); + + + 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 exceed 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; + } + + //make sure file is an image + if (!in_array($mime, $accepted_formats)) { + array_push($not_uploaded, $sent_file['name']); + array_push($error_msgs, elgg_echo('tidypics:not_image')); + continue; + } + + // check quota + if ($quota) { + if ($image_repo_size + $sent_file['size'] > $quota) { + 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 ($sent_file['size'] > $maxfilesize) { + 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 - GD only + $imginfo = getimagesize($sent_file['tmp_name']); + $mem_avail = ini_get('memory_limit'); + $mem_avail = rtrim($mem_avail, 'M'); + $mem_avail = $mem_avail * 1024 * 1024; + if ($image_lib == 'GD') { + $mem_required = ceil(5.35 * $imginfo[0] * $imginfo[1]); + + $mem_used = memory_get_usage(); + + $mem_avail = $mem_avail - $mem_used - 2097152; // 2 MB buffer + if ($mem_required > $mem_avail) { + 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; + } + } else if ($image_lib == 'ImageMagickPHP') { + // haven't been able to determine a limit like there is for GD + } + + //this will save to users folder in /image/ and organize by photo album + $prefix = "image/" . $container_guid . "/"; + $file = new ElggFile(); + $filestorename = strtolower(time().$name); + $file->setFilename($prefix.$filestorename); + $file->setMimeType($mime); + $file->originalfilename = $name; + $file->subtype="image"; + $file->simpletype="image"; + $file->access_id = $access_id; + if ($container_guid) { + $file->container_guid = $container_guid; + } + $file->open("write"); + $file->write(get_uploaded_file($key)); + $file->close(); + $result = $file->save(); + + if (!$result) { + array_push($not_uploaded, $sent_file['name']); + array_push($error_msgs, elgg_echo('tidypics:save_error')); + continue; + } + + //get and store the exif data + td_get_exif($file); + + + // resize photos to create thumbnails + if ($image_lib == 'ImageMagick') { // ImageMagick command line + + if (tp_create_im_cmdline_thumbnails($file, $prefix, $filestorename) != true) { + trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick command line', E_USER_WARNING); + } + + } else if ($image_lib == 'ImageMagickPHP') { // imagick php extension + + if (tp_create_imagick_thumbnails($file, $prefix, $filestorename) != true) { + trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick PHP', E_USER_WARNING); + } + + } else { + + if (tp_create_gd_thumbnails($file, $prefix, $filestorename) != true) { + trigger_error('Tidypics warning: failed to create thumbnails - GD', E_USER_WARNING); + } + + } // end of image library selector + + //keep one file handy so we can add a notice to the river if single image option selected + if(!$file_for_river) { + $file_for_river = $file; + } + + array_push($uploaded_images, $file->guid); + + // update user/group size for checking quota + $image_repo_size += $sent_file['size']; + + // 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); + + if (function_exists('add_to_river')) + 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) + forward(get_input('forward_url', $_SERVER['HTTP_REFERER'])); //upload failed, so forward to previous page + else { + // some images did upload so we fall through + } + } else { + system_message(elgg_echo('tidypics:upl_success')); + } + + + if (count($uploaded_images) && $img_river_view == "1") { + if (function_exists('add_to_river')) { + add_to_river('river/object/image/create', 'create', $file_for_river->getObjectOwnerGUID(), $file_for_river->getGUID()); + } + } + + // update image repo size + create_metadata($album->container_guid, "image_repo_size", $image_repo_size, 'integer', $album->container_guid); + + // 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)); + +?> |