diff options
Diffstat (limited to 'app/class')
-rw-r--r-- | app/class/Controllerinfo.php | 16 | ||||
-rw-r--r-- | app/class/Model.php | 3 | ||||
-rw-r--r-- | app/class/Modelrender.php | 46 |
3 files changed, 54 insertions, 11 deletions
diff --git a/app/class/Controllerinfo.php b/app/class/Controllerinfo.php index af81caf..856d065 100644 --- a/app/class/Controllerinfo.php +++ b/app/class/Controllerinfo.php @@ -1,6 +1,7 @@ <?php namespace Wcms; +use Michelf\MarkdownExtra; class Controllerinfo extends Controller { @@ -12,7 +13,20 @@ class Controllerinfo extends Controller public function desktop() { if($this->user->iseditor()) { - $this->showtemplate('info', ['version' => getversion()]); + + if(file_exists(Model::MAN_FILE)) { + + $render = new Modelrender($this->router); + $htmlman = file_get_contents(Model::MAN_FILE); + $htmlman = $render->rendermanual($htmlman); + + $summary = $render->sumparser($htmlman, 3); + + + $this->showtemplate('info', ['version' => getversion(), 'manual' => $htmlman, 'summary' => $summary]); + + } + } } diff --git a/app/class/Model.php b/app/class/Model.php index bb07fea..913dc34 100644 --- a/app/class/Model.php +++ b/app/class/Model.php @@ -5,7 +5,8 @@ namespace Wcms; abstract class Model { - const CONFIG_FILE = 'config.json'; + const CONFIG_FILE = 'config.json'; + const MAN_FILE = 'MANUAL.md'; const CSS_DIR = 'assets' . DIRECTORY_SEPARATOR .'css' . DIRECTORY_SEPARATOR; const JS_DIR = 'assets' . DIRECTORY_SEPARATOR .'js' . DIRECTORY_SEPARATOR; const ICONS_DIR = 'assets' . DIRECTORY_SEPARATOR .'icons' . DIRECTORY_SEPARATOR; diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php index 593a420..fe491f1 100644 --- a/app/class/Modelrender.php +++ b/app/class/Modelrender.php @@ -36,6 +36,21 @@ class Modelrender extends Modelpage } } + /** + * Used to convert the markdown user manual to html document + * + * @param string $text Input text in markdown + * @return string html formated text + */ + public function rendermanual(string $text) : string + { + $text = $this->markdown($text); + $text = $this->headerid($text, 3); + return $text; + + } + + public function upage($id) { return $this->router->generate('pageread/', ['page' => $id]); @@ -384,11 +399,25 @@ class Modelrender extends Modelpage return $text; } - public function headerid($text) + /** + * Add Id to hrml header elements and store the titles in the `sum` parameter + * + * @param string $text Input html document to scan + * @param int $maxdeepness Maximum header deepness to look for. Min = 1 Max = 6 Default = 6 + * + * @return string text with id in header + */ + + public function headerid($text, int $maxdeepness = 6) { + if($maxdeepness > 6 || $maxdeepness < 1) { + $maxdeepness = 6; + } + + $sum = []; $text = preg_replace_callback( - '/<h([1-6])(\s+(\s*\w+="\w+")*)?\s*>(.+)<\/h[1-6]>/mU', + '/<h([1-' . $maxdeepness . '])(\s+(\s*\w+="\w+")*)?\s*>(.+)<\/h[1-' . $maxdeepness . ']>/mU', function ($matches) use (&$sum) { $cleanid = idclean($matches[4]); $sum[$cleanid][$matches[1]] = $matches[4]; @@ -453,16 +482,15 @@ class Modelrender extends Modelpage return $text; } - - function sumparser($text) + /** + * Generate a Summary based on header ids. Need to use `$this->headerid` before to scan text + * + * @return string html list with anchor link + */ + function sumparser() : string { - preg_match_all('#<h([1-6]) id="(\w+)">(.+)</h[1-6]>#iU', $text, $out); - - $sum = $this->sum; - - $sumstring = ''; $last = 0; foreach ($sum as $title => $list) { |