1<?php 2 3/** 4 * DokuWiki Plugin adminperm (Action Component) 5 * 6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 7 * @author Andreas Gohr <dokuwiki@cosmocode.de> 8 */ 9class action_plugin_adminperm extends DokuWiki_Action_Plugin 10{ 11 12 /** 13 * Registers a callback function for a given event 14 * 15 * @param Doku_Event_Handler $controller DokuWiki's event controller object 16 * 17 * @return void 18 */ 19 public function register(Doku_Event_Handler $controller) 20 { 21 $controller->register_hook('ADMINPLUGIN_ACCESS_CHECK', 'AFTER', $this, 'handle_accesscheck'); 22 $controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'handle_menu'); 23 } 24 25 /** 26 * Override Access to Admin Plugins 27 * 28 * Called for event: ADMINPLUGIN_ACCESS_CHECK 29 * 30 * @param Doku_Event $event event object by reference 31 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 32 * handler was registered] 33 * 34 * @return void 35 */ 36 public function handle_accesscheck(Doku_Event $event, $param) 37 { 38 global $USERINFO; 39 global $INPUT; 40 41 if ($event->data['hasAccess']) return; // access already granted? do nothing 42 if (!$INPUT->server->str('REMOTE_USER')) return; // no user available? 43 44 /** @var admin_plugin_adminperm $plugin */ 45 $plugin = plugin_load('admin', 'adminperm'); 46 $cnf = $plugin->load(); 47 48 /** @var DokuWiki_Admin_Plugin $instance */ 49 $instance = $event->data['instance']; 50 $pname = $instance->getPluginName(); 51 52 // any override available? 53 if (empty($cnf[$pname])) return; 54 55 // check for match 56 if (auth_isMember($cnf[$pname], $INPUT->server->str('REMOTE_USER'), $USERINFO['grps'])) { 57 $event->data['hasAccess'] = true; // we found an override 58 } 59 60 // nope, still nothing 61 } 62 63 /** 64 * Readd the Admin Menu Item if the user is in an override 65 * 66 * Called for event: MENU_ITEMS_ASSEMBLY 67 * 68 * @param Doku_Event $event event object by reference 69 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 70 * handler was registered] 71 * 72 * @return void 73 */ 74 public function handle_menu(Doku_Event $event, $param) 75 { 76 global $INPUT; 77 global $INFO; 78 if (!$INPUT->server->str('REMOTE_USER')) return; // no user available? 79 if ($INFO['ismanager']) return; // already access to admin? 80 if ($event->data['view'] !== 'user') return; // we modify the user menu only 81 82 /** @var admin_plugin_adminperm $plugin */ 83 $plugin = plugin_load('admin', 'adminperm'); 84 $cnf = $plugin->load(); 85 86 // check if there is any override for the user 87 $override = false; 88 foreach ($cnf as $plugin => $members) { 89 if (auth_isMember($members, $INPUT->server->str('REMOTE_USER'), $INFO['userinfo']['grps'])) { 90 $override = true; 91 break; 92 } 93 } 94 if (!$override) return; 95 96 // add the admin menu item 97 $item = new \dokuwiki\Menu\Item\Admin(); 98 array_splice($event->data['items'], -1, 0, [$item]); 99 } 100 101} 102 103