1<?php 2/** 3 *@author Myron Turner <turnermm02@shaw.ca> 4 */ 5 6if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/'); 7if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 8require_once(DOKU_PLUGIN.'action.php'); 9class action_plugin_goto extends DokuWiki_Action_Plugin { 10 public function register(Doku_Event_Handler $controller) { 11 $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_act',array('before')); 12 $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'started',array('after')); 13 } 14 function started(Doku_Event $event, $param) { 15 global $JSINFO,$updateVersion; 16 $JSINFO['update_version'] = $updateVersion; 17 } 18 19 function handle_act(Doku_Event $event, $param) { 20 global $conf,$USERINFO,$INPUT; 21 $act = act_clean($event->data); 22 if($act != 'login') { 23 return; 24 } 25 $user = $_SERVER['REMOTE_USER']; 26 if(!$user) return; 27 $auto_login = $this->getConf('auto_login'); 28 if($auto_login) { 29 setcookie("GOTO_LOGIN",":$user" , time()+10, DOKU_BASE); 30 31 } 32 else return; 33 34 $which_only = $this->getConf('only_option'); 35 if($which_only == 'default') { 36 $users_only = false; 37 $groups_only = false; 38 } 39 else if($which_only == 'group') { 40 $groups_only = true; 41 } 42 else { 43 $users_only = true; 44 } 45 $redirect_target = ""; 46 if(! $users_only) { 47 $user_grps = $USERINFO['grps']; 48 $groups = $this->getConf('group'); 49 $groups = preg_replace("/\s+/","",$groups); 50 $groups = explode(',',$groups); 51 $grp_opt = $this->getConf('group_options'); 52 foreach($groups as $grp) { 53 if(in_array ($grp , $user_grps)) { 54 $redirect_target = "$grp:"; 55 $redirect_target .= ($grp_opt == 'user_page' ? $user : $conf['start']); 56 break; 57 } 58 } 59 if($redirect_target) { 60 setcookie("GOTO_LOGIN", $redirect_target, time()+120, DOKU_BASE); 61 return; 62 } 63 } 64 65 if($groups_only) return; 66 67 $option = $this->getConf('auto_options'); 68 $common = $this->getConf('common_ns'); 69 if($common) { 70 $common = rtrim($common,':'); 71 } 72 $srch = array('common_ns','user_page','user_ns','start_page'); 73 $repl = array($common,$user,$user,$conf['start']); 74 $value = str_replace($srch,$repl,$option); 75 setcookie("GOTO_LOGIN", $value, time()+120, DOKU_BASE); 76 } 77 78}