register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'dwstarted'); $controller->register_hook('TEMPLATE_SITETOOLS_DISPLAY', 'BEFORE', $this, 'action_link', array('site')); $controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addsvgbutton', array()); $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_act'); $controller->register_hook('HTML_UPDATEPROFILEFORM_OUTPUT', 'BEFORE', $this, 'handle_profile_form'); $controller->register_hook('FORM_UPDATEPROFILE_OUTPUT', 'BEFORE', $this, 'handle_profile_form'); $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this,'_ajax_call'); } function __construct() { $this->ui_priority_metafn = metaFN(':tplmod:ui_lang', '.ser'); if(!file_exists($this->ui_priority_metafn)) { io_saveFile($this->ui_priority_metafn, serialize(array())); } $ini = parse_ini_file( tpl_incdir() . 'style.ini'); if(isset($ini['__background_alt__'])) { $this->html_bg_color=$ini['__background_alt__']; } } function _ajax_call(Doku_Event $event, $param) { if ($event->data != 'tplmod_ui_lang' ) { return; } global $INPUT; $event->stopPropagation(); $event->preventDefault(); $ar = unserialize(file_get_contents($this->ui_priority_metafn)); $ln = $INPUT->str('tplmod_val'); $client = $INPUT->str('tplmod_client'); $ar[$client] = $ln; $retv = file_put_contents($this->ui_priority_metafn,serialize($ar)); if($retv === false) { echo $this->ui_priority_metafn; } else echo "done"; return; } function handle_profile_form(Doku_Event $event, $param) { $language = trim($this->getConf('deflang')); if(!isset($language)|| empty($language)) { return; } $language = explode( ',',$language); $client = $_SERVER['REMOTE_USER']; $ar = unserialize(file_get_contents($this->ui_priority_metafn)); if(isset($ar[$client])) { $lan = $ar[$client]; } $_form = "\n" . '
'; $_form.= '
' . $this->getLang('uprofile_title') .''; $num_langs = 0; foreach($language as $ln) { $checked = ""; list($name,$val) = preg_split("/\s+/",$ln); $_form .= ''; if( $num_langs > 0 && $num_langs % 3 == 0) { $_form .= "
\n"; } if($num_langs == 0) { $num_langs++; } $num_langs++; } $_form.= '
'; $_form.= '

 "; $_form.= ''; $_form.= '
'; if(is_a($event->data,\dokuwiki\Form\Form::class)) { $pos = $event->data->findPositionByAttribute('type','reset'); $pos+=2; $event->data->addHTML($_form,$pos); } else { $pos = $event->data->findElementByAttribute('type', 'reset'); $event->data->insertElement($pos+2, $_form); } } function dwstarted(DOKU_EVENT $event, $param) { global $INPUT, $JSINFO, $conf,$ID,$USERINFO; if(file_exists($this->ui_priority_metafn)) { $client = $_SERVER['REMOTE_USER']; $ar = unserialize(file_get_contents($this->ui_priority_metafn)); if(isset($ar[$client])) { $ln = $ar[$client]; init_lang($ln); $conf['lang']= $ln; } } $JSINFO['tmplft_template'] = $conf['template']; $JSINFO['tmplftacl'] = auth_quickaclcheck( $ID); $acl_levels = array('NONE'=>0,'READ'=>1,'EDIT'=>2,'CREATE'=>4,'UPLOAD'=>8,'DELETE'=>16); $JSINFO['tmplft_aclgen'] = $acl_levels[$this->getConf('acl_all')]; $background_color = $this->getConf('background_color'); $background_color = trim($background_color); if(!empty($background_color)) { if($background_color == 'default') $background_color = $this->html_bg_color; $JSINFO['tmplft_bgcolor'] = $background_color; } /* Suppress sidebar */ $xcludes = $this->getConf('xcl_sidebar'); if($xcludes) { // msg($xcludes); $xcludes = preg_replace("/\s+/","",$xcludes); $xcludes = trim($xcludes,','); $xcludes = str_replace(',','|',$xcludes); if(preg_match('/('.$xcludes.')/',$ID,$matches)) { $conf['sidebar'] = 0; //msg(print_r($matches,1)); } } $this->tools(); $ips = $this->getConf('ips'); $ips = trim($ips); if(!empty($ips)) { $remote_addr = $INPUT->server->str('REMOTE_ADDR'); $ips = explode(',',$ips); } else { $ips = array(); $remote_addr = ""; } $which = $this->getConf('rotatewhich'); $dateorip = $this->getConf('dateorip'); if($which == 'BOTH') { $this->logos($ips,$remote_addr,$dateorip); $this->tags($ips,$remote_addr,$dateorip); } else if($which == 'LOGO') { $this->logos($ips,$remote_addr,$dateorip); } else if($which == 'TAG') { $this->tags($ips,$remote_addr,$dateorip); } if($this->getConf('rotate_title')) { $this->wiki_names($ips,$remote_addr,$dateorip); } $profile = $this->getConf('profile'); $restricted_group = $this->getConf('restricted_group'); $restricted = false; if(isset($USERINFO) && isset($restricted_group)) { $groups = $USERINFO['grps']; if(in_array($restricted_group,$groups)) { $restricted = true; } } if( $restricted && !empty($profile) || !$restricted_group && !empty($profile)) { $JSINFO['tmplft_profile'] = '1'; } else { $JSINFO['tmplft_profile'] = ""; } $search = $this->getConf('search'); if(!empty($search)) { $JSINFO['tmplft_search'] = '1'; } else $JSINFO['tmplft_search'] = ""; $this->act_blocking = $this->getConf('blocking'); /* debuging if($JSINFO['tmplftacl'] == '255') { msg('
' . print_r($JSINFO,1) .'
');} */ } function logos($ips,$remote_addr, $dateorip) { global $JSINFO; if($dateorip == 'NEITHER') return; $logos = $this->getConf('logos'); if(empty($logos)) return; $logos = explode(',',$logos); if($dateorip == 'DAY') { $nday = date('w'); if(isset($logos[$nday])) { $slot = $nday; } else $slot = 0; list($logo,$width) = preg_split("/\s+/", trim($logos[$slot])); $JSINFO['tmplft_logo'] = trim($logo); $JSINFO['tmplft_logo_width'] = trim($width); return; } for($i=0; $igetConf('wiki_names'); $names = explode(',',$names); if($dateorip == 'DAY') { $nday = date('w'); if(isset($names[$nday])) { $slot = $nday; } else $slot = 0; $JSINFO['tmplft_title'] = trim($names[$slot]); return; } for($i=0; $igetConf('tag_date_format'); if($opt) { $JSINFO['tmplft_tag'] = date($opt); return; } if($dateorip == 'NEITHER') return; $tags = $this->getConf('taglines'); if(empty($tags)) return; $tags = explode(',',$tags); if($dateorip == 'DAY') { $nday = date('w'); if(isset($tags[$nday])) { $slot = $nday; } else $slot = 0; $JSINFO['tmplft_tag'] = trim($tags[$slot]); return; } for($i=0; $igetConf('sitetools') ; if(!empty($sitetools)) { $pat = array('/Changes/', '/Manager/','/Sitemap/', '/\s/' ); $repl = array("","","index",""); $sitetools=strtolower(preg_replace($pat, $repl,$sitetools)); $JSINFO['tmplft_sitetools'] = "$sitetools"; } else $JSINFO['tmplft_sitetools'] = ""; $pagetools = $this->getConf('pagetools') ; if(!empty($pagetools)) { $pat = array('/Old/','/\s/ ', '/Backlinks/'); $repl = array("","","backlink"); $pagetools=strtolower(preg_replace($pat, $repl,$pagetools)); if(strpos($pagetools,'all') !== false) { $pagetools_conf = 'edit,revisions,backlink,subscribe,revert'; $pagetools = '\w+'; } $JSINFO['tmplft_pagetools'] = $pagetools; } else $JSINFO['tmplft_pagetools'] = ""; $JSINFO['tmplft_ptools_xcl'] = ""; if(strpos($pagetools,'\w+') !== false) { $xcl = $this->getConf('ptools_xcl'); $xcl = preg_replace("/\s/","",$xcl); } else $xcl = 'NONE'; if(!empty($xcl)) $JSINFO['tmplft_ptools_xcl'] = $xcl; $mobile_pt = explode(',',$JSINFO['tmplft_pagetools']); $mobile_st = explode(',',$JSINFO['tmplft_sitetools']); $mobile_ar = array_merge($mobile_pt,$mobile_st); $mobile_ar = array_unique($mobile_ar); $JSINFO['tmplft_mobile'] = implode('|',$mobile_ar); if(isset($pagetools_conf)) { // $pagetools is set to \w+, i.e. all, $pt_conf = explode(',',$pagetools_conf); if(isset($JSINFO['tmplft_ptools_xcl'] )) { $pt_conf = array_diff($pt_conf, explode(',',$JSINFO['tmplft_ptools_xcl'] )); } $actions_ar = array_merge($pt_conf,$mobile_st); $actions_ar = array_unique($actions_ar); $JSINFO['tmplft_actions'] = implode(',',$actions_ar); $JSINFO['tmplft_mobile'] = implode('|',$actions_ar); } else $JSINFO['tmplft_actions'] = implode(',',$mobile_ar); if($this->getConf('search')) { $JSINFO['tmplft_actions'] .= ',search'; } if($this->getConf('profile')) { $JSINFO['tmplft_actions'] .= ',profile'; } if(preg_match('/revisions|recent/',$JSINFO['tmplft_actions'])) { $JSINFO['tmplft_actions'] .= ',diff'; } } function action_link(&$event, $param) { global $ACT,$conf; if(!$conf['sidebar']) return; $sbar = $this->getConf('toggle_sidebar'); if($ACT != 'show' || !$sbar) return; $name = $this->getLang('toggle_name'); $event->data['items']['tplmod'] = '
  • '. $name.'
  • '; } public function addsvgbutton(Doku_Event $event) { global $ACT,$conf; if(!$conf['sidebar']) return; if($event->data['view'] != 'site') return; $sbar = $this->getConf('toggle_sidebar'); if($ACT != 'show' || !$sbar) return; $btn = $this->getLang('toggle_name'); if(!$btn) $btn = 'Sidebar toggle'; array_splice($event->data['items'], -1, 0, [new \dokuwiki\plugin\tplmod\MenuItem($btn)]); } public function handle_act(Doku_Event $event) { global $JSINFO; if(!$this->act_blocking){ return; } if(empty($JSINFO['tmplftacl'])) { $JSINFO['tmplftacl']=0; } $acl = (($JSINFO['tmplftacl'] >= 0) && $JSINFO['tmplftacl'] <= $JSINFO['tmplft_aclgen']) ? true: false; if(!$acl) return; $act = act_clean($event->data); if($act == 'logout' || $act == 'login') return; if(isset($JSINFO['tmplft_ptools_xcl']) && !empty($JSINFO['tmplft_ptools_xcl'])) { if(strpos($JSINFO['tmplft_ptools_xcl'],$act) !== false) { // if excluded allow return 1; } } if(strpos($JSINFO['tmplft_actions'],$act) === false) { // if allowed action, allow return 1; } if($act == 'revert') { $event->data = 'login'; return 1; } $event->data = 'show'; return 1; } }