1<?php 2/** 3 * Tooltip Plugin: Create tooltips for sections of wikitext. 4 * 5 * syntax: <ttip::text>tooltip content<ttip> 6 * 7 * @file tooltip/syntax/tooltip.php 8 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 9 * @author Luis Machuca B. <luis [dot] machuca [at] gulix [dot] cl> 10 * @brief CSS-based inline toltips 11 * @version 1.8 12 * 13 * This plugin allows to insert "tooltips" in DokuWiki text, so that 14 * hovering the mouse over the mrked text will reveal the tooltip. 15 * The wikitext that composes the tooltip is parsed for basic 16 * formatting only (underlines, italics and bolds). Otherwise, 17 * the plugin is perfectly usable. 18 * This plugin uses CSS only; no JavaScript or server side help 19 * (beyond the actual tag parsing) is used to harm any animal, 20 * in any way. 21 * 22 * For a live demo check instructions in the lugin page. 23 * 24 * Greetings. 25 * - Luis Machuca Bezzaza ('ryan.chappelle' at the Wiki) 26 */ 27 28if(!defined('DW_LF')) define('DW_LF',"\n"); 29 30if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 31if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 32require_once(DOKU_PLUGIN.'syntax.php'); 33 34 35class syntax_plugin_tooltip_tooltip extends DokuWiki_Syntax_Plugin 36{ 37 function getInfo() 38 { 39 return array ( 40 'author' => 'Luis Machuca Bezzaza', 41 'email' => 'luis.machuca [at] gulix.cl', 42 'date' => @file_get_contents(DOKU_PLUGIN . 'tooltip/VERSION'), 43 'name' => 'Tooltip Plugin ('. $this->getLang('comp.tooltip'). ')', 44 'desc' => $this->getLang('descr.tooltip'). 45 ': <ttip:text> tooltip </ttip>', 46 'url' => 'http://www.dokuwiki.org/plugin:tooltip', 47 ); 48 } 49 50 function getType() { 51 return 'formatting'; 52 } 53 54 function getAllowedTypes() { 55 return array('substition','disabled','formatting'); 56 } 57 58 function getPType() { 59 return 'normal'; 60 } 61 62 function getSort() { 63 return 400; 64 } // get by exp 65 66 function connectTo($mode) { 67 $this->Lexer->addEntryPattern( 68 "<ttip:.+?>(?=.+?</ttip>)", 69 $mode, 70 'plugin_tooltip_tooltip'); 71 } 72 73 function postConnect() { 74 $this->Lexer->addExitPattern( 75 "</ttip>", 76 'plugin_tooltip_tooltip'); 77 } 78 79 function handle($match, $state, $pos, &$handler) { 80 81 $data= array(); 82 $data['state']= $state; 83 84 switch ($state) { 85 case DOKU_LEXER_ENTER: { 86 // here, we first look for an available ':' that 87 // would indicate a 'style' parameter 88 $match= substr($match, 6, -1); 89 list($e1, $e2)= explode( ":", $match); 90 // one ':' indicates only text folows, whereas two ':' 91 // indicate there is also a style definition 92 if ( empty($e2) ) { 93 $e2= $e1; 94 $e1= "default"; 95 } 96 else { // we have to look for things now 97 } 98 $data['class'] = $e1; 99 $data['text'] = $e2; 100 break; 101 } 102 case DOKU_LEXER_UNMATCHED: { 103 // here, we simply pass the match because we want it to be 104 // handled direclty by the DW parser 105 $data['ttip']= $match; 106 break; 107 } 108 } // end switch ($state) 109 return $data; 110 } // end function 111 112 function render($mode, &$renderer, $data) { 113 $state= $data['state']; 114 $style= "tooltip_". $data['class']; 115 $text= $data['text']; 116 $ttip= $data['ttip']; 117 118 if($mode == 'xhtml') { 119 /* let's do the jon thingie, that is, 120 create the HTML code that reveals the tooltip 121 */ 122 switch ($state) { 123 case DOKU_LEXER_ENTER: { 124 $renderer->doc.= '<span class="'. $style. '"><span>'. $text; 125 $renderer->doc.= '<span class="tip">'; 126 break; 127 } 128 case DOKU_LEXER_UNMATCHED: { 129 $renderer->doc.= $renderer->_xmlEntities($ttip); 130 break; 131 } 132 case DOKU_LEXER_EXIT: { 133 $renderer->doc.= '</span>'; 134 $renderer->doc.= '</span></span><!-- end tooltip -->'. DW_LF ; //end mark 135 break; 136 } 137 } // end switch 138 return true; 139 } // end if (xhtml) 140 141 else if ($mode == 'text') { 142 // simple for the plaintext renderer (for things like search) 143 switch ($state) { 144 case DOKU_LEXER_ENTER: { 145 $renderer->doc.= $mark. ' '; 146 break; 147 } 148 case DOKU_LEXER_UNMATCHED: { 149 $renderer->doc.= '[Tooltip: '. $content. '] '; 150 break; 151 } 152 case DOKU_LEXER_EXIT: { 153 break; 154 } 155 } // end switch 156 return true; 157 158 } // end if (text) 159 160 // no more renderers 161 return false; 162 } 163 164} 165