diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-04-07 17:16:10 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-04-07 17:16:10 +0200 |
commit | 7c9ceb23b415eb6863c51ac1eb1fab8d50e2aa99 (patch) | |
tree | 992b2d40a7b27717842be156cc8ceab7ac01c093 | |
parent | 8e8fa09a09152eb5a7bd749f58472fa385d11bbc (diff) | |
download | wcms-7c9ceb23b415eb6863c51ac1eb1fab8d50e2aa99.tar.gz wcms-7c9ceb23b415eb6863c51ac1eb1fab8d50e2aa99.zip |
model page,render refactor
getlister > pagelist
optlist now generate html
-rw-r--r-- | app/class/Controllerhome.php | 8 | ||||
-rw-r--r-- | app/class/Controllerpage.php | 2 | ||||
-rw-r--r-- | app/class/Modelhome.php | 16 | ||||
-rw-r--r-- | app/class/Modelpage.php | 23 | ||||
-rw-r--r-- | app/class/Modelrender.php | 79 | ||||
-rw-r--r-- | app/class/Modeltimeline.php | 2 | ||||
-rw-r--r-- | app/class/Modeluser.php | 2 | ||||
-rw-r--r-- | app/class/Opt.php | 11 | ||||
-rw-r--r-- | app/class/Optlist.php | 42 | ||||
-rw-r--r-- | app/class/Page.php | 9 |
10 files changed, 88 insertions, 106 deletions
diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index 907bef7..52e92c7 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -27,7 +27,7 @@ class Controllerhome extends Controllerpage } else { - $pagelist = $this->modelhome->getlister(); + $pagelist = $this->modelhome->pagelist(); $this->opt = $this->modelhome->optinit($pagelist); $vars['colors'] = new Colors($this->opt->taglist()); @@ -91,7 +91,7 @@ class Controllerhome extends Controllerpage { if (isset($_POST['query']) && $this->user->iseditor()) { $datas = array_merge($_POST, $_SESSION['opt']); - $this->optlist = $this->modelhome->Optlistinit($pagelist); + $this->optlist = new Optlist(); $this->optlist->hydrate($datas); $vars['optlist'] = $this->optlist; } @@ -145,7 +145,7 @@ class Controllerhome extends Controllerpage public function renderall() { if ($this->user->iseditor()) { - $pagelist = $this->modelhome->getlister(); + $pagelist = $this->modelhome->pagelist(); foreach ($pagelist as $page) { $this->renderpage($page); $this->pagemanager->update($page); @@ -232,7 +232,7 @@ class Controllerhome extends Controllerpage public function multirender() { $pagelist = $_POST['pagesid'] ?? []; - $pagelist = $this->pagemanager->getlisterid($pagelist); + $pagelist = $this->pagemanager->pagelistbyid($pagelist); foreach ($pagelist as $page) { $page = $this->renderpage($page); $this->pagemanager->update($page); diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php index c6983af..909a2c2 100644 --- a/app/class/Controllerpage.php +++ b/app/class/Controllerpage.php @@ -180,7 +180,7 @@ class Controllerpage extends Controller $datas['pagelist'] = $this->pagemanager->list(); - $pagelist = $this->pagemanager->getlister(); + $pagelist = $this->pagemanager->pagelist(); $datas['tagpagelist'] = $this->pagemanager->tagpagelist($this->page->tag('array'), $pagelist); $datas['lasteditedpagelist'] = $this->pagemanager->lasteditedpagelist(5, $pagelist); diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index 9957c0b..b7b063e 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -12,7 +12,7 @@ class Modelhome extends Modelpage public function optinit($table) { - $opt = new Opt(Page::classvarlist()); + $opt = new Opt(); $opt->setcol(['id', 'tag', 'linkto', 'description', 'title', 'datemodif', 'datecreation', 'date', 'secure', 'authors', 'visitcount', 'editcount', 'affcount']); $opt->settaglist($table); $opt->setauthorlist($table); @@ -22,20 +22,8 @@ class Modelhome extends Modelpage return $opt; } - /** - * Initialise Optlist object using - * - * @param array $table the list of all pages objects - * - * @return Optlist Object initialized - */ - public function Optlistinit(array $table) - { - $optlist = new Optlist(Page::classvarlist()); - return $optlist; - } - + /** * @param array $pagelist of Pages objects as `id => Page` * @param Opt $opt diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php index 43ba117..492f03e 100644 --- a/app/class/Modelpage.php +++ b/app/class/Modelpage.php @@ -10,9 +10,7 @@ use DateTimeImmutable; class Modelpage extends Modeldb { - const SELECT = ['title', 'id', 'description', 'tag', 'date', 'datecreation', 'datemodif', 'daterender', 'css', 'quickcss', 'javascript', 'body', 'header', 'main', 'nav', 'aside', 'footer', 'render', 'secure', 'invitepassword', 'interface', 'linkto', 'template', 'affcount', 'editcount']; - const BY = ['datecreation', 'title', 'id', 'description', 'datemodif', 'secure']; - const ORDER = ['DESC', 'ASC']; + protected $pagelist = []; public function __construct() @@ -25,18 +23,21 @@ class Modelpage extends Modeldb } /** - * Scan library for all pages as objects + * Scan library for all pages as objects. + * If a scan has already been perform, it will just + * read `pagelist` Propriety * * @return array of Pages objects as `id => Page` */ - public function getlister() + public function pagelist() { - $pagelist = []; - $list = $this->repo->findAll(); - foreach ($list as $pagedata) { - $pagelist[$pagedata->id] = new Page($pagedata); + if(empty($this->pagelist)) { + $list = $this->repo->findAll(); + foreach ($list as $pagedata) { + $this->pagelist[$pagedata->id] = new Page($pagedata); + } } - return $pagelist; + return $this->pagelist; } @@ -47,7 +48,7 @@ class Modelpage extends Modeldb * * @return array of Page objects */ - public function getlisterid(array $idlist = []) : array + public function pagelistbyid(array $idlist = []) : array { $pagedatalist = $this->repo->query() ->where('__id', 'IN', $idlist) diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php index 2960f70..5687f03 100644 --- a/app/class/Modelrender.php +++ b/app/class/Modelrender.php @@ -11,8 +11,6 @@ class Modelrender extends Modelpage protected $router; /** @var Page */ protected $page; - /** @var array list of ID as strings */ - protected $pagelist; protected $linkto = []; protected $sum = []; protected $internallinkblank = ''; @@ -25,7 +23,7 @@ class Modelrender extends Modelpage parent::__construct(); $this->router = $router; - $this->pagelist = $this->list(); + $this->pagelist = $this->pagelist(); if (Config::internallinkblank()) { $this->internallinkblank = ' target="_blank" '; @@ -54,7 +52,6 @@ class Modelrender extends Modelpage * Generate page relative link for given page_id including basepath * * @param string $id given page ID - * * @return string Relative URL */ public function upage(string $id): string @@ -179,7 +176,7 @@ class Modelrender extends Modelpage { $content = $this->article($element->content()); $content = $this->automedialist($content); - $content = $this->pagelist($content); + $content = $this->pageoptlist($content); $content = $this->date($content); $content = $this->thumbnail($content); if ($element->autolink()) { @@ -306,7 +303,7 @@ class Modelrender extends Modelpage if (preg_match('%https?:\/\/\S*%', $this->page->redirection(), $out)) { $url = $out[0]; $head .= PHP_EOL . '<meta http-equiv="refresh" content="' . $this->page->refresh() . '; URL=' . $url . '" />'; - } elseif (in_array($this->page->redirection(), $this->pagelist)) { + } elseif (key_exists($this->page->redirection(), $this->pagelist())) { $url = $this->upage($this->page->redirection()); $head .= PHP_EOL . '<meta http-equiv="refresh" content="' . $this->page->refresh() . '; URL=' . $url . '" />'; } @@ -545,6 +542,29 @@ class Modelrender extends Modelpage } + /** + * Render pages list + */ + public function pageoptlist(string $text): string + { + $matches = $this->match($text, 'LIST'); + + $modelhome = new Modelhome(); + + if (isset($matches)) { + + foreach ($matches as $match) { + $optlist = new Optlist(['render' => $this]); + $optlist->parsehydrate($match['options']); + $pagetable = $modelhome->pagetable($this->pagelist(), $optlist, '', []); + $content = $optlist->listhtml($pagetable); + $text = str_replace($match['fullmatch'], $content, $text); + } + } + return $text; + } + + public function date(string $text): string { @@ -617,53 +637,6 @@ class Modelrender extends Modelpage return $text; } - /** - * Render pages list - */ - public function pagelist(string $text): string - { - $matches = $this->match($text, 'LIST'); - - $modelhome = new Modelhome(); - - if (isset($matches)) { - $pagelist = $this->getlister(); - - foreach ($matches as $match) { - $optlist = $modelhome->Optlistinit($pagelist); - $optlist->parsehydrate($match['options']); - $pagetable = $modelhome->pagetable($pagelist, $optlist, '', []); - - $content = '<ul class="pagelist">' . PHP_EOL; - foreach ($pagetable as $page) { - $content .= '<li>' . PHP_EOL; - $content .= '<a href="' . $this->upage($page->id()) . '">' . $page->title() . '</a>' . PHP_EOL; - if ($optlist->description()) { - $content .= '<em>' . $page->description() . '</em>' . PHP_EOL; - } - if ($optlist->date()) { - $content .= '<code>' . $page->date('pdate') . '</code>' . PHP_EOL; - } - if ($optlist->time()) { - $content .= '<code>' . $page->date('ptime') . '</code>' . PHP_EOL; - } - if ($optlist->author()) { - $content .= $page->authors('string') . PHP_EOL; - } - $content .= '</li>'; - } - $content .= '</ul>'; - - $text = str_replace($match['fullmatch'], $content, $text); - } - } - return $text; - } - - - - - diff --git a/app/class/Modeltimeline.php b/app/class/Modeltimeline.php index 248e0f6..3e8cf99 100644 --- a/app/class/Modeltimeline.php +++ b/app/class/Modeltimeline.php @@ -45,7 +45,7 @@ class Modeltimeline extends Modeldb } - public function getlisterid(array $idlist = []) : array + public function pagelistbyid(array $idlist = []) : array { $eventdatalist = $this->repo->query() ->where('__id', 'IN', $idlist) diff --git a/app/class/Modeluser.php b/app/class/Modeluser.php index c921b4c..071320e 100644 --- a/app/class/Modeluser.php +++ b/app/class/Modeluser.php @@ -69,7 +69,7 @@ class Modeluser extends Modeldb } - public function getlisterid(array $idlist = []) + public function pagelistbyid(array $idlist = []) { $userdatalist = $this->repo->query() ->where('__id', 'IN', $idlist) diff --git a/app/class/Opt.php b/app/class/Opt.php index 821fc92..59a3302 100644 --- a/app/class/Opt.php +++ b/app/class/Opt.php @@ -22,9 +22,10 @@ class Opt extends Item protected $pagevarlist; - public function __construct(array $donnees = []) + public function __construct(array $data = []) { - $this->hydrate($donnees); + $this->hydrate($data); + $this->pagevarlist = get_object_vars(new Page()); } @@ -435,10 +436,4 @@ class Opt extends Item $this->pageidlist = $idlist; return true; } - - - public function setpagevarlist(array $pagevarlist) - { - $this->pagevarlist = $pagevarlist; - } } diff --git a/app/class/Optlist.php b/app/class/Optlist.php index d6a9cdb..122072b 100644 --- a/app/class/Optlist.php +++ b/app/class/Optlist.php @@ -12,6 +12,9 @@ class Optlist extends Opt protected $author = 0; protected $style = 0; + /** @var Modelrender Render engine used to generate pages urls */ + protected $render = null; + public function parsehydrate(string $encoded) @@ -31,6 +34,34 @@ class Optlist extends Opt } + public function listhtml(array $pagelist) + { + if(!empty($this->render)) { + $content = '<ul class="pagelist">' . PHP_EOL; + foreach ($pagelist as $page) { + $content .= '<li>' . PHP_EOL; + $content .= '<a href="' . $this->render->upage($page->id()) . '">' . $page->title() . '</a>' . PHP_EOL; + if ($this->description()) { + $content .= '<em>' . $page->description() . '</em>' . PHP_EOL; + } + if ($this->date()) { + $content .= '<code>' . $page->date('pdate') . '</code>' . PHP_EOL; + } + if ($this->time()) { + $content .= '<code>' . $page->date('ptime') . '</code>' . PHP_EOL; + } + if ($this->author()) { + $content .= $page->authors('string') . PHP_EOL; + } + $content .= '</li>'; + } + $content .= '</ul>'; + + return $content; + + } + } + // _______________________________________ G E T _____________________________________ @@ -108,8 +139,11 @@ class Optlist extends Opt { $this->style = intval($style); } -} - - -?>
\ No newline at end of file + public function setrender($render) + { + if(is_a($render, 'Wcms\Modelrender')) { + $this->render = $render; + } + } +} diff --git a/app/class/Page.php b/app/class/Page.php index 6eb6473..eefbca7 100644 --- a/app/class/Page.php +++ b/app/class/Page.php @@ -108,15 +108,6 @@ class Page extends Dbitem } - public static function classvarlist() - { - $classvarlist = []; - foreach (get_class_vars(__class__) as $var => $default) { - $classvarlist[] = $var; - } - return ['pagevarlist' => $classvarlist]; - } - // _____________________________________________________ G E T ____________________________________________________ public function id($type = 'string') |