====== Permission Styles Plugin ====== ---- plugin ---- description: Include different stylesheets depending on the groups a user is in. author : Gabriel Birke email : birke@d-scribe.de type : action lastupdate : 2008-01-30 securitywarning: partlyhidden tags : acl, users, groups, style ---- 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 ===== */ 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' => ' '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 ); } } } }