♻️ Refactor archive list creation
This commit is contained in:
parent
c4b695197d
commit
729fc7552c
5 changed files with 82 additions and 17 deletions
|
@ -46,4 +46,19 @@ class Archives extends dbList {
|
||||||
return $this->save();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -41,6 +41,7 @@ define('PATH_CONTENT', PATH_ROOT . 'bl-content' . DS);
|
||||||
define('PATH_ABSTRACT', PATH_KERNEL . 'abstract' . DS);
|
define('PATH_ABSTRACT', PATH_KERNEL . 'abstract' . DS);
|
||||||
define('PATH_RULES', PATH_KERNEL . 'boot' . DS . 'rules' . DS);
|
define('PATH_RULES', PATH_KERNEL . 'boot' . DS . 'rules' . DS);
|
||||||
define('PATH_HELPERS', PATH_KERNEL . 'helpers' . DS);
|
define('PATH_HELPERS', PATH_KERNEL . 'helpers' . DS);
|
||||||
|
define('PATH_CLASSES', PATH_KERNEL . 'class' . DS);
|
||||||
define('PATH_AJAX', PATH_KERNEL . 'ajax' . DS);
|
define('PATH_AJAX', PATH_KERNEL . 'ajax' . DS);
|
||||||
define('PATH_CORE_JS', PATH_KERNEL . 'js' . DS);
|
define('PATH_CORE_JS', PATH_KERNEL . 'js' . DS);
|
||||||
|
|
||||||
|
@ -116,6 +117,9 @@ include(PATH_KERNEL . 'social.class.php');
|
||||||
// Include functions
|
// Include functions
|
||||||
include(PATH_KERNEL . 'functions.php');
|
include(PATH_KERNEL . 'functions.php');
|
||||||
|
|
||||||
|
// Include classes
|
||||||
|
include(PATH_CLASSES . 'link.class.php');
|
||||||
|
|
||||||
// Include Helpers Classes
|
// Include Helpers Classes
|
||||||
include(PATH_HELPERS . 'text.class.php');
|
include(PATH_HELPERS . 'text.class.php');
|
||||||
include(PATH_HELPERS . 'log.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 . 'paginator.class.php');
|
||||||
include(PATH_HELPERS . 'image.class.php');
|
include(PATH_HELPERS . 'image.class.php');
|
||||||
include(PATH_HELPERS . 'media.class.php');
|
include(PATH_HELPERS . 'media.class.php');
|
||||||
|
include(PATH_HELPERS . 'menus.class.php');
|
||||||
include(PATH_HELPERS . 'tcp.class.php');
|
include(PATH_HELPERS . 'tcp.class.php');
|
||||||
include(PATH_HELPERS . 'dom.class.php');
|
include(PATH_HELPERS . 'dom.class.php');
|
||||||
include(PATH_HELPERS . 'cookie.class.php');
|
include(PATH_HELPERS . 'cookie.class.php');
|
||||||
|
|
40
bl-kernel/class/link.class.php
Normal file
40
bl-kernel/class/link.class.php
Normal 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>";
|
||||||
|
}
|
||||||
|
}
|
21
bl-kernel/helpers/menus.class.php
Normal file
21
bl-kernel/helpers/menus.class.php
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -44,23 +44,7 @@ class pluginArchives extends Plugin
|
||||||
$html = '<div class="plugin plugin-archives">';
|
$html = '<div class="plugin plugin-archives">';
|
||||||
$html .= '<h2 class="plugin-label">' . $this->getValue('label') . '</h2>';
|
$html .= '<h2 class="plugin-label">' . $this->getValue('label') . '</h2>';
|
||||||
$html .= '<div class="plugin-content">';
|
$html .= '<div class="plugin-content">';
|
||||||
$html .= '<ul class="flat-list">';
|
$html .= MenuHelper::getArchive($this->getValue('monthly'), "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 .= '</div>';
|
$html .= '</div>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue