From 2f363e8fa26ab849539e64ff7caa21bd164e8979 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sat, 10 Nov 2018 21:43:24 +0100 Subject: sidebars-html-inserts --- w/class/art2.php | 14 ++- w/class/controllerart.php | 18 +++- w/class/modelart.php | 222 ++------------------------------------ w/class/modeldb.php | 5 + w/class/modelrender.php | 67 +++++++----- w/view/templates/edit.php | 27 ++--- w/view/templates/editleftbar.php | 70 ++++++++++++ w/view/templates/editrightbar.php | 20 ++++ w/view/templates/editsidebar.php | 40 ------- w/view/templates/edittabs.php | 2 +- w/view/templates/edittopbar.php | 26 +++-- w/w.index.php | 8 -- 12 files changed, 201 insertions(+), 318 deletions(-) create mode 100644 w/view/templates/editleftbar.php create mode 100644 w/view/templates/editrightbar.php delete mode 100644 w/view/templates/editsidebar.php (limited to 'w') 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 'idalreadyexist'; - } 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 . '>
' . PHP_EOL . $this->markdown($text) . PHP_EOL . '
' . PHP_EOL; - } else { - $body .= PHP_EOL . '<' . $element . '>' . PHP_EOL . $this->markdown($text) . PHP_EOL . '' . PHP_EOL; - } + $elements[$element] = PHP_EOL . '<' . $element . '>' . PHP_EOL . $this->markdown($text) . PHP_EOL . '' . 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 .= '' . PHP_EOL; $head .= '' . PHP_EOL; - - if (array_key_exists('css', $art->template('array'))) { - $tempaltecssart = $art->template('array')['css']; - $head .= '' . PHP_EOL; - } - $head .= '' . PHP_EOL; - if (array_key_exists('quickcss', $art->template('array'))) { + if (isset($art->template('array')['quickcss'])) { $tempaltequickcssart = $art->template('array')['quickcss']; $head .= '' . PHP_EOL; } $head .= '' . PHP_EOL; - if (array_key_exists('javascript', $art->template('array'))) { + if (isset($art->template('array')['css'])) { + $tempaltecssart = $art->template('array')['css']; + $head .= '' . PHP_EOL; + } + $head .= '' . PHP_EOL; + + if (isset($art->template('array')['javascript'])) { $templatejsart = $art->template('array')['javascript']; - $head .= '' . PHP_EOL; + $head .= '' . PHP_EOL; } - $head .= '' . PHP_EOL; + $head .= '' . 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; } diff --git a/w/view/templates/edit.php b/w/view/templates/edit.php index ee231cd..33d42f4 100644 --- a/w/view/templates/edit.php +++ b/w/view/templates/edit.php @@ -3,42 +3,33 @@ - -start('customhead') ?> - -stop() ?> - - - - - - start('page') ?> + + +
insert('navart', ['user' => $user, 'art' => $art, 'artexist' => $artexist]) ?> insert('edittopbar', ['art' => $art]) ?> - insert('editsidebar', ['art' => $art]) ?> - - +
- $art->md(), 'css' => $art->css(), 'header' => $art->header(), 'nav' => $art->nav(), 'aside' => $art->aside(), 'footer' => $art->footer(), 'html' => $art->html(), 'javascript' => $art->javascript()]; - $this->insert('edittabs', ['tablist' => $tablist, 'opentab' => $art->interface()]) - ?> + insert('editleftbar', ['art' => $art, 'tablist' => $tablist, 'artlist' => $artlist, 'showleftpanel' => $showleftpanel]) ?> + insert('edittabs', ['tablist' => $tablist, 'opentab' => $art->interface()]) ?> + insert('editrightbar', ['art' => $art, 'artlist' => $artlist, 'showrightpanel' => $showrightpanel]) ?> - +
+
stop() ?> \ No newline at end of file diff --git a/w/view/templates/editleftbar.php b/w/view/templates/editleftbar.php new file mode 100644 index 0000000..7533599 --- /dev/null +++ b/w/view/templates/editleftbar.php @@ -0,0 +1,70 @@ +
+ > + +
+
+ Infos +
+ + + + + + + + +
+
+
+ Advanced +
+

Template options

+
    + $value) { + if(isset($art->template()[$element])) { + $template = $art->template()[$element]; + } else { + $template = ''; + } + echo '
  • '; + echo ''; + echo '> + +
    +
    + Links + + + + +
    + +
    + +
\ No newline at end of file diff --git a/w/view/templates/editsidebar.php b/w/view/templates/editsidebar.php deleted file mode 100644 index 99612dd..0000000 --- a/w/view/templates/editsidebar.php +++ /dev/null @@ -1,40 +0,0 @@ - \ No newline at end of file diff --git a/w/view/templates/edittabs.php b/w/view/templates/edittabs.php index c65a7c7..efb1650 100644 --- a/w/view/templates/edittabs.php +++ b/w/view/templates/edittabs.php @@ -10,7 +10,7 @@ foreach ($tablist as $key => $value) { } echo ''; echo '
'; - echo ''; + echo ''; echo '
'; echo '
'; } diff --git a/w/view/templates/edittopbar.php b/w/view/templates/edittopbar.php index 9973335..20c2d8b 100644 --- a/w/view/templates/edittopbar.php +++ b/w/view/templates/edittopbar.php @@ -1,23 +1,29 @@ -
- +
+
+ +
+ +
+ + - - + - - - -
+ + + + 👁 + id() ?> - -
+ +
\ No newline at end of file diff --git a/w/w.index.php b/w/w.index.php index 8b59228..d247c84 100644 --- a/w/w.index.php +++ b/w/w.index.php @@ -24,14 +24,6 @@ require(__DIR__.'/../vendor/autoload.php'); spl_autoload_register('class_autoloader'); - - -//$text = 'blabla il fait un temps vraiment [dégeu](=degeulasse) parce quil pleut [baucoup](?id=orthographe), en amazonie la [vie](?id=prout) et la [mort](?id=prout) sont des notions très proches.'; - -//$artmanager = new Modelart; - -// var_dump($artmanager->getlisterwhere(['id', 'description'], ['55', '44', 'lol'])); - try { $router = new Router; -- cgit v1.2.3