From d6c76b1fe30fc8065c985c31df633c3c6cbbed9f Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 1 May 2012 23:39:57 +0200 Subject: add ID/info to display more information about a file The table is shared with the old delete_form, but it doesn't display the delete button in info mode. Signed-off-by: Florian Pritz --- application/models/file_mod.php | 47 ++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'application/models/file_mod.php') diff --git a/application/models/file_mod.php b/application/models/file_mod.php index d91157a33..ab273cf58 100644 --- a/application/models/file_mod.php +++ b/application/models/file_mod.php @@ -9,14 +9,13 @@ class File_mod extends CI_Model { - var $data = array(); + var $data; function __construct() { parent::__construct(); + $this->data =& get_instance()->data; $this->load->model("muser"); - $this->data["title"] = "FileBin"; - $this->data["username"] = $this->muser->get_username(); } // Returns an unused ID @@ -55,7 +54,7 @@ class File_mod extends CI_Model { function get_filedata($id) { $sql = ' - SELECT hash, filename, mimetype, date, user + SELECT hash, filename, mimetype, date, user, filesize FROM `files` WHERE `id` = ? LIMIT 1'; @@ -268,6 +267,11 @@ class File_mod extends CI_Model { exit(); } + if ($mode == 'info') { + $this->display_info($id); + return; + } + // if there is no mimetype mapping we can't highlight it $can_highlight = $this->can_highlight($type); @@ -287,12 +291,7 @@ class File_mod extends CI_Model { header("Content-Type: text/html\n"); $this->data['current_highlight'] = htmlspecialchars($mode); - - if (filesize($file) > $this->config->item("small_upload_size")) { - $this->data['timeout'] = date("r", $filedata["date"] + $this->config->item("upload_max_age")); - } else { - $this->data['timeout'] = "never"; - } + $this->data['timeout'] = $this->get_timeout_string($id); echo $this->load->view($this->var->view_dir.'/html_header', $this->data, true); @@ -327,6 +326,18 @@ class File_mod extends CI_Model { exit(); } + function get_timeout_string($id) + { + $filedata = $this->get_filedata($id); + $file = $this->file($filedata["hash"]); + + if (filesize($file) > $this->config->item("small_upload_size")) { + return date("r", $filedata["date"] + $this->config->item("upload_max_age")); + } else { + return "unknown"; + } + } + private function unused_file($hash) { $sql = ' @@ -343,6 +354,22 @@ class File_mod extends CI_Model { } } + function display_info($id) + { + $this->data["title"] .= " - Info $id"; + $this->data["filedata"] = $this->get_filedata($id); + $this->data["id"] = $id; + $this->data['timeout'] = $this->get_timeout_string($id); + + if (!isset($this->data["can_delete"])) { + $this->data["can_delete"] = false; + } + + $this->load->view($this->var->view_dir.'/header', $this->data); + $this->load->view($this->var->view_dir.'/file_info', $this->data); + $this->load->view($this->var->view_dir.'/footer', $this->data); + } + function delete_id($id) { $this->muser->require_access(); -- cgit v1.2.3-24-g4f1b