Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lastlink committed Oct 4, 2018
2 parents 5d3e672 + 0718548 commit 7d09bb8
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 30 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());
}
}
}
22 changes: 11 additions & 11 deletions Locale/ru_RU/translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
'Wiki lines' => 'Wiki строки',
'Cost' => 'Стоимость',
'Cost breakdown' => 'Детализация затрат',
'Do you really want to remove this wiki page?' => 'Вы действительно хотите удалить эту строку wiki?',
'Do you really want to remove this wiki page?' => 'Вы действительно хотите удалить эту страницу wiki?',
'Expenses' => 'Расходы',
'New Wiki page' => 'Новая wiki строка',
'New Wiki page' => 'Новая wiki страница',
'Remove a wiki line' => 'Удалить строку в wiki',
'Remove wiki line' => 'Удалить wiki строку',
'The wiki line have been created successfully.' => 'Wiki строка успешно создана.',
'Unable to create the wiki line.' => 'Не удается создать эту wiki строку.',
'Unable to remove this wiki page.' => 'Не удается удалить эту wiki строку.',
'Unable to remove this wiki page.' => 'Не удается удалить эту wiki страницу.',
'Remaining' => 'Прочее',
'Currency rates are used to calculate project wiki.' => 'Курсы валют используются для расчета wiki проекта.',
'Burndown chart for "%s"' => 'Диаграмма сгорания для "%s"',
Expand All @@ -43,12 +43,12 @@
'Date Creation' => 'Дата создания',
'Date Modification' => 'Дата модификации',
'Content' => 'Контент',
// 'Date Created' => 'Fecha de creacion',
// 'Date Modified' => 'Fecha modificada',
// '%d Wiki pages' => '%d Páginas Wiki',
// 'Search by content' => 'Buscar por contenido',
// 'Wiki page Title' => 'Título de la página Wiki',
// 'There are no editions for this Wiki page saved to restore.' => '',
// 'There are no Wiki pages that you have access to.' => '',
// 'There are no Wiki pages for this project.' => ''
'Date Created' => 'Дата создания',
'Date Modified' => 'Дата модификации',
'%d Wiki pages' => '%d Wiki страниц',
'Search by content' => 'Поиск по содержимому',
'Wiki page Title' => 'Заголовок Wiki страницы',
'There are no editions for this Wiki page saved to restore.' => 'Нет сохраненных редакций этой Wiki страницы для восстановления.',
'There are no Wiki pages that you have access to.' => 'Нет Wiki страниц, к которым у вас есть доступ.',
'There are no Wiki pages for this project.' => 'Для этого проекта нет Wiki страниц.'
);
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
Loading

0 comments on commit 7d09bb8

Please sign in to comment.