1<?php 2/** 3 * DokuWiki Plugin dwtimeline (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author saggi <saggi@gmx.de> 7 */ 8class syntax_plugin_dwtimeline_milestone extends \dokuwiki\Extension\SyntaxPlugin 9{ 10 /** @inheritDoc */ 11 public function getType() 12 { 13 return 'substition'; 14 } 15 16 /** @inheritDoc */ 17 public function getPType() 18 { 19 return 'stack'; 20 } 21 22 /** @inheritDoc */ 23 public function getSort() 24 { 25 return 180; 26 } 27 28 /** 29 * @return array Things that may be inside the syntax 30 */ 31 function getAllowedTypes() { 32 return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); 33 } 34 35 /** 36 * Set the EntryPattern 37 * @param type $mode 38 */ 39 public function connectTo($mode) 40 { 41 $this->Lexer->addEntryPattern('<milestone\b.*?>',$mode,'plugin_dwtimeline_milestone');/* (?=.*?</milestone>) */ 42 } 43 44 /** 45 * Set the ExitPattern 46 */ 47 public function postConnect() 48 { 49 $this->Lexer->addExitPattern('</milestone>', 'plugin_dwtimeline_milestone'); 50 } 51 52 /** 53 * Handle the match 54 * @param type $match 55 * @param type $state 56 * @param type $pos 57 * @param Doku_Handler $handler 58 * @return type 59 */ 60 public function handle($match, $state, $pos, Doku_Handler $handler) 61 { 62 $data = []; 63 switch ($state) { 64 case DOKU_LEXER_ENTER : 65 $match = trim(substr($match, 10,-1));// returns match between <milestone(10) and >(-1) 66 $data = helper_plugin_dwtimeline::getTitleMatches($match, 'title'); 67 return array($state,$data); 68 69 case DOKU_LEXER_UNMATCHED : 70 return array($state,$match); 71 case DOKU_LEXER_EXIT : 72 return array($state,''); 73 } 74 return array(); 75 } 76 77 /** 78 * Render Function 79 * @param type $mode 80 * @param Doku_Renderer $renderer 81 * @param type $data 82 * @return boolean 83 */ 84 public function render($mode, Doku_Renderer $renderer, $data) 85 { 86 if ($mode == 'xhtml') { 87 88 global $direction; 89 if (!$direction) {$direction=$this->getConf('direction');} 90 list($state,$indata) = $data; 91 switch ($state) { 92 case DOKU_LEXER_ENTER : 93 $renderer->doc .= '<div class="container '.$direction.'">'. DOKU_LF; 94 $renderer->doc .= '<div class="content">'. DOKU_LF; 95 if ($indata['title']) { 96 if ($indata['link']) { 97 $renderer->doc .= '<h2>'.$this->render_text('[['.$indata['link'].'|'.$indata['title'].']]').'</h2>'. DOKU_LF; 98 } else { 99 $renderer->doc .= '<h2>'.$indata['title'].'</h2>'. DOKU_LF; 100 } 101 } 102 if ($indata['description']) {$renderer->doc .= '<h3>'.$indata['description'].'</h3>'. DOKU_LF;} 103 break; 104 105 case DOKU_LEXER_UNMATCHED : 106 $renderer->doc .= $renderer->_xmlEntities($indata); 107 break; 108 case DOKU_LEXER_EXIT : 109 $renderer->doc .= '</div>'. DOKU_LF; 110 $renderer->doc .= '</div>'. DOKU_LF; 111 $direction = helper_plugin_dwtimeline::getDirection($direction); 112 break; 113 } 114 return true; 115 } 116 return false; 117 } 118 119} 120 121