DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:permissionstyles

Permission Styles Plugin

Compatible with DokuWiki

No compatibility info given!

plugin Include different stylesheets depending on the groups a user is in.

Last updated on
2008-01-30
Provides
Action

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Security warning (please read plugin security guidelines): Hiding parts of a DokuWiki page is not supported by the core. Most attempts to introduce ACL control for parts of a page will leak information through RSS feed, search or other core functionality.

Tagged with acl, groups, style, 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

<?php
/**
 * 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(Doku_Event_Handler $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: 2013-11-02 02:28 by Klap-in