From b49830232096951202688bd775193424880bbd11 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Tue, 7 Apr 2020 19:43:58 +0200 Subject: refactor LIST fix #74 --- app/class/Model.php | 5 ++ app/class/Modelrender.php | 6 +- app/class/Optlist.php | 120 +++++++++++++++++++++++++++------------- app/view/templates/homemenu.php | 3 +- app/view/templates/info.php | 4 +- 5 files changed, 95 insertions(+), 43 deletions(-) (limited to 'app') diff --git a/app/class/Model.php b/app/class/Model.php index ea75da8..6a8f111 100644 --- a/app/class/Model.php +++ b/app/class/Model.php @@ -78,6 +78,11 @@ abstract class Model '' => 'other' ]; + const LIST_STYLES = [ + 'list' => 'list', + 'card' => 'card' + ]; + const COLUMNS = ['id', 'favicon', 'title', 'description', 'tag', 'date', 'datemodif', 'datecreation', 'secure', 'authors', 'linkto', 'visitcount', 'affcount', 'editcount']; const TEXT_ELEMENTS = ['header', 'nav', 'main', 'aside', 'footer']; diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php index 5687f03..29a3fa7 100644 --- a/app/class/Modelrender.php +++ b/app/class/Modelrender.php @@ -9,7 +9,7 @@ class Modelrender extends Modelpage { /** @var \AltoRouter */ protected $router; - /** @var Page */ + /** @var Page Actual page being rendered*/ protected $page; protected $linkto = []; protected $sum = []; @@ -557,7 +557,7 @@ class Modelrender extends Modelpage $optlist = new Optlist(['render' => $this]); $optlist->parsehydrate($match['options']); $pagetable = $modelhome->pagetable($this->pagelist(), $optlist, '', []); - $content = $optlist->listhtml($pagetable); + $content = $optlist->listhtml($pagetable, $this->page, $this); $text = str_replace($match['fullmatch'], $content, $text); } } @@ -588,7 +588,7 @@ class Modelrender extends Modelpage */ public function thumbnail(string $text): string { - $img = '' . $this->page->title() . ''; + $img = '' . $this->page->title() . ''; $img = PHP_EOL . $img . PHP_EOL; $text = str_replace('%THUMBNAIL%', $img, $text); diff --git a/app/class/Optlist.php b/app/class/Optlist.php index 122072b..37f9343 100644 --- a/app/class/Optlist.php +++ b/app/class/Optlist.php @@ -10,16 +10,13 @@ class Optlist extends Opt protected $date = 0; protected $time = 0; protected $author = 0; - protected $style = 0; - - /** @var Modelrender Render engine used to generate pages urls */ - protected $render = null; - + protected $style = 'list'; + protected $render; public function parsehydrate(string $encoded) { - if(is_string($encoded)) { + if (is_string($encoded)) { parse_str($encoded, $datas); $this->hydrate($datas); } @@ -28,40 +25,94 @@ class Optlist extends Opt /** * Get the code to insert directly */ - public function getcode() : string + public function getcode(): string { return '%LIST?' . $this->getquery() . '%'; } - public function listhtml(array $pagelist) - { - if(!empty($this->render)) { - $content = ''; + if ($this->thumbnail) { + $content .= '' . $page->title() . ''; + } + + - return $content; - + switch ($this->style) { + case 'card': + $li .= $this->li($this->a($title . $content, $class, $page->id()), $page->id()); + break; + + case 'list': + $li .= $this->li($this->a($title, $class, $page->id()) . $content, $page->id()); + break; + } } + + $html = $this->ul($li); + + return $html; + } + + public function ul(string $content) + { + return ''; } + public function li(string $content, string $id) + { + return '
  • ' . PHP_EOL . $content . PHP_EOL . '
  • ' . PHP_EOL; + } + + public function a(string $content, string $class, string $id) + { + return '' . $content . '' . PHP_EOL; + } + + public function spandescription(Page $page) + { + if ($this->description) { + return '' . $page->description() . ''; + } else { + return ''; + } + } + + // _______________________________________ G E T _____________________________________ @@ -137,13 +188,8 @@ class Optlist extends Opt public function setstyle($style) { - $this->style = intval($style); - } - - public function setrender($render) - { - if(is_a($render, 'Wcms\Modelrender')) { - $this->render = $render; + if (is_string($style) && key_exists($style, Model::LIST_STYLES)) { + $this->style = $style; } } } diff --git a/app/view/templates/homemenu.php b/app/view/templates/homemenu.php index 5f484a1..9d28ffa 100644 --- a/app/view/templates/homemenu.php +++ b/app/view/templates/homemenu.php @@ -227,8 +227,7 @@
    diff --git a/app/view/templates/info.php b/app/view/templates/info.php index a5a5213..0e722a6 100644 --- a/app/view/templates/info.php +++ b/app/view/templates/info.php @@ -53,7 +53,9 @@
  • 🎡 James Moss's Flywheel Database as json noSQL flatfile database engine
  • 📝 Michel Fortin's Markdown Extra markdown library
  • 🎨 Plates as templating engine
  • -
  • 🐶 Alto Router as router engine
  • +
  • 🐶 Alto Router as router engine
  • +
  • 🐒 Code mirror as rich text editor
  • +
  • ⚛️ Cytoscape.js as graph tool
  • Special thanks to :

    -- cgit v1.2.3