From 42e89ac398bdf2a98167b0b71123c98e297b2130 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Tue, 4 Dec 2018 20:39:48 +0100 Subject: editor right bar --- app/class/art2.php | 92 ++++++++++++++++-------------------- app/class/controlleradmin.php | 11 +++-- app/class/controllerart.php | 11 +++-- app/class/modelart.php | 34 +++++++++++-- app/class/modelrender.php | 42 +++++++++------- app/view/templates/admin.php | 14 ++++-- app/view/templates/backtopbar.php | 22 ++++++--- app/view/templates/confirmdelete.php | 2 +- app/view/templates/edit.php | 4 +- app/view/templates/editleftbar.php | 78 ++++++++++++++++++++++-------- app/view/templates/editrightbar.php | 60 +++++++++++++++++++---- app/view/templates/edittabs.php | 2 +- app/view/templates/font.php | 10 ++++ 13 files changed, 259 insertions(+), 123 deletions(-) (limited to 'app') diff --git a/app/class/art2.php b/app/class/art2.php index 000c391..0023989 100644 --- a/app/class/art2.php +++ b/app/class/art2.php @@ -26,7 +26,9 @@ class Art2 protected $interface; protected $linkfrom; protected $linkto; - protected $template; + protected $templatebody; + protected $templatecss; + protected $templatejavascript; protected $affcount; protected $editcount; @@ -90,7 +92,9 @@ class Art2 $this->setinterface('section'); $this->setlinkfrom([]); $this->setlinkto([]); - $this->settemplate([]); + $this->settemplatebody(''); + $this->settemplatecss(''); + $this->settemplatejavascript(''); $this->setaffcount(0); $this->seteditcount(0); } @@ -217,25 +221,6 @@ class Art2 } } - - public function csstemplate(App $app) - { - $data = []; - $temp = ''; - if (!empty($this->template())) { - if ($app->exist($this->template()) and !in_array($this->template(), $data)) { - $template = $app->get($this->template()); - $temp = $temp . $template->css($app); - $data[] = $template->id(); - - } - - } - $cssprint = str_replace('url(/', 'url(' . $app::MEDIA_DIR, $temp . $this->css); - return $cssprint; - } - - public function javascript($type = 'string') { return $this->javascript; @@ -251,16 +236,6 @@ class Art2 return $this->header; } - public function md($expand = false) - { - if ($expand == true) { - $md = str_replace('](=', '](?id=', $this->section); - } else { - $md = $this->section; - } - return $md; - } - public function section($type = 'string') { return $this->section; @@ -345,13 +320,27 @@ class Art2 } - public function template($type = 'array') + public function templatebody($type = 'string') { - if ($type == 'json') { - return json_encode($this->template); - } elseif ($type = 'array') { - return $this->template; - } + return $this->templatebody; + } + + public function templatecss($type = 'string') + { + return $this->templatecss; + } + + public function templatejavascript($type = 'string') + { + return $this->templatejavascript; + } + + function template() + { + $template['body'] = $this->templatebody; + $template['css'] = $this->templatecss; + $template['javascript'] = $this->templatejavascript; + return $template; } public function affcount($type = 'int') @@ -573,24 +562,25 @@ class Art2 } } - public function settemplate($template) + public function settemplatebody($templatebody) { - if (is_string($template)) { - $templatearray = json_decode($template, true); + if(is_string($templatebody)) { + $this->templatebody = $templatebody; } - if (is_array($template)) { - $templatearray = $template; + } + + public function settemplatecss($templatecss) + { + if(is_string($templatecss)) { + $this->templatecss = $templatecss; } - if(is_object($template)) { - $templatearray = (array) $template; + } + + public function settemplatejavascript($templatejavascript) + { + if(is_string($templatejavascript)) { + $this->templatejavascript = $templatejavascript; } - $this->template = array_map(function ($value) { - if(empty($value)) { - return null; - } else { - return $value; - } - }, $templatearray); } public function setaffcount($affcount) diff --git a/app/class/controlleradmin.php b/app/class/controlleradmin.php index 0829916..86d6db1 100644 --- a/app/class/controlleradmin.php +++ b/app/class/controlleradmin.php @@ -15,7 +15,10 @@ class Controlleradmin extends Controller } else { $defaultartexist = true; } - $admin = ['artlist' => $artlist, 'defaultartexist' => $defaultartexist]; + + $globalcss = file_get_contents(Model::GLOBAL_DIR . 'global.css'); + + $admin = ['artlist' => $artlist, 'defaultartexist' => $defaultartexist, 'globalcss' => $globalcss]; $this->showtemplate('admin', $admin); } } @@ -25,11 +28,13 @@ class Controlleradmin extends Controller if(!isset($_POST['showeditmenu'])) { $_POST['showeditmenu'] = false; } + $globalcss = file_put_contents(Model::GLOBAL_DIR . 'global.css', $_POST['globalcss']); + Config::hydrate($_POST); - if(Config::savejson() !== false) { + if(Config::savejson() !== false && $globalcss !== false) { $this->routedirect('admin'); } else { - echo 'Can\'t write config file'; + echo 'Can\'t write config file or global css file'; } } diff --git a/app/class/controllerart.php b/app/class/controllerart.php index 0dee8e7..f64cda8 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -116,9 +116,14 @@ 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(), 'body' => $this->art->body(), 'javascript' => $this->art->javascript()]; + $tablist = ['section' => $this->art->section(), '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(); + $idlist = $this->artmanager->list(); + + + $artlist = $this->artmanager->getlister(); + $tagartlist = $this->artmanager->tagartlist($this->art->tag('array'), $artlist); + $lasteditedartlist = $this->artmanager->lasteditedartlist(5, $artlist); if (isset($_SESSION['workspace'])) { $showleftpanel = $_SESSION['workspace']['showleftpanel']; @@ -129,7 +134,7 @@ class Controllerart extends Controller } $fonts = []; - $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true, 'tablist' => $tablist, 'artlist' => $artlist, 'showleftpanel' => $showleftpanel, 'showrightpanel' => $showrightpanel, 'fonts' => $fonts]); + $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true, 'tablist' => $tablist, 'artlist' => $idlist, 'showleftpanel' => $showleftpanel, 'showrightpanel' => $showrightpanel, 'fonts' => $fonts, 'tagartlist' => $tagartlist, 'lasteditedartlist' => $lasteditedartlist]); } else { $this->routedirect('artread/', ['art' => $this->art->id()]); } diff --git a/app/class/modelart.php b/app/class/modelart.php index e9f6ec3..54a6613 100644 --- a/app/class/modelart.php +++ b/app/class/modelart.php @@ -107,9 +107,12 @@ class Modelart extends Modeldb } - - - + /** + * @param array $artlist List of Art2 + * @param array $tagchecked list of tags + * @param string $tagcompare string, can be 'OR' or 'AND', set the tag filter method + * @return array $array + */ public function filtertagfilter(array $artlist, array $tagchecked, $tagcompare = 'OR') { @@ -168,9 +171,30 @@ class Modelart extends Modeldb return $taglist; } - public function count() + /** + * @param array $taglist list of tags + * @param array $artlist list of Art2 + * @return array list of tags each containing list of id + */ + + public function tagartlist(array $taglist, array $artlist) { - return $this->bdd->query(' SELECT COUNT(*) FROM ' . $this->arttable . ' ')->fetchColumn(); + $tagartlist = []; + foreach ($taglist as $tag) { + $tagartlist[$tag] = $this->filtertagfilter($artlist, [$tag]); + } + return $tagartlist; + } + + public function lasteditedartlist(int $last , array $artlist) + { + $this->artlistsort($artlist, 'datemodif', -1); + $artlist = array_slice($artlist, 0, $last); + $idlist = []; + foreach ($artlist as $art) { + $idlist[] = $art->id(); + } + return $idlist; } } diff --git a/app/class/modelrender.php b/app/class/modelrender.php index 43e40a9..484fae3 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -9,6 +9,7 @@ class Modelrender extends Modelart protected $sum = []; const SUMMARY = '%SUMMARY%'; + const REMPLACE_SELF_ELEMENT = false; public function __construct($router) @@ -45,10 +46,17 @@ class Modelrender extends Modelart public function readbody() { - if (isset($this->art->template('array')['body'])) { - $templateid = $this->art->template('array')['body']; - $tempalteart = $this->get($templateid); - $body = $tempalteart->body() . PHP_EOL . $this->art->body(); + if (!empty($this->art->templatebody())) { + $templateid = $this->art->templatebody(); + $templateart = $this->get($templateid); + if(self::REMPLACE_SELF_ELEMENT) { + $templatebody = preg_replace_callback('~\%(SECTION|ASIDE|NAV|HEADER|FOOTER)!\%~', function ($match) use ($templateid) { + return '%'. $match[1] . '.' . $templateid . '%'; + }, $templateart->body()); + } else { + $templatebody = $templateart->body(); + } + $body = $templatebody . PHP_EOL . $this->art->body(); } else { $body = $this->art->body(); } @@ -58,11 +66,11 @@ class Modelrender extends Modelart public function getbody(string $body) { $rend = $this; - $body = preg_replace_callback('~\%(SECTION|ASIDE|NAV|HEADER|FOOTER)(:(((\.|)?([\w-_]+|\!))*))?\%~', function ($match) use ($rend) { + $body = preg_replace_callback('~\%(SECTION|ASIDE|NAV|HEADER|FOOTER)((\.([a-z0-9-_]+|!))*|!)?\%~', function ($match) use ($rend) { $element = strtolower($match[1]); $getelement = ''; - if (isset($match[3]) && !empty($match[3])) { - $templatelist = str_replace('!', $this->art->id(), explode('.', $match[3])); + if (isset($match[2]) && !empty($match[2])) { + $templatelist = str_replace('!', $this->art->id(), explode('.', ltrim($match[2], '.'))); foreach ($templatelist as $template) { if ($template === $rend->art->id()) { $templateelement = $rend->art->$element(); @@ -96,7 +104,7 @@ class Modelrender extends Modelart public function write() { 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() . '.quick.css', $this->art->quickcss()); file_put_contents(Model::RENDER_DIR . $this->art->id() . '.js', $this->art->javascript()); } @@ -133,20 +141,20 @@ class Modelrender extends Modelart $head .= '' . PHP_EOL; $head .= '' . PHP_EOL; - if (isset($this->art->template('array')['quickcss'])) { - $tempaltequickcssart = $this->art->template('array')['quickcss']; - $head .= '' . PHP_EOL; - } - $head .= '' . PHP_EOL; + // if (!empty($this->art->templatecss())) { + // $tempaltequickcssart = $this->art->templatecss(); + // $head .= '' . PHP_EOL; + // } + // $head .= '' . PHP_EOL; - if (isset($this->art->template('array')['css'])) { - $tempaltecssart = $this->art->template('array')['css']; + if (!empty($this->art->templatecss())) { + $tempaltecssart = $this->art->templatecss(); $head .= '' . PHP_EOL; } $head .= '' . PHP_EOL; - if (isset($this->art->template('array')['javascript'])) { - $templatejsart = $this->art->template('array')['javascript']; + if (!empty($this->art->templatejavascript())) { + $templatejsart = $this->art->templatejavascript; $head .= '' . PHP_EOL; } $head .= '' . PHP_EOL; diff --git a/app/view/templates/admin.php b/app/view/templates/admin.php index d913186..7f94833 100644 --- a/app/view/templates/admin.php +++ b/app/view/templates/admin.php @@ -12,6 +12,9 @@
+ + +

Passwords

@@ -19,7 +22,7 @@

Page creation

- + - +

CSS

+ + + + +
diff --git a/app/view/templates/backtopbar.php b/app/view/templates/backtopbar.php index 1f4a246..a06c304 100644 --- a/app/view/templates/backtopbar.php +++ b/app/view/templates/backtopbar.php @@ -1,29 +1,38 @@
+ + isvisitor()) { ?> -
+
- + -
+ +User level : level() ?> + + + +
- -User level : level() ?> + + + + + iseditor()) { ?> - home isadmin()) { +| github↝ diff --git a/app/view/templates/confirmdelete.php b/app/view/templates/confirmdelete.php index e05f6da..7d8f62a 100644 --- a/app/view/templates/confirmdelete.php +++ b/app/view/templates/confirmdelete.php @@ -11,7 +11,7 @@

Delete

    -
  • Id : title() ?>
  • +
  • Id : id() ?>
  • Title : title() ?>
  • Article(s) linked to this one : linkto('sort') ?>
  • Article(s) linked from this one : linkfrom('sort') ?>
  • diff --git a/app/view/templates/edit.php b/app/view/templates/edit.php index 8071964..346d5bb 100644 --- a/app/view/templates/edit.php +++ b/app/view/templates/edit.php @@ -19,8 +19,8 @@
    insert('editleftbar', ['art' => $art, 'tablist' => $tablist, 'artlist' => $artlist, 'showleftpanel' => $showleftpanel]) ?> - insert('edittabs', ['tablist' => $tablist, 'opentab' => $art->interface(), 'template' => $art->template()]) ?> - insert('editrightbar', ['art' => $art, 'artlist' => $artlist, 'showrightpanel' => $showrightpanel, 'fonts' => $fonts]) ?> + insert('edittabs', ['tablist' => $tablist, 'opentab' => $art->interface(), 'templates' => $art->template()]) ?> + insert('editrightbar', ['art' => $art, 'artlist' => $artlist, 'showrightpanel' => $showrightpanel, 'templates' => $art->template(), 'tagartlist' => $tagartlist, 'lasteditedartlist' => $lasteditedartlist]) ?>
    diff --git a/app/view/templates/editleftbar.php b/app/view/templates/editleftbar.php index 2f184af..73468bf 100644 --- a/app/view/templates/editleftbar.php +++ b/app/view/templates/editleftbar.php @@ -24,37 +24,73 @@ -
    +
    Advanced

    Template options

    -
      + + + + + + + $value) { - if(isset($art->template()[$element])) { - $template = $art->template()[$element]; - } else { - $template = ''; - } - echo '
    • '; - echo ''; - echo ' + +
+
+ + +
+
+ + +
- - '; - echo ''; } + ?> + + + +
+ + +
+ +
diff --git a/app/view/templates/editrightbar.php b/app/view/templates/editrightbar.php index fa249ef..9572678 100644 --- a/app/view/templates/editrightbar.php +++ b/app/view/templates/editrightbar.php @@ -2,26 +2,66 @@ >
-
- Links + + +
+ Last edited + + +
+ + +
+ Tags + $idlist) { + if(count($idlist) > 1) { ?> - + '; + foreach ($idlist as $id) { + if($id === $art->id()) { + echo '
  • ★ '.$id.'
  • '; + } else { + ?> +
  • + '; } ?> +
    -
    - Fonts - + +
    diff --git a/app/view/templates/edittabs.php b/app/view/templates/edittabs.php index 6e1562a..0829c48 100644 --- a/app/view/templates/edittabs.php +++ b/app/view/templates/edittabs.php @@ -7,7 +7,7 @@ foreach ($tablist as $key => $value) { > - + +

    Fonts

    + + +
    ⚡ Render +
    +
    👓 View font CSS file +
    +

    Add Font

    @@ -24,6 +32,8 @@
    +

    Font stock

    + -- cgit v1.2.3
    font