From 924949850322144036e281bf94fb8b88c42bbd74 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Tue, 16 Feb 2016 22:06:53 -0500 Subject: Add file preview for Markdown and text files --- app/Controller/FileViewer.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'app/Controller') diff --git a/app/Controller/FileViewer.php b/app/Controller/FileViewer.php index 24ccc691..bc91c3d8 100644 --- a/app/Controller/FileViewer.php +++ b/app/Controller/FileViewer.php @@ -12,6 +12,30 @@ use Kanboard\Core\ObjectStorage\ObjectStorageException; */ class FileViewer extends Base { + /** + * 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 * @@ -20,6 +44,7 @@ class FileViewer extends Base 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') { @@ -29,6 +54,8 @@ class FileViewer extends Base $this->response->html($this->template->render('file_viewer/show', array( 'file' => $file, 'params' => $params, + 'type' => $type, + 'content' => $this->getFileContent($file), ))); } -- cgit v1.2.3