aboutsummaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2009-02-25 12:16:53 +0000
committerCash Costello <cash.costello@gmail.com>2009-02-25 12:16:53 +0000
commit4e0c1576475390faa2f1fb4c4dc2902a953f440e (patch)
treecd3a47df019344d7f6c938ebe31c60cfa9b03677 /actions
downloadelgg-4e0c1576475390faa2f1fb4c4dc2902a953f440e.tar.gz
elgg-4e0c1576475390faa2f1fb4c4dc2902a953f440e.tar.bz2
First commit
Diffstat (limited to 'actions')
-rw-r--r--actions/addalbum.php72
-rw-r--r--actions/delete.php105
-rw-r--r--actions/download.php43
-rw-r--r--actions/edit_multi.php62
-rw-r--r--actions/editalbum.php91
-rw-r--r--actions/icon.php41
-rw-r--r--actions/upload.php133
7 files changed, 547 insertions, 0 deletions
diff --git a/actions/addalbum.php b/actions/addalbum.php
new file mode 100644
index 000000000..127885270
--- /dev/null
+++ b/actions/addalbum.php
@@ -0,0 +1,72 @@
+<?php
+ /**
+ * Elgg blog: add post action
+ *
+ * @package ElggBlog
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd <info@elgg.com>
+ * @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();
+
+ // 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;
+
+ // 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);
+ // 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
+
+ // Otherwise, save the blog post
+ } 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();
+ // 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);
+
+ }
+
+?> \ No newline at end of file
diff --git a/actions/delete.php b/actions/delete.php
new file mode 100644
index 000000000..6b8789fb4
--- /dev/null
+++ b/actions/delete.php
@@ -0,0 +1,105 @@
+<?php
+
+ /**
+ * Elgg file delete
+ *
+ * @package ElggFile
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ //if not logged in, see world pictures instead
+ if (!isloggedin()) forward('pg/photos/world');
+
+ $guid = (int) get_input('file');
+ $forward_url = 'pg/photos/world'; //forward to world pictures if there is an unknown error
+
+ if ($photoObject = get_entity($guid)) {
+ if ($photoObject->canEdit()) {
+ $subtype = $photoObject->getSubtype();
+ $container = get_entity($photoObject->container_guid);
+
+ if ($subtype!='image' && $subtype!='album') forward(get_input('forward_url', $_SERVER['HTTP_REFERER'])); //back off if not an album or image
+
+ if ($subtype == 'image') { //deleting an image
+ $forward_url = $container->getURL(); //forward back to album after deleting pictures
+ $images = array($photoObject);
+ } else { //deleting an album
+ $forward_url = 'pg/photos/owned/' . $container->username;
+ $images = get_entities("object","image", $guid, '', 999); //get all the images from this album, or the image requested
+ } //end of subtype comparison
+
+ //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);
+ 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 (!$photoObject->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
+
+
+ } else { //user does not have permissions to delete this image or album
+ $container = $_SESSION['user'];
+ register_error(elgg_echo("file:deletefailed"));
+ } //end of canEdit() comparison
+
+ } else { // unable to get Elgg entity
+ register_error(elgg_echo("file:deletefailed"));
+ } //end of get_entitty()
+
+ forward($forward_url);
+
+?> \ No newline at end of file
diff --git a/actions/download.php b/actions/download.php
new file mode 100644
index 000000000..31f21f0f5
--- /dev/null
+++ b/actions/download.php
@@ -0,0 +1,43 @@
+<?php
+ /**
+ * Elgg file browser download action.
+ *
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ global $CONFIG;
+
+ $file_guid = (int) get_input("file_guid");
+ $file = get_entity($file_guid);
+
+ if ($file)
+ {
+ $filename = $file->originalfilename;
+ $mime = $file->mimetype;
+
+ header("Content-type: $mime");
+ if (strpos($mime, "image/")!==false)
+ header("Content-Disposition: inline; filename=\"$filename\"");
+ else
+ header("Content-Disposition: attachment; filename=\"$filename\"");
+
+
+ $readfile = new ElggFile($file_guid);
+ $readfile->owner_guid = $file->owner_guid;
+ //$readfile->setFilename($filename);
+
+ $contents = $readfile->grabFile();
+
+ if (empty($contents))
+ echo file_get_contents(dirname(dirname(__FILE__)) . "/graphics/icons/general.jpg" );
+ else
+ echo $contents;
+
+ exit;
+ }
+ else
+ register_error(elgg_echo("image:downloadfailed"));
+
+?> \ No newline at end of file
diff --git a/actions/edit_multi.php b/actions/edit_multi.php
new file mode 100644
index 000000000..9bb9c4eed
--- /dev/null
+++ b/actions/edit_multi.php
@@ -0,0 +1,62 @@
+<?php
+ /**
+ * Elgg album: multi image edit action
+ *
+ */
+
+ // Make sure we're logged in (send us to the front page if not)
+ if (!isloggedin()) forward();
+
+ // Get input data
+ $cover = get_input('cover');
+ $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);
+ $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 description appropriately
+ $image->title = $title_array[$key];
+
+ //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/editalbum.php b/actions/editalbum.php
new file mode 100644
index 000000000..36b0f7379
--- /dev/null
+++ b/actions/editalbum.php
@@ -0,0 +1,91 @@
+<?php
+
+ /**
+ * Elgg album: edit album action
+ *
+ * @package ElggBlog
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd <info@elgg.com>
+ * @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();
+
+ // 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;
+
+ // Make sure we actually have permission to edit
+ $album = get_entity($guid);
+ if ($album->canEdit())
+ {
+
+ // 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);
+
+ // 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;
+
+ //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;
+
+ // 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
+ }
+
+ // 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;
+ }
+
+ //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;
+ }
+
+ // Success message
+ system_message(elgg_echo("album:edited"));
+
+ // Remove the image cache
+ unset($_SESSION['albumtitle']);
+ unset($_SESSION['albumbody']);
+ unset($_SESSION['albumtags']);
+
+ // Forward to the main blog page
+ forward($album->getURL());
+
+ }
+?> \ No newline at end of file
diff --git a/actions/icon.php b/actions/icon.php
new file mode 100644
index 000000000..718425819
--- /dev/null
+++ b/actions/icon.php
@@ -0,0 +1,41 @@
+<?php
+ /**
+ * Elgg tidypics icon action
+ *
+ * @package ElggFile
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ $file_guid = get_input("file_guid");
+ $file = get_entity($file_guid);
+
+ if ($file)
+ {
+ $filename = $file->thumbnail;
+ $mime = $file->mimetype;
+
+ header("Content-type: $mime");
+ if (strpos($mime, "image/")!==false)
+ header("Content-Disposition: inline; filename=\"$filename\"");
+ else
+ header("Content-Disposition: attachment; filename=\"$filename\"");
+
+
+ $readfile = new ElggFile();
+ $readfile->owner_guid = $file->owner_guid;
+ $readfile->setFilename($filename);
+
+ $contents = $readfile->grabFile();
+
+ if (empty($contents))
+ echo file_get_contents(dirname(dirname(__FILE__)) . "/graphics/icons/general.jpg" );
+ else
+ echo $contents;
+
+ exit;
+ }
+ else
+ register_error(elgg_echo("file:downloadfailed"));
+?> \ No newline at end of file
diff --git a/actions/upload.php b/actions/upload.php
new file mode 100644
index 000000000..f969f6f40
--- /dev/null
+++ b/actions/upload.php
@@ -0,0 +1,133 @@
+<?php
+ /**
+ * Elgg multi-image uploader action
+ *
+ * This will upload up to 10 images at at time to an album
+ */
+
+ global $CONFIG;
+
+ // 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();
+
+ $not_uploaded = array();
+ $uploaded_images = array();
+
+ foreach($_FILES as $key => $sent_file) {
+ 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') {
+ //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->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) { //file was saved; now create some thumbnails
+ //get maximum file size from plugin settings
+ if (get_plugin_setting('maxfilesize','tidypics')) {
+ if (((int) get_plugin_setting('maxfilesize','tidypics')) < 1 || ((int) get_plugin_setting('maxfilesize','tidypics')) > 1048576) {
+ $maxfilesize = 10240; //if file size is less than 1KB or greater than 1GB, default to 10MB
+ } else {
+ $maxfilesize = (int) get_plugin_setting('maxfilesize','tidypics');
+ }
+ } else {
+ $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; }
+ }
+ if ($thumbnail) {
+ $thumb = new ElggFile();
+ $thumb->setMimeType($mime);
+ $thumb->setFilename($prefix."thumb".$filestorename);
+ $thumb->open("write");
+ if ($thumb->write($thumbnail)) {
+ $file->thumbnail = $prefix."thumb".$filestorename;
+ } else {
+ $thumb->delete();
+ }
+ $thumb->close();
+ }
+ if ($thumbsmall) {
+ $thumb = new ElggFile();
+ $thumb->setMimeType($mime);
+ $thumb->setFilename($prefix."smallthumb".$filestorename);
+ $thumb->open("write");
+ if ($thumb->write($thumbsmall)) {
+ $file->smallthumb = $prefix."smallthumb".$filestorename;
+ } else {
+ $thumb->delete();
+ }
+ $thumb->close();
+ }
+ if ($thumblarge) {
+ $thumb = new ElggFile();
+ $thumb->setMimeType($mime);
+ $thumb->setFilename($prefix."largethumb".$filestorename);
+ $thumb->open("write");
+ if ($thumb->write($thumblarge)) {
+ $file->largethumb = $prefix."largethumb".$filestorename;
+ } else {
+ $thumb->delete();
+ }
+ $thumb->close();
+ }
+ } else { //file exceeds file size limit, so delete it
+ $file->delete();
+ array_push($not_uploaded, $name);
+ } //end of file size check
+ } 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
+ array_push($not_uploaded, $name);
+ } //end of mimetype block
+ } //end of file name empty check
+ } //end of loop
+
+ if (count($not_uploaded) == 0) {
+ system_message(elgg_echo("images:saved"));
+ } else {
+ $error = elgg_echo("image:uploadfailed") . '<br />';
+ foreach($not_uploaded as $im_name){
+ $error .= ' [' . $im_name . '] ';
+ }
+ $error .= ' ' . elgg_echo("image:notimage");
+ register_error($error);
+ } //end of upload check
+
+ if (count($uploaded_images)>0) {
+ forward($CONFIG->wwwroot . 'mod/tidypics/edit_multi.php?files=' . implode('-', $uploaded_images)); //forward to multi-image edit page
+ } else {
+ forward(get_input('forward_url', $_SERVER['HTTP_REFERER'])); //upload failed, so forward to previous page
+ }
+
+?> \ No newline at end of file