From c1e0eaa8303a36a2701cb9109f231a7ab8d2c2bf Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 12 Mar 2019 10:40:53 +0100 Subject: [PATCH] added support for the sitemapnavi plugin When installed the navigation can be switched between the default sidebar based navigation and the site tree --- Template.php | 80 ++++++++++++++++++++++++++++----- css/area_main-sidebar-tabs.less | 19 ++++++++ css/plugins/sitemapnavi.less | 10 +++++ lang/de/lang.php | 4 ++ lang/en/lang.php | 3 ++ main.php | 1 + style.ini | 3 +- tpl/main-sidebar-nav.php | 9 ++-- 8 files changed, 113 insertions(+), 16 deletions(-) create mode 100644 css/area_main-sidebar-tabs.less create mode 100644 css/plugins/sitemapnavi.less diff --git a/Template.php b/Template.php index ba66389..163fcfc 100644 --- a/Template.php +++ b/Template.php @@ -11,15 +11,19 @@ namespace dokuwiki\template\sprintdoc; */ class Template { - /** - * @var array loaded plugins - */ + /** @var array loaded plugins */ protected $plugins = array( 'sqlite' => null, 'tagging' => null, 'magicmatcher' => null, + 'tplinc' => null, + 'sitemapnavi' => null, ); + /** @var string the type of special navigation to use */ + protected $nav = ''; + + /** * Get the singleton instance * @@ -36,12 +40,26 @@ class Template { */ protected function __construct() { $this->initializePlugins(); + $this->initNavigationCookie(); /** @var \Doku_Event_Handler */ global $EVENT_HANDLER; $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 * @@ -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() { - $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'); + protected function initNavigationCookie() { + if ($this->plugins['sitemapnavi'] === null) return; + global $INPUT; + + $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 = ''; + } + + // decide what to show + if ($this->nav === 'sitetree') { + // site tree created by sitemapnavi plugin + $nav = ''; + } else { + // main navigation, loaded from standard sidebar, fixed up by javascript + $nav = ''; + } + + return $header . $nav; } /** diff --git a/css/area_main-sidebar-tabs.less b/css/area_main-sidebar-tabs.less new file mode 100644 index 0000000..9674def --- /dev/null +++ b/css/area_main-sidebar-tabs.less @@ -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; + } + } +} diff --git a/css/plugins/sitemapnavi.less b/css/plugins/sitemapnavi.less new file mode 100644 index 0000000..75c6f3f --- /dev/null +++ b/css/plugins/sitemapnavi.less @@ -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; + } +} diff --git a/lang/de/lang.php b/lang/de/lang.php index b86959c..478cb44 100755 --- a/lang/de/lang.php +++ b/lang/de/lang.php @@ -59,6 +59,10 @@ $lang['image_detail'] = 'Detailinformationen zum Bild'; $lang['mode_edit'] = 'Seite bearbeiten'; +$lang['nav_sidebar'] = 'Navigation'; +$lang['nav_sitemap'] = 'Seitenbaum'; + + /** * preferences colors */ diff --git a/lang/en/lang.php b/lang/en/lang.php index 48d6210..af8c4b2 100755 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -59,6 +59,9 @@ $lang['image_detail'] = 'image details'; $lang['mode_edit'] = 'Editing Page'; +$lang['nav_sidebar'] = 'Navigation'; +$lang['nav_sitemap'] = 'Site Tree'; + /** * preferences colors */ diff --git a/main.php b/main.php index 990e4a8..20bd84a 100755 --- a/main.php +++ b/main.php @@ -9,6 +9,7 @@ */ use dokuwiki\template\sprintdoc\Template; +Template::getInstance(); if (!defined('DOKU_INC')) die(); /* must be run from within DokuWiki */ header('X-UA-Compatible: IE=edge,chrome=1'); diff --git a/style.ini b/style.ini index 0c266e4..519d234 100755 --- a/style.ini +++ b/style.ini @@ -70,6 +70,7 @@ css/area_nav-usertools.less = all css/area_nav-pagetools.less = all css/area_nav-metabox.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-content.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/starred.less = all css/plugins/quicksubscribe.less = all - +css/plugins/sitemapnavi.less = all css/plugins/data.less = all diff --git a/tpl/main-sidebar-nav.php b/tpl/main-sidebar-nav.php index 3079428..43e2a23 100644 --- a/tpl/main-sidebar-nav.php +++ b/tpl/main-sidebar-nav.php @@ -1,8 +1,7 @@ - + +getNavigation(); +?>