added support for the sitemapnavi plugin

When installed the navigation can be switched between the default
sidebar based navigation and the site tree
This commit is contained in:
Andreas Gohr 2019-03-12 10:40:53 +01:00
commit c1e0eaa830
8 changed files with 113 additions and 16 deletions

View file

@ -11,15 +11,19 @@ namespace dokuwiki\template\sprintdoc;
*/ */
class Template { class Template {
/** /** @var array loaded plugins */
* @var array loaded plugins
*/
protected $plugins = array( protected $plugins = array(
'sqlite' => null, 'sqlite' => null,
'tagging' => null, 'tagging' => null,
'magicmatcher' => null, 'magicmatcher' => null,
'tplinc' => null,
'sitemapnavi' => null,
); );
/** @var string the type of special navigation to use */
protected $nav = '';
/** /**
* Get the singleton instance * Get the singleton instance
* *
@ -36,12 +40,26 @@ class Template {
*/ */
protected function __construct() { protected function __construct() {
$this->initializePlugins(); $this->initializePlugins();
$this->initNavigationCookie();
/** @var \Doku_Event_Handler */ /** @var \Doku_Event_Handler */
global $EVENT_HANDLER; global $EVENT_HANDLER;
$EVENT_HANDLER->register_hook('PLUGIN_TPLINC_LOCATIONS_SET', 'BEFORE', $this, 'registerIncludes'); $EVENT_HANDLER->register_hook('PLUGIN_TPLINC_LOCATIONS_SET', 'BEFORE', $this, 'registerIncludes');
} }
/**
* Load all the plugins we support directly
*/
protected function initializePlugins() {
$this->plugins['sqlite'] = plugin_load('helper', 'sqlite');
if($this->plugins['sqlite']) {
$this->plugins['tagging'] = plugin_load('helper', 'tagging');
$this->plugins['magicmatcher'] = plugin_load('syntax', 'magicmatcher_issuelist');
}
$this->plugins['tplinc'] = plugin_load('helper', 'tplinc');
$this->plugins['sitemapnavi'] = plugin_load('helper', 'sitemapnavi');
}
/** /**
* Makes include position info available to the tplinc plugin * Makes include position info available to the tplinc plugin
* *
@ -71,15 +89,57 @@ class Template {
} }
/** /**
* Load all the plugins we support directly * Sets a cookie to remember the requested special navigation
*/ */
protected function initializePlugins() { protected function initNavigationCookie() {
$this->plugins['sqlite'] = plugin_load('helper', 'sqlite'); if ($this->plugins['sitemapnavi'] === null) return;
if($this->plugins['sqlite']) { global $INPUT;
$this->plugins['tagging'] = plugin_load('helper', 'tagging');
$this->plugins['magicmatcher'] = plugin_load('syntax', 'magicmatcher_issuelist'); $nav = $INPUT->str('nav');
if($nav) {
set_doku_pref('nav', $nav);
$this->nav = $INPUT->str('nav');
} else {
$this->nav = get_doku_pref('nav', 'sidebar');
} }
$this->plugins['tplinc'] = plugin_load('helper', 'tplinc'); }
/**
* Return the navigation for the sidebar
*
* Defaults to the standard sidebar mechanism, but supports also the sitemapnavi plugin
*
* @return string
*/
public function getNavigation() {
global $ID;
global $conf;
// add tabs if multiple navigation types available
$header = '';
if ($this->plugins['sitemapnavi'] !== null) {
$header = '<ul class="sidebar-tabs">';
$header .= '<li class="' . ($this->nav === 'sidebar' ? 'active' : '') . '">' .
'<a href="' . wl($ID, ['nav' => 'sidebar']) . '">'.tpl_getLang('nav_sidebar').'</a></li>';
$header .= '<li class="' . ($this->nav === 'sitemap' ? 'active' : '') . '">' .
'<a href="' . wl($ID, ['nav' => 'sitemap']) . '">'.tpl_getLang('nav_sitemap').'</a></li>';
$header .= '</ul>';
}
// decide what to show
if ($this->nav === 'sitetree') {
// site tree created by sitemapnavi plugin
$nav = '<nav class="nav-sitemapnavi" id="plugin__sitemapnavi">';
$nav .= $this->plugins['sitemapnavi']->getSiteMap(':');
$nav .= '</nav>';
} else {
// main navigation, loaded from standard sidebar, fixed up by javascript
$nav = '<nav class="nav-main">';
$nav .= tpl_include_page($conf['sidebar'], false, true);
$nav .= '</nav>';
}
return $header . $nav;
} }
/** /**

View file

@ -0,0 +1,19 @@
#dokuwiki__aside ul.sidebar-tabs {
margin-top: 0;
margin-bottom: @nav-margin;
border-bottom: 1px solid @ini_nav_menu_color;
li {
display: inline-block;
border: 1px solid @ini_nav_menu_color;
padding: 0.25em 0.5em;
margin-bottom: -1px;
border-top-right-radius: @fix_border-radius;
border-top-left-radius: @fix_border-radius;
&.active {
border-bottom: 1px solid @ini_background_site;
}
}
}

View file

@ -0,0 +1,10 @@
#plugin__sitemapnavi {
padding-left: @nav-margin*2.5;
padding-bottom: @nav-margin;
margin-bottom: @nav-margin;
border-bottom: 1px solid @ini_nav_menu_color;
li {
line-height: @line-height-bigger;
}
}

View file

@ -59,6 +59,10 @@ $lang['image_detail'] = 'Detailinformationen zum Bild';
$lang['mode_edit'] = 'Seite bearbeiten'; $lang['mode_edit'] = 'Seite bearbeiten';
$lang['nav_sidebar'] = 'Navigation';
$lang['nav_sitemap'] = 'Seitenbaum';
/** /**
* preferences colors * preferences colors
*/ */

View file

@ -59,6 +59,9 @@ $lang['image_detail'] = 'image details';
$lang['mode_edit'] = 'Editing Page'; $lang['mode_edit'] = 'Editing Page';
$lang['nav_sidebar'] = 'Navigation';
$lang['nav_sitemap'] = 'Site Tree';
/** /**
* preferences colors * preferences colors
*/ */

View file

@ -9,6 +9,7 @@
*/ */
use dokuwiki\template\sprintdoc\Template; use dokuwiki\template\sprintdoc\Template;
Template::getInstance();
if (!defined('DOKU_INC')) die(); /* must be run from within DokuWiki */ if (!defined('DOKU_INC')) die(); /* must be run from within DokuWiki */
header('X-UA-Compatible: IE=edge,chrome=1'); header('X-UA-Compatible: IE=edge,chrome=1');

View file

@ -70,6 +70,7 @@ css/area_nav-usertools.less = all
css/area_nav-pagetools.less = all css/area_nav-pagetools.less = all
css/area_nav-metabox.less = all css/area_nav-metabox.less = all
css/area_main-sidebar-nav.less = all css/area_main-sidebar-nav.less = all
css/area_main-sidebar-tabs.less = all
css/area_main-sidebar-search.less = all css/area_main-sidebar-search.less = all
css/area_main-content.less = all css/area_main-content.less = all
css/area_main-content-secedit.less = all css/area_main-content-secedit.less = all
@ -109,7 +110,7 @@ css/plugins/folded.less = all
css/plugins/configmanager.less = all css/plugins/configmanager.less = all
css/plugins/starred.less = all css/plugins/starred.less = all
css/plugins/quicksubscribe.less = all css/plugins/quicksubscribe.less = all
css/plugins/sitemapnavi.less = all
css/plugins/data.less = all css/plugins/data.less = all

View file

@ -1,8 +1,7 @@
<nav class="nav-main">
<?php /* main navigation, loaded from sidebar, fixed up by javascript */ <?php
tpl_include_page($conf['sidebar'], 1, 1); echo \dokuwiki\template\sprintdoc\Template::getInstance()->getNavigation();
?> ?>
</nav>
<nav class="nav-sitetools"> <nav class="nav-sitetools">
<div class="nav"><a href="#sidebar-site-tools" role="heading" aria-level="2"> <div class="nav"><a href="#sidebar-site-tools" role="heading" aria-level="2">