-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/funktechno/kanboard-plugi…
- Loading branch information
Showing
14 changed files
with
231 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.