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 --- public/css/soft.css | 171 ++++++++++++++++++++++++++++- public/test.php | 24 ----- public/test3.php | 10 -- 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 -- 15 files changed, 371 insertions(+), 353 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 diff --git a/public/css/soft.css b/public/css/soft.css index 108f44e..ff65635 100644 --- a/public/css/soft.css +++ b/public/css/soft.css @@ -7,7 +7,176 @@ div#main { display: inline-block; } +body { + margin: 0; + height: 100%; + background-color: #b1b1b1; +} + .menu { position: fixed; right: 0; -} \ No newline at end of file +} + +.editor div#leftbar { + position: relative; + height: 100%; +} + +.editor .tabs { + flex: 2; + position: relative; + height: 100%; +} + + + +.editor #leftbarpanel, .editor #rightbarpanel { + width: 250px; + display: none; + height: 100%; + overflow-y: auto; +} + +.editor #showleftpanel:checked ~ #leftbarpanel { + display: block; + overflow-y: auto; + height: 100%; +} + +.editor #showrightpanel:checked ~ #rightbarpanel { + display: block; +} + +.editor input.toggle { + display: none; +} + +.editor label.toogle:hover { + color: white; + cursor: pointer; + background-color: #e2e2e2; +} + +.editor label.toogle { + height: 100%; + line-height: 100%; + text-align: center; +} + +.editor #leftbar label.toogle { + float: right; +} + +.editor #rightbar label.toogle { + float: left; +} + + +#rightbarpanel { + display: none; + width: 250px; +} +#rightbar:target #rightbarpanel { + display: inline-block; + overflow-y: scroll; + height: 100%; +} +#rightbar:target #open { + display: none; +} + + + + + + +.editor #workspace { + display: flex; + height: calc(100% - 30px); + position: relative; +} + + +.tabs .tab +{ + float: left; +} + +.tabs .tab .content +{ + position: absolute; + background-color: #dc8ad2; + left: 0px; + width: 100%; + height: calc(100% - 30px); +} + +.checkboxtab +{ + display: none; +} + +.tab label +{ + margin-right: 10px; + border: outset; + background-color: var(--color1); +} + +.checkboxtab:checked ~ label +{ + border: inset; +} + +.checkboxtab:checked ~ .content +{ + z-index: 1; +} + + + +section.editor { + position: fixed; + width: 100%; + height: 100%; +} + + +html { + height: 100%; +} + +.tabs textarea {height: 100%;width: 100%;border: none;resize: none;} + +* { + box-sizing: border-box; +} + +.editor .tabs label { + line-height: 30px; +} + +.editor #topbar { + line-height: 30px; +} + +.editor ul { + list-style: none; + padding: 0; +} + +.editor #leftbar select { + width: 100%; +} + +.editor .panel input { + width: 100%; +} + + +.editor a {color: black;text-decoration: none;} + +.editor a:hover { + color: white; +} diff --git a/public/test.php b/public/test.php index 7e24cd6..50ff4b1 100644 --- a/public/test.php +++ b/public/test.php @@ -18,33 +18,9 @@ $art = new Art2(['id' => 'rr']); $art->reset(); $art->hydrate((['description' => 'fdsfs', 'secure' => 0, 'render' => $render2])); -var_dump($art); -$artencoded = json_encode($art); -var_dump($artencoded); -class Person -{ - public $id; - public $name; - public $table = ['coucou', 'lol', 'chouette']; - public $date; - - public function __construct(array $data) - { - $this->id = $data['id']; - $this->name = $data['name']; - $this->date = new DateTimeImmutable(); - } -} - -$person = new Person(array('id' => 1, 'name' => 'Amir')); -$jsonperson = json_encode($person); - -var_dump($jsonperson); - -var_dump(json_decode($jsonperson)); diff --git a/public/test3.php b/public/test3.php index 327e2dd..571732b 100644 --- a/public/test3.php +++ b/public/test3.php @@ -1,15 +1,5 @@ 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