aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--public/test.php13
-rw-r--r--w/class/art2.php8
-rw-r--r--w/class/config.php6
-rw-r--r--w/class/controllerart.php41
-rw-r--r--w/class/modelart.php1
-rw-r--r--w/class/modelrender.php274
-rw-r--r--w/view/templates/arthead.php6
-rw-r--r--w/view/templates/navart.php2
-rw-r--r--w/view/templates/read.php34
-rw-r--r--w/view/templates/readerlayout.php15
11 files changed, 275 insertions, 126 deletions
diff --git a/.gitignore b/.gitignore
index 83e04f8..c278a95 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ public/w/css/*
public/w/css/*/*
public/w/js/*
public/index.html
+public/render/* \ No newline at end of file
diff --git a/public/test.php b/public/test.php
index 35c8575..7e24cd6 100644
--- a/public/test.php
+++ b/public/test.php
@@ -2,10 +2,21 @@
require('../w/class/art2.php');
+require('../w/class/render.php');
+
+$render = new Render(['head' => 'ccccccc', 'body' => 'vvvvvvvvvvvv']);
+
+$render2 = ['head' => 'nnnnnnnnnn', 'body' => 'bbbbbbbbbbbbbbbbbbbbbbb'];
+
+$render3 = json_decode(json_encode($render2));
+
+var_dump($render3);
+
+var_dump($render);
$art = new Art2(['id' => 'rr']);
$art->reset();
-$art->hydrate((['description' => 'fdsfs', 'secure' => 0]));
+$art->hydrate((['description' => 'fdsfs', 'secure' => 0, 'render' => $render2]));
var_dump($art);
diff --git a/w/class/art2.php b/w/class/art2.php
index 5bad524..970058b 100644
--- a/w/class/art2.php
+++ b/w/class/art2.php
@@ -82,7 +82,7 @@ class Art2
$this->setaside('');
$this->setfooter('');
$this->setrender('');
- $this->setsecure(2);
+ $this->setsecure(3);
$this->setinvitepassword('invitepassword');
$this->setinterface('section');
$this->setlinkfrom([]);
@@ -276,7 +276,9 @@ class Art2
public function render($type = 'string')
{
- return $this->render;
+ if($type == 'string') {
+ return $this->render;
+ }
}
public function secure($type = 'int')
@@ -496,7 +498,7 @@ class Art2
}
}
- public function setrender($render)
+ public function setrender(string $render)
{
$this->render = $render;
}
diff --git a/w/class/config.php b/w/class/config.php
index 3dd93b2..ead4a40 100644
--- a/w/class/config.php
+++ b/w/class/config.php
@@ -16,6 +16,7 @@ abstract class Config
protected static $read;
protected static $color4;
protected static $fontsize = 6;
+ protected static $renderpath = './render/';
// _______________________________________ F U N _______________________________________
@@ -124,6 +125,11 @@ abstract class Config
return self::$fontsize;
}
+ public static function renderpath()
+ {
+ return self::$renderpath;
+ }
+
// __________________________________________ S E T ______________________________________
diff --git a/w/class/controllerart.php b/w/class/controllerart.php
index 340e8e5..4abc572 100644
--- a/w/class/controllerart.php
+++ b/w/class/controllerart.php
@@ -5,16 +5,17 @@ class Controllerart extends Controllerdb
/** @var Art2 */
protected $art;
protected $artmanager;
- protected $renderengine;
-
+ protected $renderengine;
+
public function __construct($id)
{
parent::__construct();
-
-
+
+
$this->art = new Art2(['id' => $id]);
$this->artmanager = new Modelart();
$this->renderengine = new Modelrender();
+
}
public function importart()
@@ -31,14 +32,40 @@ class Controllerart extends Controllerdb
public function read()
{
+ $now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
+
$artexist = $this->importart();
- $display = $this->user->level() >= $this->art->secure();
+ $canread = $this->user->level() >= $this->art->secure();
$cancreate = $this->user->cancreate();
+ $alerts = ['alertnotexist' => 'This page does not exist yet', 'alertprivate' => 'You cannot see this page'];
+ $body = '';
+ $head = '';
+
+
+ if ($artexist) {
+
+ if ($this->art->daterender() < $this->art->datemodif()) {
+ $body = $this->renderengine->renderbody($this->art);
+ $this->art->setrender($body);
+ $this->art->setdaterender($now);
+ $this->artmanager->update($this->art);
+ } else {
+ $body = $this->art->render();
+ }
+
+ $head = $this->renderengine->renderhead($this->art);
+
+ $this->art->addaffcount();
+ $this->artmanager->update($this->art);
+
+ }
+
+
+ $data = array_merge($alerts, ['art' => $this->art, 'artexist' => $artexist, 'canread' => $canread, 'cancreate' => $cancreate, 'readernav' => true, 'body' => $body, 'head' => $head]);
- $renderbody = $this->renderengine->render($this->art);
- //$this->showtemplate('read', ['art' => $this->art, 'artexist' => $artexist, 'display' => $display, 'cancreate' => $cancreate]);
+ $this->showtemplate('read', $data);
diff --git a/w/class/modelart.php b/w/class/modelart.php
index 37262ad..39ef50f 100644
--- a/w/class/modelart.php
+++ b/w/class/modelart.php
@@ -30,6 +30,7 @@ class Modelart extends Modeldb
{
$artdata = new \JamesMoss\Flywheel\Document($art->dry());
+ var_dump($artdata);
$artdata->setId($art->id());
$this->artstore->store($artdata);
}
diff --git a/w/class/modelrender.php b/w/class/modelrender.php
index 838765f..963962b 100644
--- a/w/class/modelrender.php
+++ b/w/class/modelrender.php
@@ -10,17 +10,18 @@ class Modelrender extends Modelart
parent::__construct();
}
+ public function renderhead(Art2 $art)
+ {
+
+ $head = $this->gethead($art);
+ $this->write($art);
+ return $head;
+ }
- public function render(Art2 $art)
+ public function renderbody(Art2 $art)
{
$body = $this->getbody($art);
-
- var_dump($body);
-
$parsebody = $this->parser($art, $body);
-
- echo $parsebody;
-
return $parsebody;
}
@@ -36,160 +37,219 @@ class Modelrender extends Modelart
} else {
$text = $art->$element();
}
- $body .= PHP_EOL . '<' . $element . '>' . PHP_EOL . $this->markdown($text) . PHP_EOL . '</' . $element . '>' . PHP_EOL;
+ if ($element == 'section') {
+ $body .= PHP_EOL . '<' . $element . '><article>' . PHP_EOL . $this->markdown($text) . PHP_EOL . '</article></' . $element . '>' . PHP_EOL;
+ } else {
+ $body .= PHP_EOL . '<' . $element . '>' . PHP_EOL . $this->markdown($text) . PHP_EOL . '</' . $element . '>' . PHP_EOL;
+ }
}
return $body;
}
- public function elementsrender(Art2 $art)
+ public function write(Art2 $art)
{
- foreach ($this->getelements($art) as $element => $text) {
- if (in_array($element, self::TEXT_ELEMENTS)) {
- $elements[$element] = $this->markdown($text);
- }
- }
- return $elements;
+ file_put_contents(Config::renderpath() . $art->id() . '.css', $art->css());
+ file_put_contents(Config::renderpath() . $art->id() . '.quick.css', $art->quickcss());
+ file_put_contents(Config::renderpath() . $art->id() . '.js', $art->javascript());
}
+ public function writetemplates(Art2 $art)
+ {
+ if (array_key_exists('css', $art->template('array'))) {
+ $tempaltecssart = $this->get($art->template('array')['css']);
+ file_put_contents(Config::renderpath() . $tempaltecssart->id() . '.css', $tempaltecssart->css());
+ }
+ if (array_key_exists('quickcss', $art->template('array'))) {
+ $tempaltequickcssart = $this->get($art->template('array')['quickcss']);
+ file_put_contents(Config::renderpath() . $tempaltequickcssart->id() . '.quick.css', $tempaltequickcssart->quickcss());
+ }
+ if (array_key_exists('javascript', $art->template('array'))) {
+ $templatejsart = $this->get($art->template('array')['javascript']);
+ file_put_contents(Config::renderpath() . $templatejsart->id() . '.js', $templatejsart->javascript());
+ }
+ }
- public function parser(Art2 $art, string $text)
+ public function gethead(Art2 $art)
{
- $text = str_replace('%TITLE%', $art->title(), $text);
- $text = str_replace('%DESCRIPTION%', $art->description(), $text);
+ $head = '';
- $text = str_replace(self::SUMMARY, $this->sumparser($text), $text);
+ $head .= '<meta charset="utf8" />' . PHP_EOL;
+ $head .= '<title>'.$art->title() .'</title>' . PHP_EOL;
+ $head .= '<meta name="description" content="'.$art->description() .'" />' . PHP_EOL;
+ $head .= '<meta name="viewport" content="width=device-width" />' . PHP_EOL;
- $text = str_replace('href="=', 'href="?id=', $text);
-
- $text = $this->tooltip($art->linkfrom('array'), $text);
-
- $text = str_replace('href="http', ' class="external" target="_blank" href="http', $text);
- $text = str_replace('<img src="/', '<img src="./media/', $text);
- $text = $this->autourl($text);
+ if (array_key_exists('css', $art->template('array'))) {
+ $tempaltecssart = $art->template('array')['css'];
+ $head .= '<link href="' . Config::renderpath() . $tempaltecssart . '.css" rel="stylesheet" />' . PHP_EOL;
+ }
+ $head .= '<link href="' . Config::renderpath() . $art->id() . '.css" rel="stylesheet" />' . PHP_EOL;
+ if (array_key_exists('quickcss', $art->template('array'))) {
+ $tempaltequickcssart = $art->template('array')['quickcss'];
+ $head .= '<link href="' . Config::renderpath() . $tempaltequickcssart . '.quick.css" rel="stylesheet" />' . PHP_EOL;
+ }
+ $head .= '<link href="' . Config::renderpath() . $art->id() . '.quick.css" rel="stylesheet" />' . PHP_EOL;
+ if (array_key_exists('javascript', $art->template('array'))) {
+ $templatejsart = $art->template('array')['javascript'];
+ $head .= '<script src="' . Config::renderpath() . $templatejsart . '.js" /></script>' . PHP_EOL;
+ }
+ $head .= '<script src="' . Config::renderpath() . $art->id() . '.js" /></script>' . PHP_EOL;
- return $text;
+ return $head;
+}
+
+public function elementsrender(Art2 $art)
+{
+ foreach ($this->getelements($art) as $element => $text) {
+ if (in_array($element, self::TEXT_ELEMENTS)) {
+ $elements[$element] = $this->markdown($text);
+ }
}
+ return $elements;
+}
- public function autourl($text)
- {
- $text = preg_replace('#( |\R|>)(https?:\/\/((\S+)\.([^< ]+)))#', '$1<a href="$2" class="external" target="_blank">$3</a>', $text);
- return $text;
- }
+
+public function parser(Art2 $art, string $text)
+{
+ $text = str_replace('%TITLE%', $art->title(), $text);
+ $text = str_replace('%DESCRIPTION%', $art->description(), $text);
+
+
+ $text = str_replace(self::SUMMARY, $this->sumparser($text), $text);
+
+ $text = str_replace('href="=', 'href="?id=', $text);
+
+ $text = $this->tooltip($art->linkfrom('array'), $text);
+
+ $text = str_replace('href="http', ' class="external" target="_blank" href="http', $text);
+ $text = str_replace('<img src="/', '<img src="./media/', $text);
+
+ $text = $this->autourl($text);
+
+ return $text;
+}
+
+
+public function autourl($text)
+{
+ $text = preg_replace('#( |\R|>)(https?:\/\/((\S+)\.([^< ]+)))#', '$1<a href="$2" class="external" target="_blank">$3</a>', $text);
+ return $text;
+}
- public function markdown($text)
- {
+public function markdown($text)
+{
//use Michelf\MarkdownExtra;
- $fortin = new 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;
- }
+ $fortin->header_id_func = function ($header) {
+ return preg_replace('/[^\w]/', '', strtolower($header));
+ };
+ $fortin->hard_wrap = true;
+ $text = $fortin->transform($text);
+ return $text;
+}
- public function tooltip(array $linkfrom, string $text)
- {
- $descriptions = [];
- $artlist = $this->getlisterid($linkfrom);
- foreach ($artlist as $art) {
- $descriptions[$art->id()] = $art->description();
- }
+public function tooltip(array $linkfrom, string $text)
+{
+ $descriptions = [];
+ $artlist = $this->getlisterid($linkfrom);
+ foreach ($artlist as $art) {
+ $descriptions[$art->id()] = $art->description();
+ }
- foreach ($linkfrom as $id) {
- if (isset($descriptions[$id])) {
- $title = $descriptions[$id];
- }
- $linkfrom = 'href="?id=' . $id . '"';
- $titlelinkfrom = ' title="' . $title . '" ' . $linkfrom;
- $text = str_replace($linkfrom, $titlelinkfrom, $text);
+ foreach ($linkfrom as $id) {
+ if (isset($descriptions[$id])) {
+ $title = $descriptions[$id];
}
- return $text;
+ $linkfrom = 'href="?id=' . $id . '"';
+ $titlelinkfrom = ' title="' . $title . '" ' . $linkfrom;
+ $text = str_replace($linkfrom, $titlelinkfrom, $text);
}
+ return $text;
+}
-
- function sumparser($text)
- {
- preg_match_all('#<h([1-6]) id="(\w+)">(.+)</h[1-6]>#iU', $text, $out);
+function sumparser($text)
+{
+ preg_match_all('#<h([1-6]) id="(\w+)">(.+)</h[1-6]>#iU', $text, $out);
- $sum = [];
- foreach ($out[2] as $key => $value) {
- $sum[$value][$out[1][$key]] = $out[3][$key];
- }
+
+ $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 .= '<ul>';
- }
- $sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>';
- } elseif ($h < $last) {
- for ($i = 1; $i <= ($last - $h); $i++) {
- $sumstring .= '</ul>';
- }
- $sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>';
- } elseif ($h = $last) {
- $sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>';
+ $sumstring = '';
+ $last = 0;
+ foreach ($sum as $title => $list) {
+ foreach ($list as $h => $link) {
+ if ($h > $last) {
+ for ($i = 1; $i <= ($h - $last); $i++) {
+ $sumstring .= '<ul>';
}
- $last = $h;
+ $sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>';
+ } elseif ($h < $last) {
+ for ($i = 1; $i <= ($last - $h); $i++) {
+ $sumstring .= '</ul>';
+ }
+ $sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>';
+ } elseif ($h = $last) {
+ $sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>';
}
+ $last = $h;
}
- for ($i = 1; $i <= ($last); $i++) {
- $sumstring .= '</ul>';
- }
- return $sumstring;
}
+ for ($i = 1; $i <= ($last); $i++) {
+ $sumstring .= '</ul>';
+ }
+ return $sumstring;
+}
//tag auto menu
- public function autotaglist()
- {
- $pattern = "/%%(\w*)%%/";
- preg_match_all($pattern, $this->md(), $out);
- return $out[1];
+public function autotaglist()
+{
+ $pattern = "/%%(\w*)%%/";
+ preg_match_all($pattern, $this->md(), $out);
+ return $out[1];
- }
+}
- public function autotaglistupdate($taglist)
- {
- foreach ($taglist as $tag => $artlist) {
- $replace = '<ul>';
- foreach ($artlist as $art) {
- $replace .= '<li><a href="?id=' . $art->id() . '" title="' . $art->description() . '">' . $art->title() . '</a></li>';
- }
- $replace .= '</ul>';
- $text = str_replace('%%' . $tag . '%%', $replace, $text);
+public function autotaglistupdate($taglist)
+{
+ foreach ($taglist as $tag => $artlist) {
+ $replace = '<ul>';
+ foreach ($artlist as $art) {
+ $replace .= '<li><a href="?id=' . $art->id() . '" title="' . $art->description() . '">' . $art->title() . '</a></li>';
}
+ $replace .= '</ul>';
+ $text = str_replace('%%' . $tag . '%%', $replace, $text);
}
+}
- public function autotaglistcalc($taglist)
- {
- foreach ($taglist as $tag => $artlist) {
- foreach ($artlist as $art) {
- if (!in_array($art->id(), $this->linkfrom('array')) && $art->id() != $this->id()) {
- $this->linkfrom[] = $art->id();
- }
+public function autotaglistcalc($taglist)
+{
+ foreach ($taglist as $tag => $artlist) {
+ foreach ($artlist as $art) {
+ if (!in_array($art->id(), $this->linkfrom('array')) && $art->id() != $this->id()) {
+ $this->linkfrom[] = $art->id();
}
}
}
+}
diff --git a/w/view/templates/arthead.php b/w/view/templates/arthead.php
new file mode 100644
index 0000000..b137c7f
--- /dev/null
+++ b/w/view/templates/arthead.php
@@ -0,0 +1,6 @@
+<meta charset="utf8" />
+<meta name="viewport" content="width=device-width" />
+<link rel="shortcut icon" href="./media/logo.png" type="image/x-icon">
+<title><?= $title ?></title>
+<meta name="description" content="<?= $description ?>">
+<link rel="stylesheet" href="./css/soft.css"> \ No newline at end of file
diff --git a/w/view/templates/navart.php b/w/view/templates/navart.php
index 0ddba17..d591307 100644
--- a/w/view/templates/navart.php
+++ b/w/view/templates/navart.php
@@ -1,4 +1,4 @@
-<div class="menu">
+<div class="menu" style="all: initial; position: fixed; top: 0; right: 0;">
<?= $user->level() ?>
<div id="dropmenu">
diff --git a/w/view/templates/read.php b/w/view/templates/read.php
index 4964a47..35b1e7d 100644
--- a/w/view/templates/read.php
+++ b/w/view/templates/read.php
@@ -1,6 +1,22 @@
-<?php $this->layout('layout', ['title' => $art->title(), 'description' => $art->description()]) ?>
+<?php $this->layout('readerlayout') ?>
+<?php
+$this->start('head');
+if ($artexist) {
+ if ($canread) {
+ echo $head;
+ } else {
+ $this->insert('arthead', ['title' => $art->title(), 'description' => $art->description()]);
+ }
+} else {
+ $this->insert('arthead', ['title' => $art->id(), 'description' => $alertnotexist]);
+}
+
+
+
+$this->stop();
+?>
@@ -16,22 +32,26 @@
- <?php $this->insert('navart', ['user' => $user, 'art' => $art, 'artexist' => $artexist]) ?>
+ <?php
+ if ($readernav) {
+ $this->insert('navart', ['user' => $user, 'art' => $art, 'artexist' => $artexist]);
+ }
+ ?>
<?php
- if($artexist) {
+ if ($artexist) {
- if($display) {
- $this->insert('readart', ['art' => $art]);
+ if ($canread) {
+ echo $body;
} else {
- echo '<h1>You dont have enought rights to see this article</h1>';
+ echo '<h1>'.$alertprivate.'</h1>';
}
} else {
- echo '<h1>This article does not exist yet</h1>';
+ echo '<h1>' . $alertnotexist . '</h1>';
if ($cancreate) {
$this->insert('readcreate', ['id' => $art->id()]);
}
diff --git a/w/view/templates/readerlayout.php b/w/view/templates/readerlayout.php
new file mode 100644
index 0000000..51ab406
--- /dev/null
+++ b/w/view/templates/readerlayout.php
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+ <?=$this->section('head')?>
+
+
+</head>
+
+
+
+<?=$this->section('page')?>
+
+
+</html> \ No newline at end of file