diff options
Diffstat (limited to 'app/class/modelrender.php')
-rw-r--r-- | app/class/modelrender.php | 32 |
1 files changed, 30 insertions, 2 deletions
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 '<a href="' . $rend->uart($matches[1]) . '">' . $matches[1] . '</a>'; + } else { + return '<a href="' . $rend->uart($matches[1]) . '" title="' . $matchart->description() . '">' . $matchart->title() . '</a>'; + } + }, + $text + ); + return $text; + } + public function markdown($text) { |