aboutsummaryrefslogtreecommitdiff
path: root/w/class
diff options
context:
space:
mode:
Diffstat (limited to 'w/class')
-rw-r--r--w/class/art2.php14
-rw-r--r--w/class/controllerart.php18
-rw-r--r--w/class/modelart.php222
-rw-r--r--w/class/modeldb.php5
-rw-r--r--w/class/modelrender.php67
5 files changed, 85 insertions, 241 deletions
diff --git a/w/class/art2.php b/w/class/art2.php
index 970058b..867b17a 100644
--- a/w/class/art2.php
+++ b/w/class/art2.php
@@ -555,11 +555,21 @@ class Art2
public function settemplate($template)
{
if (is_string($template)) {
- $template = json_decode($template, true);
+ $templatearray = json_decode($template, true);
}
if (is_array($template)) {
- $this->template = $template;
+ $templatearray = $template;
}
+ if(is_object($template)) {
+ $templatearray = (array) $template;
+ }
+ $this->template = array_map(function ($value) {
+ if(empty($value)) {
+ return null;
+ } else {
+ return $value;
+ }
+ }, $templatearray);
}
public function setaffcount($affcount)
diff --git a/w/class/controllerart.php b/w/class/controllerart.php
index ef65f48..33bd93f 100644
--- a/w/class/controllerart.php
+++ b/w/class/controllerart.php
@@ -75,7 +75,20 @@ class Controllerart extends Controllerdb
public function edit()
{
if ($this->importart() && $this->user->canedit()) {
- $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true]);
+ $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()];
+
+ $artlist = $this->artmanager->list();
+
+ if(isset($_SESSION['workspace'])) {
+ $showleftpanel = $_SESSION['workspace']['showleftpanel'];
+ $showrightpanel = $_SESSION['workspace']['showrightpanel'];
+ } else {
+ $showleftpanel = false;
+ $showrightpanel = false;
+ }
+
+
+ $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true, 'tablist' => $tablist, 'artlist' => $artlist, 'showleftpanel' => $showleftpanel, 'showrightpanel' => $showrightpanel]);
} else {
$this->redirect('?id=' . $this->art->id());
}
@@ -112,7 +125,8 @@ class Controllerart extends Controllerdb
public function update()
{
-
+ $_SESSION['workspace']['showrightpanel'] = isset($_POST['workspace']['showrightpanel']);
+ $_SESSION['workspace']['showleftpanel'] = isset($_POST['workspace']['showleftpanel']);
if ($this->importart() && $this->user->canedit()) {
$this->art->hydrate($_POST);
diff --git a/w/class/modelart.php b/w/class/modelart.php
index 37262ad..ef4d61d 100644
--- a/w/class/modelart.php
+++ b/w/class/modelart.php
@@ -34,14 +34,18 @@ class Modelart extends Modeldb
$this->artstore->store($artdata);
}
- public function get($art)
+ public function get($id)
{
- if($art instanceof Art2) {
- $id = $art->id();
+ if($id instanceof Art2) {
+ $id = $id->id();
}
- $artdata = $this->artstore->findById($id);
- if($artdata !== false) {
- return new Art2($artdata);
+ if(is_string($id)) {
+ $artdata = $this->artstore->findById($id);
+ if($artdata !== false) {
+ return new Art2($artdata);
+ } else {
+ return false;
+ }
} else {
return false;
}
@@ -59,205 +63,6 @@ class Modelart extends Modeldb
$this->artstore->store($artdata);
}
-
- public function exist3($id)
- {
-
- $req = $this->bdd->prepare(' SELECT COUNT(*) FROM ' . Config::arttable() . ' WHERE id = :id ');
- $req->execute(array('id' => $id));
- $donnees = $req->fetch(PDO::FETCH_ASSOC);
-
- return (bool)$donnees['COUNT(*)'];
- }
-
- public function add3(Art2 $art)
- {
-
- if ($this->exist($art->id())) {
- echo '<span class="alert">idalreadyexist</span>';
- } else {
-
- $now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
-
- $table = Config::arttable();
- $request = "INSERT INTO $table (id, title, description, tag, date, datecreation, datemodif, daterender, css, quickcss, javascript, html, header, section, nav, aside, footer, render, secure, invitepassword, interface, linkfrom, linkto, template, affcount, editcount)
- VALUES(:id, :title, :description, :tag, :date, :datecreation, :datemodif, :daterender, :css, :quickcss, :javascript, :html, :header, :section, :nav, :aside, :footer, :render, :secure, :invitepassword, :interface, :linkfrom, :linkto, :template, :affcount, :editcount)";
-
- $q = $this->bdd->prepare($request);
-
- $q->bindValue(':id', $art->id());
- $q->bindValue(':title', $art->title());
- $q->bindValue(':description', $art->description());
- $q->bindValue(':tag', $art->tag('string'));
- $q->bindValue(':date', $now->format('Y-m-d H:i:s'));
- $q->bindValue(':datecreation', $now->format('Y-m-d H:i:s'));
- $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s'));
- $q->bindValue(':daterender', $now->format('Y-m-d H:i:s'));
- $q->bindValue(':css', $art->css());
- $q->bindValue(':quickcss', $art->quickcss('json'));
- $q->bindValue(':javascript', $art->javascript());
- $q->bindValue(':html', $art->html());
- $q->bindValue(':header', $art->header());
- $q->bindValue(':section', $art->md());
- $q->bindValue(':nav', $art->nav());
- $q->bindValue(':aside', $art->aside());
- $q->bindValue(':footer', $art->footer());
- $q->bindValue(':render', $art->render());
- $q->bindValue(':secure', $art->secure());
- $q->bindValue(':invitepassword', $art->invitepassword());
- $q->bindValue(':interface', $art->interface());
- $q->bindValue(':linkfrom', $art->linkfrom('json'));
- $q->bindValue(':linkto', $art->linkto('json'));
- $q->bindValue(':template', $art->template('json'));
- $q->bindValue(':affcount', $art->affcount());
- $q->bindValue(':editcount', $art->editcount());
-
- $q->execute();
- }
- }
-
-
- public function delete3(Art2 $art)
- {
- $req = $this->bdd->prepare('DELETE FROM ' . Config::arttable() . ' WHERE id = :id ');
- $req->execute(array('id' => $art->id()));
- $req->closeCursor();
- }
-
- public function get3(Art2 $art)
- {
-
- $req = $this->bdd->prepare('SELECT * FROM ' . Config::arttable() . ' WHERE id = :id ');
- $req->execute(array('id' => $art->id()));
- $donnees = $req->fetch(PDO::FETCH_ASSOC);
-
- return new Art2($donnees);
-
- $req->closeCursor();
-
- }
-
-
-
-
- public function update3(Art2 $art)
- {
- $now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
-
- //$request = 'UPDATE ' . $this->arttable . '(id, title, description, tag, date, datecreation, datemodif, daterender, css, quickcss, javascript, html, header, section, nav, aside, footer, render, secure, invitepassword, interface, linkfrom, template, affcount, editcount) VALUES(:id, :title, :description, :tag, :date, :datecreation, :datemodif, :daterender, :css, :quickcss, :javascript, :html, :header, :section, :nav, :aside, :footer, :render, :secure, :invitepassword, :interface, :linkfrom, :template, :affcount, :editcount) WHERE id = :id';
- $table = Config::arttable();
- $request = "UPDATE $table SET id = :id, title = :title, description = :description, tag = :tag, date = :date, datecreation = :datecreation, datemodif = :datemodif, daterender = :daterender, css = :css, quickcss = :quickcss, javascript = :javascript, html = :html, header = :header, section = :section, nav = :nav, aside = :aside, footer = :footer, render = :footer, secure = :secure, invitepassword = :invitepassword, interface = :interface, linkfrom = :linkfrom, linkto = :linkto, template = :template, affcount = :affcount, editcount = :editcount WHERE id = :id";
-
- $q = $this->bdd->prepare($request);
-
- $q->bindValue(':id', $art->id());
- $q->bindValue(':title', $art->title());
- $q->bindValue(':description', $art->description());
- $q->bindValue(':tag', $art->tag('string'));
- $q->bindValue(':date', $art->date('string'));
- $q->bindValue(':datecreation', $art->datecreation('string'));
- $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s'));
- $q->bindValue(':daterender', $art->daterender('string'));
- $q->bindValue(':css', $art->css());
- $q->bindValue(':quickcss', $art->quickcss('json'));
- $q->bindValue(':javascript', $art->javascript());
- $q->bindValue(':html', $art->html());
- $q->bindValue(':header', $art->header());
- $q->bindValue(':section', $art->md());
- $q->bindValue(':nav', $art->nav());
- $q->bindValue(':aside', $art->aside());
- $q->bindValue(':footer', $art->footer());
- $q->bindValue(':render', $art->render());
- $q->bindValue(':secure', $art->secure());
- $q->bindValue(':invitepassword', $art->invitepassword());
- $q->bindValue(':interface', $art->interface());
- $q->bindValue(':linkfrom', $art->linkfrom('json'));
- $q->bindValue(':linkto', $art->linkto('json'));
- $q->bindValue(':template', $art->template('json'));
- $q->bindValue(':affcount', $art->affcount());
- $q->bindValue(':editcount', $art->editcount());
-
- $q->execute();
- }
-
-
-
-
- public function getlister3(array $selection = ['id'], array $opt = [])
- {
- // give an array using SELECTION columns and sort and desc OPTIONS
-
- $default = ['tri' => 'id', 'desc' => 'DESC'];
- $opt = array_update($default, $opt);
-
- $list = [];
- $option = ['datecreation', 'title', 'id', 'description', 'datemodif', 'tag', 'secure'];
- if (is_array($selection) && is_string($opt['tri']) && strlen($opt['tri']) < 16 && is_string($opt['desc']) && strlen($opt['desc']) < 5 && in_array($opt['tri'], $option)) {
-
- $selection = implode(", ", $selection);
-
-
- $select = 'SELECT ' . $selection . ' FROM ' . Config::arttable() . ' ORDER BY ' . $opt['tri'] . ' ' . $opt['desc'];
- $req = $this->bdd->query($select);
- while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) {
- $list[] = new Art2($donnees);
- }
- return $list;
- }
- }
-
-
-
- public function getlisterwhere3(array $select = ['id'], array $whereid = [], $by = 'id', $order = 'DESC')
- {
- // give an array using SELECTION columns and sort and desc OPTIONS
-
-
- $select = array_intersect(array_unique($select), self::SELECT);
- if (empty($select)) {
- $select = ' * ';
- } else {
- $select = implode(", ", $select);
- }
-
-
- $whereid = array_unique($whereid);
-
- $list = [];
-
- if (!in_array($by, self::BY)) {
- $by = 'id';
- }
- if (!in_array($order, self::ORDER)) {
- $order = 'DESC';
- }
-
-
- if (!empty($whereid)) {
- $wherestatements = array_map(function ($element) {
- return ' id= ?';
- }, $whereid);
- $where = 'WHERE ' . implode(' OR ', $wherestatements);
- } else {
- $where = '';
- }
-
- $table = Config::arttable();
- $prepare = "SELECT $select FROM $table $where ORDER BY $by $order";
- $req = $this->bdd->prepare($prepare);
- $req->execute($whereid);
- while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) {
- $list[] = new Art2($donnees);
- }
-
- return $list;
- }
-
-
-
-
-
-
public function getlisteropt(Opt $opt)
{
@@ -272,13 +77,6 @@ class Modelart extends Modeldb
}
- public function listcalclinkfrom(&$artlist)
- {
- foreach ($artlist as $art) {
- $art->calclinkto($artlist);
- }
- }
-
public function artcompare($art1, $art2, $method = 'id', $order = 1)
{
$result = ($art1->$method('sort') <=> $art2->$method('sort'));
diff --git a/w/class/modeldb.php b/w/class/modeldb.php
index 0d4e630..a5ebf6f 100644
--- a/w/class/modeldb.php
+++ b/w/class/modeldb.php
@@ -31,6 +31,11 @@ class Modeldb extends Model
return $artlist;
}
+ public function list()
+ {
+ return $this->artstore->getAllIds();
+ }
+
public function getlisterid(array $idlist = [])
{
$artdatalist = $this->artstore->query()
diff --git a/w/class/modelrender.php b/w/class/modelrender.php
index 963962b..53d1aca 100644
--- a/w/class/modelrender.php
+++ b/w/class/modelrender.php
@@ -20,31 +20,49 @@ class Modelrender extends Modelart
public function renderbody(Art2 $art)
{
- $body = $this->getbody($art);
+ $body = $this->getbody($this->gethtml($art), $this->getelements($art));
$parsebody = $this->parser($art, $body);
return $parsebody;
}
- public function getbody(Art2 $art)
+ public function getelements(Art2 $art)
{
- $body = '';
+ $elements = [];
foreach (self::TEXT_ELEMENTS as $element) {
- if (array_key_exists($element, $art->template('array'))) {
- $tempalteart = $this->get($art->template('array')[$element]);
+ if (isset($art->template('array')[$element])) {
+ $templateid = $art->template('array')[$element];
+ $tempalteart = $this->get($templateid);
$text = $tempalteart->$element() . PHP_EOL . $art->$element();
} else {
$text = $art->$element();
}
- 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;
- }
+ $elements[$element] = PHP_EOL . '<' . $element . '>' . PHP_EOL . $this->markdown($text) . PHP_EOL . '</' . $element . '>' . PHP_EOL;
+
}
- return $body;
+ return $elements;
+ }
+
+ public function gethtml(Art2 $art)
+ {
+ if (isset($art->template('array')['html'])) {
+ $templateid = $art->template('array')['html'];
+ $tempalteart = $this->get($templateid);
+ $html = $tempalteart->html() . PHP_EOL . $art->html();
+ } else {
+ $html = $art->html();
+ }
+ return $html;
+ }
+
+ public function getbody(string $html, array $elements)
+ {
+ $html = preg_replace_callback('~\%(SECTION|ASIDE|NAV|HEADER|FOOTER)\%~', function ($match) use ($elements) {
+ return $elements[strtolower($match[1])];
+ }, $html);
+ return $html;
}
public function write(Art2 $art)
@@ -81,22 +99,22 @@ class Modelrender extends Modelart
$head .= '<meta name="description" content="'.$art->description() .'" />' . PHP_EOL;
$head .= '<meta name="viewport" content="width=device-width" />' . PHP_EOL;
-
- 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'))) {
+ if (isset($art->template('array')['quickcss'])) {
$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'))) {
+ if (isset($art->template('array')['css'])) {
+ $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 (isset($art->template('array')['javascript'])) {
$templatejsart = $art->template('array')['javascript'];
- $head .= '<script src="' . Config::renderpath() . $templatejsart . '.js" /></script>' . PHP_EOL;
+ $head .= '<script src="' . Config::renderpath() . $templatejsart . '.js" async/></script>' . PHP_EOL;
}
- $head .= '<script src="' . Config::renderpath() . $art->id() . '.js" /></script>' . PHP_EOL;
+ $head .= '<script src="' . Config::renderpath() . $art->id() . '.js" async/></script>' . PHP_EOL;
return $head;
}
@@ -167,11 +185,10 @@ public function tooltip(array $linkfrom, string $text)
foreach ($linkfrom as $id) {
if (isset($descriptions[$id])) {
- $title = $descriptions[$id];
+ $linkfrom = 'href="?id=' . $id . '"';
+ $titlelinkfrom = ' title="' . $descriptions[$id] . '" ' . $linkfrom;
+ $text = str_replace($linkfrom, $titlelinkfrom, $text);
}
- $linkfrom = 'href="?id=' . $id . '"';
- $titlelinkfrom = ' title="' . $title . '" ' . $linkfrom;
- $text = str_replace($linkfrom, $titlelinkfrom, $text);
}
return $text;
}