1<?php 2/** 3 * enable menuPop Up things 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Gerry Weißbach <gerry.w@gammaproduction.de> 7 */ 8 9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once(DOKU_PLUGIN.'syntax.php'); 12 13class syntax_plugin_menuPopUp extends DokuWiki_Syntax_Plugin { 14 /** 15 * return some info 16 */ 17 function getInfo(){ 18 return array( 19 'author' => 'Gerry Weissbach', 20 'email' => 'gerry.w@gammaproduction.de', 21 'date' => '2006-01-28', 22 'name' => 'Menu Pop Up', 23 'desc' => 'Pops up an DIV - Block with more Navigational Information (can be used for more) 24 Syntax: {{popup>[[link]]?pageName(?width/height)}} 25 All Options ar optional. 26 ', 27 'url' => 'http://wiki.gammaproduction.de/dokuwiki/plugins/menupopup', 28 ); 29 } 30 31 /** 32 * What kind of syntax are we? 33 */ 34 function getType(){ 35 return 'substition'; 36 } 37 38 /** 39 * What about paragraphs? 40 */ 41 function getPType(){ 42 return 'block'; 43 } 44 45 /** 46 * Where to sort in? 47 */ 48 function getSort(){ 49 return 301; 50 } 51 52 53 /** 54 * Connect pattern to lexer 55 */ 56 function connectTo($mode) { 57 $this->Lexer->addSpecialPattern('\{\{popup>[^}]*\}\}',$mode, 'plugin_menuPopUp'); 58 } 59 60 61 /** 62 * Handle the match 63 */ 64 function handle($match, $state, $pos, &$handler){ 65 66 $match = substr($match, 8, -2); //strip markup from start and end 67 68 $data = array(); 69 70 //handle params 71 list($data['link'], $data['page'], $params) = explode('?', $match, 3); 72 73 //max thumb dimensions 74 if(preg_match('/\b(\d+)(%|px|pt|em)\/(\d+)(%|px|pt|em)\b/i',$params,$match)) { 75 $data['width'] = $match[1].$match[2]; 76 $data['height'] = $match[3].$match[4]; 77 } 78 79 if(preg_match('/\bvertical\b/i',$params,$match)) { 80 $data['vertical'] = 1; 81 } 82 else 83 $data['vertical'] = 0; 84 85/* if(preg_match('/\b(onmouseover|onclick)\b/i',$params,$match)) { 86 $data['event'] = $match[1]; 87 }*/ 88 89 if (empty($data['event'])) $data['event'] = 'onmouseover'; 90 91 if (empty($data['link']) || empty($data['page'])) return false; 92 93 return $data; 94 } 95 96 /** 97 * Create output 98 */ 99 function render($mode, &$renderer, $data) { 100 101 $renderer->info['cache'] = FALSE; 102 if($mode == 'xhtml'){ 103 104 $popUp = new menuPopUp($data); 105 $renderer->doc .= $popUp->html(); 106 107 return true; 108 } 109 return false; 110 } 111 112} 113 114/** 115 * @author Gerry Weißbach <gerry.w@gammaporduction.de> 116 */ 117 118if (!class_exists('menuPopUp')) { 119 class menuPopUp { 120 121 var $link; 122 var $page; 123 var $width; 124 var $width_lower; 125 var $height; 126 var $event; 127 var $vertical; 128 var $linkAlign; 129 130 function menuPopUp($data) 131 { 132 133 $this->link = $data['link']; 134 $this->page = $data['page']; 135 $this->width = $data['width']; 136 $this->height = $data['height']; 137 $this->event = $data['event']; 138 $this->vertical = $data['vertical']; 139 140 $substract = array ( 141 '%' => 10, 142 'px' => 50, 143 'pt' => 25, 144 'em' => 1 145 ); 146 147 if(preg_match('/\b(\d+)(%|px|pt|em)\b/i',$this->width,$match)) { 148 $this->width_lower = ($match[1]-$substract[$match[2]]).$match[2]; 149 } 150 else 151 $this->width_lower = $this->width; 152 153 154 if ( preg_match('/^[\s]{2}/', $this->link) ) { 155 $this->link = preg_replace('/^\s{2}/', '', $this->link); 156 $this->linkAlign .= ' left'; 157 } 158 159 if ( preg_match('/[\s]{2}$/', $this->link) ) { 160 $this->link = preg_replace('/\s{2}$/', '', $this->link); 161 $this->linkAlign .= ' right'; 162 } 163 } 164 165 function html() 166 { 167 168 $includePage = new pageInclude($this->page); 169 170 $output = '<div class="menuContainer'.$this->linkAlign.'" onmouseover="this.className=\'menuContainerOver'.$this->linkAlign.'\'" onmouseout="this.className=\'menuContainer'.$this->linkAlign.'\';">'; // id="'.$this->link.'">'; 171 172 $output .= '<div class="menuLink'.($this->vertical?' vertical':'').'">'.p_render('xhtml', p_get_instructions($this->link), $info); 173 174 $output .= '<div class="menuContent'.($this->vertical?' vertical':'').'" style="width:'.(empty($this->width)?'150px':$this->width).'; '.(empty($this->height)?'':'max-height:'.$this->height.';').( preg_match('/right/', $this->linkAlign)? ' margin-left:-'.(empty($this->width_lower)?'125px':$this->width_lower).';' : '' ) . '">'; 175 $output .= $includePage->html(); 176 $output .= '</div>'; 177 178 $output .= '</div></div>'; 179 return $output; 180 } 181 } 182} 183 184/* Include the inner Page */ 185if (!class_exists('pageInclude')) { 186 class pageInclude { 187 188 var $page; 189 190 function pageInclude($page) 191 { 192 global $ID; 193 global $filechain; 194 195 resolve_pageid(getNS($ID),$page,$exists); // resolve shortcuts 196 197 // check for existence and permission 198// if ((auth_quickaclcheck($page) < 1)) echo "noauth"; 199 if ((auth_quickaclcheck($page) < 1)) return false; 200 201 // check for and establish start of $filechain 202 if (!isset($filechain)) $filechain[] = $ID; 203 204 // don't allow the same file to be included more than once 205// if (in_array($page, $filechain)) "filechain"; 206 if (in_array($page, $filechain)) return false; 207 208 // add included page to the filechain 209 $filechain[] = $page; 210 211 $this->page = $page; 212 } 213 214 function html() 215 { 216 global $conf; 217 218 $file = wikiFN($this->page); 219 return p_render('xhtml', p_cached_instructions($file), $info).$this->incl_editButton($this->page, $file, auth_quickaclcheck($this->page)); 220 } 221 222 function incl_editButton($id, $file, $perm){ 223 $ret = ''; 224 225 if (@file_exists($file)){ 226 if (($perm >= AUTH_EDIT) && (is_writable($file))) $ret = '<div class="secedit">'.html_btn('edit', $id, '', array('do' => 'edit'), 'post').'</div>'; 227 } elseif ($perm >= AUTH_CREATE){ 228 $ret = '<div class="secedit">'.html_btn('create', $id, '', array('do' => 'edit'), 'post').'</div>'; 229 } 230 return $ret; 231 } 232 } 233} 234 235//Setup VIM: ex: et ts=4 enc=utf-8 : 236?> 237