Skip to content

Commit

Permalink
Merge pull request #90 from funktechno/f/fileviewer
Browse files Browse the repository at this point in the history
Completing the file viewer and screenshot handling
  • Loading branch information
alfredbuehler authored Jul 29, 2024
2 parents 8eb0094 + 5ea2746 commit 207d92f
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 93 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 0.3.8
Improvements:

* Fixed file viewer for attachments.
* Added screenshot support.

Version 0.3.7
Improvements:

Expand Down
13 changes: 7 additions & 6 deletions Controller/WikiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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']);
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
}

}
86 changes: 16 additions & 70 deletions Controller/WikiFileViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,29 @@

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
*
* @access public
*/
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'],
)
)));
}

Expand All @@ -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']));
}

Expand All @@ -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']));
}
}
}
Expand All @@ -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']);
Expand Down
2 changes: 1 addition & 1 deletion Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function getPluginAuthor()

public function getPluginVersion()
{
return '0.3.7';
return '0.3.8';
}

public function getPluginHomepage()
Expand Down
14 changes: 7 additions & 7 deletions Template/wiki/detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@
<div class="sidebar column list">
<?php if (!empty($wikipages)): ?>
<ul id="columns" <?php if (!$not_editable): ?>data-reorder-url="<?= $this->url->href('WikiAjaxController', 'reorder_by_index', array('plugin' => 'wiki', 'project_id' => $project['id'], 'csrf_token' => $this->app->getToken()->getReusableCSRFToken())) ?>"<?php endif ?>>

<?php foreach ($wikipages as $page): ?>
<li class="wikipage" data-project-id="<?=$project['id']?>" data-page-order="<?=$page['ordercolumn']?>" data-page-id="<?=$page['id']?>">
<?php if (!$not_editable): ?>
<?=$this->url->link(t($page['title']), 'WikiController', 'detail', array('plugin' => 'wiki', 'project_id' => $project['id'], 'wiki_id' => $page['id']))?>

<?=$this->modal->confirm('trash-o', t(''), 'WikiController', 'confirm', array('plugin' => 'wiki', 'project_id' => $project['id'], 'wiki_id' => $page['id']))?>
<?php else: ?>
<?php else: ?>
<?=$this->url->link(t($page['title']), 'WikiController', 'detail_readonly', array('plugin' => 'wiki', 'token' => $project['token'], 'wiki_id' => $page['id']))?>
<?php endif ?>
<?php endif ?>
<?php if (count($page['children']) > 0): ?>
<?=$this->wikiHelper->renderChildren($page['children'], $page['id'], $project, $not_editable)?>
<?php endif ?>
</li>


<?php endforeach?>
</ul>
<?php else: ?>
Expand All @@ -68,7 +68,7 @@
<?=$this->modal->medium('plus', t('New Wiki page'), 'WikiController', 'create', array('plugin' => 'wiki', 'project_id' => $project['id']))?>
</li>
</ul>
<?php endif ?>
<?php endif ?>

</ul>
</div>
Expand All @@ -90,7 +90,7 @@
<?=$this->modal->large('edit', t('Edit page'), 'WikiController', 'edit', array('plugin' => 'wiki', 'wiki_id' => $wikipage['id']))?>
<br>
<?=$this->url->icon('window-restore', t('View Editions'), 'WikiController', 'editions', array('plugin' => 'wiki', 'project_id' => $project['id'], 'wiki_id' => $wikipage['id']))?>
<?php endif ?>
<?php endif ?>
</div>
<ul class="panel">
<?php if ($wikipage['creator_id'] > 0): ?>
Expand Down Expand Up @@ -125,6 +125,7 @@
error_reporting(E_ALL);
?>
<?=$this->modal->medium('file', t('Attach a document'), 'WikiFileController', 'create', array('plugin' => 'wiki', 'wiki_id' => $wikipage['id'], 'project_id' => $wikipage['project_id']))?>
<?= $this->modal->medium('camera', t('Add a screenshot'), 'WikiFileController', 'screenshot', array('plugin' => 'wiki', 'wiki_id' => $wikipage['id'], 'project_id' => $wikipage['project_id'])) ?>
</ul>

<?php if (!empty($files) || !empty($images)): ?>
Expand All @@ -138,4 +139,3 @@
<?php endif ?>

</div>

6 changes: 3 additions & 3 deletions Template/wiki_file/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
<ul>
<?php if ($this->file->getPreviewType($file['name']) !== null): ?>
<li>
<?= $this->modal->large('eye', t('View file'), 'WikiFileViewController', 'show', array('plugin' => 'wiki', 'wikipage_id' => $wiki['id'], 'project_id' => $wiki['project_id'], 'file_id' => $file['id'], 'fid' => $file['id'])) ?>
<?= $this->modal->large('eye', t('View file'), 'WikiFileViewController', 'show', array('plugin' => 'wiki', 'wikipage_id' => $wiki['id'], 'project_id' => $wiki['project_id'], 'file_id' => $file['id'])) ?>
</li>
<?php elseif ($this->file->getBrowserViewType($file['name']) !== null): ?>
<li>
<i class="fa fa-eye fa-fw"></i>
<?= $this->url->link(t('View file'), 'WikiFileViewController', 'browser', array('plugin' => 'wiki', 'wikipage_id' => $wiki['id'], 'project_id' => $wiki['project_id'], 'file_id' => $file['id'], 'fid' => $file['id']), false, '', '', true) ?>
<?= $this->url->link(t('View file'), 'WikiFileViewController', 'browser', array('plugin' => 'wiki', 'wikipage_id' => $wiki['id'], 'project_id' => $wiki['project_id'], 'file_id' => $file['id']), false, '', '', true) ?>
</li>
<?php endif ?>
<li>
<?= $this->url->icon('download', t('Download'), 'WikiFileViewController', 'download', array('plugin' => 'wiki', 'wikipage_id' => $wiki['id'], 'project_id' => $wiki['project_id'], 'file_id' => $file['id'], 'fid' => $file['id'])) ?>
<?= $this->url->icon('download', t('Download'), 'WikiFileViewController', 'download', array('plugin' => 'wiki', 'wikipage_id' => $wiki['id'], 'project_id' => $wiki['project_id'], 'file_id' => $file['id'])) ?>
</li>
<?php if ($this->user->hasProjectAccess('WikiFileController', 'remove', $wiki['project_id'])): ?>
<li>
Expand Down
7 changes: 4 additions & 3 deletions Template/wiki_file/images.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
<?= $this->app->component('image-slideshow', array(
'images' => $images,
'image' => $file,
'regex' => 'FILE_ID',
'regex_file_id' => 'FILE_ID',
'regex_etag' => 'ETAG',
'url' => array(
'image' => $this->url->to('WikiFileViewController', 'image', array('plugin' => 'wiki', 'file_id' => 'FILE_ID', 'project_id' => $wiki['project_id'], 'wikipage_id' => $wiki['id'])),
'image' => $this->url->to('WikiFileViewController', 'image', array('plugin' => 'wiki', 'file_id' => 'FILE_ID', 'project_id' => $wiki['project_id'], 'wikipage_id' => $wiki['id'])),
'thumbnail' => $this->url->to('WikiFileViewController', 'thumbnail', array('plugin' => 'wiki', 'file_id' => 'FILE_ID', 'project_id' => $wiki['project_id'], 'wikipage_id' => $wiki['id'])),
'download' => $this->url->to('WikiFileViewController', 'download', array('plugin' => 'wiki', 'file_id' => 'FILE_ID', 'project_id' => $wiki['project_id'], 'wikipage_id' => $wiki['id'])),
'download' => $this->url->to('WikiFileViewController', 'download', array('plugin' => 'wiki', 'file_id' => 'FILE_ID', 'project_id' => $wiki['project_id'], 'wikipage_id' => $wiki['id'])),
)
)) ?>

Expand Down
3 changes: 0 additions & 3 deletions Template/wiki_file/show.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<section class="accordion-section <?= empty($files) && empty($images) ? 'accordion-collapsed' : '' ?>">
<div class="accordion-title">
<h3><a href="#" class="fa accordion-toggle"></a> <?= t('Attachments') ?></h3>
</div>
<div class="accordion-content">
<?= $this->render('wiki:wiki_file/images', array('wiki' => $wiki, 'images' => $images)) ?>
<?= $this->render('wiki:wiki_file/files', array('wiki' => $wiki, 'files' => $files)) ?>
Expand Down

0 comments on commit 207d92f

Please sign in to comment.