diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2014-03-15 15:04:14 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2014-03-15 15:04:14 -0300 |
commit | 4a86fa9b2e63b9d6bb0a07333d4c7d59df621270 (patch) | |
tree | 5770bd548bc70a10dbd5c24aee13c3449bf428a9 /mod/lightbox/lib/lightbox.php | |
parent | d7317abf01cc1f5a6e4ee54f25664e51d23217b9 (diff) | |
parent | 66dd3f3f5f14bb0ba6d2c7ef83b5b612d5ee2e30 (diff) | |
download | elgg-4a86fa9b2e63b9d6bb0a07333d4c7d59df621270.tar.gz elgg-4a86fa9b2e63b9d6bb0a07333d4c7d59df621270.tar.bz2 |
Merge commit '66dd3f3f5f14bb0ba6d2c7ef83b5b612d5ee2e30' as 'mod/lightbox'
Diffstat (limited to 'mod/lightbox/lib/lightbox.php')
-rw-r--r-- | mod/lightbox/lib/lightbox.php | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/mod/lightbox/lib/lightbox.php b/mod/lightbox/lib/lightbox.php new file mode 100644 index 000000000..6b557d241 --- /dev/null +++ b/mod/lightbox/lib/lightbox.php @@ -0,0 +1,107 @@ +<?php +/** + * Lightbox helper functions + * + * @package ElggLightbox + */ + +/** + * Save uploaded images and return an array of its entities + * + * @return array of LightboxPluginImages + */ +function lightbox_get_image_inputs() { + + $files = array(); + $file = new ElggFile(); + + // check if upload failed + foreach($_FILES as $key => $sent_file) { + if (empty($sent_file['name'])) { + continue; + } + if($sent_file['error'] != 0) { + register_error(elgg_echo('file:cannotload')); + forward(REFERER); + } + $mime_type = $file->detectMimeType($sent_file['tmp_name'], $sent_file['type']); + if(file_get_simple_type($mime_type) != "image"){ + register_error(elgg_echo('lightbox:noimage')); + forward(REFERER); + } + } + + foreach($_FILES as $key => $sent_file) { + + if (empty($sent_file['name'])) { + continue; + } + + $file = new LightboxPluginImage(); + + $prefix = "image/"; + $filestorename = elgg_strtolower(time().$sent_file['name']); + + $mime_type = $file->detectMimeType($sent_file['tmp_name'], $sent_file['type']); + $file->setFilename($prefix . $filestorename); + $file->setMimeType($mime_type); + $file->originalfilename = $sent_file['name']; + $file->simpletype = "image"; + + // Open the file to guarantee the directory exists + $file->open("write"); + $file->close(); + move_uploaded_file($sent_file['tmp_name'], $file->getFilenameOnFilestore()); + + // We need to create thumbnails (this should be moved into a function) + if ($file->save()) { + $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),60,60, true); + if ($thumbnail) { + $thumb = new ElggFile(); + $thumb->setMimeType($_FILES['upload']['type']); + + $thumb->setFilename($prefix."thumb".$filestorename); + $thumb->open("write"); + $thumb->write($thumbnail); + $thumb->close(); + + $file->thumbnail = $prefix."thumb".$filestorename; + unset($thumbnail); + } + + $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),153,153, true); + if ($thumbsmall) { + $thumb->setFilename($prefix."smallthumb".$filestorename); + $thumb->open("write"); + $thumb->write($thumbsmall); + $thumb->close(); + $file->smallthumb = $prefix."smallthumb".$filestorename; + unset($thumbsmall); + } + + $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(),600,600, false); + if ($thumblarge) { + $thumb->setFilename($prefix."largethumb".$filestorename); + $thumb->open("write"); + $thumb->write($thumblarge); + $thumb->close(); + $file->largethumb = $prefix."largethumb".$filestorename; + unset($thumblarge); + } + + $files[$file->guid] = $file; + } + } + + return $files; +} + +/** + * Delete uploaded images if album creation fails + * + * @params array $images Array of LightboxPluginImages + * @return null + */ +function lightbox_delete_image_inputs($images) { + //TODO +} |