bludit/plugins/pages/plugin.php

88 lines
2.2 KiB
PHP
Raw Normal View History

2015-07-07 01:24:51 -03:00
<?php
class pluginPages extends Plugin {
public function init()
{
$this->dbFields = array(
2015-08-01 13:28:47 -03:00
'homeLink'=>true,
'label'=>'Pages'
2015-07-07 01:24:51 -03:00
);
}
2015-07-13 23:16:28 -03:00
public function form()
{
global $Language;
$html = '<div>';
2015-08-01 13:28:47 -03:00
$html .= '<label>Plugin label</label>';
$html .= '<input name="label" id="jslabel" type="text" value="'.$this->getDbField('label').'">';
$html .= '</div>';
$html .= '<div>';
2015-07-13 23:16:28 -03:00
$html .= '<input name="homeLink" id="jshomeLink" type="checkbox" value="true" '.($this->getDbField('homeLink')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jshomeLink">'.$Language->get('Show home link').'</label>';
2015-08-01 13:28:47 -03:00
$html .= '</div>';
2015-07-13 23:16:28 -03:00
return $html;
}
2015-08-06 23:13:55 -03:00
public function siteSidebar()
2015-07-07 01:24:51 -03:00
{
global $Language;
global $pagesParents;
2015-09-08 19:40:25 +02:00
global $Site, $Url;
$home = $Url->whereAmI()==='home';
2015-09-09 23:33:31 -03:00
2015-07-07 01:24:51 -03:00
$html = '<div class="plugin plugin-pages">';
2015-09-07 21:51:48 -03:00
2015-09-09 23:33:31 -03:00
// Print the label if it not empty.
2015-09-07 21:51:48 -03:00
$label = $this->getDbField('label');
if( !empty($label) ) {
$html .= '<h2>'.$label.'</h2>';
}
2015-07-07 01:24:51 -03:00
$html .= '<div class="plugin-content">';
$parents = $pagesParents[NO_PARENT_CHAR];
$html .= '<ul>';
2015-07-13 23:16:28 -03:00
if($this->getDbField('homeLink')) {
2015-09-08 19:40:25 +02:00
$current = ($Site->homeLink()==$home) ? ' class="active"' : '';
$html .= '<li' .$current. '><a class="parent" href="'.$Site->homeLink().'">'.$Language->get('Home').'</a></li>';
2015-07-13 23:16:28 -03:00
}
2015-07-07 01:24:51 -03:00
foreach($parents as $parent)
{
2015-08-13 22:36:03 -03:00
//if($Site->homepage()!==$parent->key())
2015-07-07 01:24:51 -03:00
{
2015-09-08 19:40:25 +02:00
$current_parent = ($parent->slug()==$Url->slug()) ? ' class="active"' : '';
2015-08-07 14:22:13 -03:00
// Print the parent
2015-09-08 19:40:25 +02:00
$html .= '<li' .$current_parent. '><a class="parent" href="'.$parent->permalink().'">'.$parent->title().'</a>';
2015-07-07 01:24:51 -03:00
// Check if the parent has children
2015-08-07 14:22:13 -03:00
if(isset($pagesParents[$parent->key()]))
2015-07-07 01:24:51 -03:00
{
2015-08-07 14:22:13 -03:00
$children = $pagesParents[$parent->key()];
// Print the children
$html .= '<ul>';
2015-08-07 14:22:13 -03:00
foreach($children as $child)
{
2015-09-08 19:40:25 +02:00
$current_child = ($child->slug()==$Url->slug()) ? ' class="active"' : '';
$html .= '<li' .$current_child. '><a class="children" href="'.$child->permalink().'">'.$child->title().'</a></li>';
2015-08-07 14:22:13 -03:00
}
$html .= '</ul>';
2015-07-07 01:24:51 -03:00
}
}
}
$html .= '</li></ul>';
2015-07-07 01:24:51 -03:00
$html .= '</div>';
$html .= '</div>';
return $html;
}
}