From 7acd3a2947f7bd92ded5bc5f02baa5db87f6b212 Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sat, 21 Mar 2009 18:12:50 +0000 Subject: cleaned up actions - formatting --- actions/addalbum.php | 100 +++++++++++++++++++++------------------------ actions/delete.php | 6 +-- actions/download.php | 7 +--- actions/edit_multi.php | 58 +++++++++++++------------- actions/editalbum.php | 108 +++++++++++++++++++++++-------------------------- actions/icon.php | 13 ++---- actions/upload.php | 33 ++++++++++----- 7 files changed, 156 insertions(+), 169 deletions(-) diff --git a/actions/addalbum.php b/actions/addalbum.php index 127885270..f2d423abd 100644 --- a/actions/addalbum.php +++ b/actions/addalbum.php @@ -1,72 +1,66 @@ - * @copyright Curverider Ltd 2008 - * @link http://elgg.org/ */ // Make sure we're logged in (send us to the front page if not) - if (!isloggedin()) forward(); + if (!isloggedin()) forward(); // Get input data - $title = get_input('albumtitle'); - $body = get_input('albumbody'); - $tags = get_input('albumtags'); - $access = get_input('access_id'); - $container_guid = get_input('container_guid', $_SESSION['user']->getGUID()); - $back_url = 'pg/photos/new/' . get_entity($container_guid)->username; + $title = get_input('albumtitle'); + $body = get_input('albumbody'); + $tags = get_input('albumtags'); + $access = get_input('access_id'); + $container_guid = get_input('container_guid', $_SESSION['user']->getGUID()); + $back_url = 'pg/photos/new/' . get_entity($container_guid)->username; // Cache to the session - $_SESSION['albumtitle'] = $title; - $_SESSION['albumbody'] = $body; - $_SESSION['albumtags'] = $tags; + $_SESSION['albumtitle'] = $title; + $_SESSION['albumbody'] = $body; + $_SESSION['albumtags'] = $tags; // Convert string of tags into a preformatted array - $tagarray = string_to_tag_array($tags); + $tagarray = string_to_tag_array($tags); // Make sure the title / description aren't blank - if (empty($title) || empty($body)) { - register_error(elgg_echo("album:blank")); - forward(get_input('forward_url', $_SERVER['HTTP_REFERER'])); //failed, so forward to previous page + if (empty($title) || empty($body)) { + register_error(elgg_echo("album:blank")); + forward(get_input('forward_url', $_SERVER['HTTP_REFERER'])); //failed, so forward to previous page - // Otherwise, save the blog post - } else { + // Otherwise, save the album + } else { - // Initialise a new ElggObject - $album = new ElggObject(); - // Tell the system it's an album - $album->subtype = "album"; + // 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(); - // For now, set its access to public (we'll add an access dropdown shortly) - $album->access_id = $access; - // Set its title and description appropriately - $album->title = $title; - $album->description = $body; - // Before we can set metadata, we need to save the blog post - 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. We can pass an array directly to the object property! Easy. - if (is_array($tagarray)) { - $album->tags = $tagarray; - } - // Success message - system_message(elgg_echo("album:created")); - // Remove the blog post cache - unset($_SESSION['albumtitle']); - unset($_SESSION['albumbody']); - unset($_SESSION['albumtags']); - // Forward to the main blog page - - forward("pg/photos/upload/" . $album->guid); - + // Set its owner to the current user + $album->container_guid = $container_guid; + $album->owner_guid = $_SESSION['user']->getGUID(); + // For now, set its access to public (we'll add an access dropdown shortly) + $album->access_id = $access; + // Set its title and description appropriately + $album->title = $title; + $album->description = $body; + // Before we can set metadata, we need to save the blog post + 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. We can pass an array directly to the object property! Easy. + if (is_array($tagarray)) { + $album->tags = $tagarray; + } + // Success message + system_message(elgg_echo("album:created")); + // Remove the album post cache + unset($_SESSION['albumtitle']); + unset($_SESSION['albumbody']); + unset($_SESSION['albumtags']); + + forward("pg/photos/upload/" . $album->guid); + } + ?> \ No newline at end of file diff --git a/actions/delete.php b/actions/delete.php index 6b8789fb4..e142e9660 100644 --- a/actions/delete.php +++ b/actions/delete.php @@ -1,12 +1,8 @@ $im){ + foreach($image_guid_array as $key => $im) { $image = get_entity($im); - if ($image->canEdit()){ + if ($image->canEdit()) { - // Convert string of tags into a preformatted array + // Convert string of tags into a preformatted array $tagarray = string_to_tag_array($tags_array[$key]); - //set description appropriately + //set description appropriately $image->title = $title_array[$key]; - //set description appropriately + //set description appropriately $image->description = $caption_array[$key]; - // Before we can set metadata, we need to save the image + // 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. + // 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){ + //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")); - } + } + + // 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()); - + // Forward to the main album page + forward($album_entity->getURL()); ?> \ No newline at end of file diff --git a/actions/editalbum.php b/actions/editalbum.php index 36b0f7379..78b1f1653 100644 --- a/actions/editalbum.php +++ b/actions/editalbum.php @@ -1,91 +1,85 @@ - * @copyright Curverider Ltd 2008 - * @link http://elgg.org/ */ // Make sure we're logged in (send us to the front page if not) - if (!isloggedin()) forward(); + if (!isloggedin()) forward(); // Get input data - $guid = (int) get_input('albumpost'); - $title = get_input('albumtitle'); - $body = get_input('albumbody'); - $access = get_input('access_id'); - $tags = get_input('albumtags'); - $back_url = 'mod/tidypics/edit.php?file_guid=' . $guid; + $guid = (int) get_input('albumpost'); + $title = get_input('albumtitle'); + $body = get_input('albumbody'); + $access = get_input('access_id'); + $tags = get_input('albumtags'); + $back_url = 'mod/tidypics/edit.php?file_guid=' . $guid; // Make sure we actually have permission to edit - $album = get_entity($guid); - if ($album->canEdit()) - { + $album = get_entity($guid); + if ($album->canEdit()) + { - // Cache to the session - $_SESSION['albumtitle'] = $title; - $_SESSION['albumbody'] = $body; - $_SESSION['albumtags'] = $tags; + // Cache to the session + $_SESSION['albumtitle'] = $title; + $_SESSION['albumbody'] = $body; + $_SESSION['albumtags'] = $tags; - // Convert string of tags into a preformatted array - $tagarray = string_to_tag_array($tags); + // Convert string of tags into a preformatted array + $tagarray = string_to_tag_array($tags); - // Get owning user - $owner = get_entity($album->getOwner()); + // Get owning user + $owner = get_entity($album->getOwner()); - // edit access only if access is different from current - - if($album->access_id != $access) - { - $album->access_id = $access; + // edit access only if access is different from current + if ($album->access_id != $access) + { + $album->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(); - //new core updates all metadata access as well! - } + //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(); + //new core updates all metadata access as well! } + } // Set its title and description appropriately - $album->title = $title; - $album->description = $body; + $album->title = $title; + $album->description = $body; // Before we can set metadata, we need to save the image - if (!$album->save()) { - register_error(elgg_echo("album:error")); - $album->delete(); - forward(get_input('forward_url', $_SERVER['HTTP_REFERER'])); //failed, so forward to previous page - } + if (!$album->save()) { + register_error(elgg_echo("album:error")); + $album->delete(); + forward(get_input('forward_url', $_SERVER['HTTP_REFERER'])); //failed, so forward to previous page + } // Now let's add tags. We can pass an array directly to the object property! Easy. - $album->clearMetadata('tags'); - if (is_array($tagarray)) { - $album->tags = $tagarray; - } + $album->clearMetadata('tags'); + if (is_array($tagarray)) { + $album->tags = $tagarray; + } //if cover meta is sent from image save as metadata - if(get_input('cover') == elgg_echo('album:cover:yes')){ - $container = get_entity($album->container_guid); - $container->cover = $album->guid; - } + if (get_input('cover') == elgg_echo('album:cover:yes')) { + $container = get_entity($album->container_guid); + $container->cover = $album->guid; + } // Success message - system_message(elgg_echo("album:edited")); + system_message(elgg_echo("album:edited")); // Remove the image cache - unset($_SESSION['albumtitle']); - unset($_SESSION['albumbody']); - unset($_SESSION['albumtags']); + unset($_SESSION['albumtitle']); + unset($_SESSION['albumbody']); + unset($_SESSION['albumtags']); // Forward to the main blog page - forward($album->getURL()); + forward($album->getURL()); - } + } ?> \ No newline at end of file diff --git a/actions/icon.php b/actions/icon.php index 718425819..bfc18198a 100644 --- a/actions/icon.php +++ b/actions/icon.php @@ -1,18 +1,13 @@ thumbnail; $mime = $file->mimetype; @@ -35,7 +30,7 @@ echo $contents; exit; - } - else + } else { register_error(elgg_echo("file:downloadfailed")); + } ?> \ No newline at end of file diff --git a/actions/upload.php b/actions/upload.php index f969f6f40..896cce8e7 100644 --- a/actions/upload.php +++ b/actions/upload.php @@ -17,12 +17,12 @@ $uploaded_images = array(); foreach($_FILES as $key => $sent_file) { - if(!empty($sent_file['name'])) { + if (!empty($sent_file['name'])) { $name = $_FILES[$key]['name']; $mime = $_FILES[$key]['type']; - //make sure file is an image - if($mime == 'image/jpeg' || $mime == 'image/gif' || $mime == 'image/png' || $mime == 'image/pjpeg') { + //make sure file is an image + if ($mime == 'image/jpeg' || $mime == 'image/gif' || $mime == 'image/png' || $mime == 'image/pjpeg') { //this will save to users folder in /image/ and organize by photo album $prefix = "image/" . $container_guid . "/"; $file = new ElggFile(); @@ -52,18 +52,27 @@ $maxfilesize = 10240; //if the file size limit is not set, default to 10MB } $maxfilesize = 1024 * $maxfilesize; //convert to bytes - + //check file size and remove picture if it exceeds the maximum if (filesize($file->getFilenameOnFilestore())<= $maxfilesize) { array_push($uploaded_images, $file->guid); - + // Generate thumbnail //TODO: REMOVE THE BELOW IF STATEMENT ONCE get_resized_image_from_existing_file() ACCEPTS IMAGES OVER 0.9MB IN SIZE if (filesize($file->getFilenameOnFilestore())<= 943718) { //create thumbnails if file size < 0.9MB - try {$thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),600,600, false); } catch (Exception $e) { $thumblarge = false; } - try {$thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),153,153, true); } catch (Exception $e) { $thumbsmall = false; } - try {$thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),60,60, true); } catch (Exception $e) { $thumbnail = false; } + try { + $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),600,600, false); + } catch (Exception $e) { $thumblarge = false; } + + try { + $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),153,153, true); + } catch (Exception $e) { $thumbsmall = false; } + + try { + $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),60,60, true); + } catch (Exception $e) { $thumbnail = false; } } + if ($thumbnail) { $thumb = new ElggFile(); $thumb->setMimeType($mime); @@ -76,6 +85,7 @@ } $thumb->close(); } + if ($thumbsmall) { $thumb = new ElggFile(); $thumb->setMimeType($mime); @@ -88,6 +98,7 @@ } $thumb->close(); } + if ($thumblarge) { $thumb = new ElggFile(); $thumb->setMimeType($mime); @@ -107,11 +118,11 @@ } else { //file was not saved for some unknown reason array_push($not_uploaded, $name); } //end of file saved check and thumbnail creation - } else { // file is not a supported image type + } else { // file is not a supported image type array_push($not_uploaded, $name); - } //end of mimetype block + } //end of mimetype block } //end of file name empty check - } //end of loop + } //end of for loop if (count($not_uploaded) == 0) { system_message(elgg_echo("images:saved")); -- cgit v1.2.3