1<?php 2/** 3 * Folded plugin: enables folded text font size with syntax ++ text ++ 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Michael Hamann <michael@content-space.de> 7 */ 8 9/** 10 * Action part: makes the show/hide strings available in the browser 11 */ 12class action_plugin_folded extends DokuWiki_Action_Plugin { 13 /** 14 * Register the handle function in the controller 15 * 16 * @param Doku_event_handler $controller The event controller 17 */ 18 function register(Doku_Event_Handler $controller) { 19 $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'addhidereveal'); 20 $controller->register_hook('TEMPLATE_PAGETOOLS_DISPLAY', 'BEFORE', $this, 'add_button', array()); 21 $controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'add_button_new', array()); 22 } 23 24 /** 25 * Add the hide and reveal strings to $JSINFO so it can be used in the javascript 26 * 27 * @param Doku_Event $event The event 28 * @param array $params The parameters for the event 29 */ 30 function addhidereveal($event, $params) { 31 global $JSINFO; 32 33 $hide = $this->getConf('hide') ? $this->getConf('hide') : $this->getLang('hide'); 34 $reveal = $this->getConf('reveal') ? $this->getConf('reveal') : $this->getLang('reveal'); 35 36 $JSINFO['plugin_folded'] = array( 37 'hide' => $hide, 38 'reveal' => $reveal 39 ); 40 } 41 42 /** 43 * Add 'fold/unfold all'-button to pagetools 44 * 45 * @param Doku_Event $event 46 * @param mixed $param not defined 47 */ 48 public function add_button(&$event, $param) { 49 global $ID, $REV; 50 51 if($this->getConf('show_fold_unfold_all_button') && $event->data['view'] == 'main') { 52 $params = array('do' => 'fold_unfold_all'); 53 if($REV) $params['rev'] = $REV; 54 55 // insert button at position before last (up to top) 56 $event->data['items'] = array_slice($event->data['items'], 0, -1, true) + 57 array('fold_unfold_all' => 58 '<li>' 59 .'<a href="javascript:void(0);" class="fold_unfold_all" onclick="fold_unfold_all();" rel="nofollow" title="'.$this->getLang('fold_unfold_all_button').'">' 60 .'<span>'.$this->getLang('fold_unfold_all_button').'</span>' 61 .'</a>' 62 .'</li>' 63 ) + 64 array_slice($event->data['items'], -1 , 1, true); 65 } 66 } 67 68 /** 69 * Add 'fold/unfold all'-button to pagetools, new SVG based mechanism 70 * 71 * @param Doku_Event $event 72 */ 73 public function add_button_new(Doku_Event $event) { 74 if($event->data['view'] != 'page') return; 75 if($this->getConf('show_fold_unfold_all_button')) { 76 array_splice($event->data['items'], -1, 0, [new \dokuwiki\plugin\folded\MenuItemFolded()]); 77 } 78 } 79} 80