Permalink
Browse files

Added dynamic sidebar content and widths per namespace

NEW: sidebar content can be set via a sidebar.txt file at namespace level
NEW: sidebar and site width can be set per namespace via a new nsWidth config setting
CHG: updated header comment in main.php to add author name
  • Loading branch information...
1 parent ad2b91c commit d9c8aa1ca46a3823e2e0bfe88fc79c94fb9edc1a @MrBertie committed Dec 27, 2011
Showing with 68 additions and 6 deletions.
  1. +2 −1 conf/default.php
  2. +1 −0 conf/metadata.php
  3. +1 −1 css/custom.css
  4. +1 −0 lang/en/settings.php
  5. +9 −3 main.php
  6. +1 −1 style.ini
  7. +53 −0 tpl_functions.php
View
@@ -7,4 +7,5 @@
$conf['discussionPage'] = 'discussion:@ID@';
$conf['userPage'] = 'user:@USER@:';
$conf['sidebarID'] = 'sidebar';
-$conf['hideTools'] = 0;
+$conf['hideTools'] = 0;
+$conf['nsWidth'] = 'drafts 100% 22em';
View
@@ -8,3 +8,4 @@
$meta['userPage'] = array('string');
$meta['sidebarID'] = array('string');
$meta['hideTools'] = array('onoff');
+$meta['nsWidth'] = array('string');
View
@@ -260,6 +260,6 @@ input[type=text] {
}
#dokuwiki__site .wrapper {
margin: 0.7em auto;
- max-width: __site-width__;
+ max-width: __site_width__;
padding: 0 1em;
}
View
@@ -8,5 +8,6 @@
$lang['userPage'] = 'User page (leave empty to disable user pages)';
$lang['sidebarID'] = 'page name of page included in sidebar';
$lang['hideTools'] = 'Hide tools when not logged in?';
+$lang['nsWidth'] = 'Define site and sidebar width according to namespace. Syntax: "<namespace> <site-width> <sidebar-width>", you can add other namespaces also, using a semicolon to separate';
View
@@ -1,9 +1,13 @@
<?php
/**
- * DokuWiki Starter Template
+ * DokuWiki Taratasy Template
*
- * @link http://dokuwiki.org/template:starter
+ * @link http://dokuwiki.org/template:taratasy
+ * @author Symon Bent <hendrybadao@gmail.com>
+ *
+ * Based on Starter Template by
* @author Anika Henke <anika@selfthinker.org>
+ *
*/
if (!defined('DOKU_INC')) die(); /* must be run from within DokuWiki */
@@ -23,6 +27,8 @@
<meta name="viewport" content="width=device-width,initial-scale=1" />
<?php echo tpl_favicon(array('favicon', 'mobile')) ?>
<?php _tpl_include('meta.html') ?>
+ <!-- load any dynamic styles needed for this namespace only, used to set site/sidebar widths via config setting -->
+ <?php _tpl_ns_styles(); ?>
</head>
<body>
@@ -112,7 +118,7 @@
<!-- ********** ASIDE ********** -->
<div id="dokuwiki__aside"><div class="pad include">
- <?php tpl_include_page(tpl_getConf('sidebarID')) /* includes the given wiki page */ ?>
+ <?php tpl_include_page(_tpl_sidebar()) /* includes the given wiki page */ ?>
<div class="clearer"></div>
</div></div><!-- /aside -->
View
@@ -68,5 +68,5 @@ __missing__ = "#A31E39"
__highlight__ = "#ff9"
; widths
-__site_width__ = "64em"
+__site_width__ = "70em"
__sidebar_width__ = "12em"
View
@@ -187,3 +187,56 @@ function _tpl_include($fn) {
else if (file_exists($tplFile))
include($tplFile);
}
+
+
+/**
+ * Use the sidebar page from current namespace if available, if not use the global
+ *
+ * @author Symon Bent hendrybadao@gmail.com
+ */
+
+function _tpl_sidebar() {
+ global $INFO;
+
+ $id = tpl_getConf('sidebarID');
+ $ns = $INFO['namespace'];
+
+ do {
+ $sidebar = $ns . ':' . $id;
+ if (page_exists($sidebar)) {
+ return $sidebar;
+ }
+ $ns = substr($ns, 0, strrpos($ns, ':'));
+ } while ( ! empty($ns));
+ return $id;
+}
+
+
+/**
+ * Custom styles to allow different site/sidebar widths per namespace
+ * Set in template configuration (nsWidth)
+ * Syntax: "<namespace> <site-width> <sidebar-width>;<namespace-2> <site-width-2> <sidebar-width-2>"
+ * (semicolons between namespaces sections, spaces within a section)
+ */
+function _tpl_ns_styles() {
+ global $INFO;
+ $result = '';
+
+ $cur_ns = $INFO['namespace'];
+ $args = explode(';', tpl_getConf('nsWidth'));
+ foreach ($args as $arg) {
+ list ($ns, $site_width, $sidebar_width) = explode(' ', $arg);
+ $ns = ltrim(trim($ns), ':');
+ $match = strpos($cur_ns, $ns);
+ if ($match == 0 && $match !== false) {
+ $result = '<style>' .
+ '.mode_show #dokuwiki__aside { width: ' . $sidebar_width . '; }' . DOKU_LF .
+ '.mode_show #dokuwiki__content { margin-left: -' . $sidebar_width . '; }' . DOKU_LF .
+ '.mode_show #dokuwiki__content .pad { margin-left: ' . $sidebar_width . '; }' . DOKU_LF .
+ '#dokuwiki__site .wrapper { max-width: ' . $site_width . '; }' . DOKU_LF .
+ '</style>';
+ echo $result;
+ break;
+ }
+ }
+}

0 comments on commit d9c8aa1

Please sign in to comment.