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 */ 8 9use dokuwiki\plugin\dwtimeline\support\support; 10 11class syntax_plugin_dwtimeline_milestone extends \dokuwiki\Extension\SyntaxPlugin 12{ 13 /** @inheritDoc */ 14 public function getType() 15 { 16 return 'plugin_dwtimeline_milestone'; 17 } 18 19 /** @inheritDoc */ 20 public function getPType() 21 { 22 return 'stack'; 23 } 24 25 /** @inheritDoc */ 26 public function getSort() 27 { 28 return 400; 29 } 30 31 function accepts($mode) { 32 if ($mode == "plugin_dwtimeline_timeline") return true; 33 return parent::accepts($mode); 34 } 35 36 /** 37 * @return array Things that may be inside the syntax 38 */ 39 function getAllowedTypes() { 40 return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); 41 } 42 43 /** 44 * Set the EntryPattern 45 * @param string $mode 46 */ 47 public function connectTo($mode) 48 { 49 $this->Lexer->addEntryPattern('<milestone\b.*?>(?=.*?</milestone>)',$mode,'plugin_dwtimeline_milestone'); 50 } 51 52 /** 53 * Set the ExitPattern 54 */ 55 public function postConnect() 56 { 57 $this->Lexer->addExitPattern('</milestone>', 'plugin_dwtimeline_milestone'); 58 } 59 60 /** 61 * Handle the match 62 * @param string $match The match of the syntax 63 * @param int $state The state of the handler 64 * @param int $pos The position in the document 65 * @param Doku_Handler $handler The handler 66 * @return array Data for the renderer 67 */ 68 public function handle($match, $state, $pos, Doku_Handler $handler) 69 { 70 $data = []; 71 switch ($state) { 72 case DOKU_LEXER_ENTER : 73 $match = trim(substr($match, 10,-1));// returns match between <milestone(10) and >(-1) 74 $data = support::getTitleMatches($match, 'title'); 75 global $align; 76 $data['align'] = $align; 77 return array($state,$data); 78 case DOKU_LEXER_UNMATCHED : 79 return array($state,$match); 80 case DOKU_LEXER_EXIT : 81 return array($state,''); 82 } 83 return array(); 84 } 85 86 /** 87 * Create output 88 * 89 * @param string $mode string output format being rendered 90 * @param Doku_Renderer $renderer the current renderer object 91 * @param array $data data created by handler() 92 * @return boolean rendered correctly? 93 */ 94 public function render($mode, Doku_Renderer $renderer, $data) 95 { 96 if ($mode == 'xhtml') { 97 global $direction; 98 if (!$direction) {$direction='tl-'.$this->getConf('direction');} 99 list($state,$indata) = $data; 100 switch ($state) { 101 case DOKU_LEXER_ENTER : 102 $renderer->doc .= '<div class="container-'.$indata['align'].' '.$direction.'"'.$indata['data'].$indata['backcolor'].'>'. DOKU_LF; 103 $renderer->doc .= '<div class="tlcontent">'. DOKU_LF; 104 if (isset($indata['title'])) { 105 if (isset($indata['link'])) { 106 $renderer->doc .= '<div class="mstitle">'.$this->render_text('[['.$indata['link'].'|'.$indata['title'].']]').'</div>'. DOKU_LF; 107 } else { 108 $renderer->doc .= '<div class="mstitle">'.$indata['title'].'</div>'. DOKU_LF; 109 } 110 } 111 if (isset($indata['description'])) {$renderer->doc .= '<div class="msdesc">'.$indata['description'].'</div>'. DOKU_LF;} 112 break; 113 case DOKU_LEXER_UNMATCHED : 114 $renderer->doc .= $renderer->cdata($indata); 115 break; 116 case DOKU_LEXER_EXIT : 117 $renderer->doc .= '</div>'. DOKU_LF; 118 $renderer->doc .= '</div>'. DOKU_LF; 119 $direction = support::getDirection($direction); 120 break; 121 } 122 return true; 123 } 124 return false; 125 } 126 127} 128 129