Make images works in embedded documentation
This commit is contained in:
@@ -5,31 +5,13 @@ namespace Kanboard\Controller;
|
|||||||
use Parsedown;
|
use Parsedown;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Documentation controller
|
* Documentation Viewer
|
||||||
*
|
*
|
||||||
* @package controller
|
* @package controller
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
class Doc extends Base
|
class Doc extends Base
|
||||||
{
|
{
|
||||||
private function readFile($filename)
|
|
||||||
{
|
|
||||||
$url = $this->helper->url;
|
|
||||||
$data = file_get_contents($filename);
|
|
||||||
list($title, ) = explode("\n", $data, 2);
|
|
||||||
|
|
||||||
$replaceUrl = function (array $matches) use ($url) {
|
|
||||||
return '('.$url->to('doc', 'show', array('file' => str_replace('.markdown', '', $matches[1]))).')';
|
|
||||||
};
|
|
||||||
|
|
||||||
$content = preg_replace_callback('/\((.*.markdown)\)/', $replaceUrl, $data);
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'content' => Parsedown::instance()->text($content),
|
|
||||||
'title' => $title !== 'Documentation' ? t('Documentation: %s', $title) : $title,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show()
|
public function show()
|
||||||
{
|
{
|
||||||
$page = $this->request->getStringParam('file', 'index');
|
$page = $this->request->getStringParam('file', 'index');
|
||||||
@@ -38,21 +20,17 @@ class Doc extends Base
|
|||||||
$page = 'index';
|
$page = 'index';
|
||||||
}
|
}
|
||||||
|
|
||||||
$filenames = array(__DIR__.'/../../doc/'.$page.'.markdown');
|
|
||||||
$filename = __DIR__.'/../../doc/index.markdown';
|
|
||||||
|
|
||||||
if ($this->config->getCurrentLanguage() === 'fr_FR') {
|
if ($this->config->getCurrentLanguage() === 'fr_FR') {
|
||||||
array_unshift($filenames, __DIR__.'/../../doc/fr/'.$page.'.markdown');
|
$filename = __DIR__.'/../../doc/fr/' . $page . '.markdown';
|
||||||
|
} else {
|
||||||
|
$filename = __DIR__ . '/../../doc/' . $page . '.markdown';
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($filenames as $file) {
|
if (!file_exists($filename)) {
|
||||||
if (file_exists($file)) {
|
$filename = __DIR__.'/../../doc/index.markdown';
|
||||||
$filename = $file;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->response->html($this->helper->layout->app('doc/show', $this->readFile($filename)));
|
$this->response->html($this->helper->layout->app('doc/show', $this->render($filename)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,4 +40,49 @@ class Doc extends Base
|
|||||||
{
|
{
|
||||||
$this->response->html($this->template->render('config/keyboard_shortcuts'));
|
$this->response->html($this->template->render('config/keyboard_shortcuts'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare Markdown file
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @param string $filename
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function render($filename)
|
||||||
|
{
|
||||||
|
$data = file_get_contents($filename);
|
||||||
|
$content = preg_replace_callback('/\((.*.markdown)\)/', array($this, 'replaceMarkdownUrl'), $data);
|
||||||
|
$content = preg_replace_callback('/\((screenshots.*\.png)\)/', array($this, 'replaceImageUrl'), $content);
|
||||||
|
|
||||||
|
list($title, ) = explode("\n", $data, 2);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'content' => Parsedown::instance()->text($content),
|
||||||
|
'title' => $title !== 'Documentation' ? t('Documentation: %s', $title) : $title,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regex callback to replace Markdown links
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param array $matches
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function replaceMarkdownUrl(array $matches)
|
||||||
|
{
|
||||||
|
return '('.$this->helper->url->to('doc', 'show', array('file' => str_replace('.markdown', '', $matches[1]))).')';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regex callback to replace image links
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param array $matches
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function replaceImageUrl(array $matches)
|
||||||
|
{
|
||||||
|
return '('.$this->helper->url->base().'doc/'.$matches[1].')';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
<IfVersion >= 2.3>
|
|
||||||
Require all denied
|
|
||||||
</IfVersion>
|
|
||||||
<IfVersion < 2.3>
|
|
||||||
Order allow,deny
|
|
||||||
Deny from all
|
|
||||||
</IfVersion>
|
|
||||||
Reference in New Issue
Block a user