aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-04-07 19:43:58 +0200
committervincent-peugnet <v.peugnet@free.fr>2020-04-07 19:43:58 +0200
commitb49830232096951202688bd775193424880bbd11 (patch)
treeb41d9b23fd853b45ece6c3f9b9e255e0da364ca7
parent7c9ceb23b415eb6863c51ac1eb1fab8d50e2aa99 (diff)
downloadwcms-b49830232096951202688bd775193424880bbd11.tar.gz
wcms-b49830232096951202688bd775193424880bbd11.zip
refactor LIST fix #74
-rw-r--r--MANUAL.md8
-rw-r--r--app/class/Model.php5
-rw-r--r--app/class/Modelrender.php6
-rw-r--r--app/class/Optlist.php120
-rw-r--r--app/view/templates/homemenu.php3
-rw-r--r--app/view/templates/info.php4
6 files changed, 103 insertions, 43 deletions
diff --git a/MANUAL.md b/MANUAL.md
index 072182b..78f9dfc 100644
--- a/MANUAL.md
+++ b/MANUAL.md
@@ -294,7 +294,15 @@ Generate :
....
</ul>
+##### styling
+Some `.class` and `#id` are generated to optimize styling.
+
+`.public`, `.private`, `not_published` are used to define the privacity level of pages.
+
+`.current_page` is used to highlight the current page.
+
+`#<pageid>` is set to each item to allow selective styling.
#### Media list
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 = '<img class="thumbnail" src="' . Model::thumbnailpath() . $this->page->id() . '.jpg" alt="' . $this->page->title() . '">';
+ $img = '<img class="thumbnail" src="' . Model::thumbnailpath() . $this->page->thumbnail() . '" alt="' . $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 = '<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>';
+ public function listhtml(array $pagelist, Page $actualpage, Modelrender $render)
+ {
+ $this->render = $render;
+
+ $li = '';
+
+ foreach ($pagelist as $page) {
+
+ // ================= Class =============
+
+ $classdata = [];
+ if ($page->id() === $actualpage->id()) {
+ $classdata['actual'] = 'current_page';
+ }
+ $classdata['secure'] = $page->secure('string');
+ $class = ' class="' . implode(' ', $classdata) . '" ';
+
+
+ // ================ Content
+
+ $content = '';
+
+ $title = '<span class="title">' . $page->title() . '</span>';
+ if ($this->description()) {
+ $content .= '<span class="description">' . $page->description() . '</span>';
+ }
+ if ($this->date()) {
+ $content .= '<time datetime="' . $page->date('pdate') . '">' . $page->date('pdate') . '</time>' . PHP_EOL;
+ }
+ if ($this->time()) {
+ $content .= '<time datetime="' . $page->date('ptime') . '">' . $page->date('ptime') . '</time>' . PHP_EOL;
+ }
+ if ($this->author()) {
+ $content .= $page->authors('string') . PHP_EOL;
}
- $content .= '</ul>';
+ if ($this->thumbnail) {
+ $content .= '<img class="thumbnail" src="' . Model::thumbnailpath() . $page->thumbnail() . '" alt="' . $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 '<ul class="pagelist">' . PHP_EOL . $content . PHP_EOL . '</ul>';
}
+ public function li(string $content, string $id)
+ {
+ return '<li id="' . $id . '">' . PHP_EOL . $content . PHP_EOL . '</li>' . PHP_EOL;
+ }
+
+ public function a(string $content, string $class, string $id)
+ {
+ return '<a ' . $class . ' href="' . $this->render->upage($id) . '">' . $content . '</a>' . PHP_EOL;
+ }
+
+ public function spandescription(Page $page)
+ {
+ if ($this->description) {
+ return '<span class="description">' . $page->description() . '</span>';
+ } 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 @@
<label for="list_author">Show author(s)</label>
</br>
<select name="style" id="list_style">
- <option value="0">list</option>
- <option value="1" <?= !empty($optlist) && $optlist->style() == 1 ? 'selected' : '' ?>>div</option>
+ <?= options(Wcms\Model::LIST_STYLES , !empty($optlist) ? $optlist->style() : null) ?>
</select>
<input type="submit" value="generate">
</form>
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 @@
<li><a href="https://github.com/jamesmoss/flywheel" target="_blank">🎡 James Moss's Flywheel Database</a> <i>as json noSQL flatfile database engine</i></li>
<li><a href="https://github.com/michelf/php-markdown" target="_blank">📝 Michel Fortin's Markdown Extra</a> <i>markdown library</i></li>
<li><a href="https://github.com/thephpleague/plates" target="_blank">🎨 Plates</a> <i>as templating engine</i></li>
- <li><a href="https://github.com/dannyvankooten/AltoRouter">🐶 Alto Router</a> <i>as router engine</i></li>
+ <li><a href="https://github.com/dannyvankooten/AltoRouter" target="_blank">🐶 Alto Router</a> <i>as router engine</i></li>
+ <li><a href="https://codemirror.net/" target="_blank">🐒 Code mirror</a> <i>as rich text editor</i></li>
+ <li><a href="https://js.cytoscape.org/" target="_blank">⚛️ Cytoscape.js</a> <i>as graph tool</i></li>
</ul>
<h3>Special thanks to :</h3>