1<?php 2/** 3 * DokuWiki Plugin caption (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Till Biskup <till@till-biskup.de> 7 */ 8 9class syntax_plugin_caption_reference extends DokuWiki_Syntax_Plugin { 10 11 /** 12 * Array containing the types of environment supported by the plugin 13 */ 14 15 /** 16 * return some info 17 */ 18 function getInfo(){ 19 return confToHash(dirname(__FILE__).'/../plugin.info.txt'); 20 } 21 22 public function getType() { 23 return 'substition'; 24 } 25 26 public function getAllowedTypes() { 27 return array('formatting', 'substition', 'disabled', 'container', 'protected'); 28 } 29 30 public function getPType() { 31 return 'normal'; 32 } 33 34 public function getSort() { 35 return 319; 36 } 37 38 39 public function connectTo($mode) { 40 $this->Lexer->addSpecialPattern('{{ref>.+?}}',$mode,'plugin_caption_reference'); 41 } 42 43 public function handle($match, $state, $pos, Doku_Handler $handler){ 44 if (!(strpos($match,'{{ref>')===false)) { 45 return array($state, substr($match,6,-2)); 46 } 47 return array(); 48 } 49 50 public function render($mode, Doku_Renderer $renderer, $data) { 51 if ($mode == 'xhtml') { 52 53 list($state,$match) = $data; 54 55 switch ($state) { 56 case DOKU_LEXER_SPECIAL : 57 global $caption_labels; 58 $renderer->doc .= '<a href="#'.$match.'">'; 59 if (isset($caption_labels[$match]) && $caption_labels[$match]) { 60 $renderer->doc .= $caption_labels[$match]; 61 } else { 62 $renderer->doc .= '##REF:'.$match.'##'; 63 } 64 $renderer->doc .= '</a>'; 65 break; 66 } 67 return true; 68 } 69 70 if ($mode == 'latex') { 71 72 list($state,$match) = $data; 73 74 switch ($state) { 75 case DOKU_LEXER_SPECIAL : 76 $renderer->doc .= '\ref{'.$match.'}'; 77 break; 78 } 79 return true; 80 } 81 82 if ($mode == 'odt') { 83 84 list($state,$match) = $data; 85 86 switch ($state) { 87 case DOKU_LEXER_SPECIAL : 88 $renderer->doc .= '<text:sequence-ref text:reference-format="value" text:ref-name="'.$match.'">'; 89 global $caption_labels; 90 if (isset($caption_labels[$match]) && $caption_labels[$match]) { 91 $renderer->doc .= $caption_labels[$match]; 92 } else { 93 $renderer->doc .= '##REF:'.$match.'##'; 94 } 95 $renderer->doc .= '</text:sequence-ref>'; 96 break; 97 } 98 return true; 99 } 100 101 // unsupported $mode 102 return false; 103 } 104} 105 106// vim:ts=4:sw=4:et: 107