From 0f44c6d918a2932b68019c02de5bc55e7057600a Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Mon, 12 Nov 2018 12:03:39 +0100 Subject: wiki-url --- app/class/modelrender.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'app/class/modelrender.php') diff --git a/app/class/modelrender.php b/app/class/modelrender.php index ed50893..0951537 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -2,12 +2,21 @@ class Modelrender extends Modelart { + protected $router; + const SUMMARY = '%SUMMARY%'; - public function __construct() + public function __construct($router) { parent::__construct(); + + $this->router = $router; + } + + public function uart($id) + { + return $this->router->generate('artread/', ['art' => $id]); } public function renderhead(Art2 $art) @@ -142,7 +151,7 @@ class Modelrender extends Modelart $text = str_replace(self::SUMMARY, $this->sumparser($text), $text); - $text = str_replace('href="=', 'href="?id=', $text); + $text = $this->wikiurl($text); $text = $this->tooltip($art->linkfrom('array'), $text); @@ -161,6 +170,25 @@ class Modelrender extends Modelart return $text; } + public function wikiurl(string $text) + { + $rend = $this; + $artlist = []; + $text = preg_replace_callback( + '%\[([\w-]+)\]%', + function ($matches) use ($rend) { + $matchart = $rend->get($matches[1]); + if (!$matchart) { + return '' . $matches[1] . ''; + } else { + return '' . $matchart->title() . ''; + } + }, + $text + ); + return $text; + } + public function markdown($text) { -- cgit v1.2.3