1<?php
2/**
3* based on https://github.com/turnermm/Dokuwiki-Nav-Overlay
4* @author   Myron Turner <turnermm02@shaw.ca>
5* developed with suggestions from torpedo <dgtorpedo@gmail.com>
6*
7* 2021/04 by KalleAPunkt
8*
9*/
10
11if(!defined('DOKU_INC')) die();
12
13
14class action_plugin_dirtylittlehelper extends DokuWiki_Action_Plugin {
15
16	var $dlh_overlay = '';
17	var $dlh_topmenu = '';
18
19
20	function register(Doku_Event_Handler $controller) {
21
22		$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'dirtylittlehelper_varis');
23		$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'dirtylittlehelper_add_js_mermaid');
24		$controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'dirtylittlehelper_insert_button', array ());
25		$controller->register_hook('TPL_ACT_RENDER', 'AFTER',  $this, 'dirtylittlehelper_output', array('after'));
26
27	}
28
29	function dirtylittlehelper_insert_button(Doku_Event $event, $param) {
30
31		$event->data[] = array (
32		'type' => 'dirtylittlehelper',
33		'title' => 'DLH', //$this->getLang('abutton'),
34		'icon' => '../../plugins/dirtylittlehelper/images/dirtylittlehelper_ovl_sprite.png',
35		);
36
37	}//function dirtylittlehelper_insert_button
38
39
40	function dirtylittlehelper_output(&$event, $param) {
41		echo $this->dlh_overlay;
42		echo $this->dlh_topmenu;
43	}
44
45
46	function dirtylittlehelper_varis(&$event, $param){
47
48		global $ACT, $JSINFO, $ID, $INPUT, $auth, $TPL, $INFO;
49
50		$INFO['dlh'] = array(
51			  'isadmin' => (int) $INFO['isadmin']
52			, 'isauth'  => (int) $INFO['userinfo']
53		);
54
55
56
57		//LOGIN NEEDED ?
58		//NOT LOGGED IN ? -> FORCE LOGIN
59		if( !$INFO['userinfo'] && $_GET['do']!='login' && $this->getConf('must_login') ) {
60		  header("Location: ?do=login");
61		  die('<a href="?do=login">LOGIN</a>');
62		}
63
64
65
66
67		$JSINFO['dlh'] = array(
68			  'QUOT'		=> '"'
69			, 'WL' 			=> wl('','',true)
70			, 'DOKU_BASE'	=> DOKU_BASE
71			, 'DOKU_URL'	=> DOKU_URL
72			, 'isadmin' 	=> (int) $INFO['isadmin']
73			, 'isauth'  	=> (int) $INFO['userinfo']
74		);
75
76        if(is_array($ACT)) {
77            $ACT = act_clean($ACT);
78        }
79
80		$regex = 'edit|preview';
81
82        $INFO['dlh']['act_edit'] = preg_match("/" . $regex ."/",$ACT);
83        $JSINFO['dlh']['act_edit'] = preg_match("/" . $regex ."/",$ACT);
84
85		$JSINFO['dlh']['edit_active'] = 0;
86
87		if($INFO['dlh']['act_edit'] && $INFO['dlh']['isadmin'] && $INFO['dlh']['isauth']){
88
89			$JSINFO['dlh']['edit_active'] = $this->getConf('edit_active');
90
91			if( $JSINFO['dlh']['edit_active']){
92				$JSINFO['dlh']['edit_dlh_wikiid']	= $this->getConf('edit_dlh_wikiid');
93				$JSINFO['dlh']['edit_tb_min_max'] 	= $this->getConf('edit_tb_minmax');
94				$JSINFO['dlh']['edit_tb_maximize'] 	= $this->getConf('edit_tb_maximize');
95				$JSINFO['dlh']['edit_tb_code']	 	= $this->getConf('edit_tb_code');
96				$JSINFO['dlh']['edit_tb_mermaid']	= $this->getConf('edit_tb_mermaid');
97				$JSINFO['dlh']['edit_tb_drawio']	= $this->getConf('edit_tb_drawio');
98				$JSINFO['dlh']['edit_tb_struct']	= $this->getConf('edit_tb_struct');
99				$JSINFO['dlh']['edit_tb_dlhid']		= $this->getConf('edit_tb_dlhid');
100			}
101
102		}//editor?
103
104		$JSINFO['dlh']['top_active'] = $this->getConf('top_active');
105
106		//ONLY IF ACT = EDIT/PREVIEW && CONF = 1 && ISADMIN && ISAUTH
107		if( $INFO['dlh']['act_edit']
108			&& $this->getConf('edit_active')
109			&& $INFO['dlh']['isadmin']
110			&& $INFO['dlh']['isauth']
111		){
112
113
114			$edit_dlh_wikiid = trim($this->getConf('edit_dlh_wikiid'));
115
116			if($edit_dlh_wikiid){
117				$edit_dlh_wiki_body =  p_wiki_xhtml($edit_dlh_wikiid);
118			}else{
119				$edit_dlh_wiki_body=false;
120			}
121
122			if(!$edit_dlh_wiki_body){
123				$JSINFO['dlh']['edit_look4struct']='0';
124				$edit_dlh_wiki_body='';
125			}else{
126				$JSINFO['dlh']['edit_look4struct']='1';
127			}
128
129			$text = <<<TEXT
130<div id='dirtylittlehelper_overlay'>
131<div class = "close">
132<a href="javascript:jQuery('#dirtylittlehelper_overlay').toggle();void(0);"  rel="nofollow" title="close">close</a>
133</div><div class="dirtylittlehelper_overlay_insert">$edit_dlh_wiki_body</div></div>
134
135TEXT;
136
137			$this->dlh_overlay .= $text;
138
139
140
141		}//overlay?
142
143
144		//TOPBAR
145		//ONLY IF CONF = 1 && ISADMIN && ISAUTH
146		if(   $this->getConf('top_active')
147			&& $INFO['dlh']['isadmin']
148			&& $INFO['dlh']['isauth']
149		){
150
151			$topbar = '';
152
153			//HELPER
154			$top_helper_wikiid = trim($this->getConf('top_helper_wikiid'));
155
156			if($top_helper_wikiid){
157				$top_helper_wiki_body = p_wiki_xhtml($top_helper_wikiid);
158			}else{
159				$top_helper_wiki_body = false;
160			}
161
162			if(!$top_helper_wiki_body){
163				$top_helper_wiki_body='';
164			}else{
165				$top_helper_wiki_body = '<div id="dlh_top_helper_a">&nbsp;&#128173;&nbsp;'
166										.'<div id="dlh_top_helper_b">'
167										.'<div id="dlh_top_helper_c1">'
168										.$top_helper_wiki_body
169										.'</div>'
170										.'<div id="dlh_top_helper_c2">'
171										.'<button class="dlh_top_helper_reload" title="reload" '
172										.' onClick="dlh_ajax_wikiid_body(\''.$top_helper_wikiid.'\',\'dlh_top_helper_c1\');">&#128472;'
173										.'</button>'
174										.'</div>'
175										.'</div>'
176										.'</div>';
177			}
178
179			$topbar .= $top_helper_wiki_body;
180
181
182			//TEMPLATES
183			$templates = trim($this->getConf('top_templates') );
184			if( $templates  != '' ) {
185
186				$templates_out='';
187
188				$templates = explode("\n" , $templates);
189
190				foreach ($templates as $value){
191					$value=explode('|',$value);
192
193					if( isset( $value[0] ) && isset( $value[1] )){
194						$value[0] = htmlspecialchars(trim($value[0]), ENT_QUOTES);
195						$value[1] = htmlspecialchars(trim($value[1]), ENT_QUOTES);
196
197						$templates_out .= '<option value="'.$value[1].'">'.$value[0].'</option>';
198					}
199				}
200
201				if( $templates_out != '' ){
202
203					$templates_out = '<select id="dlh_top_template">'
204									. $templates_out
205									. '</select>';
206				}
207
208				$topbar .= $templates_out;
209			}
210			//TEMPLATES
211
212
213			//STRUCT LOOKUP
214
215			$top_struct_wikiid = trim($this->getConf('top_struct_wikiid'));
216
217			if($top_struct_wikiid){
218				$top_struct_wiki_body = p_wiki_xhtml($top_struct_wikiid);
219			}else{
220				$top_struct_wiki_body = false;
221			}
222
223
224			if(!$top_struct_wiki_body){
225				$top_struct_wiki_body='';
226			}else{
227				$top_struct_wiki_body = '<div id="dlh_top_struct_a">'
228										.'<div id="dlh_top_struct_b">'
229										.'</div>'
230										.'<div id="dlh_top_struct_c">'
231										.$top_struct_wiki_body
232										.'</div>'
233										.'</div>';
234			}
235
236			$topbar .= $top_struct_wiki_body;
237
238
239			// top_pagesuggest
240			if($this->getConf('top_pagesuggest')){
241
242				$topbar .= '<div id="dlh_top_pagesuggest">'
243							.'<input type="text" id="dlh_top_pagesuggest_input" title="pagesuggest">'
244							.'<button id="dlh_top_pagesuggest_button" onClick="dlh_top_call(\'dlh_top_pagesuggest_input\');" title="call pagesuggest...">&GT;</button>'
245							.'</div>';
246
247			} //top_pagesuggest?
248
249			// top_dlhid
250			if($this->getConf('top_dlhid_active')){
251
252				$topbar .= '<div id="dlh_top_dlhid">'
253							.'<input type="text" id="dlh_top_dlhid_input" title="dlhID">'
254							.'<button id="dlh_top_dlhid_button" onClick="dlh_renew_dlhid(\'dlh_top_dlhid_input\');" title="renew dlhID">*</button>'
255							.'</div>';
256
257			} //top_pagesuggest?
258
259
260
261
262			//MENU?
263			if( $this->getConf('top_adm_active') ){
264
265				$topmenu = '';
266
267
268				$dlh_for_left_side = array('usermanager', 'acl', 'extension', 'config', 'styling', 'revert', 'popularity');
269				$dlh_left_side=array();
270				$dlh_right_side=array();
271
272				$hidden = trim($this->getConf('top_adm_link_wikiid'));
273				$hidden_label = trim($this->getConf('top_adm_link_text'));
274
275				if( $hidden_label == '') { $hidden_label = '&#8734 hidden area';}
276				if( $hidden !='' ){
277
278					$dlh_left_side[]=array('item'=>'hidden area'
279											,'menutext'=> $hidden_label
280											,'menuicon'=> false
281											,'adminonly'=> 1
282											,'link' => '?id=' . $hidden //wl($ID, array('id' => $hidden) )
283											,'inline_icon' => ''
284											);
285				}//if hidden != ''
286
287				$dlh_left_side[]=array('item'=>'check'
288							,'menutext'=> '&#128736; check'
289							,'menuicon'=> false
290							,'adminonly'=> 1
291							,'link' => '?do=check'
292							,'inline_icon' => ''
293							);
294
295				$dlh_left_side[]=array('item'=>'purge'
296							,'menutext'=> '&#128736; purge'
297							,'menuicon'=> false
298							,'adminonly'=> 1
299							,'link' => '?purge=true'
300							,'inline_icon' => ''
301							);
302
303				$dlh_left_side[]=array('item'=>'export_xhtmlbody'
304							,'menutext'=> '&#128736; export_xhtmlbody'
305							,'menuicon'=> false
306							,'adminonly'=> 1
307							,'link' => '?do=export_xhtmlbody'
308							,'inline_icon' => ''
309							);
310
311
312				$dlh_left_side[]=array('item'=>'export_raw'
313							,'menutext'=> '&#128736; export_raw !! .TXT FILE !!'
314							,'menuicon'=> false
315							,'adminonly'=> 1
316							,'link' => '?do=export_raw'
317							,'inline_icon' => ''
318							);
319
320
321
322				$dlh_plugin_list = plugin_list('admin',false);
323
324
325				foreach($dlh_plugin_list as $thisplugin) {
326
327					$tmp_plugin = plugin_load('admin', $thisplugin);
328
329					if( $tmp_plugin !== null){
330
331						$this_data = array(  'item'=>$thisplugin
332											,'menutext'=> $tmp_plugin->getMenuText($conf['lang'])
333											,'menuicon'=> $tmp_plugin->getMenuIcon()
334											,'adminonly'=> $tmp_plugin->forAdminOnly()
335											,'linkx' => wl($ID, array('do' => 'admin', 'page' => $thisplugin))
336											,'link' => '?do=admin&page='.$thisplugin
337											,'inline_icon' => preg_replace('/style="[^"]{1,99}"/i', '',
338																preg_replace('/width="[0-9a-z]{1,9}"/i', '',
339																	preg_replace('/height="[0-9a-z]{1,9}"/i', '',
340																	inlineSVG( $tmp_plugin->getMenuIcon() )
341																	)
342																)
343															  )
344											);
345
346						if( trim($this_data['menutext']) == '') { $this_data['menutext'] = ucfirst( $thisplugin );}
347
348						if( in_array($thisplugin, $dlh_for_left_side )) {
349							$dlh_left_side[] = $this_data;
350
351						}else{
352							$dlh_right_side[] = $this_data;
353
354						}//left or right?
355
356					}//if( $tmp_plugin !== null){
357
358				}//foreach($dlh_plugin_list as $thisplugin) {
359
360				$topmenu.= '<div class="dlh_top_menu">'
361						 .'<div class="dlh_top_menu_dropdown_admin" id="dlh_topmenu_admin">'
362						 .'<a class="dlh_top_menu_dropbtn_admin">~MENU~</a>'
363						 .'<div class="dlh_top_menu_dropdown_content_admin">'
364						 .'<table><tr><td>';
365
366
367				foreach( $dlh_left_side as $item){
368					$topmenu .= '<a title="'.$item['menutext'].'" href="'.$item['link'].'">'.$item['inline_icon'].' '. $item['menutext'] .'</a>';
369				}
370
371				$topmenu .= '</td><td>';
372
373				foreach( $dlh_right_side as $item){
374					$topmenu .= '<a title="'.$item['menutext'].'" href="'.$item['link'].'">'.$item['inline_icon'].' '. $item['menutext'] .'</a>';
375				}
376
377				$topmenu.= '</td></tr></table></div></div></div>';
378
379
380				$topbar .= $topmenu;
381
382
383			}//MENU?
384
385			if( $topbar != ''){
386				$this->dlh_topmenu .= '<div id="dlh_top0">'.$topbar.'</div>';
387			}
388
389
390		}//TOPBAR??
391
392
393
394
395	} //function dirtylittlehelper_get_set_varis
396
397
398
399	function dirtylittlehelper_add_js_mermaid(Doku_Event $event, $param){
400		$event->data['script'][] = array(
401                            'type'    => 'text/javascript',
402                            'charset' => 'utf-8',
403                            '_data'   => '',
404                            'src' => DOKU_BASE."lib/plugins/dirtylittlehelper/script/mermaid.min.js");
405
406		$event->data['script'][] = array(
407                    'type'    => 'text/javascript',
408                    'charset' => 'utf-8',
409                    '_data'   => 'document.addEventListener("DOMContentLoaded", function(event) {   mermaid.initialize({securityLevel: "loose"}); }); '
410		    );
411	}
412
413
414
415
416
417
418
419/*
420
421================== ================== ================== ================== ================== ================== ==================
422================== ================== ================== ================== ================== ================== ==================
423================== ================== ================== ================== ================== ================== ==================
424================== ================== ================== ================== ================== ================== ==================
425================== ================== ================== ================== ================== ================== ==================
426================== ================== ================== ================== ================== ================== ==================
427
428
429*/
430
431
432
433
434
435
436    function dirtylittlehelper_active(){
437
438        global $ACT;
439
440        if(is_array($ACT)) {
441             $ACT = act_clean($ACT);
442        }
443
444        $regex = 'edit|preview';
445        return preg_match("/" . $regex ."/",$ACT);
446
447    }//function dirtylittlehelper_active
448
449
450
451
452
453
454    function dirtylittlehelper_extendJSINFO(&$event, $param) {
455
456        global $INFO, $JSINFO;
457
458    	$JSINFO['dlh']=array(
459
460        'isadmin' => (int) $INFO['isadmin'],
461        'isauth'  => (int) $INFO['userinfo'],
462        'overlay' => $this->dirtylittlehelper_active(),
463		'show_id' => $this->getConf('show_id'),
464		'show_mermaid' => $this->getConf('show_mermaid'),
465		'show_drawio' =>  $this->getConf('show_drawio'),
466        'fullscreen_edit' =>  $this->getConf('fullscreen_edit'),
467		'WL' => wl('','',true),
468        'DOKU_BASE'=> DOKU_BASE,
469        'DOKU_URL'=>DOKU_URL,
470        'QUOT'=>'"'
471	);
472    }//function dirtylittlehelper_extendJSINFO
473
474
475
476
477	function dirtylittlehelper_menu(&$event, $param){
478
479
480		global $ID, $INPUT, $auth, $TPL, $INFO;
481
482		if ($event->data['view']=='user' && $INFO['isadmin'] && $this->getConf('show_menu') && $this->dlh_top_menu_make === true ){
483
484			$this->dlh_top_menu_make=false;
485
486			$dlh_for_left_side = array('usermanager', 'acl', 'extension', 'config', 'styling', 'revert', 'popularity');
487			$dlh_left_side=array();
488			$dlh_right_side=array();
489
490			$hidden = trim($this->getConf('hidden_area'));
491			$hidden_label = trim($this->getConf('hidden_area_label'));
492
493			if( $hidden_label == '') { $hidden_label = '&#8734 hidden area';}
494			if( $hidden !='' ){
495
496				$dlh_left_side[]=array('item'=>'hidden area'
497										,'menutext'=> $hidden_label
498										,'menuicon'=> false
499										,'adminonly'=> 1
500										,'link' => '?id=' . $hidden //wl($ID, array('id' => $hidden) )
501										,'inline_icon' => ''
502										);
503			}//if hidden != ''
504
505			$dlh_left_side[]=array('item'=>'check'
506						,'menutext'=> '&#128736; check'
507						,'menuicon'=> false
508						,'adminonly'=> 1
509						,'linkx' => wl($ID, array('do' => 'check') )
510						,'link' => '?do=check'
511						,'inline_icon' => ''
512						);
513
514			$dlh_left_side[]=array('item'=>'purge'
515						,'menutext'=> '&#128736; purge'
516						,'menuicon'=> false
517						,'adminonly'=> 1
518						,'linkx' => wl($ID, array('purge' => 'true') )
519						,'link' => '?purge=true'
520						,'inline_icon' => ''
521						);
522
523
524
525			$dlh_plugin_list = plugin_list('admin',false);
526
527
528			foreach($dlh_plugin_list as $thisplugin) {
529
530				$tmp_plugin = plugin_load('admin', $thisplugin);
531
532				if( $tmp_plugin !== null){
533
534					$this_data = array(  'item'=>$thisplugin
535										,'menutext'=> $tmp_plugin->getMenuText($conf['lang'])
536										,'menuicon'=> $tmp_plugin->getMenuIcon()
537										,'adminonly'=> $tmp_plugin->forAdminOnly()
538										,'linkx' => wl($ID, array('do' => 'admin', 'page' => $thisplugin))
539										,'link' => '?do=admin&page='.$thisplugin
540										,'inline_icon' => preg_replace('/style="[^"]{1,99}"/i', '',
541															preg_replace('/width="[0-9a-z]{1,9}"/i', '',
542																preg_replace('/height="[0-9a-z]{1,9}"/i', '',
543																inlineSVG( $tmp_plugin->getMenuIcon() )
544																)
545															)
546														  )
547										);
548
549					if( trim($this_data['menutext']) == '') { $this_data['menutext'] = ucfirst( $thisplugin );}
550
551					if( in_array($thisplugin, $dlh_for_left_side )) {
552						$dlh_left_side[] = $this_data;
553
554					}else{
555						$dlh_right_side[] = $this_data;
556
557					}//left or right?
558
559				}//if( $tmp_plugin !== null){
560
561			}//foreach($dlh_plugin_list as $thisplugin) {
562
563$toptext = <<<TOPTEXT
564<div style="width:400px;display: inline;"><input type="text" id="dlh_top_newpage" title="autocomplete path" style="
565    display: inline;
566    width: 230px;
567"><button onClick="dlh_call_top_new();" title="call AUTOCOMPLETE..." style="
568    display: inline;
569    margin-left: 5px;
570">&GT;</button><input class="dlh_top_id" id="dlh_top_id" type="text" title="DLH AutoID" style="
571    display: inline;
572    width: 80px;
573    margin-left: 5px;
574"><button onClick="dlh_renew_dlhid('dlh_top_id');" title="RENEW DLH AutoID" style="
575    display: inline;
576    margin-left: 5px;
577">*</button></div>
578TOPTEXT;
579
580$toptext2 = '';
581if( $this->getConf('page_top')){
582  $toptext2 = '<div id="dlh_topmenu_page">'.p_wiki_xhtml( $this->getConf('page_top'),'',false,'' ).'</div>';
583}
584
585
586                        echo '<div class="dlh_topmenu">'
587. $toptext2
588. $toptext
589
590                                 . '<div class="dlh_topmenu_dropdown_admin" id="dlh_topmenu_admin">'
591                                 .'<a class="dlh_topmenu_dropbtn_admin">ADMIN</a>'
592                                 .'<div class="dlh_topmenu_dropdown_content_admin">';
593
594
595
596//                      echo $toptext;
597                        echo '<table><tr><td>';
598
599
600			foreach( $dlh_left_side as $item){
601				echo '<a title="'.$item['menutext'].'" href="'.$item['link'].'">'.$item['inline_icon'].' '. $item['menutext'] .'</a>';
602			}
603
604			echo '</td><td>';
605
606			foreach( $dlh_right_side as $item){
607				echo '<a title="'.$item['menutext'].'" href="'.$item['link'].'">'.$item['inline_icon'].' '. $item['menutext'] .'</a>';
608			}
609
610			echo '</td></tr></table></div></div></div>';
611
612		}//if menu and admin
613
614	}//function dirtylittlehelper_menu
615
616
617
618    function dirtylittlehelper_print_overlay(&$event, $param) {
619
620        //exit if not needed...
621        if(! $this->dirtylittlehelper_active() ){ return false; }
622
623        global $ID, $INFO;
624        $page = "";
625
626        if(!$page) $page = trim($this->getConf('page'));
627
628        if(!$page) return;
629
630        $insert =  p_wiki_xhtml($page);
631
632        if(!$insert) return;
633
634        $close = trim($this->getLang('close'));
635
636        $text = <<<TEXT
637<div id='dirtylittlehelper_overlay'>
638<div  class = "close">
639<a href="javascript:jQuery('#dirtylittlehelper_overlay').toggle();void(0);"  rel="nofollow" title="$close">$close</a>
640</div><div class="dirtylittlehelper_ovl-insert">$insert</div></div>
641
642TEXT;
643	echo $text;
644
645
646
647    }//function dirtylittlehelper_print_overlay
648
649
650
651}//class action_plugin_dirtylittlehelper
652
653
654
655
656