Skip to content

Commit

Permalink
Merge pull request #96 from funktechno/dev
Browse files Browse the repository at this point in the history
release 0.3.8
  • Loading branch information
lastlink committed Aug 19, 2024
2 parents 9cc54e2 + 827f174 commit 63902fb
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 115 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 0.3.8
Improvements:

* Fixed file viewer for attachments.
* Added screenshot support.
* fixes for composer install 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
10 changes: 4 additions & 6 deletions Helper/WikiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ public function getWikipages($project_id)
/**
* Add a Javascript asset
*
* @param string $filename Filename
* @param string $filepath Filepath
* @param bool $async
* @return string
*/
public function js($filename, $async = false)
public function js($filepath, $async = false)
{
$dir = dirname(__DIR__,2);
$filepath = $dir.'/'.$filename;
return '<script '.($async ? 'async' : '').' defer type="text/javascript" src="'.$this->helper->url->dir()."plugins".$filename.'?'.filemtime($filepath).'"></script>';
return '<script '.($async ? 'async' : '').' defer type="text/javascript" src="'.$this->helper->url->dir().$filepath.'?'.filemtime($filepath).'"></script>';
}
/**
* render wiki page html children recursively
Expand Down Expand Up @@ -76,4 +74,4 @@ public function renderChildren($children, $parent_id, $project, $not_editable){
// {
// return 'foobar';
// }
}
}
7 changes: 3 additions & 4 deletions Model/WikiFileModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Kanboard\Plugin\Wiki\Model;

use Kanboard\Model\FileModel;
use Kanboard\Plugin\Wiki\Model\Wiki;

/**
* Wiki File Model
Expand All @@ -26,7 +25,7 @@ class WikiFileModel extends FileModel
* @var string
*/
const EVENT_CREATE = 'wiki.file.create';


/**
* Get the table
Expand All @@ -39,7 +38,7 @@ protected function getTable()
{
return self::TABLE;
}


/**
* Define the foreign key
Expand Down Expand Up @@ -105,7 +104,7 @@ protected function fireCreationEvent($file_id)
{
return null;
}

protected function fireDestructionEvent($file_id)
{
return null;
Expand Down
9 changes: 4 additions & 5 deletions Model/WikiModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Kanboard\Core\Base;
use Kanboard\Core\Controller\PageNotFoundException;
use Kanboard\Core\Controller\AccessForbiddenException;
// use Kanboard\Model\WikiModel;
use Kanboard\Model\UserModel;
use SimpleValidator\Validator;
use SimpleValidator\Validators;
Expand Down Expand Up @@ -53,7 +52,7 @@ public function getEditions($wiki_id)
const EVENT_UPDATE = 'wikipage.update';
const EVENT_CREATE = 'wikipage.create';
const EVENT_DELETE = 'wikipage.delete';


/**
* retrieve wikipages by parent id
Expand Down Expand Up @@ -178,7 +177,7 @@ public function reorderPagesByIndex($project_id, $src_wiki_id, $index, $parent_i

// echo json_encode($wikiPages), true;

// echo "project_id: " . $project_id . " src_wiki_id: " . $src_wiki_id . " index: " .
// echo "project_id: " . $project_id . " src_wiki_id: " . $src_wiki_id . " index: " .
$index . " parent_id: " . $parent_id ." count list: " . count($wikiPages) . "<br>";
// change order of each in for loop, move matching id to one before target
$orderColumn = 0;
Expand Down Expand Up @@ -260,7 +259,7 @@ public function reorderPages($project_id, $src_wiki_id, $target_wiki_id){
if(!$result){
return false;
}
}
}
}
$orderColumn++;
}
Expand Down Expand Up @@ -436,7 +435,7 @@ public function updatepage($paramvalues, $editions, $date = '')
if ($this->userSession->isLogged()) {
$values['modifier_id'] = $this->userSession->getId();
}

$wikiEventJob = new WikiEventJob($this->container);
$wikiEventJob->executeWithId($paramvalues['id'], self::EVENT_UPDATE);
// $wikiEventJob = new WikiEventJob($this->container);
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
18 changes: 9 additions & 9 deletions Template/wiki/detail.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php (isset($not_editable)) ?: $not_editable = false;
?>
<?php if (!$not_editable): ?>
<?=$this->wikiHelper->js("/Wiki/Asset/vendor/jquery-sortable/jquery-sortable.js")?>
<?=$this->wikiHelper->js("/Wiki/Asset/Javascript/wiki.js")?>
<?=$this->wikiHelper->js("plugins/Wiki/Asset/vendor/jquery-sortable/jquery-sortable.js")?>
<?=$this->wikiHelper->js("plugins/Wiki/Asset/Javascript/wiki.js")?>
<?= $this->projectHeader->render($project, 'TaskListController', 'show') ?>
<?php endif ?>
<div class="page-header">
Expand Down 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>

Loading

0 comments on commit 63902fb

Please sign in to comment.