1<?php 2 3/** 4 * DokuWiki Plugin dwtimeline (Syntax Component) 5 * 6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 7 * @author saggi <saggi@gmx.de> 8 */ 9 10class syntax_plugin_dwtimeline_milestone extends syntax_plugin_dwtimeline_dwtimeline 11{ 12 /** @inheritDoc */ 13 public function getType() 14 { 15 return 'plugin_dwtimeline_milestone'; 16 } 17 18 public function accepts($mode) 19 { 20 if ($mode == 'plugin_dwtimeline_timeline') { 21 return true; 22 } 23 return parent::accepts($mode); 24 } 25 26 /** 27 * @return array Things that may be inside the syntax 28 */ 29 public function getAllowedTypes() 30 { 31 return ['container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs']; 32 } 33 34 /** 35 * Set the EntryPattern 36 * @param string $mode 37 */ 38 public function connectTo($mode) 39 { 40 $pattern = '<milestone\b(?:[^>"\']+|"(?:[^"\\\\]|\\\\.)*"|\'(?:[^\'\\\\]|\\\\.)*\')*>(?=.*?\</milestone>)'; 41 $this->Lexer->addEntryPattern($pattern, $mode, 'plugin_dwtimeline_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 string $match The match of the syntax 55 * @param int $state The state of the handler 56 * @param int $pos The position in the document 57 * @param Doku_Handler $handler The handler 58 * @return array Data for the renderer 59 */ 60 public function handle($match, $state, $pos, Doku_Handler $handler) 61 { 62 switch ($state) { 63 case DOKU_LEXER_ENTER: 64 $match = trim(substr($match, 10, -1));// returns match between <milestone(10) and >(-1) 65 $data = $this->getTitleMatches($match); 66 $data['align'] = parent::$align; 67 return [$state, $data]; 68 case DOKU_LEXER_UNMATCHED: 69 return [$state, $match]; 70 case DOKU_LEXER_EXIT: 71 return [$state, '']; 72 } 73 return []; 74 } 75 76 /** 77 * Create output 78 * 79 * @param string $mode string output format being rendered 80 * @param Doku_Renderer $renderer the current renderer object 81 * @param array $data data created by handler() 82 * @return bool rendered correctly? 83 */ 84 public function render($mode, Doku_Renderer $renderer, $data) 85 { 86 if ($mode == 'xhtml') { 87 if (!parent::$direction) { 88 parent::$direction = $this->getDirection(); 89 } 90 [$state, $indata] = $data; 91 switch ($state) { 92 case DOKU_LEXER_ENTER: 93 $renderer->doc .= '<div class="container-' . $indata['align'] . ' '; 94 $renderer->doc .= parent::$direction . '"' . $indata['data'] . $indata['style'] . '>' . DOKU_LF; 95 $renderer->doc .= '<div class="tlcontent">' . DOKU_LF; 96 if (isset($indata['title'])) { 97 if (!empty($indata['link'])) { 98 // get back raw title-value 99 $label = htmlspecialchars_decode($indata['title'], ENT_QUOTES); 100 101 // create link with label 102 $wikilink = '[[' . $indata['link'] . '|' . $label . ']]'; 103 104 // render link 105 $info = []; 106 $renderer->doc .= '<div class="mstitle">' 107 . p_render('xhtml', p_get_instructions($wikilink), $info) 108 . '</div>' . DOKU_LF; 109 } else { 110 $renderer->doc .= '<div class="mstitle">' . $indata['title'] . '</div>' . DOKU_LF; 111 } 112 } 113 if (isset($indata['description'])) { 114 $renderer->doc .= '<div class="msdesc">' . $indata['description'] . '</div>' . DOKU_LF; 115 } 116 break; 117 case DOKU_LEXER_UNMATCHED: 118 $renderer->cdata($indata); 119 break; 120 case DOKU_LEXER_EXIT: 121 $renderer->doc .= '</div>' . DOKU_LF; 122 $renderer->doc .= '</div>' . DOKU_LF; 123 parent::$direction = $this->changeDirection(parent::$direction); 124 break; 125 } 126 return true; 127 } 128 return false; 129 } 130} 131