♻️ Refactor archive list creation

This commit is contained in:
Kazhnuz 2025-08-22 11:36:30 +02:00
parent c4b695197d
commit 729fc7552c
5 changed files with 82 additions and 17 deletions

View file

@ -46,4 +46,19 @@ class Archives extends dbList {
return $this->save();
}
public function getLinkList($month, $class = "", $classActive = "active")
{
$listLink = array();
foreach ($this->db as $pageKey=>$pageFields) {
if (
($month && strlen($pageKey) != 4)
|| (!$month && strlen($pageKey) == 4)
) {
$link = DOMAIN_ARCHIVES . $pageKey;
$listLink[] = new Link($pageFields['name'], $link, $class, $classActive);
}
}
return $listLink;
}
}

View file

@ -41,6 +41,7 @@ define('PATH_CONTENT', PATH_ROOT . 'bl-content' . DS);
define('PATH_ABSTRACT', PATH_KERNEL . 'abstract' . DS);
define('PATH_RULES', PATH_KERNEL . 'boot' . DS . 'rules' . DS);
define('PATH_HELPERS', PATH_KERNEL . 'helpers' . DS);
define('PATH_CLASSES', PATH_KERNEL . 'class' . DS);
define('PATH_AJAX', PATH_KERNEL . 'ajax' . DS);
define('PATH_CORE_JS', PATH_KERNEL . 'js' . DS);
@ -116,6 +117,9 @@ include(PATH_KERNEL . 'social.class.php');
// Include functions
include(PATH_KERNEL . 'functions.php');
// Include classes
include(PATH_CLASSES . 'link.class.php');
// Include Helpers Classes
include(PATH_HELPERS . 'text.class.php');
include(PATH_HELPERS . 'log.class.php');
@ -131,6 +135,7 @@ include(PATH_HELPERS . 'alert.class.php');
include(PATH_HELPERS . 'paginator.class.php');
include(PATH_HELPERS . 'image.class.php');
include(PATH_HELPERS . 'media.class.php');
include(PATH_HELPERS . 'menus.class.php');
include(PATH_HELPERS . 'tcp.class.php');
include(PATH_HELPERS . 'dom.class.php');
include(PATH_HELPERS . 'cookie.class.php');

View file

@ -0,0 +1,40 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
/**
* Basic representation of a Link
*/
class Link {
private $label;
private $href;
private $class;
private $classActive;
function __construct($label, $href, $class = "", $classActive = "active")
{
$this->label = $label;
$this->href = $href;
$this->class = $class;
$this->classActive = $classActive;
}
function isActive()
{
return false;
}
function haveClass()
{
return ($this->getClasses() != "");
}
function getClasses()
{
return $this->class . ($this->isActive() ? " " . $this->classActive : "");
}
function toHTML()
{
return "<a href='" . $this->href . "' " . ($this->haveClass() ? "class='" . $this->getClasses() . "'" : "" ) . " >".$this->label."</a>";
}
}

View file

@ -0,0 +1,21 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
class MenuHelper {
public static function getArchive($monthly, $classUl = "", $classLink = "", $classActive = "active")
{
global $archives;
return MenuHelper::toMenu($archives->getLinkList($monthly, $classLink, $classActive), $classUl);
}
private static function toMenu($links, $classUl)
{
$html = '<ul '. ($classUl != '' ? 'class="'.$classUl.'"' : '') .'>';
foreach ($links as $link) {
$html .= "<li>" . $link->toHTML() . "</li>";
}
$html .= "</ul>";
return $html;
}
}

View file

@ -44,23 +44,7 @@ class pluginArchives extends Plugin
$html = '<div class="plugin plugin-archives">';
$html .= '<h2 class="plugin-label">' . $this->getValue('label') . '</h2>';
$html .= '<div class="plugin-content">';
$html .= '<ul class="flat-list">';
// By default the database of tags are alphanumeric sorted
foreach ($archives->db as $key => $fields) {
if (
($this->getValue('monthly') && strlen($key) != 4)
|| (!$this->getValue('monthly') && strlen($key) == 4)
) {
$html .= '<li>';
$html .= '<a href="' . DOMAIN_ARCHIVES . $key . '">';
$html .= $fields['name'];
$html .= '</a>';
$html .= '</li>';
}
}
$html .= '</ul>';
$html .= MenuHelper::getArchive($this->getValue('monthly'), "flat-list");
$html .= '</div>';
$html .= '</div>';