bludit/bl-plugins/latest-content/plugin.php

120 lines
3.3 KiB
PHP
Raw Permalink Normal View History

2015-07-07 06:24:51 +02:00
<?php
2017-10-04 23:42:14 +02:00
class pluginLatestContent extends Plugin {
2015-07-07 06:24:51 +02:00
public function init()
{
// Fields and default values for the database of this plugin
2015-07-07 06:24:51 +02:00
$this->dbFields = array(
2017-10-04 23:42:14 +02:00
'label'=>'Latest content',
'homeLink'=>true,
'amountOfItems'=>5
2015-07-07 06:24:51 +02:00
);
}
// Method called on the settings of the plugin on the admin area
2015-07-14 04:16:28 +02:00
public function form()
{
global $Language;
$html = '<div>';
$html .= '<label>'.$Language->get('Label').'</label>';
$html .= '<input id="jslabel" name="label" type="text" value="'.$this->getValue('label').'">';
$html .= '<span class="tip">'.$Language->get('This title is almost always used in the sidebar of the site').'</span>';
2015-08-01 18:28:47 +02:00
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$Language->get('Home link').'</label>';
$html .= '<select name="homeLink">';
2017-10-23 22:11:56 +02:00
$html .= '<option value="true" '.($this->getValue('homeLink')===true?'selected':'').'>'.$Language->get('Enabled').'</option>';
$html .= '<option value="false" '.($this->getValue('homeLink')===false?'selected':'').'>'.$Language->get('Disabled').'</option>';
$html .= '</select>';
$html .= '<span class="tip">'.$Language->get('Show the home link on the sidebar').'</span>';
2015-08-01 18:28:47 +02:00
$html .= '</div>';
2016-11-08 22:56:41 +01:00
$html .= '<div>';
$html .= '<label>'.$Language->get('Amount of items').'</label>';
$html .= '<input id="jsamountOfItems" name="amountOfItems" type="text" value="'.$this->getValue('amountOfItems').'">';
2016-11-08 22:56:41 +01:00
$html .= '</div>';
2015-07-14 04:16:28 +02:00
return $html;
}
// Method called on the sidebar of the website
2015-08-07 04:13:55 +02:00
public function siteSidebar()
2015-07-07 06:24:51 +02:00
{
global $Language;
global $Url;
2017-05-31 20:17:21 +02:00
global $Site;
global $dbPages;
2017-07-10 23:40:46 +02:00
global $pagesByParent;
2015-09-08 02:51:48 +02:00
// Amount of pages to show
$amountOfItems = $this->getValue('amountOfItems');
2017-05-31 20:17:21 +02:00
// Page number the first one
$pageNumber = 1;
// Only published pages
$onlyPublished = true;
// Get the list of pages
$pages = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished, true);
// HTML for sidebar
$html = '<div class="plugin plugin-pages">';
$html .= '<h2 class="plugin-label">'.$this->getValue('label').'</h2>';
2015-07-07 06:24:51 +02:00
$html .= '<div class="plugin-content">';
$html .= '<ul>';
2015-07-07 06:24:51 +02:00
2017-07-10 23:40:46 +02:00
if(ORDER_BY==='position') {
2017-08-03 23:28:32 +02:00
foreach($pagesByParent[PARENT] as $Parent) {
2017-07-10 23:40:46 +02:00
$html .= '<li class="parent">';
$html .= '<h3>';
2017-08-03 23:28:32 +02:00
$html .= $Parent->title();
2017-07-10 23:40:46 +02:00
$html .= '</h3>';
2017-08-03 23:28:32 +02:00
if(!empty($pagesByParent[$Parent->key()])) {
2017-07-10 23:40:46 +02:00
$html .= '<ul class="child">';
2017-08-03 23:28:32 +02:00
foreach($pagesByParent[$Parent->key()] as $child) {
2017-07-10 23:40:46 +02:00
$html .= '<li class="child">';
$html .= '<a class="child" href="'.$child->permalink().'">';
$html .= $child->title();
$html .= '</a>';
$html .= '</li>';
}
$html .= '</ul>';
}
$html .= '</li>';
}
}
2017-07-10 23:40:46 +02:00
else {
// Show Home page link
if( $this->getValue('homeLink') ) {
$html .= '<li>';
$html .= '<a href="'.$Site->url().'">';
$html .= $Language->get('Home page');
$html .= '</a>';
$html .= '</li>';
}
// Get keys of pages
$keys = array_keys($pages);
foreach($keys as $pageKey) {
// Create the page object from the page key
$page = buildPage($pageKey);
$html .= '<li>';
$html .= '<a href="'.$page->permalink().'">';
$html .= $page->title();
$html .= '</a>';
$html .= '</li>';
}
2015-07-14 04:16:28 +02:00
}
2016-09-28 01:49:58 +02:00
$html .= '</ul>';
2015-07-07 06:24:51 +02:00
$html .= '</div>';
$html .= '</div>';
return $html;
}
}