koblog/bl-plugins/last-articles/plugin.php
2025-08-22 23:54:43 +02:00

59 lines
1.5 KiB
PHP

<?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 = '<nav 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 .= MenuHelper::getArticles($this->getValue('numberOfItems'), false);
$html .= '</div>';
$html .= '</nav>';
return $html;
}
}