summaryrefslogtreecommitdiff
path: root/app/Controller/FileViewer.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-28 13:41:54 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-28 13:41:54 -0400
commit1353929a7dbd3f2e897fa7d3ab88e959ca573f9f (patch)
tree30bdbac4e466e74c3dfb4d451422f03c62bcbe41 /app/Controller/FileViewer.php
parentab48a09f0d674b703467975b376c5ac7352670ae (diff)
Rename controllers
Diffstat (limited to 'app/Controller/FileViewer.php')
-rw-r--r--app/Controller/FileViewer.php136
1 files changed, 0 insertions, 136 deletions
diff --git a/app/Controller/FileViewer.php b/app/Controller/FileViewer.php
deleted file mode 100644
index a49b0fb2..00000000
--- a/app/Controller/FileViewer.php
+++ /dev/null
@@ -1,136 +0,0 @@
-<?php
-
-namespace Kanboard\Controller;
-
-use Kanboard\Core\ObjectStorage\ObjectStorageException;
-
-/**
- * File Viewer Controller
- *
- * @package controller
- * @author Frederic Guillot
- */
-class FileViewer extends BaseController
-{
- /**
- * Get file content from object storage
- *
- * @access private
- * @param array $file
- * @return string
- */
- private function getFileContent(array $file)
- {
- $content = '';
-
- try {
- if ($file['is_image'] == 0) {
- $content = $this->objectStorage->get($file['path']);
- }
- } catch (ObjectStorageException $e) {
- $this->logger->error($e->getMessage());
- }
-
- return $content;
- }
-
- /**
- * Show file content in a popover
- *
- * @access public
- */
- public function show()
- {
- $file = $this->getFile();
- $type = $this->helper->file->getPreviewType($file['name']);
- $params = array('file_id' => $file['id'], 'project_id' => $this->request->getIntegerParam('project_id'));
-
- if ($file['model'] === 'taskFile') {
- $params['task_id'] = $file['task_id'];
- }
-
- $this->response->html($this->template->render('file_viewer/show', array(
- 'file' => $file,
- 'params' => $params,
- 'type' => $type,
- 'content' => $this->getFileContent($file),
- )));
- }
-
- /**
- * Display image
- *
- * @access public
- */
- public function image()
- {
- $file = $this->getFile();
- $etag = md5($file['path']);
- $this->response->withContentType($this->helper->file->getImageMimeType($file['name']));
- $this->response->withCache(5 * 86400, $etag);
-
- if ($this->request->getHeader('If-None-Match') === '"'.$etag.'"') {
- $this->response->status(304);
- } else {
-
- try {
- $this->response->send();
- $this->objectStorage->output($file['path']);
- } catch (ObjectStorageException $e) {
- $this->logger->error($e->getMessage());
- }
- }
- }
-
- /**
- * Display image thumbnail
- *
- * @access public
- */
- public function thumbnail()
- {
- $file = $this->getFile();
- $model = $file['model'];
- $filename = $this->$model->getThumbnailPath($file['path']);
- $etag = md5($filename);
-
- $this->response->withCache(5 * 86400, $etag);
- $this->response->withContentType('image/jpeg');
-
- if ($this->request->getHeader('If-None-Match') === '"'.$etag.'"') {
- $this->response->status(304);
- } else {
-
- $this->response->send();
-
- try {
-
- $this->objectStorage->output($filename);
- } catch (ObjectStorageException $e) {
- $this->logger->error($e->getMessage());
-
- // Try to generate thumbnail on the fly for images uploaded before Kanboard < 1.0.19
- $data = $this->objectStorage->get($file['path']);
- $this->$model->generateThumbnailFromData($file['path'], $data);
- $this->objectStorage->output($this->$model->getThumbnailPath($file['path']));
- }
- }
- }
-
- /**
- * File download
- *
- * @access public
- */
- public function download()
- {
- try {
- $file = $this->getFile();
- $this->response->withFileDownload($file['name']);
- $this->response->send();
- $this->objectStorage->output($file['path']);
- } catch (ObjectStorageException $e) {
- $this->logger->error($e->getMessage());
- }
- }
-}