1<?php 2/** 3 * @file hide/syntax.php 4 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 5 * @author Luis Machuca B. <luis.machuca [at] gulix.cl> 6 * @brief hides text by making it invisible (using CSS) 7 * @version 1.0 8 * 9 * syntax: {?:hidden text:?} 10 * 11 * For a live demo check instructions in the plugin page. 12 * 13 * Greetings. 14 * - Luis Machuca B. <a.k.a. 'ryan.chappelle'> 15 */ 16 17if(!defined('DW_LF')) define('DW_LF',"\n"); 18 19if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 20if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 21require_once(DOKU_PLUGIN.'syntax.php'); 22 23 24class syntax_plugin_hide extends DokuWiki_Syntax_Plugin 25{ 26 function getInfo() 27 { 28 return array( 29 'author' => 'Luis Machuca B.', 30 'email' => 'luis.machuca@gulix.cl', 31 'date' => '2009-07-07', 32 'name' => 'Hide Plugin', 33 'desc' => 'Reveals text when user selects', 34 'url' => 'http://www.dokuwiki.org/plugin:hide', 35 ); 36 } 37 38 function getType() { 39 return 'formatting'; 40 } 41 42 function getAllowedTypes() { 43 return array('substition','disabled','formatting'); 44 } 45 46 function getPType() { 47 return 'normal'; 48 } 49 50 function getSort() { 51 return 500; 52 } // get by exp 53 54 function connectTo($mode) { 55 $this->Lexer->addEntryPattern( 56 '\{\?(?=.+?\?\})', 57 $mode, 58 'plugin_hide' ); 59 } 60 61 function postConnect() { 62 $this->Lexer->addExitPattern( 63 '\?\}', 64 'plugin_hide'); 65 } 66 67 function handle($match, $state, $pos, &$handler) { 68 // there is not much to do here... 69 $data= array(); 70 $data['state']= $state; 71 switch ($state) { 72 case DOKU_LEXER_UNMATCHED: { 73 $data['content']= $match; 74 break; 75 } 76 } // end switch ($state) 77 return $data; 78 } // end function 79 80 function render($mode, &$renderer, $data) { 81 $state= $data['state']; 82 $content= $data['content']; 83 84 if($mode == 'xhtml') { 85 /* let's do the jon thingie, that is, 86 create the HTML code that reveals the hoverview 87 */ 88 switch ($state) { 89 case DOKU_LEXER_ENTER: { 90 $renderer->doc.= '<span class="selectview">'; 91 break; 92 } 93 case DOKU_LEXER_UNMATCHED: { 94 $renderer->doc.= $renderer->_xmlEntities($content); 95 break; 96 } 97 case DOKU_LEXER_EXIT: { 98 $renderer->doc.= '</span>'; 99 break; 100 } 101 } // end switch 102 return true; 103 } // end if (xhtml) 104 // no more renderers, maybe Text renderer in the future? 105 return false; 106 } 107 108} 109