diff options
Diffstat (limited to 'mod/file/actions')
-rw-r--r-- | mod/file/actions/file/delete.php | 96 | ||||
-rw-r--r-- | mod/file/actions/file/download.php | 42 | ||||
-rw-r--r-- | mod/file/actions/file/save.php | 48 | ||||
-rw-r--r-- | mod/file/actions/file/upload.php | 377 |
4 files changed, 226 insertions, 337 deletions
diff --git a/mod/file/actions/file/delete.php b/mod/file/actions/file/delete.php index 9357d4955..fe03e5077 100644 --- a/mod/file/actions/file/delete.php +++ b/mod/file/actions/file/delete.php @@ -1,65 +1,33 @@ <?php - - /** - * Elgg file delete - * - * @package ElggFile - */ - - $guid = (int) get_input('file'); - if ($file = get_entity($guid)) { - - if ($file->canEdit()) { - - $container = get_entity($file->container_guid); - - $thumbnail = $file->thumbnail; - $smallthumb = $file->smallthumb; - $largethumb = $file->largethumb; - if ($thumbnail) { - - $delfile = new ElggFile(); - $delfile->owner_guid = $file->owner_guid; - $delfile->setFilename($thumbnail); - $delfile->delete(); - - } - if ($smallthumb) { - - $delfile = new ElggFile(); - $delfile->owner_guid = $file->owner_guid; - $delfile->setFilename($smallthumb); - $delfile->delete(); - - } - if ($largethumb) { - - $delfile = new ElggFile(); - $delfile->owner_guid = $file->owner_guid; - $delfile->setFilename($largethumb); - $delfile->delete(); - - } - - if (!$file->delete()) { - register_error(elgg_echo("file:deletefailed")); - } else { - system_message(elgg_echo("file:deleted")); - } - - } else { - - $container = get_loggedin_user(); - register_error(elgg_echo("file:deletefailed")); - - } - - } else { - - register_error(elgg_echo("file:deletefailed")); - - } - - forward("pg/file/$container->username/"); - -?>
\ No newline at end of file +/** +* Elgg file delete +* +* @package ElggFile +*/ + +$guid = (int) get_input('guid'); + +$file = new FilePluginFile($guid); +if (!$file->guid) { + register_error(elgg_echo("file:deletefailed")); + forward('pg/file/all'); +} + +if (!$file->canEdit()) { + register_error(elgg_echo("file:deletefailed")); + forward($file->getURL()); +} + +$container = $file->getContainerEntity(); + +if (!$file->delete()) { + register_error(elgg_echo("file:deletefailed")); +} else { + system_message(elgg_echo("file:deleted")); +} + +if (elgg_instanceof($container, 'group')) { + forward("pg/file/group/$container->guid/owner"); +} else { + forward("pg/file/owner/$container->username"); +} diff --git a/mod/file/actions/file/download.php b/mod/file/actions/file/download.php index 210735b74..6768bd4b1 100644 --- a/mod/file/actions/file/download.php +++ b/mod/file/actions/file/download.php @@ -1,37 +1,11 @@ <?php - /** - * Elgg file browser download action. - * - * @package ElggFile - */ +/** + * Elgg file browser download action. + * + * @package ElggFile + */ - // Get the guid - $file_guid = get_input("file_guid"); - - // Get the file - $file = get_entity($file_guid); - - if ($file) - { - $mime = $file->getMimeType(); - if (!$mime) $mime = "application/octet-stream"; - - $filename = $file->originalfilename; - - // fix for IE https issue - header("Pragma: public"); - header("Content-type: $mime"); - if (strpos($mime, "image/")!==false) - header("Content-Disposition: inline; filename=\"$filename\""); - else - header("Content-Disposition: attachment; filename=\"$filename\""); +// @todo this is here for backwards compatibility (first version of embed plugin?) +$download_page_handler = elgg_get_plugin_path() . 'file/download.php'; - $contents = $file->grabFile(); - $splitString = str_split($contents, 8192); - foreach($splitString as $chunk) - echo $chunk; - exit; - } - else - register_error(elgg_echo("file:downloadfailed")); -?>
\ No newline at end of file +include $download_page_handler; diff --git a/mod/file/actions/file/save.php b/mod/file/actions/file/save.php deleted file mode 100644 index 17a9b16fb..000000000 --- a/mod/file/actions/file/save.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php - /** - * Elgg file browser save action - * - * @package ElggFile - */ - - global $CONFIG; - - // Get variables - $title = strip_tags(get_input("title")); - $desc = get_input("description"); - $tags = get_input("tags"); - $access_id = (int) get_input("access_id"); - - $guid = (int) get_input('file_guid'); - - if (!$file = get_entity($guid)) { - register_error(elgg_echo("file:uploadfailed")); - forward(elgg_get_site_url() . "pg/file/" . get_loggedin_user()->username); - exit; - } - - $result = false; - - $container_guid = $file->container_guid; - $container = get_entity($container_guid); - - if ($file->canEdit()) { - - $file->access_id = $access_id; - $file->title = $title; - $file->description = $desc; - - // Save tags - $tags = explode(",", $tags); - $file->tags = $tags; - - $result = $file->save(); - } - - if ($result) - system_message(elgg_echo("file:saved")); - else - register_error(elgg_echo("file:uploadfailed")); - - forward(elgg_get_site_url() . "pg/file/" . $container->username); -?>
\ No newline at end of file diff --git a/mod/file/actions/file/upload.php b/mod/file/actions/file/upload.php index 081b6a312..5ce98c101 100644 --- a/mod/file/actions/file/upload.php +++ b/mod/file/actions/file/upload.php @@ -1,205 +1,200 @@ <?php - /** - * Elgg file browser uploader/edit action - * - * @package ElggFile - */ - - global $CONFIG; - - // Get variables - $title = get_input("title"); - $desc = get_input("description"); - $access_id = (int) get_input("access_id"); - $container_guid = (int) get_input('container_guid', 0); - $ajax = get_input('ajax', FALSE); - - if ($container_guid == 0) { - $container_guid = get_loggedin_userid(); +/** + * Elgg file uploader/edit action + * + * @package ElggFile + */ + +// Get variables +$title = get_input("title"); +$desc = get_input("description"); +$access_id = (int) get_input("access_id"); +$container_guid = (int) get_input('container_guid', 0); +$guid = (int) get_input('file_guid'); +$tags = get_input("tags"); + +$ajax = get_input('ajax', FALSE); + +if ($container_guid == 0) { + $container_guid = get_loggedin_userid(); +} + +elgg_make_sticky_form('file'); + + +// check whether this is a new file or an edit +$new_file = true; +if ($guid > 0) { + $new_file = false; +} + +if ($new_file) { + // must have a file if a new file upload + if (empty($_FILES['upload']['name'])) { + + $error = elgg_echo('file:nofile'); + + if ($ajax) { + echo json_encode(array( + 'status' => 'error', + 'message' => $error + )); + exit; + } else { + register_error($error); + forward(REFERER); + } } - $guid = (int) get_input('file_guid'); - $tags = get_input("tags"); - - // check whether this is a new file or an edit - $new_file = true; - if ($guid > 0) { - $new_file = false; + + $file = new FilePluginFile(); + $file->subtype = "file"; + + // if no title on new upload, grab filename + if (empty($title)) { + $title = $_FILES['upload']['name']; } - - if ($new_file) { - // must have a file if a new file upload - if (empty($_FILES['upload']['name'])) { - // cache information in session - $_SESSION['uploadtitle'] = $title; - $_SESSION['uploaddesc'] = $desc; - $_SESSION['uploadtags'] = $tags; - $_SESSION['uploadaccessid'] = $access_id; - - $error = elgg_echo('file:nofile'); - - if ($ajax) { - echo json_encode(array( - 'status' => 'error', - 'message' => $error - )); - exit; - } else { - register_error($error); - forward(REFERER); - } - } - - $file = new FilePluginFile(); - $file->subtype = "file"; - - // if no title on new upload, grab filename - if (empty($title)) { - $title = $_FILES['upload']['name']; + +} else { + // load original file object + $file = new FilePluginFile($guid); + if (!$file) { + register_error(elgg_echo('file:cannotload')); + forward(REFERER); + } + + // user must be able to edit file + if (!$file->canEdit()) { + register_error(elgg_echo('file:noaccess')); + forward(REFERER); + } +} + +$file->title = $title; +$file->description = $desc; +$file->access_id = $access_id; +$file->container_guid = $container_guid; + +$tags = explode(",", $tags); +$file->tags = $tags; + +// we have a file upload, so process it +if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) { + + $prefix = "file/"; + + // if previous file, delete it + if ($new_file == false) { + $filename = $file->getFilenameOnFilestore(); + if (file_exists($filename)) { + unlink($filename); } - + + // use same filename on the disk - ensures thumbnails are overwritten + $filestorename = $file->getFilename(); + $filestorename = elgg_substr($filestorename, elgg_strlen($prefix)); } else { - // load original file object - $file = get_entity($guid); - if (!$file) { - register_error(elgg_echo('file:cannotload')); - forward(REFERER); - } - - // user must be able to edit file - if (!$file->canEdit()) { - register_error(elgg_echo('file:noaccess')); - forward(REFERER); - } + $filestorename = elgg_strtolower(time().$_FILES['upload']['name']); } - - $file->title = $title; - $file->description = $desc; - $file->access_id = $access_id; - $file->container_guid = $container_guid; - - $tags = explode(",", $tags); - $file->tags = $tags; - - // we have a file upload, so process it - if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) { - - $prefix = "file/"; - - // if previous file, delete it - if ($new_file == false) { - $filename = $file->getFilenameOnFilestore(); - if (file_exists($filename)) { - unlink($filename); - } - - // use same filename on the disk - ensures thumbnails are overwritten - $filestorename = $file->getFilename(); - $filestorename = elgg_substr($filestorename, elgg_strlen($prefix)); - } else { - $filestorename = elgg_strtolower(time().$_FILES['upload']['name']); + + $file->setFilename($prefix.$filestorename); + $file->setMimeType($_FILES['upload']['type']); + $file->originalfilename = $_FILES['upload']['name']; + $file->simpletype = file_get_simple_type($_FILES['upload']['type']); + + $file->open("write"); + $file->write(get_uploaded_file('upload')); + $file->close(); + + $guid = $file->save(); + + // if image, we need to create thumbnails (this should be moved into a function) + if ($guid && $file->simpletype == "image") { + $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); } - - $file->setFilename($prefix.$filestorename); - $file->setMimeType($_FILES['upload']['type']); - $file->originalfilename = $_FILES['upload']['name']; - $file->simpletype = get_general_file_type($_FILES['upload']['type']); - - $file->open("write"); - $file->write(get_uploaded_file('upload')); - $file->close(); - - $guid = $file->save(); - - // if image, we need to create thumbnails (this should be moved into a function) - if ($guid && $file->simpletype == "image") { - $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); - } + + $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); } - } else { - // not saving a file but still need to save the entity to push attributes to database - $file->save(); } - - // make sure session cache is cleared - unset($_SESSION['uploadtitle']); - unset($_SESSION['uploaddesc']); - unset($_SESSION['uploadtags']); - unset($_SESSION['uploadaccessid']); - - // handle results differently for new files and file updates - // ajax is only for new files from embed right now. - if ($new_file) { - if ($guid) { - $message = elgg_echo("file:saved"); - if ($ajax) { - echo json_encode(array( - 'status' => 'success', - 'message' => $message - )); - exit; - - } else { - system_message($message); - add_to_river('river/object/file/create', 'create', get_loggedin_userid(), $file->guid); - } +} else { + // not saving a file but still need to save the entity to push attributes to database + $file->save(); +} + +// file saved so clear sticky form +elgg_clear_sticky_form('file'); + + +// handle results differently for new files and file updates +// ajax is only for new files from embed right now. +if ($new_file) { + if ($guid) { + $message = elgg_echo("file:saved"); + if ($ajax) { + echo json_encode(array( + 'status' => 'success', + 'message' => $message + )); + exit; + } else { - // failed to save file object - nothing we can do about this - $error = elgg_echo("file:uploadfailed"); - - if ($ajax) { - echo json_encode(array( - 'status' => 'error', - 'message' => $error - )); - exit; - - } else { - register_error($error); - } - } - - if (!$ajax) { - $container_user = get_entity($container_guid); - forward(elgg_get_site_url() . "pg/file/" . $container_user->username); + system_message($message); + add_to_river('river/object/file/create', 'create', get_loggedin_userid(), $file->guid); } - } else { - if ($guid) { - system_message(elgg_echo("file:saved")); + // failed to save file object - nothing we can do about this + $error = elgg_echo("file:uploadfailed"); + + if ($ajax) { + echo json_encode(array( + 'status' => 'error', + 'message' => $error + )); + exit; + } else { - register_error(elgg_echo("file:uploadfailed")); + register_error($error); } - - forward($file->getURL()); - } + } + + if (!$ajax) { + $container_user = get_entity($container_guid); + forward(elgg_get_site_url() . "pg/file/" . $container_user->username); + } + +} else { + if ($guid) { + system_message(elgg_echo("file:saved")); + } else { + register_error(elgg_echo("file:uploadfailed")); + } + + forward($file->getURL()); +} |