diff options
author | Cash Costello <cash.costello@gmail.com> | 2012-07-13 22:50:23 -0400 |
---|---|---|
committer | Cash Costello <cash.costello@gmail.com> | 2012-07-13 22:50:23 -0400 |
commit | 01730a85bced88f32d88efac995ea12294934a63 (patch) | |
tree | 62b71d96d02fce3a75393da08219714fdad4789d /actions | |
parent | 919ae814fa2b651072b5bbb901e2183220a0dd30 (diff) | |
parent | 5cc8de829c0a7b86c8df27293f4825d0e340d592 (diff) | |
download | elgg-01730a85bced88f32d88efac995ea12294934a63.tar.gz elgg-01730a85bced88f32d88efac995ea12294934a63.tar.bz2 |
flash uploader working
Diffstat (limited to 'actions')
-rw-r--r-- | actions/ajax_upload.php | 61 | ||||
-rw-r--r-- | actions/ajax_upload_complete.php | 56 | ||||
-rw-r--r-- | actions/photos/image/ajax_upload.php | 57 | ||||
-rw-r--r-- | actions/photos/image/ajax_upload_complete.php | 74 | ||||
-rw-r--r-- | actions/photos/image/upload.php | 2 |
5 files changed, 133 insertions, 117 deletions
diff --git a/actions/ajax_upload.php b/actions/ajax_upload.php deleted file mode 100644 index 1f5588197..000000000 --- a/actions/ajax_upload.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php -/** - * Elgg single upload action for flash/ajax uploaders - * - */ - -include_once dirname(dirname(__FILE__)) . "/lib/upload.php"; - -$album_guid = (int) get_input('album_guid'); -$file_var_name = get_input('file_var_name', 'Image'); - -$album = get_entity($album_guid); -if (!$album) { - exit; -} - -// probably POST limit exceeded -if (empty($_FILES)) { - echo 'Image was too large'; - exit; -} - -$image_lib = get_plugin_setting('image_lib', 'tidypics'); -if (!$image_lib) { - $image_lib = "GD"; -} - -$temp_file = $_FILES['Image']['tmp_name']; -$name = $_FILES['Image']['name']; -$file_size = $_FILES['Image']['size']; - -$mime = tp_upload_get_mimetype($name); -if ($mime == 'unknown') { - echo 'Not an image'; - exit; -} - -$image = new TidypicsImage(); -$image->container_guid = $album_guid; -$image->setMimeType($mime); -$image->simpletype = "image"; -$image->access_id = $album->access_id; -$image->title = substr($name, 0, strrpos($name, '.')); -$image->batch = get_input('batch'); -$result = $image->save(); - -$image->setOriginalFilename($name); -$image->saveImageFile($temp_file, $file_size); - -$image->extractExifData(); -$image->saveThumbnails($image_lib); - -$album->prependImageList(array($image->guid)); - - -if (get_plugin_setting('img_river_view', 'tidypics') === "all") { - add_to_river('river/object/image/create', 'create', $image->owner_guid, $image->guid); -} - -echo "success"; -exit;
\ No newline at end of file diff --git a/actions/ajax_upload_complete.php b/actions/ajax_upload_complete.php deleted file mode 100644 index 2abca50dc..000000000 --- a/actions/ajax_upload_complete.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php -/** - * A batch is complete so check if this is first upload to album - * - */ - -$album_guid = (int) get_input('album_guid'); - -$album = get_entity($album_guid); -if (!$album) { - exit; -} - -if ($album->new_album == TP_NEW_ALBUM) { - $new_album = true; -} else { - $new_album = false; -} - -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); -} - -$params = array( - 'type' => 'object', - 'subtype' => 'image', - 'metadata_names' => 'batch', - 'metadata_values' => get_input('batch'), -); -$images = elgg_get_entities_from_metadata($params); -if ($images) { - // Create a new batch object to contain these photos - $batch = new ElggObject(); - $batch->subtype = "tidypics_batch"; - $batch->access_id = ACCESS_PUBLIC; - $batch->container_guid = $album->guid; - if ($batch->save()) { - foreach ($images as $image) { - add_entity_relationship($image->guid, "belongs_to_batch", $batch->getGUID()); - } - if (get_plugin_setting('img_river_view', 'tidypics') == "batch" && $new_album == false) { - add_to_river('river/object/tidypics_batch/create', 'create', $batch->getObjectOwnerGUID(), $batch->getGUID()); - } - } -} - -// plugins can register to be told when a Tidypics album has had images added -trigger_elgg_event('upload', 'tp_album', $album); - -exit;
\ No newline at end of file diff --git a/actions/photos/image/ajax_upload.php b/actions/photos/image/ajax_upload.php new file mode 100644 index 000000000..d6b083cf6 --- /dev/null +++ b/actions/photos/image/ajax_upload.php @@ -0,0 +1,57 @@ +<?php +/** + * Elgg single upload action for flash/ajax uploaders + */ + +elgg_load_library('tidypics:upload'); + +$album_guid = (int) get_input('album_guid'); +$file_var_name = get_input('file_var_name', 'Image'); +$batch = get_input('batch'); + +$album = get_entity($album_guid); +if (!$album) { + echo elgg_echo('tidypics:baduploadform'); + exit; +} + +// probably POST limit exceeded +if (empty($_FILES)) { + trigger_error('Tidypics warning: user exceeded post limit on image upload', E_USER_WARNING); + register_error(elgg_echo('tidypics:exceedpostlimit')); + exit; +} + +$file = $_FILES['Image']; + +$mime = tp_upload_get_mimetype($file['name']); +if ($mime == 'unknown') { + echo 'Not an image'; + exit; +} + +// we have to override the mime type because uploadify sends everything as application/octet-string +$file['type'] = $mime; + +$image = new TidypicsImage(); +$image->container_guid = $album->getGUID(); +$image->setMimeType($mime); +$image->access_id = $album->access_id; +$image->batch = $batch; + +try { + $image->save($file); + $album->prependImageList(array($image->guid)); + + if (elgg_get_plugin_setting('img_river_view', 'tidypics') === "all") { + add_to_river('river/object/image/create', 'create', $image->getObjectOwnerGUID(), $image->getGUID()); + } + + echo elgg_echo('success'); +} catch (Exception $e) { + // remove the bits that were saved + $image->delete(); + echo $e->getMessage(); +} + +exit;
\ No newline at end of file diff --git a/actions/photos/image/ajax_upload_complete.php b/actions/photos/image/ajax_upload_complete.php new file mode 100644 index 000000000..6d398b3aa --- /dev/null +++ b/actions/photos/image/ajax_upload_complete.php @@ -0,0 +1,74 @@ +<?php +/** + * A batch is complete so check if this is first upload to album + * + */ + +$batch = get_input('batch'); +$album_guid = (int) get_input('album_guid'); +$img_river_view = elgg_get_plugin_setting('img_river_view', 'tidypics'); + +$album = get_entity($album_guid); +if (!elgg_instanceof($album, 'object', 'album')) { + exit; +} + +$params = array( + 'type' => 'object', + 'subtype' => 'image', + 'metadata_names' => 'batch', + 'metadata_values' => $batch, + 'limit' => 0 +); + +$images = elgg_get_entities_from_metadata($params); +if ($images) { + // Create a new batch object to contain these photos + $batch = new ElggObject(); + $batch->subtype = "tidypics_batch"; + $batch->access_id = ACCESS_PUBLIC; + $batch->container_guid = $album->guid; + + if ($batch->save()) { + foreach ($images as $image) { + add_entity_relationship($image->guid, "belongs_to_batch", $batch->getGUID()); + } + } +} else { + // @todo some sort of message to edit them manually. + exit; +} + +// "added images to album" river +if ($img_river_view == "batch" && $album->new_album == false) { + add_to_river('river/object/tidypics_batch/create', 'create', $batch->getObjectOwnerGUID(), $batch->getGUID()); +} + +// "created album" river +if ($album->new_album) { + $album->new_album = false; + $album->first_upload = true; + + add_to_river('river/object/album/create', 'create', $album->getOwnerGUID(), $album->getGUID()); + + // "created album" notifications + // we throw the notification manually here so users are not told about the new album until + // there are at least a few photos in it + if ($album->shouldNotify()) { + object_notifications('create', 'object', $album); + $album->last_notified = time(); + } +} else { + // "added image to album" notifications + if ($album->first_upload) { + $album->first_upload = false; + } + + if ($album->shouldNotify()) { + object_notifications('create', 'object', $album); + $album->last_notified = time(); + } +} + +echo json_encode(array('batch_guid' => $batch->getGUID())); +exit;
\ No newline at end of file diff --git a/actions/photos/image/upload.php b/actions/photos/image/upload.php index 29df59b63..b917a1598 100644 --- a/actions/photos/image/upload.php +++ b/actions/photos/image/upload.php @@ -50,6 +50,8 @@ foreach ($_FILES['images']['name'] as $index => $value) { continue; } + $mime = tp_upload_get_mimetype($data['name']); + $image = new TidypicsImage(); $image->container_guid = $album->getGUID(); $image->setMimeType($mime); |