Hello DokuWiki fan's,
This is not really strictly "templates and layout" but it seems to me the right place.
The problem
Some users do want different style (background, text, border,link colors) for theirs account. Some wants to easily know which avatar (user, admin, groupA; groupB) they use when they browse or edit a page.
A solution
For the version 2010-11-07 - Anteater"
- In your mytemplate directory lib/tpl/mytemplate
* for each user mygroup you want to customize
- copy style.ini to style_mygroup.ini
- customize your(s) style_mygroup.ini
- Transfert the first group of the logged user to the css.php stuff :
In /inc/template.php change
[m]// load stylesheets
$head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css',
- 'href'=>DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed);
+ 'href'=>DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed.'&grps0='.$INFO['userinfo']['grps'][0]);
[/m]
- From the css_out() pass the group0 to 'apply style replacements' css_applystyle function :
In /lib/exe/css.php change
// apply style replacements
- $css = css_applystyle($css,$tplinc);
+ $css = css_applystyle($css,$tplinc,$_REQUEST['grps0']);
- at the end of the function css_cacheok($cache,$files,$tplinc)
[m]
}
}
- return true;
+ //return true;
+ return false;
[/m]
- Change the function
[m]-function css_applystyle($css,$tplinc){
- if(@file_exists($tplinc.'style.ini')){
- $ini = parse_ini_file($tplinc.'style.ini',true);
- $css = strtr($css,$ini['replacements']);
- }
- return $css;
-}[/m]
to
[m]+function css_applystyle($css,$tplinc,$grps0){
+
+ $style_ini = 'style.ini';
+ $group_style = 'style_'.$grps0.'.ini';
+ if(@file_exists($tplinc.$group_style)){
+ $style_ini = $group_style;
+ }
+ if(@file_exists($tplinc.$style_ini)){
+ $ini = parse_ini_file($tplinc.$style_ini,true);
+ $css = strtr($css,$ini['replacements']);
+ }
+ return $css;
+}[/m]
Note : The style chosen one is the first of the user's group list.
Limitations
* The css cache is disabled :-(
* But it should be ok for low traffic site.
* The user could not choose/set himself his color schema.
* For future ?
Room for improvement
The hack disable the css cache in css_cacheok :-( . It should be somewhere a flag (an update of a file ?) that tells "user logoff" an "user login". This condition could be added in the css_cacheok function to minimize the performance penalization. If this could be achieved I personally think this feature could be proposed in a next version.
Have a nice day,
Patrick Installé
[mail]
PatrickInstalle@P-Installe.be[/mail]