From e17392e46259e6f2e012017987cf7c31c171488f Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sun, 28 Oct 2018 19:56:27 +0100 Subject: abstract config NWY --- w/class/modelrender.php | 187 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 w/class/modelrender.php (limited to 'w/class/modelrender.php') diff --git a/w/class/modelrender.php b/w/class/modelrender.php new file mode 100644 index 0000000..219e88e --- /dev/null +++ b/w/class/modelrender.php @@ -0,0 +1,187 @@ +template('array') as $element => $tempalteid) { + if(isset($tempalteid) && $tempalteid != $art->id()) { + $templateart = new Art2(['id' => $templateid]); + $templateart = $this->get($templateart); + $templates[$element] = $templateart->$element(); + } + } + + $elements = []; + foreach ($art->template('array') as $element) { + if(array_key_exists($element, $templates)) { + $elements[$element] = $templates[$element] . PHP_EOL . $art->$element(); + } else { + $elements[$element] = $art->$element(); + } + } + return $elements; + } + + public function elementsrender(array $elements) + { + foreach ($elements as $element => $text) { + if(in_array($element, self::TEXT_ELEMENTS)) { + $elements[$element] = $this->textrender($text); + } + } + return $elements; + } + + + + public function textrender($text) + { + + } + + + public function parser($text) + { + $text = str_replace('%TITLE%', $this->title(), $this->text); + $text = str_replace('%DESCRIPTION%', $this->description(), $text); + + $text = $this->markdown($text); + + $text = str_replace('%SUMMARY%', sumparser($text), $text); + + $text = str_replace('href="=', 'href="?id=', $text); + + return $text; + } + + + public function markdown($text) + { + //use Michelf\MarkdownExtra; + $fortin = new Michelf\MarkdownExtra; + // id in headers + $fortin->header_id_func = function ($header) { + return preg_replace('/[^\w]/', '', strtolower($header)); + }; + $text = $fortin->transform($text); + return $text; + } + + + + + public function tooltip($linkfrom, $text) + { + $descriptions = []; + $artlist = $app->getlisterwhere(['id', 'description'], $linkfrom); + foreach ($artlist as $art) { + $descriptions[$art->id()] = $art->description(); + } + + + + foreach ($linkfrom as $id) { + if(isset($descriptions[$id])) { + $title = $descriptions[$id]; + } else { + $title = "This page does not exist yet"; + } + $linkfrom = 'href="?id=' . $id . '"'; + $titlelinkfrom = ' title="' . $title . '" ' . $linkfrom; + $text = str_replace($linkfrom, $titlelinkfrom, $text); + } + } + + public function parserff($text) + { + $section = str_replace('%TITLE%', $this->title(), $this->section); + $section = str_replace('%DESCRIPTION%', $this->description(), $section); + + + + // replace = > ?id= + $section = str_replace('href="=', 'href="?id=', $section); + + + // infobulles tooltip + + + + + if (!empty(strstr($section, '%SUMMARY%'))) { + + + + + } + + + $section = str_replace('href="./media/', ' class="file" target="_blank" href="./media/', $section); + $section = str_replace('href="http', ' class="external" target="_blank" href="http', $section); + $section = str_replace('
', $section); + return $section; + + } + + + + + function sumparser($text) + { + preg_match_all('#(.+)#iU', $text, $out); + + + $sum = []; + foreach ($out[2] as $key => $value) { + $sum[$value][$out[1][$key]] = $out[3][$key]; + } + + + $sumstring = ''; + $last = 0; + foreach ($sum as $title => $list) { + foreach ($list as $h => $link) { + if($h > $last) { + for ($i = 1; $i <= ($h - $last); $i++) { + $sumstring .= ''; + } + $sumstring .= '
  • '.$link.'
  • ' ; + } elseif ($h = $last) { + $sumstring .= '
  • '.$link.'
  • ' ; + } + $last = $h; + } + } + for ($i = 1; $i <= ($last); $i++) { + $sumstring .= ''; + } + return $sumstring; + } + + + + + +} + + + +?> \ No newline at end of file -- cgit v1.2.3