2018-02-20 17:43:41 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class pluginNavigation extends Plugin {
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
// Fields and default values for the database of this plugin
|
|
|
|
$this->dbFields = array(
|
|
|
|
'label'=>'Navigation',
|
|
|
|
'homeLink'=>true,
|
2018-08-06 21:46:58 +02:00
|
|
|
'numberOfItems'=>5
|
2018-02-20 17:43:41 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method called on the settings of the plugin on the admin area
|
|
|
|
public function form()
|
|
|
|
{
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2018-02-20 17:43:41 +01:00
|
|
|
|
2018-07-02 00:24:53 +02:00
|
|
|
$html = '<div class="alert alert-primary" role="alert">';
|
|
|
|
$html .= $this->description();
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
2018-08-05 17:54:20 +02:00
|
|
|
$html .= '<label>'.$L->get('Label').'</label>';
|
2018-02-20 17:43:41 +01:00
|
|
|
$html .= '<input id="jslabel" name="label" type="text" value="'.$this->getValue('label').'">';
|
2018-08-05 17:54:20 +02:00
|
|
|
$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>';
|
2018-02-20 17:43:41 +01:00
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
2018-08-05 17:54:20 +02:00
|
|
|
$html .= '<label>'.$L->get('Home link').'</label>';
|
2018-02-20 17:43:41 +01:00
|
|
|
$html .= '<select name="homeLink">';
|
2018-08-05 17:54:20 +02:00
|
|
|
$html .= '<option value="true" '.($this->getValue('homeLink')===true?'selected':'').'>'.$L->get('Enabled').'</option>';
|
|
|
|
$html .= '<option value="false" '.($this->getValue('homeLink')===false?'selected':'').'>'.$L->get('Disabled').'</option>';
|
2018-02-20 17:43:41 +01:00
|
|
|
$html .= '</select>';
|
2018-08-05 17:54:20 +02:00
|
|
|
$html .= '<span class="tip">'.$L->get('Show the home link on the sidebar').'</span>';
|
2018-02-20 17:43:41 +01:00
|
|
|
$html .= '</div>';
|
|
|
|
|
2018-02-24 22:39:39 +01:00
|
|
|
if (ORDER_BY=='date') {
|
|
|
|
$html .= '<div>';
|
2018-08-05 17:54:20 +02:00
|
|
|
$html .= '<label>'.$L->get('Amount of items').'</label>';
|
2018-08-06 21:46:58 +02:00
|
|
|
$html .= '<input id="jsnumberOfItems" name="numberOfItems" type="text" value="'.$this->getValue('numberOfItems').'">';
|
2018-02-24 22:39:39 +01:00
|
|
|
$html .= '</div>';
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:43:41 +01:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method called on the sidebar of the website
|
|
|
|
public function siteSidebar()
|
|
|
|
{
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2018-07-17 19:13:01 +02:00
|
|
|
global $url;
|
|
|
|
global $site;
|
2018-08-03 18:59:23 +02:00
|
|
|
global $pages;
|
2018-02-20 17:43:41 +01:00
|
|
|
|
|
|
|
// HTML for sidebar
|
|
|
|
$html = '<div class="plugin plugin-navigation">';
|
|
|
|
|
|
|
|
// 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>';
|
|
|
|
|
2018-02-24 22:39:39 +01:00
|
|
|
// Show Home page link
|
|
|
|
if ($this->getValue('homeLink')) {
|
|
|
|
$html .= '<li>';
|
2018-08-05 17:54:20 +02:00
|
|
|
$html .= '<a href="' . $site->url() . '">' . $L->get('Home page') . '</a>';
|
2018-02-24 22:39:39 +01:00
|
|
|
$html .= '</li>';
|
2018-02-20 17:43:41 +01:00
|
|
|
}
|
2018-02-24 22:39:39 +01:00
|
|
|
|
2018-03-07 12:31:08 +01:00
|
|
|
// 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>';
|
|
|
|
|
|
|
|
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>';
|
|
|
|
}
|
2018-02-20 17:43:41 +01:00
|
|
|
$html .= '</li>';
|
|
|
|
}
|
2018-02-24 22:39:39 +01:00
|
|
|
}
|
2018-03-07 12:31:08 +01:00
|
|
|
// Pages order by date
|
|
|
|
else {
|
|
|
|
// List of published pages
|
|
|
|
$onlyPublished = true;
|
|
|
|
$pageNumber = 1;
|
2018-08-06 21:46:58 +02:00
|
|
|
$numberOfItems = $this->getValue('numberOfItems');
|
|
|
|
$publishedPages = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
|
2018-03-07 12:31:08 +01:00
|
|
|
|
|
|
|
foreach ($publishedPages as $pageKey) {
|
2018-07-18 21:48:37 +02:00
|
|
|
try {
|
2018-08-02 17:06:53 +02:00
|
|
|
$page = new Page($pageKey);
|
2018-07-18 21:48:37 +02:00
|
|
|
$html .= '<li>';
|
|
|
|
$html .= '<a href="' . $page->permalink() . '">' . $page->title() . '</a>';
|
|
|
|
$html .= '</li>';
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// Continue
|
|
|
|
}
|
2018-02-20 17:43:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= '</ul>';
|
|
|
|
$html .= '</div>';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
}
|