aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
Diffstat (limited to 'app/class')
-rw-r--r--app/class/Model.php5
-rw-r--r--app/class/Modelrender.php6
-rw-r--r--app/class/Optlist.php120
3 files changed, 91 insertions, 40 deletions
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;
}
}
}