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_timeline extends \dokuwiki\Extension\SyntaxPlugin 12{ 13 14 /** @inheritDoc */ 15 public function getType() 16 { 17 return 'substition'; 18 } 19 20 /** @inheritDoc */ 21 public function getPType() 22 { 23 return 'stack'; 24 } 25 26 /** @inheritDoc */ 27 public function getSort() 28 { 29 return 400; 30 } 31 32 33 /** 34 * @return array Things that may be inside the syntax 35 */ 36 function getAllowedTypes() { 37 return array('plugin_dwtimeline_milestone'); 38 } 39 40 /** 41 * Set the EntryPattern 42 * @param string $mode 43 */ 44 public function connectTo($mode) 45 { 46 $this->Lexer->addEntryPattern('<dwtimeline\b.*?>(?=.*?</dwtimeline\b.*?>)',$mode,'plugin_dwtimeline_timeline'); 47 } 48 49 /** 50 * Set the ExitPattern 51 */ 52 public function postConnect() 53 { 54 $this->Lexer->addExitPattern('</dwtimeline\b.*?>', 'plugin_dwtimeline_timeline'); 55 } 56 57 /** 58 * Handle the match 59 * @param string $match The match of the syntax 60 * @param int $state The state of the handler 61 * @param int $pos The position in the document 62 * @param Doku_Handler $handler The handler 63 * @return array Data for the renderer 64 */ 65 public function handle($match, $state, $pos, Doku_Handler $handler) 66 { 67 $data = []; 68 switch ($state) { 69 case DOKU_LEXER_ENTER : 70 global $align; 71 $align = $this->getConf('align'); 72 $match = trim(substr($match, 11,-1));// returns match between <dwtimeline(11) and >(-1) 73 $data = support::getTitleMatches($match); 74 $align = $data['align']; 75 return array($state,$data); 76 case DOKU_LEXER_UNMATCHED : 77 return array ($state,$match); 78 case DOKU_LEXER_EXIT : 79 $match = trim(substr($match, 12,-1));//returns match between </dwtimeline(12) and >(-1) 80 $data = support::getTitleMatches($match); 81 return array($state,$data); 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="dwtimeline">'. DOKU_LF; 103 if ($indata['align'] === 'horz'){$renderer->doc .= '<div class="timeline-'.$indata['align'].'-line"></div>'. DOKU_LF;}; 104 $renderer->doc .= '<div class="timeline-'.$indata['align'].'">'. DOKU_LF; 105 if (isset($indata['title']) or isset($indata['description'])) { 106 $renderer->doc .= '<div class="container-'.$indata['align'].' tl-top">'. DOKU_LF; 107 $renderer->doc .= '<div class="tlcontent">'. DOKU_LF; 108 if (isset($indata['title'])) {$renderer->doc .= '<div class="tltitle">'.$indata['title'].'</div>'. DOKU_LF;} 109 if (isset($indata['description'])) {$renderer->doc .= '<p>'. DOKU_LF.$indata['description']. DOKU_LF.'</p>'. DOKU_LF;} 110 $renderer->doc .= '</div>'. DOKU_LF; 111 $renderer->doc .= '</div>'. DOKU_LF; 112 } 113 break; 114 case DOKU_LEXER_UNMATCHED : 115 $renderer->doc .= $renderer->cdata($indata); 116 break; 117 case DOKU_LEXER_EXIT : 118 if (isset($indata['title']) or isset($indata['description'])) { 119 $renderer->doc .= '<div class="container-'.$indata['align'].' tl-bottom">'. DOKU_LF; 120 $renderer->doc .= '<div class="tlcontent">'. DOKU_LF; 121 if (isset($indata['title'])) {$renderer->doc .= '<div class="tltitle">'.$indata['title'].'</div>'. DOKU_LF;} 122 if (isset($indata['description'])) {$renderer->doc .= '<p>'.$indata['description'].'</p>'. DOKU_LF;} 123 $renderer->doc .= '</div>'. DOKU_LF; 124 $renderer->doc .= '</div>'. DOKU_LF; 125 $renderer->doc .= '</div>'. DOKU_LF; 126 } 127 $renderer->doc .= '</div>'. DOKU_LF; 128 $direction='tl-'.$this->getConf('direction');//Reset direction 129 break; 130 } 131 return true; 132 } 133 return false; 134 } 135 136} 137 138