From 66dd3f3f5f14bb0ba6d2c7ef83b5b612d5ee2e30 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 15 Mar 2014 15:04:14 -0300 Subject: Squashed 'mod/lightbox/' content from commit a83b8d8 git-subtree-dir: mod/lightbox git-subtree-split: a83b8d89691c31b4568f47790fb40d0bc962aca5 --- lib/lightbox.php | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 lib/lightbox.php (limited to 'lib/lightbox.php') diff --git a/lib/lightbox.php b/lib/lightbox.php new file mode 100644 index 000000000..6b557d241 --- /dev/null +++ b/lib/lightbox.php @@ -0,0 +1,107 @@ + $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 +} -- cgit v1.2.3