From 2f363e8fa26ab849539e64ff7caa21bd164e8979 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sat, 10 Nov 2018 21:43:24 +0100 Subject: sidebars-html-inserts --- w/class/modelrender.php | 67 +++++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 25 deletions(-) (limited to 'w/class/modelrender.php') diff --git a/w/class/modelrender.php b/w/class/modelrender.php index 963962b..53d1aca 100644 --- a/w/class/modelrender.php +++ b/w/class/modelrender.php @@ -20,31 +20,49 @@ class Modelrender extends Modelart public function renderbody(Art2 $art) { - $body = $this->getbody($art); + $body = $this->getbody($this->gethtml($art), $this->getelements($art)); $parsebody = $this->parser($art, $body); return $parsebody; } - public function getbody(Art2 $art) + public function getelements(Art2 $art) { - $body = ''; + $elements = []; foreach (self::TEXT_ELEMENTS as $element) { - if (array_key_exists($element, $art->template('array'))) { - $tempalteart = $this->get($art->template('array')[$element]); + if (isset($art->template('array')[$element])) { + $templateid = $art->template('array')[$element]; + $tempalteart = $this->get($templateid); $text = $tempalteart->$element() . PHP_EOL . $art->$element(); } else { $text = $art->$element(); } - if ($element == 'section') { - $body .= PHP_EOL . '<' . $element . '>
' . PHP_EOL . $this->markdown($text) . PHP_EOL . '
' . PHP_EOL; - } else { - $body .= PHP_EOL . '<' . $element . '>' . PHP_EOL . $this->markdown($text) . PHP_EOL . '' . PHP_EOL; - } + $elements[$element] = PHP_EOL . '<' . $element . '>' . PHP_EOL . $this->markdown($text) . PHP_EOL . '' . PHP_EOL; + } - return $body; + return $elements; + } + + public function gethtml(Art2 $art) + { + if (isset($art->template('array')['html'])) { + $templateid = $art->template('array')['html']; + $tempalteart = $this->get($templateid); + $html = $tempalteart->html() . PHP_EOL . $art->html(); + } else { + $html = $art->html(); + } + return $html; + } + + public function getbody(string $html, array $elements) + { + $html = preg_replace_callback('~\%(SECTION|ASIDE|NAV|HEADER|FOOTER)\%~', function ($match) use ($elements) { + return $elements[strtolower($match[1])]; + }, $html); + return $html; } public function write(Art2 $art) @@ -81,22 +99,22 @@ class Modelrender extends Modelart $head .= '' . PHP_EOL; $head .= '' . PHP_EOL; - - if (array_key_exists('css', $art->template('array'))) { - $tempaltecssart = $art->template('array')['css']; - $head .= '' . PHP_EOL; - } - $head .= '' . PHP_EOL; - if (array_key_exists('quickcss', $art->template('array'))) { + if (isset($art->template('array')['quickcss'])) { $tempaltequickcssart = $art->template('array')['quickcss']; $head .= '' . PHP_EOL; } $head .= '' . PHP_EOL; - if (array_key_exists('javascript', $art->template('array'))) { + if (isset($art->template('array')['css'])) { + $tempaltecssart = $art->template('array')['css']; + $head .= '' . PHP_EOL; + } + $head .= '' . PHP_EOL; + + if (isset($art->template('array')['javascript'])) { $templatejsart = $art->template('array')['javascript']; - $head .= '' . PHP_EOL; + $head .= '' . PHP_EOL; } - $head .= '' . PHP_EOL; + $head .= '' . PHP_EOL; return $head; } @@ -167,11 +185,10 @@ public function tooltip(array $linkfrom, string $text) foreach ($linkfrom as $id) { if (isset($descriptions[$id])) { - $title = $descriptions[$id]; + $linkfrom = 'href="?id=' . $id . '"'; + $titlelinkfrom = ' title="' . $descriptions[$id] . '" ' . $linkfrom; + $text = str_replace($linkfrom, $titlelinkfrom, $text); } - $linkfrom = 'href="?id=' . $id . '"'; - $titlelinkfrom = ' title="' . $title . '" ' . $linkfrom; - $text = str_replace($linkfrom, $titlelinkfrom, $text); } return $text; } -- cgit v1.2.3