From 90e2789f7cd977a73f1b5bc667a4b35c4956d5e8 Mon Sep 17 00:00:00 2001 From: chenfeiCF Date: Fri, 13 Jan 2017 11:11:31 +0800 Subject: [PATCH] * finish task #2883. --- module/file/config.php | 2 + module/file/control.php | 35 ++++++++++------- module/file/lang/en.php | 1 + module/file/lang/zh-cn.php | 1 + module/file/view/download.html.php | 56 ++++++++++++++++++++++++++++ module/file/view/printfiles.html.php | 16 ++++++-- 6 files changed, 94 insertions(+), 17 deletions(-) create mode 100644 module/file/view/download.html.php diff --git a/module/file/config.php b/module/file/config.php index f7dc597d20..7b55622f10 100644 --- a/module/file/config.php +++ b/module/file/config.php @@ -7,6 +7,8 @@ $config->file->mimes['default'] = 'application/octet-stream'; $config->file->imageExtensions = array('jpeg', 'jpg', 'gif', 'png'); $config->file->image2Compress = array('.jpg', '.bmp', '.jpeg'); +$config->file->charset = array('UTF-8' => 'UTF-8', 'GBK' => 'GBK', 'BIG5' => 'BIG5'); + $config->file->ueditor["imageActionName"] = "uploadimage"; $config->file->ueditor["imageFieldName"] = "upfile"; $config->file->ueditor["imageMaxSize"] = 2048000; diff --git a/module/file/control.php b/module/file/control.php index 2e72eda9a3..d080ceb988 100644 --- a/module/file/control.php +++ b/module/file/control.php @@ -133,25 +133,34 @@ class file extends control $fileTypes = 'txt|jpg|jpeg|gif|png|bmp|xml|html'; if(stripos($fileTypes, $file->extension) !== false and $mouse == 'left') $mode = 'open'; - /* If the mode is open, locate directly. */ - if($mode == 'open') + if(file_exists($file->realPath)) { - if(file_exists($file->realPath))$this->locate($file->webPath); - $this->app->triggerError("The file you visit $fileID not found.", __FILE__, __LINE__, true); - } - else - { - /* Down the file. */ - if(file_exists($file->realPath)) + /* If the mode is open, locate directly. */ + if($mode == 'open') { + if(stripos('txt|jpg|jpeg|gif|png|bmp', $file->extension) !== false) + { + $this->view->file = $file; + $this->view->charset = $this->get->charset ? $this->get->charset : $this->config->charset; + $this->view->fileType = ($file->extension == 'txt') ? 'txt' : 'image'; + $this->display(); + } + else + { + $this->locate($file->webPath); + } + } + else + { + /* Down the file. */ $fileName = $file->title . '.' . $file->extension; $fileData = file_get_contents($file->realPath); $this->sendDownHeader($fileName, $file->extension, $fileData); } - else - { - $this->app->triggerError("The file you visit $fileID not found.", __FILE__, __LINE__, true); - } + } + else + { + $this->app->triggerError("The file you visit $fileID not found.", __FILE__, __LINE__, true); } } diff --git a/module/file/lang/en.php b/module/file/lang/en.php index af66704224..f9f20b7b60 100644 --- a/module/file/lang/en.php +++ b/module/file/lang/en.php @@ -25,6 +25,7 @@ $lang->file->setPublic = "Set Public Template"; $lang->file->exportFields = "Fileds to be Exported"; $lang->file->defaultTPL = "Default Template"; $lang->file->setExportTPL = "Settings"; +$lang->file->preview = "Preview"; $lang->file->errorNotExists = "'%s' is not found."; $lang->file->errorCanNotWrite = "'%s' is not writable. Please change its permission. Enter sudo chmod -R 777 '%s' in Linux."; diff --git a/module/file/lang/zh-cn.php b/module/file/lang/zh-cn.php index 15c7908b0f..63ec72e365 100644 --- a/module/file/lang/zh-cn.php +++ b/module/file/lang/zh-cn.php @@ -25,6 +25,7 @@ $lang->file->setPublic = "设置公共模板"; $lang->file->exportFields = "要导出字段"; $lang->file->defaultTPL = "默认模板"; $lang->file->setExportTPL = "设置"; +$lang->file->preview = "预览"; $lang->file->errorNotExists = "文件夹 '%s' 不存在"; $lang->file->errorCanNotWrite = "文件夹 '%s' 不可写,请改变文件夹的权限。在linux中输入指令:sudo chmod -R 777 '%s'"; diff --git a/module/file/view/download.html.php b/module/file/view/download.html.php new file mode 100644 index 0000000000..f8b9870ff2 --- /dev/null +++ b/module/file/view/download.html.php @@ -0,0 +1,56 @@ + +id);?> + +
+
+ file->common;?> + file->preview;?> + + file->charset, $charset, "onchange='setCharset(this.value)'");?> + +
+
+ +
+webPath);?> +
+ +
+realPath); +if($charset != $config->charset) +{ + $fileContent = helper::convertEncoding($fileContent, $charset, $config->charset); +} +else +{ + if(!extension_loaded('mbstring')) + { + $encoding = mb_detect_encoding($fileContent, array('ASCII','UTF-8','GB2312','GBK','BIG5')); + if($encoding != 'UTF-8') $fileContent = helper::convertEncoding($fileContent, $encoding, $config->charset); + } + else + { + if($config->default->lang == 'zh-cn') $encoding = 'GBK'; + if($config->default->lang == 'zh-tw') $encoding = 'BIG5'; + $fileContent = helper::convertEncoding($fileContent, $encoding, $config->charset); + } +} +a($fileContent); +?> +
+ + + diff --git a/module/file/view/printfiles.html.php b/module/file/view/printfiles.html.php index fbe5cc9ec5..abf3daccef 100644 --- a/module/file/view/printfiles.html.php +++ b/module/file/view/printfiles.html.php @@ -15,12 +15,20 @@ function deleteFile(fileID) hiddenwin.location.href =createLink('file', 'delete', 'fileID=' + fileID); } /* Download a file, append the mouse to the link. Thus we call decide to open the file in browser no download it. */ -function downloadFile(fileID) +function downloadFile(fileID, extension) { if(!fileID) return; + var fileTypes = 'txt,jpg,jpeg,gif,png,bmp'; var sessionString = ''; - var url = createLink('file', 'download', 'fileID=' + fileID + '&mouse=left') + sessionString; - window.open(url, '_blank'); + var url = createLink('file', 'download', 'fileID=' + fileID + '&mouse=left') + sessionString; + if(fileTypes.indexOf(extension) >= 0) + { + $('').modalTrigger({url: url, type: 'iframe'}).trigger('click'); + } + else + { + window.open(url, '_blank'); + } return false; } @@ -36,7 +44,7 @@ function downloadFile(fileID) { $uploadDate = $lang->file->uploadDate . $file->addedDate; $fileTitle = "
  •  " . $file->title .'.' . $file->extension; - echo html::a($this->createLink('file', 'download', "fileID=$file->id") . $sessionString, $fileTitle, '_blank', "onclick='return downloadFile($file->id)'"); + echo html::a($this->createLink('file', 'download', "fileID=$file->id") . $sessionString, $fileTitle, '_blank', "onclick=\"return downloadFile($file->id, '$file->extension')\""); /* Show size info. */ if($file->size < 1024)