From 1d011471674ede030407c351abfbf2bfc93d8b7a Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Fri, 18 Oct 2019 14:20:55 +0200 Subject: new page render system create html files in `/render` folder --- app/class/modelrender.php | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'app/class/modelrender.php') diff --git a/app/class/modelrender.php b/app/class/modelrender.php index 3db21f6..d74ddec 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -36,23 +36,35 @@ class Modelrender extends Modelart return $this->router->generate('artread/', ['art' => $id]); } - public function renderhead(Art2 $art) + + /** + * Main function + * + * @param Art2 $art page to render + */ + public function render(Art2 $art) { $this->art = $art; - $head = $this->gethead(); - $this->write(); - return $head; + $this->write($this->gethmtl()); } - public function renderbody(Art2 $art) + /** + * Combine body and head to create html file + * + * @return string html string + */ + public function gethmtl() { - $this->art = $art; + + $head = $this->gethead(); $body = $this->getbody($this->readbody()); $parsebody = $this->parser($body); - return $parsebody; - } + $html = '' . PHP_EOL . '' . PHP_EOL . '' . PHP_EOL . $head . PHP_EOL . '' . PHP_EOL . $parsebody . PHP_EOL . ''; + + return $html; + } public function readbody() @@ -166,8 +178,12 @@ class Modelrender extends Modelart } - public function write() + /** + * Write css javascript and html as files in the assets folder + */ + public function write(string $html) { + file_put_contents(Model::HTML_RENDER_DIR . $this->art->id() . '.html', $html); file_put_contents(Model::RENDER_DIR . $this->art->id() . '.css', $this->art->css()); //file_put_contents(Model::RENDER_DIR . $this->art->id() . '.quick.css', $this->art->quickcss()); file_put_contents(Model::RENDER_DIR . $this->art->id() . '.js', $this->art->javascript()); @@ -226,8 +242,11 @@ class Modelrender extends Modelart if (!empty($this->art->templatecss() && in_array('externalcss', $this->art->templateoptions()))) { $templatecss = $this->get($this->art->templatecss()); - foreach ($templatecss->externalcss() as $externalcss) { - $head .= '' . PHP_EOL; + if($templatecss !== false) { + + foreach ($templatecss->externalcss() as $externalcss) { + $head .= '' . PHP_EOL; + } } } -- cgit v1.2.3