From d46c05b12b9dcd65d2d9cd230bf45b5bdf6fa8bd Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Thu, 22 Nov 2018 00:09:55 +0100 Subject: linkfrom analyse --- app/class/modelrender.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'app/class/modelrender.php') diff --git a/app/class/modelrender.php b/app/class/modelrender.php index 82911aa..3fb1f81 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -4,6 +4,7 @@ class Modelrender extends Modelart { protected $router; protected $artlist; + protected $linkfrom = []; const SUMMARY = '%SUMMARY%'; @@ -172,7 +173,8 @@ class Modelrender extends Modelart $text = $this->wikiurl($text); $text = str_replace('href="http', ' class="external" target="_blank" href="http', $text); - $text = str_replace('autourl($text); @@ -188,37 +190,43 @@ class Modelrender extends Modelart public function wurl(string $text) { + $linkfrom = []; $rend = $this; $text = preg_replace_callback( '%href="([\w-]+)"%', - function ($matches) use ($rend) { + function ($matches) use ($rend, &$linkfrom) { $matchart = $rend->get($matches[1]); if (!$matchart) { return 'href="' . $rend->uart($matches[1]) . '"" title="' . Config::existnot() . '" class="internal"'; } else { + $linkfrom[] = $matchart->id(); return 'href="' . $rend->uart($matches[1]) . '" title="' . $matchart->description() . '" class="internal"'; } }, $text ); + $this->linkfrom = array_unique(array_merge($this->linkfrom, $linkfrom)); return $text; } public function wikiurl(string $text) { + $linkfrom = []; $rend = $this; $text = preg_replace_callback( '%\[([\w-]+)\]%', - function ($matches) use ($rend) { + function ($matches) use ($rend, &$linkfrom) { $matchart = $rend->get($matches[1]); if (!$matchart) { return '' . $matches[1] . ''; } else { + $linkfrom[] = $matchart->id(); return '' . $matchart->title() . ''; } }, $text ); + $this->linkfrom = array_unique(array_merge($this->linkfrom, $linkfrom)); return $text; } @@ -321,10 +329,19 @@ class Modelrender extends Modelart $text = str_replace('%%'.$tag.'%%', $ul, $text); + $this->linkfrom = array_unique(array_merge($this->linkfrom, $li)); } return $text; } + public function linkfrom() + { + sort($this->linkfrom); + $linkfrom = $this->linkfrom; + $this->linkfrom = []; + return $linkfrom; + } + -- cgit v1.2.3