1<?php 2 3use dokuwiki\Extension\ActionPlugin; 4use dokuwiki\Extension\Event; 5use dokuwiki\Extension\EventHandler; 6use dokuwiki\plugin\virtualgroup\VirtualGroups; 7 8/** 9 * DokuWiki Plugin virtualgroup (Action Component) 10 * 11 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 12 */ 13class action_plugin_virtualgroup extends ActionPlugin 14{ 15 /** @inheritdoc */ 16 public function register(EventHandler $controller) 17 { 18 $controller->register_hook('DOKUWIKI_INIT_DONE', 'BEFORE', $this, 'start'); 19 } 20 21 /** 22 * Add the virtual groups to the current user 23 * 24 * @param Event $event DOKUWIKI_INIT_DONE 25 * @return void 26 */ 27 public function start(Event $event) 28 { 29 global $USERINFO; 30 global $INFO; 31 global $INPUT; 32 33 $user = $INPUT->server->str('REMOTE_USER'); 34 if (!$user) return; 35 36 $virtualgroups = (new VirtualGroups())->getUserGroups($user); 37 if (!$virtualgroups) return; 38 39 if (!isset($USERINFO['grps'])) $USERINFO['grps'] = []; 40 $grps = array_unique(array_merge($USERINFO['grps'], $virtualgroups)); 41 $USERINFO['grps'] = $grps; 42 $_SESSION[DOKU_COOKIE]['auth']['info']['grps'] = $grps; 43 $INFO = pageinfo(); 44 } 45} 46