Skip to content

Commit

Permalink
File Attachments (#19)
Browse files Browse the repository at this point in the history
* Update WikiFile.php

* Update WikiFile.php

* Update Sqlite.php

* Update Sqlite.php

* Update Mysql.php

* Update Postgres.php

* Create WikiFileEventJob.php

* Delete WikiFileEventJob.php

* Update WikiFile.php

* Update WikiFile.php

* Update WikiController.php

* Update WikiController.php

* Update detail.php

* Update detail.php

* Update detail.php

* Update WikiController.php

* Update images.php

* Update files.php

* Update images.php

* Update WikiFileController.php

* Update WikiFile.php

* Update WikiFileController.php

* Update WikiFileController.php

* Update images.php

* Update images.php

* Update images.php

* Update images.php

* Create WikiFileViewController.php

* Update images.php

* Update WikiFileViewController.php

* Update WikiFile.php

* Update WikiFileViewController.php

* Update WikiFileViewController.php

* Update WikiFileViewController.php

* Update WikiFileViewController.php

* Update Plugin.php

* Update images.php

* Update images.php

* Update WikiFileViewController.php

* Update WikiFileViewController.php

* Update images.php

* Update images.php

* Update WikiFileViewController.php

* Update WikiFileViewController.php

* Update WikiFileViewController.php

* Update images.php

* Update files.php

* Update ChangeLog

* Update Plugin.php

* Update Makefile

* Update ChangeLog

* Update README.md
  • Loading branch information
creecros authored and lastlink committed Oct 4, 2018
1 parent 46e428b commit 0718548
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 19 deletions.
13 changes: 12 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Version 0.2.9-alpha

Improvements:

* File and Image Attachments Feature
* Added Upload Support
* Added Thumbnail Support
* Added Download Support
* Added Removal Support
* Added Slideshow Support for images

Version 0.2.8-alpha

Improvements:
Expand Down Expand Up @@ -124,4 +135,4 @@ Improvements:

Bug fixes:

*
*
3 changes: 3 additions & 0 deletions Controller/WikiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public function detail()
'project' => $project,
'title' => t('Wikipage'),
'wiki_id' => $wiki_id,
'wiki' => $wikipage,
'files' => $this->wikiFile->getAllDocuments($wiki_id),
'images' => $this->wikiFile->getAllImages($wiki_id),
// 'wikipage' => $this->wiki->getWikipage($wiki_id),
'wikipage' => $wikipage,
'wikipages' => $wikipages,
Expand Down
4 changes: 2 additions & 2 deletions Controller/WikiFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ public function remove()
$wiki = $this->wiki->getWiki();
$file = $this->wikiFile->getById($this->request->getIntegerParam('file_id'));

if ($file['wiki_id'] == $wiki['id'] && $this->wikiFile->remove($file['id'])) {
if ($file['wikipage_id'] == $wiki['id'] && $this->wikiFile->remove($file['id'])) {
$this->flash->success(t('File removed successfully.'));
} else {
$this->flash->failure(t('Unable to remove this file.'));
}
$this->response->redirect($this->helper->url->to('WikiController', 'detail', array('plugin' => 'wiki', 'project_id' => $wiki['project_id'], 'wiki_id' => $wiki['id'])), true);

$this->response->redirect($this->helper->url->to('WikiViewController', 'show', array('wiki_id' => $wiki['id'], 'project_id' => $wiki['project_id'])));
}

/**
Expand Down
159 changes: 159 additions & 0 deletions Controller/WikiFileViewController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?php

namespace Kanboard\Plugin\Wiki\Controller;

use Kanboard\Core\ObjectStorage\ObjectStorageException;
use Kanboard\Controller\BaseController;

/**
* File Viewer Controller
*
* @package Kanbaord\Controller
* @author Frederic Guillot
*/
class WikiFileViewController extends BaseController
{
/**
* 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 = $file = $this->wikiFile->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'];


$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->wikiFile->getById($this->request->getIntegerParam('fid'));
$this->renderFileWithCache($file, $this->helper->file->getImageMimeType($file['name']));
}

/**
* Display file in browser
*
* @access public
*/
public function browser()
{
$file = $this->wikiFile->getById($this->request->getIntegerParam('fid'));
$this->renderFileWithCache($file, $this->helper->file->getBrowserViewType($file['name']));
}

/**
* Display image thumbnail
*
* @access public
*/
public function thumbnail()
{
$file = $this->wikiFile->getById($this->request->getIntegerParam('fid'));
$model = 'wikiFile';
$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->wikiFile->getById($this->request->getIntegerParam('fid'));
$file['model'] = 'wikiFile';
$this->response->withFileDownload($file['name']);
$this->response->send();
$this->objectStorage->output($file['path']);
} catch (ObjectStorageException $e) {
$this->logger->error($e->getMessage());
}
}
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugin=Wiki
version=0.2.8
version=0.2.9
all:
@ echo "Build archive for plugin ${plugin} version=${version}"
@ git archive HEAD --prefix=${plugin}/ --format=zip -o ${plugin}-${version}.zip
10 changes: 8 additions & 2 deletions Model/WikiFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Kanboard\Plugin\Wiki\Model;

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

/**
* Wiki File Model
*
* @package Kanboard\Model
* @author Frederic Guillot
*/
class WikiFileModel extends FileModel
class WikiFile extends FileModel
{
/**
* Table name
Expand All @@ -23,6 +26,7 @@ class WikiFileModel extends FileModel
* @var string
*/
const EVENT_CREATE = 'wiki.file.create';


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


/**
* Define the foreign key
Expand Down Expand Up @@ -98,6 +103,7 @@ public function uploadScreenshot($wiki_id, $blob)
*/
protected function fireCreationEvent($file_id)
{
$this->queueManager->push($this->wikiFileEventJob->withParams($file_id, self::EVENT_CREATE));
return null;
}

}
3 changes: 2 additions & 1 deletion Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function initialize()
{
$this->projectAccessMap->add('WikiController', '*', Role::PROJECT_MEMBER);
$this->projectAccessMap->add('WikiFileController', '*', Role::PROJECT_MEMBER);
$this->projectAccessMap->add('WikiFileViewController', '*', Role::PROJECT_MEMBER);

$this->route->addRoute('/wiki/project/:project_id', 'WikiController', 'show', 'wiki');
$this->route->addRoute('/wiki/project/:project_id', 'WikiController', 'detail', 'wiki');
Expand Down Expand Up @@ -84,7 +85,7 @@ public function getPluginAuthor()

public function getPluginVersion()
{
return '0.2.8';
return '0.2.9';
}

public function getPluginHomepage()
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Note that you can only restore **saved** editions. So you if you have the global

- style updates
- ordering
- [file attachment support](https://github.com/funktechno/kanboard-plugin-wiki/issues/3)
- [x] [file attachment support](https://github.com/funktechno/kanboard-plugin-wiki/issues/3)
- [x] global wiki page search [issue 5](https://github.com/funktechno/kanboard-plugin-wiki/issues/5) prob next year
- rest support - LOW PRIORITY
- [issues/bugs](https://github.com/funktechno/kanboard-plugin-wiki/issues)
Expand Down Expand Up @@ -128,4 +128,4 @@ After testing create a new tag in github or via cli. `git tag -a 0.2.6 -m "Trans
"compatible_version": ">=1.0.37"
}
}
```
```
9 changes: 8 additions & 1 deletion Schema/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

use PDO;

const VERSION = 7;
const VERSION = 8;

function version_8(PDO $pdo)
{
$pdo->exec('ALTER TABLE wikipage_has_files ADD COLUMN `date` INT NOT NULL DEFAULT 0');
$pdo->exec('ALTER TABLE wikipage_has_files ADD COLUMN `user_id` INT NOT NULL DEFAULT 0');
$pdo->exec('ALTER TABLE wikipage_has_files ADD COLUMN `size` INT NOT NULL DEFAULT 0');
}

function version_7(PDO $pdo){
$pdo->exec("ALTER TABLE wikipage CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;");
Expand Down
9 changes: 8 additions & 1 deletion Schema/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

use PDO;

const VERSION = 2;
const VERSION = 3;

function version_3(PDO $pdo)
{
$pdo->exec('ALTER TABLE files ADD COLUMN "date" INTEGER NOT NULL DEFAULT 0');
$pdo->exec('ALTER TABLE files ADD COLUMN "user_id" INTEGER NOT NULL DEFAULT 0');
$pdo->exec('ALTER TABLE files ADD COLUMN "size" INTEGER NOT NULL DEFAULT 0');
}

function version_2(PDO $pdo)
{
Expand Down
9 changes: 8 additions & 1 deletion Schema/Sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

use PDO;

const VERSION = 2;
const VERSION = 3;

function version_3(PDO $pdo)
{
$pdo->exec('ALTER TABLE wikipage_has_files ADD COLUMN "date" INTEGER NOT NULL DEFAULT 0');
$pdo->exec('ALTER TABLE wikipage_has_files ADD COLUMN "user_id" INTEGER NOT NULL DEFAULT 0');
$pdo->exec('ALTER TABLE wikipage_has_files ADD COLUMN "size" INTEGER NOT NULL DEFAULT 0');
}

function version_2(PDO $pdo)
{
Expand Down
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'), 'FileViewerController', 'show', array('wiki_id' => $wiki['id'], 'project_id' => $wiki['project_id'], 'file_id' => $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'], 'fid' => $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'), 'FileViewerController', 'browser', array('wiki_id' => $wiki['id'], 'project_id' => $wiki['project_id'], 'file_id' => $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'], 'fid' => $file['id']), false, '', '', true) ?>
</li>
<?php endif ?>
<li>
<?= $this->url->icon('download', t('Download'), 'FileViewerController', 'download', array('wiki_id' => $wiki['id'], 'project_id' => $wiki['project_id'], 'file_id' => $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'], 'fid' => $file['id'])) ?>
</li>
<?php if ($this->user->hasProjectAccess('WikiFileController', 'remove', $wiki['project_id'])): ?>
<li>
Expand Down
8 changes: 4 additions & 4 deletions Template/wiki_file/images.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
'image' => $file,
'regex' => 'FILE_ID',
'url' => array(
'image' => $this->url->to('FileViewerController', 'image', array('file_id' => 'FILE_ID', 'project_id' => $wiki['project_id'], 'wiki_id' => $wiki['id'])),
'thumbnail' => $this->url->to('FileViewerController', 'thumbnail', array('file_id' => 'FILE_ID', 'project_id' => $wiki['project_id'], 'wiki_id' => $wiki['id'])),
'download' => $this->url->to('FileViewerController', 'download', array('file_id' => 'FILE_ID', 'project_id' => $wiki['project_id'], 'wiki_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'], 'fid' => $file['id'])),
'thumbnail' => $this->url->to('WikiFileViewController', 'thumbnail', array('plugin' => 'wiki', 'file_id' => 'FILE_ID', 'project_id' => $wiki['project_id'], 'wikipage_id' => $wiki['id'], 'fid' => $file['id'])),
'download' => $this->url->to('WikiFileViewController', 'download', array('plugin' => 'wiki', 'file_id' => 'FILE_ID', 'project_id' => $wiki['project_id'], 'wikipage_id' => $wiki['id'], 'fid' => $file['id'])),
)
)) ?>

Expand All @@ -19,7 +19,7 @@
<a href="#" class="dropdown-menu dropdown-menu-link-text" title="<?= $this->text->e($file['name']) ?>"><?= $this->text->e($file['name']) ?> <i class="fa fa-caret-down"></i></a>
<ul>
<li>
<?= $this->url->icon('download', t('Download'), 'FileViewerController', 'download', array('wiki_id' => $wiki['id'], 'project_id' => $wiki['project_id'], 'file_id' => $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'], 'fid' => $file['id'])) ?>
</li>
<?php if ($this->user->hasProjectAccess('WikiFileController', 'remove', $wiki['project_id'])): ?>
<li>
Expand Down

0 comments on commit 0718548

Please sign in to comment.