From f92d03d49f5ea5f7ee942b791c1bb5a9861afac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfred=20B=C3=BChler?= Date: Sun, 28 Jul 2024 14:29:40 +0200 Subject: [PATCH 1/6] Completing the file viewer and screenshot handling --- Controller/WikiController.php | 13 ++-- Controller/WikiFileViewController.php | 86 +++++---------------------- Template/wiki/detail.php | 14 ++--- Template/wiki_file/files.php | 6 +- Template/wiki_file/images.php | 7 ++- Template/wiki_file/show.php | 3 - 6 files changed, 37 insertions(+), 92 deletions(-) diff --git a/Controller/WikiController.php b/Controller/WikiController.php index 161a650..4da7b37 100755 --- a/Controller/WikiController.php +++ b/Controller/WikiController.php @@ -31,7 +31,7 @@ public function index() // echo json_encode($query->findAll()); - // exit(); + // exit(); // $wikipages = $this->wikiModel->getWikipages($project['id']); $search = $this->request->getStringParam('search'); @@ -149,7 +149,7 @@ public function edit(array $values = array(), array $errors = array()) public function detail_readonly() { $token = $this->request->getStringParam('token'); - + $project = $this->projectModel->getByToken($token); if (empty($project)) { @@ -207,7 +207,7 @@ function getNestedChildren($parent_id, $items) { public function detail() { $project = $this->getProject(); - + $wiki_id = $this->request->getIntegerParam('wiki_id'); $wikipages = $this->wikiModel->getWikipages($project['id']); @@ -218,9 +218,9 @@ public function detail() $wikipage = $page; } if(!isset($page['parent_id'])){ - + $page['children'] = $this->getNestedChildren($page['id'], $wikipages); - + array_push($wikiPagesResult, $page); } } @@ -449,7 +449,8 @@ public function remove() $this->flash->failure(t('Unable to remove this wiki page.')); } + // FIXME This works only if there are remaining pages. $this->response->redirect($this->helper->url->to('WikiController', 'show', array('plugin' => 'wiki', 'project_id' => $project['id'])), true); } - + } diff --git a/Controller/WikiFileViewController.php b/Controller/WikiFileViewController.php index d87c769..744733b 100644 --- a/Controller/WikiFileViewController.php +++ b/Controller/WikiFileViewController.php @@ -2,58 +2,11 @@ namespace Kanboard\Plugin\Wiki\Controller; +use Kanboard\Controller\FileViewerController; use Kanboard\Core\ObjectStorage\ObjectStorageException; -use Kanboard\Controller\BaseController; - -class WikiFileViewController extends BaseController +class WikiFileViewController extends FileViewerController { - /** - * Get file content from object storage - * - * @access protected - * @param array $file - * @return string - */ - protected 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; - } - - /** - * Output file with cache - * - * @param array $file - * @param $mimetype - */ - protected function renderFileWithCache(array $file, $mimetype) - { - $etag = md5($file['path']); - - if ($this->request->getHeader('If-None-Match') === '"'.$etag.'"') { - $this->response->status(304); - } else { - try { - $this->response->withContentType($mimetype); - $this->response->withCache(5 * 86400, $etag); - $this->response->send(); - $this->objectStorage->output($file['path']); - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - } - } - } - /** * Show file content in a popover * @@ -61,19 +14,17 @@ protected function renderFileWithCache(array $file, $mimetype) */ public function show() { - $file = $this->wikiFileModel->getById($this->request->getIntegerParam('fid')); - $type = $this->helper->file->getPreviewType($file['name']); - $params = array('file_id' => $file['id'], 'project_id' => $this->request->getIntegerParam('project_id')); - - - $params['wikipage_id'] = $file['wikipage_id']; - + $file = $this->wikiFileModel->getById($this->request->getIntegerParam('file_id')); $this->response->html($this->template->render('file_viewer/show', array( 'file' => $file, - 'params' => $params, - 'type' => $type, + 'type' => $this->helper->file->getPreviewType($file['name']), 'content' => $this->getFileContent($file), + 'params' => array( + 'file_id' => $file['id'], + 'project_id' => $this->request->getIntegerParam('project_id'), + 'wikipage_id' => $file['wikipage_id'], + ) ))); } @@ -95,7 +46,7 @@ public function image() */ public function browser() { - $file = $this->wikiFileModel->getById($this->request->getIntegerParam('fid')); + $file = $this->wikiFileModel->getById($this->request->getIntegerParam('file_id')); $this->renderFileWithCache($file, $this->helper->file->getBrowserViewType($file['name'])); } @@ -107,29 +58,25 @@ public function browser() public function thumbnail() { $file = $this->wikiFileModel->getById($this->request->getIntegerParam('file_id')); - $model = 'wikiFile'; - $filename = $this->$model->getThumbnailPath($file['path']); - $etag = md5($filename); + $filename = $this->wikiFileModel->getThumbnailPath($file['path']); - $this->response->withCache(5 * 86400, $etag); - $this->response->withContentType('image/jpeg'); + $this->response->withCache(5 * 86400, $file['etag']); + $this->response->withContentType('image/png'); - if ($this->request->getHeader('If-None-Match') === '"'.$etag.'"') { + if ($this->request->getHeader('If-None-Match') === '"'.$file['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'])); + $this->wikiFileModel->generateThumbnailFromData($file['path'], $data); + $this->objectStorage->output($this->wikiFileModel->getThumbnailPath($file['path'])); } } } @@ -143,7 +90,6 @@ public function download() { try { $file = $this->wikiFileModel->getById($this->request->getIntegerParam('file_id')); - $file['model'] = 'wikiFile'; $this->response->withFileDownload($file['name']); $this->response->send(); $this->objectStorage->output($file['path']); diff --git a/Template/wiki/detail.php b/Template/wiki/detail.php index 92c97ed..94a48ad 100755 --- a/Template/wiki/detail.php +++ b/Template/wiki/detail.php @@ -37,22 +37,22 @@ @@ -90,7 +90,7 @@ modal->large('edit', t('Edit page'), 'WikiController', 'edit', array('plugin' => 'wiki', 'wiki_id' => $wikipage['id']))?>
url->icon('window-restore', t('View Editions'), 'WikiController', 'editions', array('plugin' => 'wiki', 'project_id' => $project['id'], 'wiki_id' => $wikipage['id']))?> - + @@ -138,4 +139,3 @@ - diff --git a/Template/wiki_file/files.php b/Template/wiki_file/files.php index 85b604a..beda880 100644 --- a/Template/wiki_file/files.php +++ b/Template/wiki_file/files.php @@ -15,16 +15,16 @@