♻️ Separation plugin navigation et derniers articles

Ils ont des rôles différents
This commit is contained in:
Kazhnuz 2025-08-22 18:24:38 +02:00
parent b1800721f8
commit 849b15ed59
7 changed files with 128 additions and 48 deletions

View file

@ -15,6 +15,12 @@ class MenuHelper {
return MenuHelper::toMenu($categories->getLinkList($showEmpty, $showCount, $classLink, $classActive), $classUl);
}
public static function getArticles($monthly, $classUl = "", $classLink = "", $classActive = "active")
{
global $pages;
return MenuHelper::toMenu($pages->getLinkList($monthly, $classLink, $classActive), $classUl);
}
private static function toMenu($links, $classUl)
{
$html = '<ul '. ($classUl != '' ? 'class="'.$classUl.'"' : '') .'>';

View file

@ -0,0 +1,8 @@
{
"plugin-data":
{
"name": "Latest articles",
"description": "Show latest articles in the blog."
},
"amount-of-items": "Amount of items"
}

View file

@ -0,0 +1,8 @@
{
"plugin-data":
{
"name": "Derniers articles",
"description": "Afficher les derniers articles parus sur le blog."
},
"amount-of-items": "Quantité darticles"
}

View file

@ -0,0 +1,11 @@
{
"author": "Koblog",
"email": "",
"website": "https://plugins.koblog.com",
"version": "kb_0.0.1",
"releaseDate": "2024-08-23",
"license": "MIT",
"compatible": "kb_0.0.1",
"notes": "",
"type": "widget"
}

View file

@ -0,0 +1,78 @@
<?php
class pluginLastArticles extends Plugin
{
public function init()
{
global $L;
// Fields and default values for the database of this plugin
$this->dbFields = array(
'label' => $L->get('Lastest articles'),
'numberOfItems' => 5
);
}
// Method called on the settings of the plugin on the admin area
public function form()
{
global $L;
$html = '<div>';
$html .= '<label>' . $L->get('Label') . '</label>';
$html .= '<input id="jslabel" name="label" type="text" dir="auto" value="' . $this->getValue('label') . '">';
$html .= '<span class="tip">' . $L->get('This title is almost always used in the sidebar of the site') . '</span>';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>' . $L->get('Amount of items') . '</label>';
$html .= '<input id="jsnumberOfItems" name="numberOfItems" type="text" dir="auto" value="' . $this->getValue('numberOfItems') . '">';
$html .= '</div>';
return $html;
}
// Method called on the sidebar of the website
public function siteSidebar()
{
global $L;
global $url;
global $site;
global $pages;
// HTML for sidebar
$html = '<div class="plugin plugin-lastarticles">';
// Print the label if not empty
$label = $this->getValue('label');
if (!empty($label)) {
$html .= '<h2 class="plugin-label">' . $label . '</h2>';
}
$html .= '<div class="plugin-content">';
$html .= '<ul>';
// List of published pages
$onlyPublished = true;
$pageNumber = 1;
$numberOfItems = $this->getValue('numberOfItems');
$publishedPages = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
foreach ($publishedPages as $pageKey) {
try {
$page = new Page($pageKey);
$html .= '<li>';
$html .= '<a href="' . $page->permalink() . '">' . $page->title() . '</a>';
$html .= '</li>';
} catch (Exception $e) {
// Continue
}
}
$html .= '</ul>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
}

View file

@ -2,9 +2,8 @@
"plugin-data":
{
"name": "Navigation",
"description": "Créez votre propre menu de navigation avec les dernières pages ou pages statiques."
"description": "Créez votre propre menu de navigation avec les différentes pages non-statiques et leurs enfants."
},
"home-link": "Lien de la page daccueil",
"show-the-home-link-on-the-sidebar": "Afficher un lien vers la page daccueil dans la barre latérale.",
"amount-of-items": "Quantité darticles"
"show-the-home-link-on-the-sidebar": "Afficher un lien vers la page daccueil dans la barre latérale."
}

View file

@ -8,8 +8,7 @@ class pluginNavigation extends Plugin
// Fields and default values for the database of this plugin
$this->dbFields = array(
'label' => 'Navigation',
'homeLink' => true,
'numberOfItems' => 5
'homeLink' => true
);
}
@ -33,13 +32,6 @@ class pluginNavigation extends Plugin
$html .= '<span class="tip">' . $L->get('Show the home link on the sidebar') . '</span>';
$html .= '</div>';
if (ORDER_BY == 'date') {
$html .= '<div>';
$html .= '<label>' . $L->get('Amount of items') . '</label>';
$html .= '<input id="jsnumberOfItems" name="numberOfItems" type="text" dir="auto" value="' . $this->getValue('numberOfItems') . '">';
$html .= '</div>';
}
return $html;
}
@ -70,46 +62,24 @@ class pluginNavigation extends Plugin
$html .= '</li>';
}
// Pages order by position
if (ORDER_BY == 'position') {
// Get parents
$parents = buildParentPages();
foreach ($parents as $parent) {
$html .= '<li class="parent">';
$html .= '<a href="' . $parent->permalink() . '">' . $parent->title() . '</a>';
// Get parents
$parents = buildParentPages();
foreach ($parents as $parent) {
$html .= '<li class="parent">';
$html .= '<a href="' . $parent->permalink() . '">' . $parent->title() . '</a>';
if ($parent->hasChildren()) {
// Get children
$children = $parent->children();
$html .= '<ul class="child">';
foreach ($children as $child) {
$html .= '<li class="child">';
$html .= '<a class="child" href="' . $child->permalink() . '">' . $child->title() . '</a>';
$html .= '</li>';
}
$html .= '</ul>';
}
$html .= '</li>';
}
}
// Pages order by date
else {
// List of published pages
$onlyPublished = true;
$pageNumber = 1;
$numberOfItems = $this->getValue('numberOfItems');
$publishedPages = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
foreach ($publishedPages as $pageKey) {
try {
$page = new Page($pageKey);
$html .= '<li>';
$html .= '<a href="' . $page->permalink() . '">' . $page->title() . '</a>';
if ($parent->hasChildren()) {
// Get children
$children = $parent->children();
$html .= '<ul class="child">';
foreach ($children as $child) {
$html .= '<li class="child">';
$html .= '<a class="child" href="' . $child->permalink() . '">' . $child->title() . '</a>';
$html .= '</li>';
} catch (Exception $e) {
// Continue
}
$html .= '</ul>';
}
$html .= '</li>';
}
$html .= '</ul>';