1<?php 2 /** 3 * @author Myron Turner <turnermm02@shaw.ca> 4 * developed with suggestions from torpedo <dgtorpedo@gmail.com> 5 */ 6 7 if(!defined('DOKU_INC')) die(); 8 9 10 class action_plugin_overlay extends DokuWiki_Action_Plugin { 11 12 function register(Doku_Event_Handler $controller) { 13 $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'set_admin'); 14 $controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this, 'print_overlay', array('after')); 15 $controller->register_hook('TEMPLATE_PAGETOOLS_DISPLAY', 'BEFORE', $this, 'action_link', array('page')); 16 $controller->register_hook('TEMPLATE_SITETOOLS_DISPLAY', 'BEFORE', $this, 'action_link', array('site')); 17 $controller->register_hook('TEMPLATE_USERTOOLS_DISPLAY', 'BEFORE', $this, 'action_link', array('user')); 18 $controller->register_hook('TEMPLATE_OVLTOOLS_DISPLAY', 'BEFORE', $this, 'overlay_tools', array('user')); 19 $controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addsvgbutton', array()); 20 // $controller->register_hook('', 'AFTER', $this, 'addsvgbutton', array()); 21 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'get_scripts', array()); 22 } 23 24 function get_scripts(Doku_Event $event, $param) { 25 $event->data["script"][] = array ( 26 "type" => "text/javascript", 27 "src" => DOKU_BASE."lib/plugins/overlay/script/jquery-ui-touch-punch-cmpr.js", 28 "_data" => "", 29 ) + ([ 'defer' => 'defer']); 30 } 31 32 function set_admin(&$event, $param) { 33 global $JSINFO, $ACT; 34 35 if(is_array($ACT)) { 36 $ACT = act_clean($ACT); 37 } 38 39 if($this->getConf('always')){ 40 $JSINFO['overlay'] = 1; 41 } 42 else { 43 $exclusions = array('admin','profile','recent','revisions','backlink','login','index','media','register','edit'); 44 $regex = ""; 45 foreach($exclusions as $xcl) { 46 if($this->getConf($xcl)) { 47 $regex .= "$xcl|" ; 48 } 49 } 50 $regex = trim($regex, '|'); 51 $regex .= '|preview'; 52 $JSINFO['overlay'] = preg_match("/" . $regex ."/",$ACT); 53 } 54 55 $JSINFO['ol_left'] = 0; 56 $JSINFO['ol_top'] = 0; 57 $JSINFO['position'] = 'fixed'; 58 59 $height = preg_replace('/[^0-9]+/', '', $this->getConf('height')); 60 $width = preg_replace('/[^0-9]+/', '', $this->getConf('width')); 61 62 if($height) { 63 $JSINFO['ol_height'] = $height; 64 } 65 if($width) { 66 $JSINFO['ol_width'] = $width ; 67 } 68 } 69 70 function print_overlay(&$event, $param) { 71 global $ID, $INFO; 72 $page = ""; 73 74 $tools = $this->getConf('tools'); 75 if(!empty($tools)) { 76 $choices = explode(',',$tools); 77 $action = tpl_action($choices[0], true, '', 1, '<span class = "oltools-left">', '</span>', ''); 78 for($i = 1; $i<count($choices); $i++) 79 $action .= tpl_action($choices[$i], true, '', 1, '<span class = "oltools-right">', '</span>', ''); 80 } 81 82 if($INFO['userinfo']) { 83 $wiki_page = 'overlay:' . $INFO['client']; 84 $file = wikiFN($wiki_page); 85 if(file_exists($file) && auth_quickaclcheck('overlay:' . $INFO['client']) >= AUTH_READ) { // check ACL for overlay page 86 $page = $wiki_page; 87 } 88 else { 89 $wiki_page = $INFO['client'] . ':overlay'; 90 $file = wikiFN($wiki_page); 91 if(file_exists($file) && auth_quickaclcheck($INFO['client'] . "overlay") >= AUTH_READ) { // check ACL for overlay page 92 $page = $wiki_page; 93 } 94 } 95 } 96 if(!$page) { 97 $namespaces = $this->getConf('nsoverlays'); // check for alternate overlay pages 98 $alternates = explode(',',$namespaces); 99 100 $ns = getNS($ID); 101 foreach($alternates as $nmsp) { 102 if($ns == trim($nmsp,': ')) { 103 $wikiFile = wikiFN("$ns:overlay"); 104 if(file_exists($wikiFile) && auth_quickaclcheck("$ns:overlay") >= AUTH_READ) { // check ACL for overlay page 105 $page = "$ns:overlay"; // if an alternate exists put it in $page 106 break; 107 } 108 } 109 } 110 } 111 if(!$page) { 112 foreach($alternates as $nmsp) { 113 if(strrpos($nmsp,'*')) { 114 $nmsp = trim($nmsp,'* '); 115 if(preg_match("#^$nmsp#",$ns)) { 116 $wikiFile = wikiFN("$nmsp:overlay"); 117 if(file_exists($wikiFile) && auth_quickaclcheck("$nmsp:overlay") >= AUTH_READ) { // check ACL for overlay page 118 $page = "$nmsp:overlay"; // if a parent namespace alternate exists put it in $page 119 break; 120 } 121 } 122 } 123 } 124 } 125 126 if(!$page) $page = trim($this->getConf('page')); 127 if(!$page) return; 128 $insert = p_wiki_xhtml($page); 129 if(!$insert) return; 130 $close = trim($this->getLang('close')); 131 $detach = trim($this->getLang('detach')); 132 $fixed = trim($this->getLang('fix_title')); 133 $resize = trim($this->getLang('resize')); 134 $action .=' <a href="javascript:void(0);" class="ovl_fix_toggle" title ="' .$fixed .'">' . $detach. '</a>'; 135$text = <<<TEXT 136 <div id='overlay'> 137 <div class="ui-resizable-handle ui-resizable-nw" id="nwgrip" title="$resize"></div> 138 <div class="ui-resizable-handle ui-resizable-ne" id="negrip" title="$resize"></div> 139 <div class="ui-resizable-handle ui-resizable-sw" id="swgrip" title="$resize"></div> 140 <div class="ui-resizable-handle ui-resizable-se" id="segrip" title="$resize"></div> 141 <div class="ui-resizable-handle ui-resizable-n" id="ngrip" title="$resize"></div> 142 <div class="ui-resizable-handle ui-resizable-e" id="egrip" title="$resize"></div> 143 <div class="ui-resizable-handle ui-resizable-w" id="wgrip" title="$resize"></div> 144 <div class = "close">$action 145 <a href="javascript:jQuery('#overlay').toggle();void(0);" rel="nofollow" title="$close">$close</a> 146 </div><div class="ovl-insert">$insert</div></div> 147 148TEXT; 149 echo $text; 150 151 } 152 153 /** 154 * The three types of action links all use the same html 155 * They are treated differently according to which event is calling this callback 156 * $param holds the link type for the event to be processed; it has to match the menu type 157 * configured for the plugin (page, site, user) 158 */ 159 function action_link(&$event, $param) 160 { 161 global $ID; 162 if (auth_quickaclcheck($ID) < AUTH_READ) return; //no access to page, suppress index link 163 $type = $this->getConf('menutype'); 164 if($type !=$param[0]) return; 165 $name = $this->getLang('toggle_name'); 166 $edclass = 'ovl' . $type .'tool'; 167 $title = $name; 168 169 $link = '<a href="javascript:jQuery(\'#overlay\').toggle();void(0);" class="' . $edclass . '" rel="nofollow" title="' .$title. '"><span>'. $name .'</span></a>'; 170 if($param[0] == 'page') { 171 $link = '<li class = "dwedit">' . $link .'</li>'; 172 } 173 else { 174 $link = '<span class = "ovltitle">' . $link .'</span>'; 175 } 176 177 $event->data['items'] = array_slice($event->data['items'], 0, 1, true) + 178 array('overlay' => $link) + array_slice($event->data['items'], 1, NULL, true); 179 } 180 public function addsvgbutton(Doku_Event $event) { 181 182 if($event->data['view'] == 'any') { 183 $this->overlay_tools($event, array('any')); 184 return; 185 } 186 $type = $this->getConf('menutype'); 187 if($event->data['view'] != $type ) return; 188 $btn = $this->getLang('toggle_name'); 189 190 if(!$btn) $btn = 'Overlay'; 191 array_splice($event->data['items'], -1, 0, [new \dokuwiki\plugin\overlay\MenuItem($btn)]); 192} 193 194 function overlay_tools(&$event, $param) { 195 $name = $this->getLang('toggle_name'); 196 $type = $this->getConf('toggletype'); 197 if($type == 'link') { 198 if($param[0] == 'any') { 199 echo '<a href="javascript:jQuery(\'#overlay\').toggle();void(0);" class="overlaytools" rel="nofollow" title="' .$name. '">'. $name.'</a>'; 200 return; 201 } 202 $event->data['items']['overlay'] = '<a href="javascript:jQuery(\'#overlay\').toggle();void(0);" class="overlaytools" rel="nofollow" title="' .$name. '">'. $name.'</a>'; 203 } 204 elseif($type == 'button') { 205 if($param[0] == 'any') { 206 echo '<button class="overlaytools" onclick="jQuery(\'#overlay\').toggle();void(0);">Index</button>'; 207 return; 208 } 209 $event->data['items']['overlay'] = '<button class="overlaytools" onclick="jQuery(\'#overlay\').toggle();void(0);">Index</button>'; 210 } 211 } 212} 213 214