diff options
-rw-r--r-- | app/class/config.php | 6 | ||||
-rw-r--r-- | app/class/controller.php | 5 | ||||
-rw-r--r-- | app/class/controllerart.php | 2 | ||||
-rw-r--r-- | app/class/modelrender.php | 32 | ||||
-rw-r--r-- | app/fn/fn.php | 4 |
5 files changed, 41 insertions, 8 deletions
diff --git a/app/class/config.php b/app/class/config.php index 39c741a..bfc0c9e 100644 --- a/app/class/config.php +++ b/app/class/config.php @@ -177,9 +177,11 @@ abstract class Config self::$basepath = strip_tags($basepath); } - public static function setroute404(string $id) + public static function setroute404($id) { - self::$route404 = idclean($id); + if(is_string($id)) { + self::$route404 = idclean($id); + } } diff --git a/app/class/controller.php b/app/class/controller.php index 1c3fee5..f7a3bd6 100644 --- a/app/class/controller.php +++ b/app/class/controller.php @@ -96,7 +96,10 @@ class Controller $this->redirect($this->router->generate($route, $vars)); } - + public function uart($id) + { + return $this->router->generate('artread/', ['art' => $id]); + } } diff --git a/app/class/controllerart.php b/app/class/controllerart.php index bec4b1d..e385201 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -12,7 +12,7 @@ class Controllerart extends Controller parent::__construct($router); $this->artmanager = new Modelart(); - $this->renderengine = new Modelrender(); + $this->renderengine = new Modelrender($router); } 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) { diff --git a/app/fn/fn.php b/app/fn/fn.php index 03bb2d0..3c7d32c 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -73,8 +73,8 @@ function arrayclean($input) function idclean(string $input) { $input = urldecode($input); - $search = ['é', 'à', 'è', 'ç', ' ']; - $replace = ['e', 'a', 'e', 'c', '-']; + $search = ['é', 'à', 'è', 'ç', 'ù', 'ï', 'î', ' ']; + $replace = ['e', 'a', 'e', 'c', 'u', 'i', 'i', '-']; $input = str_replace($search, $replace, $input); return preg_replace('%[^a-z0-9-_+]%', '', strtolower(trim($input))); |