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