diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2018-11-28 10:30:41 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2018-11-28 10:30:41 +0100 |
commit | afad95324de8f078e9f3dedc66df66b6c2eebe72 (patch) | |
tree | 989a3890dc563cb1903fc3f78d0c7f4fe2598ef0 | |
parent | 0660c99cb9e2dae3b0e41975f643609231258147 (diff) | |
download | wcms-afad95324de8f078e9f3dedc66df66b6c2eebe72.tar.gz wcms-afad95324de8f078e9f3dedc66df66b6c2eebe72.zip |
force render button
-rw-r--r-- | app/class/art2.php | 43 | ||||
-rw-r--r-- | app/class/controllerart.php | 61 | ||||
-rw-r--r-- | app/class/modelart.php | 2 | ||||
-rw-r--r-- | app/class/modelrender.php | 115 | ||||
-rw-r--r-- | app/class/routes.php | 1 | ||||
-rw-r--r-- | app/view/templates/edittabs.php | 2 | ||||
-rw-r--r-- | app/view/templates/navart.php | 3 | ||||
-rw-r--r-- | assets/css/edit.css | 8 |
8 files changed, 137 insertions, 98 deletions
diff --git a/app/class/art2.php b/app/class/art2.php index 8c48dee..000c391 100644 --- a/app/class/art2.php +++ b/app/class/art2.php @@ -13,13 +13,14 @@ class Art2 protected $css; protected $quickcss; protected $javascript; - protected $html; + protected $body; protected $header; protected $section; protected $nav; protected $aside; protected $footer; - protected $render; + protected $renderhead; + protected $renderbody; protected $secure; protected $invitepassword; protected $interface; @@ -36,7 +37,7 @@ class Art2 const LENCOULEUR = 7; const DEBUT = '(?id='; const FIN = ')'; - const TABS = ['section', 'css', 'header', 'html', 'nav', 'aside', 'footer', 'javascript']; + const TABS = ['section', 'css', 'header', 'body', 'nav', 'aside', 'footer', 'javascript']; const VAR_DATE = ['date', 'datecreation', 'datemodif', 'daterender']; @@ -46,6 +47,7 @@ class Art2 public function __construct($datas = []) { + $this->reset(); $this->hydrate($datas); } @@ -75,13 +77,14 @@ class Art2 $this->setcss(''); $this->setquickcss([]); $this->setjavascript(''); - $this->sethtml(''); + $this->setbody(''); $this->setheader(''); $this->setsection(''); $this->setnav(''); $this->setaside(''); $this->setfooter(''); - $this->setrender(''); + $this->setrenderhead(''); + $this->setrenderbody(''); $this->setsecure(3); $this->setinvitepassword('invitepassword'); $this->setinterface('section'); @@ -238,9 +241,9 @@ class Art2 return $this->javascript; } - public function html($type = 'string') + public function body($type = 'string') { - return $this->html; + return $this->body; } public function header($type = 'string') @@ -278,10 +281,17 @@ class Art2 return $this->footer; } - public function render($type = 'string') + public function renderhead($type = 'string') { if($type == 'string') { - return $this->render; + return $this->renderhead; + } + } + + public function renderbody($type = 'string') + { + if($type == 'string') { + return $this->renderbody; } } @@ -462,10 +472,10 @@ class Art2 } - public function sethtml($html) + public function setbody($body) { - if (strlen($html < self::LENTEXT && is_string($html))) { - $this->html = $html; + if (strlen($body < self::LENTEXT && is_string($body))) { + $this->body = $body; } } @@ -504,9 +514,14 @@ class Art2 } } - public function setrender(string $render) + public function setrenderhead(string $render) + { + $this->renderhead = $render; + } + + public function setrenderbody(string $render) { - $this->render = $render; + $this->renderbody = $render; } public function setsecure($secure) diff --git a/app/class/controllerart.php b/app/class/controllerart.php index 7a0ec93..f766d12 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -13,7 +13,6 @@ class Controllerart extends Controller parent::__construct($router); $this->artmanager = new Modelart(); - $this->renderengine = new Modelrender($router); $this->fontmanager = new Modelfont(); } @@ -21,7 +20,7 @@ class Controllerart extends Controller public function setart(string $id, string $route) { $cleanid = idclean($id); - if($cleanid !== $id) { + if ($cleanid !== $id) { $this->routedirect($route, ['art' => $cleanid]); } $this->art = new Art2(['id' => $cleanid]); @@ -42,10 +41,10 @@ class Controllerart extends Controller public function canedit() { - if($this->user->iseditor()) { + if ($this->user->iseditor()) { return true; - } elseif($this->user->isinvite()) { - if($this->user->password() === $this->art->invitepassword()) { + } elseif ($this->user->isinvite()) { + if ($this->user->password() === $this->art->invitepassword()) { return true; } else { return false; @@ -55,42 +54,54 @@ class Controllerart extends Controller } } + function render($id) + { + $this->setart($id, 'artupdate'); - public function read($id) + if ($this->importart() && $this->user->iseditor()) { + $this->renderart(); + $this->artmanager->update($this->art); + } + $this->routedirect('artread/', ['art' => $this->art->id()]); + } + + public function renderart() { - $this->setart($id, 'artread/'); $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $this->renderengine = new Modelrender($this->router); + + $body = $this->renderengine->renderbody($this->art); + $head = $this->renderengine->renderhead($this->art); + $this->art->setrenderbody($body); + $this->art->setrenderhead($head); + $this->art->setdaterender($now); + $this->art->setlinkfrom($this->renderengine->linkfrom()); + + return ['head' => $head, 'body' => $body]; + + } + + + public function read($id) + { + $this->setart($id, 'artread/'); $artexist = $this->importart(); $canread = $this->user->level() >= $this->art->secure(); $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->art->setlinkfrom($this->renderengine->linkfrom()); + $page = $this->renderart(); } else { - $body = $this->art->render(); + $page = ['head' => $this->art->renderhead(), 'body' => $this->art->renderbody()]; } - - $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, 'readernav' => true, 'body' => $body, 'head' => $head]); - + $data = array_merge($alerts, $page, ['art' => $this->art, 'artexist' => $artexist, 'canread' => $canread, 'readernav' => true]); $this->showtemplate('read', $data); @@ -104,7 +115,7 @@ class Controllerart extends Controller if ($this->importart() && $this->canedit()) { - $tablist = ['section' => $this->art->md(), 'css' => $this->art->css(), 'header' => $this->art->header(), 'nav' => $this->art->nav(), 'aside' => $this->art->aside(), 'footer' => $this->art->footer(), 'html' => $this->art->html(), 'javascript' => $this->art->javascript()]; + $tablist = ['section' => $this->art->md(), 'css' => $this->art->css(), 'header' => $this->art->header(), 'nav' => $this->art->nav(), 'aside' => $this->art->aside(), 'footer' => $this->art->footer(), 'body' => $this->art->body(), 'javascript' => $this->art->javascript()]; $artlist = $this->artmanager->list(); diff --git a/app/class/modelart.php b/app/class/modelart.php index d887436..8117284 100644 --- a/app/class/modelart.php +++ b/app/class/modelart.php @@ -2,7 +2,7 @@ class Modelart extends Modeldb { - const SELECT = ['title', 'id', 'description', 'tag', 'date', 'datecreation', 'datemodif', 'daterender', 'css', 'quickcss', 'javascript', 'html', 'header', 'section', 'nav', 'aside', 'footer', 'render', 'secure', 'invitepassword', 'interface', 'linkfrom', 'linkto', 'template', 'affcount', 'editcount']; + const SELECT = ['title', 'id', 'description', 'tag', 'date', 'datecreation', 'datemodif', 'daterender', 'css', 'quickcss', 'javascript', 'body', 'header', 'section', 'nav', 'aside', 'footer', 'render', 'secure', 'invitepassword', 'interface', 'linkfrom', 'linkto', 'template', 'affcount', 'editcount']; const BY = ['datecreation', 'title', 'id', 'description', 'datemodif', 'secure']; const ORDER = ['DESC', 'ASC']; diff --git a/app/class/modelrender.php b/app/class/modelrender.php index e00dcc8..37bc741 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -3,6 +3,7 @@ class Modelrender extends Modelart { protected $router; + protected $art; protected $artlist; protected $linkfrom = []; protected $sum = []; @@ -25,35 +26,37 @@ class Modelrender extends Modelart public function renderhead(Art2 $art) { + $this->art = $art; - $head = $this->gethead($art); - $this->write($art); + $head = $this->gethead(); + $this->write(); return $head; } public function renderbody(Art2 $art) { - $body = $this->getbody($this->gethtml($art), $this->getelements($art)); - $parsebody = $this->parser($art, $body); + $this->art = $art; + $body = $this->getbody($this->readbody(), $this->getelements()); + $parsebody = $this->parser($body); return $parsebody; } - public function getelements(Art2 $art) + public function getelements() { $elements = []; foreach (self::TEXT_ELEMENTS as $element) { - if (isset($art->template('array')[$element])) { - $templateid = $art->template('array')[$element]; + if (isset($this->art->template('array')[$element])) { + $templateid = $this->art->template('array')[$element]; $tempalteart = $this->get($templateid); if($tempalteart) { - $text = $tempalteart->$element() . PHP_EOL . $art->$element(); + $text = $tempalteart->$element() . PHP_EOL . $this->art->$element(); } else { - $text = $art->$element(); + $text = $this->art->$element(); } } else { - $text = $art->$element(); + $text = $this->art->$element(); } $text = $this->article($text); $text = $this->autotaglistupdate($text); @@ -66,45 +69,45 @@ class Modelrender extends Modelart return $elements; } - public function gethtml(Art2 $art) + public function readbody() { - if (isset($art->template('array')['html'])) { - $templateid = $art->template('array')['html']; + if (isset($this->art->template('array')['body'])) { + $templateid = $this->art->template('array')['body']; $tempalteart = $this->get($templateid); - $html = $tempalteart->html() . PHP_EOL . $art->html(); + $body = $tempalteart->body() . PHP_EOL . $this->art->body(); } else { - $html = $art->html(); + $body = $this->art->body(); } - return $html; + return $body; } - public function getbody(string $html, array $elements) + public function getbody(string $body, array $elements) { - $html = preg_replace_callback('~\%(SECTION|ASIDE|NAV|HEADER|FOOTER)\%~', function ($match) use ($elements) { + $body = preg_replace_callback('~\%(SECTION|ASIDE|NAV|HEADER|FOOTER)\%~', function ($match) use ($elements) { return $elements[strtolower($match[1])]; - }, $html); - return $html; + }, $body); + return $body; } - public function write(Art2 $art) + public function write() { - file_put_contents(Model::RENDER_DIR . $art->id() . '.css', $art->css()); - file_put_contents(Model::RENDER_DIR . $art->id() . '.quick.css', $art->quickcss()); - file_put_contents(Model::RENDER_DIR . $art->id() . '.js', $art->javascript()); + 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()); } - public function writetemplates(Art2 $art) + public function writetemplates() { - if (array_key_exists('css', $art->template('array'))) { - $tempaltecssart = $this->get($art->template('array')['css']); + if (array_key_exists('css', $this->art->template('array'))) { + $tempaltecssart = $this->get($this->art->template('array')['css']); file_put_contents(Model::RENDER_DIR . $tempaltecssart->id() . '.css', $tempaltecssart->css()); } - if (array_key_exists('quickcss', $art->template('array'))) { - $tempaltequickcssart = $this->get($art->template('array')['quickcss']); + if (array_key_exists('quickcss', $this->art->template('array'))) { + $tempaltequickcssart = $this->get($this->art->template('array')['quickcss']); file_put_contents(Model::RENDER_DIR . $tempaltequickcssart->id() . '.quick.css', $tempaltequickcssart->quickcss()); } - if (array_key_exists('javascript', $art->template('array'))) { - $templatejsart = $this->get($art->template('array')['javascript']); + if (array_key_exists('javascript', $this->art->template('array'))) { + $templatejsart = $this->get($this->art->template('array')['javascript']); file_put_contents(Model::RENDER_DIR . $templatejsart->id() . '.js', $templatejsart->javascript()); } } @@ -112,48 +115,37 @@ class Modelrender extends Modelart - public function gethead(Art2 $art) + public function gethead() { $head = ''; $head .= '<meta charset="utf8" />' . PHP_EOL; - $head .= '<title>' . $art->title() . '</title>' . PHP_EOL; - $head .= '<meta name="description" content="' . $art->description() . '" />' . PHP_EOL; + $head .= '<title>' . $this->art->title() . '</title>' . PHP_EOL; + $head .= '<meta name="description" content="' . $this->art->description() . '" />' . PHP_EOL; $head .= '<meta name="viewport" content="width=device-width" />' . PHP_EOL; - if (isset($art->template('array')['quickcss'])) { - $tempaltequickcssart = $art->template('array')['quickcss']; + if (isset($this->art->template('array')['quickcss'])) { + $tempaltequickcssart = $this->art->template('array')['quickcss']; $head .= '<link href="' . Model::renderpath() . $tempaltequickcssart . '.quick.css" rel="stylesheet" />' . PHP_EOL; } - $head .= '<link href="' . Model::renderpath() . $art->id() . '.quick.css" rel="stylesheet" />' . PHP_EOL; + $head .= '<link href="' . Model::renderpath() . $this->art->id() . '.quick.css" rel="stylesheet" />' . PHP_EOL; - if (isset($art->template('array')['css'])) { - $tempaltecssart = $art->template('array')['css']; + if (isset($this->art->template('array')['css'])) { + $tempaltecssart = $this->art->template('array')['css']; $head .= '<link href="' . Model::renderpath() . $tempaltecssart . '.css" rel="stylesheet" />' . PHP_EOL; } - $head .= '<link href="' . Model::renderpath() . $art->id() . '.css" rel="stylesheet" />' . PHP_EOL; + $head .= '<link href="' . Model::renderpath() . $this->art->id() . '.css" rel="stylesheet" />' . PHP_EOL; - if (isset($art->template('array')['javascript'])) { - $templatejsart = $art->template('array')['javascript']; + if (isset($this->art->template('array')['javascript'])) { + $templatejsart = $this->art->template('array')['javascript']; $head .= '<script src="' . Model::renderpath() . $templatejsart . '.js" async/></script>' . PHP_EOL; } - $head .= '<script src="' . Model::renderpath() . $art->id() . '.js" async/></script>' . PHP_EOL; + $head .= '<script src="' . Model::renderpath() . $this->art->id() . '.js" async/></script>' . PHP_EOL; 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 desctitle($text, $desc, $title) { $text = str_replace('%TITLE%', $title, $text); @@ -162,7 +154,7 @@ class Modelrender extends Modelart } - public function parser(Art2 $art, string $text) + public function parser(string $text) { $text = $this->headerid($text); @@ -172,7 +164,7 @@ class Modelrender extends Modelart $text = $this->wurl($text); $text = $this->wikiurl($text); - $text = $this->desctitle($text, $art->description(), $art->title()); + $text = $this->desctitle($text, $this->art->description(), $this->art->title()); $text = str_replace('href="http', ' class="external" target="_blank" href="http', $text); @@ -339,12 +331,21 @@ class Modelrender extends Modelart $ul = '<ul id="'.$tag.'">' . PHP_EOL; $this->artlistsort($li, 'date', -1); foreach ($li as $item ) { - $ul .= '<li><a href="'.$this->router->generate('artread/', ['art' => $item->id()]).'" title="'.$item->description().'" class="internal" >'.$item->title().'</a></li>' . PHP_EOL; + if($item->id() === $this->art->id()) { + $actual = ' actual'; + } else { + $actual = ''; + } + $ul .= '<li><a href="'.$this->router->generate('artread/', ['art' => $item->id()]).'" title="'.$item->description().'" class="internal'.$actual.'" >'.$item->title().'</a></li>' . PHP_EOL; } $ul .= '</ul>' . PHP_EOL; $text = str_replace('%%'.$tag.'%%', $ul, $text); + + $li = array_map(function($item) { + return $item->id(); + }, $li); $this->linkfrom = array_unique(array_merge($this->linkfrom, $li)); } return $text; diff --git a/app/class/routes.php b/app/class/routes.php index 384d274..2215b5f 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -22,6 +22,7 @@ class Routes ['GET', '/[cid:art]', 'Controllerart#read', 'artread'], ['GET', '/[cid:art]/add', 'Controllerart#add', 'artadd'], ['GET', '/[cid:art]/edit', 'Controllerart#edit', 'artedit'], + ['GET', '/[cid:art]/render', 'Controllerart#render', 'artrender'], ['GET', '/[cid:art]/log', 'Controllerart#log', 'artlog'], ['POST', '/[cid:art]/edit', 'Controllerart#update', 'artupdate'], ['GET', '/[cid:art]/delete', 'Controllerart#confirmdelete', 'artconfirmdelete'], diff --git a/app/view/templates/edittabs.php b/app/view/templates/edittabs.php index 5d74ef1..62d86ad 100644 --- a/app/view/templates/edittabs.php +++ b/app/view/templates/edittabs.php @@ -7,7 +7,7 @@ foreach ($tablist as $key => $value) { <input name="interface" type="radio" value="<?= $key ?>" id="tab<?= $key ?>" class="checkboxtab" <?= $key == $opentab ? 'checked' : '' ?> > - <label for="tab<?= $key ?>"><?= empty($template[$key]) ? $key : '<a class="templatetooltip" title="'.$template[$key].'" >*</a>'.$key ?> </label> + <label for="tab<?= $key ?>" <?= empty($template[$key]) ? '' : 'title="'.$template[$key].'" ' ?> class="<?= empty($template[$key]) ? '' : 'template' ?> <?= empty($value) ? '' : 'edited' ?>"><?= $key ?> </label> <?php diff --git a/app/view/templates/navart.php b/app/view/templates/navart.php index d3baef5..45e9cda 100644 --- a/app/view/templates/navart.php +++ b/app/view/templates/navart.php @@ -97,6 +97,9 @@ <li class="drop"> <a class="button" href="<?= $this->uart('artedit', $art->id()) ?>" >edit</a> </li> + <li class="drop"> + <a class="button" href="<?= $this->uart('artrender', $art->id()) ?>" >render</a> + </li> <?php } ?> diff --git a/assets/css/edit.css b/assets/css/edit.css index b3cb30d..7113853 100644 --- a/assets/css/edit.css +++ b/assets/css/edit.css @@ -125,6 +125,14 @@ body { padding: 0px 2px; } +.tab label.edited { + text-decoration: underline dotted red; +} + +.tab label.template { + color: #7b97b9; +} + .checkboxtab:checked ~ label { border: solid 1px; |