Translations of this page?:

Permission Styles Plugin

permissionstyles plugin by Gabriel Birke
Include different stylesheets depending on the groups a user is in.

Last updated on 2008-01-30. Provides Action.
No compatibility info given!

Tagged with css, group, permission, style, stylesheet, users.

If you want to hide some elements from users which are not in the admin group, if you want different backgrounds for different company departments—this plugin is for you. Just install it and put css files into the lib/styles/ folder that follow the convention of group_groupname.css, for example group_admin.css .

To Do

  • Cache the available style files to avoid too many file_exist calls.
  • User-Specific stylesheets?

Plugin Code

/**
 * Permission Styles: Include different stylesheets depending on the groups a user is in.
 * 
 * @author     Gabriel Birke <birke@d-scribe.de>
 */
 
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
 
class action_plugin_permissionstyles extends DokuWiki_Action_Plugin {
 
  /**
   * return some info
   */
  function getInfo(){
    return array(
     'author' => 'Gabriel Birke',
     'email'  => '<birke@d-scribe.de',
     'date'   => '2008-01-30',
     'name'   => 'Action Plugin Permission Styles',
     'desc'   => 'Include different stylesheets depending on the groups a user is in.',
     'url'    => 'http://www.d-scribe.de',
     );
  }
 
  /**
   * Register its handlers with the dokuwiki's event controller
   */
  function register(&$controller) {
    $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE',  $this, '_includeStylesheets');
  }
 
  /**
   * Look for group_*.css files in lib/styles/. 
   * Include the stylesheets for the group where the user is a member.
   */
  function _includeStylesheets(&$event, $param) {
    global $conf;
    $auth_class = 'auth_'.$conf['authtype'];
    $auth = new $auth_class();
    $userdata = $auth->getUserData($_SERVER['REMOTE_USER']);
    if(empty($userdata) || empty($userdata['grps']))
      return;
    foreach($userdata['grps'] as $group)
    {
      $file = 'lib/styles/group_'.$group.'.css';
      if(file_exists(DOKU_INC.$file))
      {
        $event->data['link'][] = array (
            'rel' => 'stylesheet',
            'type' => 'text/css',
            'href' => DOKU_BASE.$file
        );
      }
    }
  }
}
 
plugin/permissionstyles.txt · Last modified: 2008/02/18 22:18 by gbirke
 
Imprint Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsTranslate