* developed with suggestions from torpedo * * 2021/04 by KalleAPunkt * */ if(!defined('DOKU_INC')) die(); class action_plugin_dirtylittlehelper extends DokuWiki_Action_Plugin { var $dlh_overlay = ''; var $dlh_topmenu = ''; function register(Doku_Event_Handler $controller) { $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'dirtylittlehelper_varis'); $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'dirtylittlehelper_add_js_mermaid'); $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'dirtylittlehelper_insert_button', array ()); $controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this, 'dirtylittlehelper_output', array('after')); } function dirtylittlehelper_insert_button(Doku_Event $event, $param) { $event->data[] = array ( 'type' => 'dirtylittlehelper', 'title' => 'DLH', //$this->getLang('abutton'), 'icon' => '../../plugins/dirtylittlehelper/images/dirtylittlehelper_ovl_sprite.png', ); }//function dirtylittlehelper_insert_button function dirtylittlehelper_output(&$event, $param) { echo $this->dlh_overlay; echo $this->dlh_topmenu; } function dirtylittlehelper_varis(&$event, $param){ global $ACT, $JSINFO, $ID, $INPUT, $auth, $TPL, $INFO; $INFO['dlh'] = array( 'isadmin' => (int) $INFO['isadmin'] , 'isauth' => (int) $INFO['userinfo'] ); //LOGIN NEEDED ? //NOT LOGGED IN ? -> FORCE LOGIN if( !$INFO['userinfo'] && $_GET['do']!='login' && $this->getConf('must_login') ) { header("Location: ?do=login"); die('LOGIN'); } $JSINFO['dlh'] = array( 'QUOT' => '"' , 'WL' => wl('','',true) , 'DOKU_BASE' => DOKU_BASE , 'DOKU_URL' => DOKU_URL , 'isadmin' => (int) $INFO['isadmin'] , 'isauth' => (int) $INFO['userinfo'] ); if(is_array($ACT)) { $ACT = act_clean($ACT); } $regex = 'edit|preview'; $INFO['dlh']['act_edit'] = preg_match("/" . $regex ."/",$ACT); $JSINFO['dlh']['act_edit'] = preg_match("/" . $regex ."/",$ACT); $JSINFO['dlh']['edit_active'] = 0; if($INFO['dlh']['act_edit'] && $INFO['dlh']['isadmin'] && $INFO['dlh']['isauth']){ $JSINFO['dlh']['edit_active'] = $this->getConf('edit_active'); if( $JSINFO['dlh']['edit_active']){ $JSINFO['dlh']['edit_dlh_wikiid'] = $this->getConf('edit_dlh_wikiid'); $JSINFO['dlh']['edit_tb_min_max'] = $this->getConf('edit_tb_minmax'); $JSINFO['dlh']['edit_tb_maximize'] = $this->getConf('edit_tb_maximize'); $JSINFO['dlh']['edit_tb_code'] = $this->getConf('edit_tb_code'); $JSINFO['dlh']['edit_tb_mermaid'] = $this->getConf('edit_tb_mermaid'); $JSINFO['dlh']['edit_tb_drawio'] = $this->getConf('edit_tb_drawio'); $JSINFO['dlh']['edit_tb_struct'] = $this->getConf('edit_tb_struct'); $JSINFO['dlh']['edit_tb_dlhid'] = $this->getConf('edit_tb_dlhid'); } }//editor? $JSINFO['dlh']['top_active'] = $this->getConf('top_active'); //ONLY IF ACT = EDIT/PREVIEW && CONF = 1 && ISADMIN && ISAUTH if( $INFO['dlh']['act_edit'] && $this->getConf('edit_active') && $INFO['dlh']['isadmin'] && $INFO['dlh']['isauth'] ){ $edit_dlh_wikiid = trim($this->getConf('edit_dlh_wikiid')); if($edit_dlh_wikiid){ $edit_dlh_wiki_body = p_wiki_xhtml($edit_dlh_wikiid); }else{ $edit_dlh_wiki_body=false; } if(!$edit_dlh_wiki_body){ $JSINFO['dlh']['edit_look4struct']='0'; $edit_dlh_wiki_body=''; }else{ $JSINFO['dlh']['edit_look4struct']='1'; } $text = <<
$edit_dlh_wiki_body
TEXT; $this->dlh_overlay .= $text; }//overlay? //TOPBAR //ONLY IF CONF = 1 && ISADMIN && ISAUTH if( $this->getConf('top_active') && $INFO['dlh']['isadmin'] && $INFO['dlh']['isauth'] ){ $topbar = ''; //HELPER $top_helper_wikiid = trim($this->getConf('top_helper_wikiid')); if($top_helper_wikiid){ $top_helper_wiki_body = p_wiki_xhtml($top_helper_wikiid); }else{ $top_helper_wiki_body = false; } if(!$top_helper_wiki_body){ $top_helper_wiki_body=''; }else{ $top_helper_wiki_body = '
 💭 ' .'
' .'
' .$top_helper_wiki_body .'
' .'
' .'' .'
' .'
' .'
'; } $topbar .= $top_helper_wiki_body; //TEMPLATES $templates = trim($this->getConf('top_templates') ); if( $templates != '' ) { $templates_out=''; $templates = explode("\n" , $templates); foreach ($templates as $value){ $value=explode('|',$value); if( isset( $value[0] ) && isset( $value[1] )){ $value[0] = htmlspecialchars(trim($value[0]), ENT_QUOTES); $value[1] = htmlspecialchars(trim($value[1]), ENT_QUOTES); $templates_out .= ''; } } if( $templates_out != '' ){ $templates_out = ''; } $topbar .= $templates_out; } //TEMPLATES //STRUCT LOOKUP $top_struct_wikiid = trim($this->getConf('top_struct_wikiid')); if($top_struct_wikiid){ $top_struct_wiki_body = p_wiki_xhtml($top_struct_wikiid); }else{ $top_struct_wiki_body = false; } if(!$top_struct_wiki_body){ $top_struct_wiki_body=''; }else{ $top_struct_wiki_body = '
' .'
' .'
' .'
' .$top_struct_wiki_body .'
' .'
'; } $topbar .= $top_struct_wiki_body; // top_pagesuggest if($this->getConf('top_pagesuggest')){ $topbar .= '
' .'' .'' .'
'; } //top_pagesuggest? // top_dlhid if($this->getConf('top_dlhid_active')){ $topbar .= '
' .'' .'' .'
'; } //top_pagesuggest? //MENU? if( $this->getConf('top_adm_active') ){ $topmenu = ''; $dlh_for_left_side = array('usermanager', 'acl', 'extension', 'config', 'styling', 'revert', 'popularity'); $dlh_left_side=array(); $dlh_right_side=array(); $hidden = trim($this->getConf('top_adm_link_wikiid')); $hidden_label = trim($this->getConf('top_adm_link_text')); if( $hidden_label == '') { $hidden_label = '∞ hidden area';} if( $hidden !='' ){ $dlh_left_side[]=array('item'=>'hidden area' ,'menutext'=> $hidden_label ,'menuicon'=> false ,'adminonly'=> 1 ,'link' => '?id=' . $hidden //wl($ID, array('id' => $hidden) ) ,'inline_icon' => '' ); }//if hidden != '' $dlh_left_side[]=array('item'=>'check' ,'menutext'=> '🛠 check' ,'menuicon'=> false ,'adminonly'=> 1 ,'link' => '?do=check' ,'inline_icon' => '' ); $dlh_left_side[]=array('item'=>'purge' ,'menutext'=> '🛠 purge' ,'menuicon'=> false ,'adminonly'=> 1 ,'link' => '?purge=true' ,'inline_icon' => '' ); $dlh_left_side[]=array('item'=>'export_xhtmlbody' ,'menutext'=> '🛠 export_xhtmlbody' ,'menuicon'=> false ,'adminonly'=> 1 ,'link' => '?do=export_xhtmlbody' ,'inline_icon' => '' ); $dlh_left_side[]=array('item'=>'export_raw' ,'menutext'=> '🛠 export_raw !! .TXT FILE !!' ,'menuicon'=> false ,'adminonly'=> 1 ,'link' => '?do=export_raw' ,'inline_icon' => '' ); $dlh_plugin_list = plugin_list('admin',false); foreach($dlh_plugin_list as $thisplugin) { $tmp_plugin = plugin_load('admin', $thisplugin); if( $tmp_plugin !== null){ $this_data = array( 'item'=>$thisplugin ,'menutext'=> $tmp_plugin->getMenuText($conf['lang']) ,'menuicon'=> $tmp_plugin->getMenuIcon() ,'adminonly'=> $tmp_plugin->forAdminOnly() ,'linkx' => wl($ID, array('do' => 'admin', 'page' => $thisplugin)) ,'link' => '?do=admin&page='.$thisplugin ,'inline_icon' => preg_replace('/style="[^"]{1,99}"/i', '', preg_replace('/width="[0-9a-z]{1,9}"/i', '', preg_replace('/height="[0-9a-z]{1,9}"/i', '', inlineSVG( $tmp_plugin->getMenuIcon() ) ) ) ) ); if( trim($this_data['menutext']) == '') { $this_data['menutext'] = ucfirst( $thisplugin );} if( in_array($thisplugin, $dlh_for_left_side )) { $dlh_left_side[] = $this_data; }else{ $dlh_right_side[] = $this_data; }//left or right? }//if( $tmp_plugin !== null){ }//foreach($dlh_plugin_list as $thisplugin) { $topmenu.= '
' .'
' .'~MENU~' .'
' .'
'; foreach( $dlh_left_side as $item){ $topmenu .= ''.$item['inline_icon'].' '. $item['menutext'] .''; } $topmenu .= ''; foreach( $dlh_right_side as $item){ $topmenu .= ''.$item['inline_icon'].' '. $item['menutext'] .''; } $topmenu.= '
'; $topbar .= $topmenu; }//MENU? if( $topbar != ''){ $this->dlh_topmenu .= '
'.$topbar.'
'; } }//TOPBAR?? } //function dirtylittlehelper_get_set_varis function dirtylittlehelper_add_js_mermaid(Doku_Event $event, $param){ $event->data['script'][] = array( 'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => DOKU_BASE."lib/plugins/dirtylittlehelper/script/mermaid.min.js"); $event->data['script'][] = array( 'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => 'document.addEventListener("DOMContentLoaded", function(event) { mermaid.initialize({securityLevel: "loose"}); }); ' ); } /* ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== ================== */ function dirtylittlehelper_active(){ global $ACT; if(is_array($ACT)) { $ACT = act_clean($ACT); } $regex = 'edit|preview'; return preg_match("/" . $regex ."/",$ACT); }//function dirtylittlehelper_active function dirtylittlehelper_extendJSINFO(&$event, $param) { global $INFO, $JSINFO; $JSINFO['dlh']=array( 'isadmin' => (int) $INFO['isadmin'], 'isauth' => (int) $INFO['userinfo'], 'overlay' => $this->dirtylittlehelper_active(), 'show_id' => $this->getConf('show_id'), 'show_mermaid' => $this->getConf('show_mermaid'), 'show_drawio' => $this->getConf('show_drawio'), 'fullscreen_edit' => $this->getConf('fullscreen_edit'), 'WL' => wl('','',true), 'DOKU_BASE'=> DOKU_BASE, 'DOKU_URL'=>DOKU_URL, 'QUOT'=>'"' ); }//function dirtylittlehelper_extendJSINFO function dirtylittlehelper_menu(&$event, $param){ global $ID, $INPUT, $auth, $TPL, $INFO; if ($event->data['view']=='user' && $INFO['isadmin'] && $this->getConf('show_menu') && $this->dlh_top_menu_make === true ){ $this->dlh_top_menu_make=false; $dlh_for_left_side = array('usermanager', 'acl', 'extension', 'config', 'styling', 'revert', 'popularity'); $dlh_left_side=array(); $dlh_right_side=array(); $hidden = trim($this->getConf('hidden_area')); $hidden_label = trim($this->getConf('hidden_area_label')); if( $hidden_label == '') { $hidden_label = '∞ hidden area';} if( $hidden !='' ){ $dlh_left_side[]=array('item'=>'hidden area' ,'menutext'=> $hidden_label ,'menuicon'=> false ,'adminonly'=> 1 ,'link' => '?id=' . $hidden //wl($ID, array('id' => $hidden) ) ,'inline_icon' => '' ); }//if hidden != '' $dlh_left_side[]=array('item'=>'check' ,'menutext'=> '🛠 check' ,'menuicon'=> false ,'adminonly'=> 1 ,'linkx' => wl($ID, array('do' => 'check') ) ,'link' => '?do=check' ,'inline_icon' => '' ); $dlh_left_side[]=array('item'=>'purge' ,'menutext'=> '🛠 purge' ,'menuicon'=> false ,'adminonly'=> 1 ,'linkx' => wl($ID, array('purge' => 'true') ) ,'link' => '?purge=true' ,'inline_icon' => '' ); $dlh_plugin_list = plugin_list('admin',false); foreach($dlh_plugin_list as $thisplugin) { $tmp_plugin = plugin_load('admin', $thisplugin); if( $tmp_plugin !== null){ $this_data = array( 'item'=>$thisplugin ,'menutext'=> $tmp_plugin->getMenuText($conf['lang']) ,'menuicon'=> $tmp_plugin->getMenuIcon() ,'adminonly'=> $tmp_plugin->forAdminOnly() ,'linkx' => wl($ID, array('do' => 'admin', 'page' => $thisplugin)) ,'link' => '?do=admin&page='.$thisplugin ,'inline_icon' => preg_replace('/style="[^"]{1,99}"/i', '', preg_replace('/width="[0-9a-z]{1,9}"/i', '', preg_replace('/height="[0-9a-z]{1,9}"/i', '', inlineSVG( $tmp_plugin->getMenuIcon() ) ) ) ) ); if( trim($this_data['menutext']) == '') { $this_data['menutext'] = ucfirst( $thisplugin );} if( in_array($thisplugin, $dlh_for_left_side )) { $dlh_left_side[] = $this_data; }else{ $dlh_right_side[] = $this_data; }//left or right? }//if( $tmp_plugin !== null){ }//foreach($dlh_plugin_list as $thisplugin) { $toptext = << TOPTEXT; $toptext2 = ''; if( $this->getConf('page_top')){ $toptext2 = '
'.p_wiki_xhtml( $this->getConf('page_top'),'',false,'' ).'
'; } echo '
' . $toptext2 . $toptext . '
' .'ADMIN' .'
'; // echo $toptext; echo '
'; foreach( $dlh_left_side as $item){ echo ''.$item['inline_icon'].' '. $item['menutext'] .''; } echo ''; foreach( $dlh_right_side as $item){ echo ''.$item['inline_icon'].' '. $item['menutext'] .''; } echo '
'; }//if menu and admin }//function dirtylittlehelper_menu function dirtylittlehelper_print_overlay(&$event, $param) { //exit if not needed... if(! $this->dirtylittlehelper_active() ){ return false; } global $ID, $INFO; $page = ""; if(!$page) $page = trim($this->getConf('page')); if(!$page) return; $insert = p_wiki_xhtml($page); if(!$insert) return; $close = trim($this->getLang('close')); $text = <<
$insert
TEXT; echo $text; }//function dirtylittlehelper_print_overlay }//class action_plugin_dirtylittlehelper