aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--app/class/art2.php28
-rw-r--r--app/class/controllerart.php17
-rw-r--r--app/class/controllermedia.php6
-rw-r--r--app/class/model.php17
-rw-r--r--app/class/modelart.php14
-rw-r--r--app/class/modelmedia.php26
-rw-r--r--app/class/modelrender.php41
-rw-r--r--composer.json2
9 files changed, 74 insertions, 78 deletions
diff --git a/.gitignore b/.gitignore
index caf0c5b..c75be90 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@ assets/global/*
database/*
fonts/*
media/*
+render/
vendor/*
config.json
error_log
diff --git a/app/class/art2.php b/app/class/art2.php
index 4561773..754ba14 100644
--- a/app/class/art2.php
+++ b/app/class/art2.php
@@ -21,8 +21,6 @@ class Art2
protected $footer;
protected $externalcss;
protected $customhead;
- protected $renderhead;
- protected $renderbody;
protected $secure;
protected $interface;
protected $linkfrom;
@@ -92,8 +90,6 @@ class Art2
$this->setfooter('');
$this->setexternalcss([]);
$this->setcustomhead('');
- $this->setrenderhead('');
- $this->setrenderbody('');
$this->setsecure(Config::defaultprivacy());
$this->setinterface('main');
$this->setlinkfrom([]);
@@ -308,20 +304,6 @@ class Art2
return $this->footer;
}
- public function renderhead($type = 'string')
- {
- if ($type == 'string') {
- return $this->renderhead;
- }
- }
-
- public function renderbody($type = 'string')
- {
- if ($type == 'string') {
- return $this->renderbody;
- }
- }
-
public function secure($type = 'int')
{
if ($type == 'string') {
@@ -631,16 +613,6 @@ class Art2
}
}
- public function setrenderhead(string $render)
- {
- $this->renderhead = $render;
- }
-
- public function setrenderbody(string $render)
- {
- $this->renderbody = $render;
- }
-
public function setsecure($secure)
{
if ($secure >= 0 and $secure <= self::SECUREMAX) {
diff --git a/app/class/controllerart.php b/app/class/controllerart.php
index 5a9634b..8d8e3bb 100644
--- a/app/class/controllerart.php
+++ b/app/class/controllerart.php
@@ -99,10 +99,7 @@ class Controllerart extends Controller
$renderengine = new Modelrender($this->router);
- $body = $renderengine->renderbody($art);
- $head = $renderengine->renderhead($art);
- $art->setrenderbody($body);
- $art->setrenderhead($head);
+ $renderengine->render($art);
$art->setdaterender($now);
$art->setlinkfrom($renderengine->linkfrom());
$art->setlinkto($renderengine->linkto());
@@ -140,7 +137,6 @@ class Controllerart extends Controller
}
$this->art = $this->renderart($this->art);
}
- $page = ['head' => $this->art->renderhead(), 'body' => $this->art->renderbody()];
if ($canread) {
$this->art->addaffcount();
if ($this->user->level() < 2) {
@@ -149,12 +145,17 @@ class Controllerart extends Controller
}
$this->artmanager->update($this->art);
}
- $data = array_merge($page, ['art' => $this->art, 'artexist' => $artexist , 'readernav' => Config::showeditmenu(), 'canedit' => $this->canedit()]);
if($artexist && $canread) {
- $this->showtemplate('read', $data);
+ $filedir = Model::HTML_RENDER_DIR . $id . '.html';
+ if(file_exists($filedir)) {
+ $html = file_get_contents($filedir);
+ echo $html;
+ } else {
+ echo 'Please render this page';
+ }
} else {
- $this->showtemplate('alert', $data);
+ $this->showtemplate('alert', ['art' => $this->art, 'artexist' => $artexist, 'canedit' => $this->canedit()]);
}
}
diff --git a/app/class/controllermedia.php b/app/class/controllermedia.php
index 93ab218..6cde0ce 100644
--- a/app/class/controllermedia.php
+++ b/app/class/controllermedia.php
@@ -19,13 +19,13 @@ class Controllermedia extends Controller
{
if ($this->user->iseditor()) {
- if (!$this->mediamanager->basedircheck()) {
+ if (!$this->mediamanager->dircheck(Model::MEDIA_DIR)) {
throw new Exception("Media error : Cant create /media folder");
}
- if (!$this->mediamanager->favicondircheck()) {
+ if (!$this->mediamanager->dircheck(Model::FAVICON_DIR)) {
throw new Exception("Media error : Cant create /media/favicon folder");
}
- if (!$this->mediamanager->thumbnaildircheck()) {
+ if (!$this->mediamanager->dircheck(Model::THUMBNAIL_DIR)) {
throw new Exception("Media error : Cant create /media/thumbnail folder");
}
diff --git a/app/class/model.php b/app/class/model.php
index 6f5a62d..45ac2d1 100644
--- a/app/class/model.php
+++ b/app/class/model.php
@@ -12,6 +12,7 @@ abstract class Model
const THUMBNAIL_DIR = 'media' . DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR;
const TEMPLATES_DIR = '.'. DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
const RENDER_DIR = 'assets'. DIRECTORY_SEPARATOR . 'render' . DIRECTORY_SEPARATOR;
+ const HTML_RENDER_DIR = 'render' . DIRECTORY_SEPARATOR;
const GLOBAL_DIR = 'assets'. DIRECTORY_SEPARATOR . 'global' . DIRECTORY_SEPARATOR;
const DATABASE_DIR = '.' . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR;
@@ -92,4 +93,20 @@ abstract class Model
return self::dirtopath(Model::ICONS_DIR);
}
+ /**
+ * Check if dir exist. If not, create it
+ *
+ * @param string $dir Directory to check
+ *
+ * @return bool return true if the dir already exist or was created succesfullt. Otherwise return false
+ */
+ public function dircheck(string $dir) : bool
+ {
+ if (!is_dir($dir)) {
+ return mkdir($dir);
+ } else {
+ return true;
+ }
+ }
+
}
diff --git a/app/class/modelart.php b/app/class/modelart.php
index 8462675..8dee09c 100644
--- a/app/class/modelart.php
+++ b/app/class/modelart.php
@@ -11,6 +11,9 @@ class Modelart extends Modeldb
{
parent::__construct();
$this->storeinit(Config::arttable());
+ if(!$this->dircheck(Model::HTML_RENDER_DIR)) {
+ throw new Exception("Media error : Cant create /rendernew folder");
+ }
}
/**
@@ -50,7 +53,13 @@ class Modelart extends Modeldb
$this->repo->store($artdata);
}
-
+ /**
+ * Obtain a page object from the database
+ *
+ * @param Art2|string $id could be an Art2 object or a id string
+ *
+ * @return Art2|false The Art2 object or false if it does not exist.
+ */
public function get($id)
{
if ($id instanceof Art2) {
@@ -120,6 +129,9 @@ class Modelart extends Modeldb
unlink(Model::RENDER_DIR . $artid . $file);
}
}
+ if(file_exists(Model::HTML_RENDER_DIR . $artid . '.html')) {
+ unlink(Model::HTML_RENDER_DIR . $artid . '.html');
+ }
}
public function update(Art2 $art)
diff --git a/app/class/modelmedia.php b/app/class/modelmedia.php
index c2c1b47..8cd0224 100644
--- a/app/class/modelmedia.php
+++ b/app/class/modelmedia.php
@@ -6,32 +6,6 @@ class Modelmedia extends Model
const MEDIA_SORTBY = ['id', 'size', 'type'];
- public function basedircheck()
- {
- if (!is_dir(Model::MEDIA_DIR)) {
- return mkdir(Model::MEDIA_DIR);
- } else {
- return true;
- }
- }
-
- public function favicondircheck()
- {
- if (!is_dir(Model::FAVICON_DIR)) {
- return mkdir(Model::FAVICON_DIR);
- } else {
- return true;
- }
- }
-
- public function thumbnaildircheck()
- {
- if (!is_dir(Model::THUMBNAIL_DIR)) {
- return mkdir(Model::THUMBNAIL_DIR);
- } else {
- return true;
- }
- }
/**
* Get the Media Object
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;
+ }
}
}
diff --git a/composer.json b/composer.json
index 72053b6..d1c01b7 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
{
"name": "w-cms",
"description": "point'n think",
- "version": "1.5.7",
+ "version": "1.6.0",
"require": {
"michelf/php-markdown": "^1.8",
"league/plates": "3.*",