made template functions more flexible
* attention: incompatible to previous version! * introduced _tpl_action() (wrapper similar to tpl_action()) * improved discussion and user page functions * made them work independent from config * added full control to how the page links are built (with placeholders @ID@ and @USER@) * config option changes: removed 'discussNSreverse', renamed 'discussionNS' and 'userNS' to 'discussionPage' and 'userPage'
This commit is contained in:
parent
c21fe1fab8
commit
afe47fae3b
5 changed files with 42 additions and 34 deletions
|
|
@ -5,8 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$conf['tagline'] = 'This is the tagline - explaining what this site is about.';
|
$conf['tagline'] = 'This is the tagline - explaining what this site is about.';
|
||||||
$conf['discussionNS'] = 'discussion';
|
$conf['discussionPage'] = 'discussion:@ID@';
|
||||||
$conf['discussNSreverse'] = 0;
|
$conf['userPage'] = 'user:@USER@:';
|
||||||
$conf['userNS'] = 'user';
|
|
||||||
$conf['sidebarID'] = 'sidebar';
|
$conf['sidebarID'] = 'sidebar';
|
||||||
$conf['hideTools'] = 0;
|
$conf['hideTools'] = 0;
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$meta['tagline'] = array('string');
|
$meta['tagline'] = array('string');
|
||||||
$meta['discussionNS'] = array('string');
|
$meta['discussionPage'] = array('string');
|
||||||
$meta['discussNSreverse'] = array('onoff');
|
$meta['userPage'] = array('string');
|
||||||
$meta['userNS'] = array('string');
|
|
||||||
$meta['sidebarID'] = array('string');
|
$meta['sidebarID'] = array('string');
|
||||||
$meta['hideTools'] = array('onoff');
|
$meta['hideTools'] = array('onoff');
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$lang['tagline'] = 'Tagline';
|
$lang['tagline'] = 'Tagline';
|
||||||
$lang['discussionNS'] = 'Discussion namespace (leave empty to disable discussions)';
|
$lang['discussionPage'] = 'Discussion page (leave empty to disable discussions)';
|
||||||
$lang['discussNSreverse'] = 'Reverse discussion namespace? (e.g. "foo:bar:discussion" instead of "discussion:foo:bar")';
|
$lang['userPage'] = 'User page (leave empty to disable user pages)';
|
||||||
$lang['userNS'] = 'User namespace (leave empty to disable user pages)';
|
|
||||||
$lang['sidebarID'] = 'page name of page included in sidebar';
|
$lang['sidebarID'] = 'page name of page included in sidebar';
|
||||||
$lang['hideTools'] = 'Hide tools when not logged in?';
|
$lang['hideTools'] = 'Hide tools when not logged in?';
|
||||||
|
|
|
||||||
8
main.php
8
main.php
|
|
@ -66,9 +66,7 @@ $showTools = !tpl_getConf('hideTools') || ( tpl_getConf('hideTools') && $_SERVER
|
||||||
echo '</li>';
|
echo '</li>';
|
||||||
}
|
}
|
||||||
tpl_action('admin', 1, 'li');
|
tpl_action('admin', 1, 'li');
|
||||||
if (tpl_getConf('userNS')) {
|
_tpl_action('userpage', 1, 'li');
|
||||||
_tpl_userpage(tpl_getConf('userNS'),1,'li');
|
|
||||||
}
|
|
||||||
tpl_action('profile', 1, 'li');
|
tpl_action('profile', 1, 'li');
|
||||||
tpl_action('login', 1, 'li');
|
tpl_action('login', 1, 'li');
|
||||||
?>
|
?>
|
||||||
|
|
@ -138,9 +136,7 @@ $showTools = !tpl_getConf('hideTools') || ( tpl_getConf('hideTools') && $_SERVER
|
||||||
<ul>
|
<ul>
|
||||||
<?php
|
<?php
|
||||||
tpl_action('edit', 1, 'li');
|
tpl_action('edit', 1, 'li');
|
||||||
if (tpl_getConf('discussionNS')) {
|
_tpl_action('discussion', 1, 'li');
|
||||||
_tpl_discussion(tpl_getConf('discussionNS'),1,'li',tpl_getConf('discussNSreverse'));
|
|
||||||
}
|
|
||||||
tpl_action('history', 1, 'li');
|
tpl_action('history', 1, 'li');
|
||||||
tpl_action('backlink', 1, 'li');
|
tpl_action('backlink', 1, 'li');
|
||||||
tpl_action('subscribe', 1, 'li');
|
tpl_action('subscribe', 1, 'li');
|
||||||
|
|
|
||||||
|
|
@ -16,31 +16,26 @@ if (!defined('DOKU_INC')) die();
|
||||||
*
|
*
|
||||||
* @author Anika Henke <anika@selfthinker.org>
|
* @author Anika Henke <anika@selfthinker.org>
|
||||||
*/
|
*/
|
||||||
function _tpl_discussion($discussNS='discussion',$link=0,$wrapper=0,$reverse=0) {
|
function _tpl_discussion($discussionPage,$title,$backTitle,$link=0,$wrapper=0) {
|
||||||
global $ID;
|
global $ID;
|
||||||
|
|
||||||
if ($reverse) {
|
$discussPage = str_replace('@ID@',$ID,$discussionPage);
|
||||||
$discussPage = $ID.':'.$discussNS;
|
$discussPageRaw = str_replace('@ID@','',$discussionPage);
|
||||||
$isDiscussPage = substr($ID,-strlen($discussNS),strlen($discussNS))==$discussNS;
|
$isDiscussPage = strpos($ID,$discussPageRaw)!==false;
|
||||||
$backID = substr($ID,0,-strlen($discussNS));
|
$backID = str_replace($discussPageRaw,'',$ID);
|
||||||
} else {
|
|
||||||
$discussPage = $discussNS.':'.$ID;
|
|
||||||
$isDiscussPage = substr($ID,0,strlen($discussNS))==$discussNS;
|
|
||||||
$backID = strstr($ID,':');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($wrapper) echo "<$wrapper>";
|
if ($wrapper) echo "<$wrapper>";
|
||||||
|
|
||||||
if($isDiscussPage) {
|
if ($isDiscussPage) {
|
||||||
if ($link)
|
if ($link)
|
||||||
tpl_pagelink($backID,tpl_getLang('back_to_article'));
|
tpl_pagelink($backID,$backTitle);
|
||||||
else
|
else
|
||||||
echo html_btn('back2article',$backID,'',array(),0,0,tpl_getLang('back_to_article'));
|
echo html_btn('back2article',$backID,'',array(),0,0,$backTitle);
|
||||||
} else {
|
} else {
|
||||||
if ($link)
|
if ($link)
|
||||||
tpl_pagelink($discussPage,tpl_getLang('discussion'));
|
tpl_pagelink($discussPage,$title);
|
||||||
else
|
else
|
||||||
echo html_btn('discussion',$discussPage,'',array(),0,0,tpl_getLang('discussion'));
|
echo html_btn('discussion',$discussPage,'',array(),0,0,$title);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($wrapper) echo "</$wrapper>";
|
if ($wrapper) echo "</$wrapper>";
|
||||||
|
|
@ -51,22 +46,42 @@ function _tpl_discussion($discussNS='discussion',$link=0,$wrapper=0,$reverse=0)
|
||||||
*
|
*
|
||||||
* @author Anika Henke <anika@selfthinker.org>
|
* @author Anika Henke <anika@selfthinker.org>
|
||||||
*/
|
*/
|
||||||
function _tpl_userpage($userNS='user',$link=0,$wrapper=false) {
|
function _tpl_userpage($userPage,$title,$link=0,$wrapper=0) {
|
||||||
if (!$_SERVER['REMOTE_USER']) return;
|
if (!$_SERVER['REMOTE_USER']) return;
|
||||||
|
|
||||||
global $conf;
|
global $conf;
|
||||||
$userPage = $userNS.':'.$_SERVER['REMOTE_USER'].':'.$conf['start'];
|
$userPage = str_replace('@USER@',$_SERVER['REMOTE_USER'],$userPage);
|
||||||
|
|
||||||
if ($wrapper) echo "<$wrapper>";
|
if ($wrapper) echo "<$wrapper>";
|
||||||
|
|
||||||
if ($link)
|
if ($link)
|
||||||
tpl_pagelink($userPage,tpl_getLang('userpage'));
|
tpl_pagelink($userPage,$title);
|
||||||
else
|
else
|
||||||
echo html_btn('userpage',$userPage,'',array(),0,0,tpl_getLang('userpage'));
|
echo html_btn('userpage',$userPage,'',array(),0,0,$title);
|
||||||
|
|
||||||
if ($wrapper) echo "</$wrapper>";
|
if ($wrapper) echo "</$wrapper>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper around custom template actions
|
||||||
|
*
|
||||||
|
* @author Anika Henke <anika@selfthinker.org>
|
||||||
|
*/
|
||||||
|
function _tpl_action($type,$link=0,$wrapper=0) {
|
||||||
|
switch ($type) {
|
||||||
|
case 'discussion':
|
||||||
|
if (tpl_getConf('discussionPage')) {
|
||||||
|
_tpl_discussion(tpl_getConf('discussionPage'),tpl_getLang('discussion'),tpl_getLang('back_to_article'),$link,$wrapper);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'userpage':
|
||||||
|
if (tpl_getConf('userPage')) {
|
||||||
|
_tpl_userpage(tpl_getConf('userPage'),tpl_getLang('userpage'),$link,$wrapper);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use favicon.ico from data/media root directory if it exists, otherwise use
|
* Use favicon.ico from data/media root directory if it exists, otherwise use
|
||||||
* the one in the template's image directory.
|
* the one in the template's image directory.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue