aboutsummaryrefslogtreecommitdiff
path: root/app/class/modelrender.php
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2019-10-18 14:20:55 +0200
committervincent-peugnet <v.peugnet@free.fr>2019-10-18 14:20:55 +0200
commit1d011471674ede030407c351abfbf2bfc93d8b7a (patch)
tree91bbe902de1d9c31eea09eb3961781f5886cf70c /app/class/modelrender.php
parent8b6848dfb5d469076f05be226e862fab928cd53f (diff)
downloadwcms-1d011471674ede030407c351abfbf2bfc93d8b7a.tar.gz
wcms-1d011471674ede030407c351abfbf2bfc93d8b7a.zip
new page render system
create html files in `/render` folder
Diffstat (limited to 'app/class/modelrender.php')
-rw-r--r--app/class/modelrender.php41
1 files changed, 30 insertions, 11 deletions
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 = '<!DOCTYPE html>' . PHP_EOL . '<html>' . PHP_EOL . '<head>' . PHP_EOL . $head . PHP_EOL . '</head>' . PHP_EOL . $parsebody . PHP_EOL . '</html>';
+
+ 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 .= '<link href="' . $externalcss . '" rel="stylesheet" />' . PHP_EOL;
+ if($templatecss !== false) {
+
+ foreach ($templatecss->externalcss() as $externalcss) {
+ $head .= '<link href="' . $externalcss . '" rel="stylesheet" />' . PHP_EOL;
+ }
}
}