From 74bda3f086ab1922246107df01b577c5e7723bb9 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 18 Dec 2011 16:46:12 +0100 Subject: improve readability of download() Signed-off-by: Florian Pritz --- application/models/file_mod.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/application/models/file_mod.php b/application/models/file_mod.php index db3fa6252..af425b8df 100644 --- a/application/models/file_mod.php +++ b/application/models/file_mod.php @@ -228,8 +228,8 @@ class File_mod extends CI_Model { $type = $filedata['mimetype']; - // autodetect the mode for highlighting if the URL contains a / after the ID (URL: /ID/) - // URL: /ID/mode disables autodetection + // autodetect the mode for highlighting if the URL contains a / after the ID (/ID/) + // /ID/mode disables autodetection if (!$mode && substr_count(ltrim($this->uri->uri_string(), "/"), '/') >= 1) { $mode = $this->mime2extension($type); $mode = $this->filename2extension($filedata['filename']) ? $this->filename2extension($filedata['filename']) : $mode; @@ -241,6 +241,7 @@ class File_mod extends CI_Model { header("Last-Modified: ".date('D, d M Y H:i:s', $filedata["date"])." GMT"); header('Etag: "'.$etag.'"'); + // create the qr code for /ID/ if ($mode == "qr") { header("Content-disposition: inline; filename=\"".$id."_qr.png\"\n"); header("Content-Type: image/png\n"); @@ -248,17 +249,18 @@ class File_mod extends CI_Model { exit(); } + // user wants to the the plain file + if ( $mode == 'plain') { + rangeDownload($file, $filedata["filename"], "text/plain"); + exit(); + } - $special_modes = array("ascii"); - // directly download the file - if (!in_array($mode, $special_modes) && (!$mode // user didn't specify a mode/didn't enable autodetection - || !$this->mime2extension($type) // file can't be highlighted - || $mode == "plain" // user wants to the the plain file - || filesize($file) > $this->config->item('upload_max_text_size') - )) { - if ($mode == 'plain') { - $type = "text/plain"; - } + // if there is no mimetype mapping we can't highlight it + $can_highlight = $this->mime2extension($type); + + $filesize_too_big = filesize($file) > $this->config->item('upload_max_text_size'); + + if (!$can_highlight || $filesize_too_big || !$mode) { rangeDownload($file, $filedata["filename"], $type); exit(); } @@ -276,7 +278,7 @@ class File_mod extends CI_Model { $data['current_highlight'] = $mode; if (filesize($file) > $this->config->item("small_upload_size")) { - $data['timeout'] = date("r", $filedata["date"]+$this->config->item("upload_max_age")); + $data['timeout'] = date("r", $filedata["date"] + $this->config->item("upload_max_age")); } else { $data['timeout'] = "never"; } @@ -308,7 +310,9 @@ class File_mod extends CI_Model { $this->memcachelibrary->set($filedata['hash'].'_'.$mode, $cached, 100); } echo $cached; + echo $this->load->view($this->var->view_dir.'/html_footer', $data, true); + exit(); } -- cgit v1.2.3-24-g4f1b