From ab48a09f0d674b703467975b376c5ac7352670ae Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 28 May 2016 11:31:54 -0400 Subject: Rename controllers --- app/Controller/DocumentationController.php | 92 ++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 app/Controller/DocumentationController.php (limited to 'app/Controller/DocumentationController.php') diff --git a/app/Controller/DocumentationController.php b/app/Controller/DocumentationController.php new file mode 100644 index 00000000..379e3dab --- /dev/null +++ b/app/Controller/DocumentationController.php @@ -0,0 +1,92 @@ +request->getStringParam('file', 'index'); + + if (!preg_match('/^[a-z0-9\-]+/', $page)) { + $page = 'index'; + } + + if ($this->language->getCurrentLanguage() === 'fr_FR') { + $filename = __DIR__.'/../../doc/fr/' . $page . '.markdown'; + } else { + $filename = __DIR__ . '/../../doc/' . $page . '.markdown'; + } + + if (!file_exists($filename)) { + $filename = __DIR__.'/../../doc/index.markdown'; + } + + $this->response->html($this->helper->layout->app('doc/show', $this->render($filename))); + } + + /** + * Display keyboard shortcut + */ + public function 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('DocumentationController', '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) + { + if ($this->language->getCurrentLanguage() === 'fr_FR') { + return '('.$this->helper->url->base().'doc/fr/'.$matches[1].')'; + } + + return '('.$this->helper->url->base().'doc/'.$matches[1].')'; + } +} -- cgit v1.2.3