185220f43Ssaggi-dw<?php 2*545c554bSsaggi-dw 385220f43Ssaggi-dw/** 485220f43Ssaggi-dw * DokuWiki Plugin dwtimeline (Syntax Component) 585220f43Ssaggi-dw * 685220f43Ssaggi-dw * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 785220f43Ssaggi-dw * @author saggi <saggi@gmx.de> 885220f43Ssaggi-dw */ 94ff971beSsaggi-dw 10c78eb039Ssaggi-dwclass syntax_plugin_dwtimeline_timeline extends syntax_plugin_dwtimeline_dwtimeline 1185220f43Ssaggi-dw{ 1285220f43Ssaggi-dw /** 1385220f43Ssaggi-dw * @return array Things that may be inside the syntax 1485220f43Ssaggi-dw */ 15*545c554bSsaggi-dw public function getAllowedTypes() 16*545c554bSsaggi-dw { 172ddb0813SSteffen Sagert return array('plugin_dwtimeline_milestone'); 1885220f43Ssaggi-dw } 1985220f43Ssaggi-dw 2085220f43Ssaggi-dw /** 2185220f43Ssaggi-dw * Set the EntryPattern 224fa647deSsaggi-dw * @param string $mode 2385220f43Ssaggi-dw */ 2485220f43Ssaggi-dw public function connectTo($mode) 2585220f43Ssaggi-dw { 26*545c554bSsaggi-dw $this->Lexer->addEntryPattern( 27*545c554bSsaggi-dw '<dwtimeline\b.*?>(?=.*?</dwtimeline\b.*?>)', 28*545c554bSsaggi-dw $mode, 29*545c554bSsaggi-dw 'plugin_dwtimeline_timeline' 30*545c554bSsaggi-dw ); 3185220f43Ssaggi-dw } 3285220f43Ssaggi-dw 3385220f43Ssaggi-dw /** 3485220f43Ssaggi-dw * Set the ExitPattern 3585220f43Ssaggi-dw */ 3685220f43Ssaggi-dw public function postConnect() 3785220f43Ssaggi-dw { 3885220f43Ssaggi-dw $this->Lexer->addExitPattern('</dwtimeline\b.*?>', 'plugin_dwtimeline_timeline'); 3985220f43Ssaggi-dw } 4085220f43Ssaggi-dw 4185220f43Ssaggi-dw /** 4285220f43Ssaggi-dw * Handle the match 434fa647deSsaggi-dw * @param string $match The match of the syntax 444fa647deSsaggi-dw * @param int $state The state of the handler 454fa647deSsaggi-dw * @param int $pos The position in the document 464fa647deSsaggi-dw * @param Doku_Handler $handler The handler 474fa647deSsaggi-dw * @return array Data for the renderer 4885220f43Ssaggi-dw */ 4985220f43Ssaggi-dw public function handle($match, $state, $pos, Doku_Handler $handler) 5085220f43Ssaggi-dw { 5185220f43Ssaggi-dw switch ($state) { 5285220f43Ssaggi-dw case DOKU_LEXER_ENTER: 53c78eb039Ssaggi-dw parent::$align = $this->getConf('align'); 5485220f43Ssaggi-dw $match = trim(substr($match, 11, -1));// returns match between <dwtimeline(11) and >(-1) 55c78eb039Ssaggi-dw $data = $this->getTitleMatches($match); 56c78eb039Ssaggi-dw parent::$align = $data['align']; 57*545c554bSsaggi-dw return [$state, $data]; 5885220f43Ssaggi-dw case DOKU_LEXER_UNMATCHED: 59*545c554bSsaggi-dw return [$state, $match]; 6085220f43Ssaggi-dw case DOKU_LEXER_EXIT: 6185220f43Ssaggi-dw $match = trim(substr($match, 12, -1));//returns match between </dwtimeline(12) and >(-1) 62c78eb039Ssaggi-dw $data = $this->getTitleMatches($match); 63*545c554bSsaggi-dw return [$state, $data]; 6485220f43Ssaggi-dw } 65*545c554bSsaggi-dw return []; 6685220f43Ssaggi-dw } 6785220f43Ssaggi-dw 6885220f43Ssaggi-dw /** 694fa647deSsaggi-dw * Create output 704fa647deSsaggi-dw * 714fa647deSsaggi-dw * @param string $mode string output format being rendered 724fa647deSsaggi-dw * @param Doku_Renderer $renderer the current renderer object 734fa647deSsaggi-dw * @param array $data data created by handler() 74*545c554bSsaggi-dw * @return bool rendered correctly? 7585220f43Ssaggi-dw */ 7685220f43Ssaggi-dw public function render($mode, Doku_Renderer $renderer, $data) 7785220f43Ssaggi-dw { 7885220f43Ssaggi-dw if ($mode == 'xhtml') { 79*545c554bSsaggi-dw if (!parent::$direction) { 80*545c554bSsaggi-dw parent::$direction = $this->getDirection(); 81*545c554bSsaggi-dw } 8285220f43Ssaggi-dw list($state, $indata) = $data; 8385220f43Ssaggi-dw switch ($state) { 8485220f43Ssaggi-dw case DOKU_LEXER_ENTER: 852ddb0813SSteffen Sagert $renderer->doc .= '<div class="dwtimeline">' . DOKU_LF; 86*545c554bSsaggi-dw if ($indata['align'] === 'horz') { 87*545c554bSsaggi-dw $renderer->doc .= '<div class="timeline-' . $indata['align'] . '-line"></div>' . DOKU_LF; 88*545c554bSsaggi-dw } 894ff971beSsaggi-dw $renderer->doc .= '<div class="timeline-' . $indata['align'] . '">' . DOKU_LF; 904ff971beSsaggi-dw if (isset($indata['title']) or isset($indata['description'])) { 9108c5c745SSteffen Sagert $renderer->doc .= '<div class="container-' . $indata['align'] . ' tl-top">' . DOKU_LF; 9208c5c745SSteffen Sagert $renderer->doc .= '<div class="tlcontent">' . DOKU_LF; 93*545c554bSsaggi-dw if (isset($indata['title'])) { 94*545c554bSsaggi-dw $renderer->doc .= '<div class="tltitle">' . $indata['title'] . '</div>' . DOKU_LF; 95*545c554bSsaggi-dw } 96*545c554bSsaggi-dw if (isset($indata['description'])) { 97*545c554bSsaggi-dw $renderer->doc .= '<p>' . DOKU_LF . $indata['description'] . DOKU_LF . '</p>' . DOKU_LF; 98*545c554bSsaggi-dw } 9985220f43Ssaggi-dw $renderer->doc .= '</div>' . DOKU_LF; 10085220f43Ssaggi-dw $renderer->doc .= '</div>' . DOKU_LF; 10185220f43Ssaggi-dw } 10285220f43Ssaggi-dw break; 10385220f43Ssaggi-dw case DOKU_LEXER_UNMATCHED: 104*545c554bSsaggi-dw $renderer->cdata($indata); 10585220f43Ssaggi-dw break; 10685220f43Ssaggi-dw case DOKU_LEXER_EXIT: 1074ff971beSsaggi-dw if (isset($indata['title']) or isset($indata['description'])) { 10808c5c745SSteffen Sagert $renderer->doc .= '<div class="container-' . $indata['align'] . ' tl-bottom">' . DOKU_LF; 10908c5c745SSteffen Sagert $renderer->doc .= '<div class="tlcontent">' . DOKU_LF; 110*545c554bSsaggi-dw if (isset($indata['title'])) { 111*545c554bSsaggi-dw $renderer->doc .= '<div class="tltitle">' . $indata['title'] . '</div>' . DOKU_LF; 112*545c554bSsaggi-dw } 113*545c554bSsaggi-dw if (isset($indata['description'])) { 114*545c554bSsaggi-dw $renderer->doc .= '<p>' . $indata['description'] . '</p>' . DOKU_LF; 115*545c554bSsaggi-dw } 11685220f43Ssaggi-dw $renderer->doc .= '</div>' . DOKU_LF; 11785220f43Ssaggi-dw $renderer->doc .= '</div>' . DOKU_LF; 1182ddb0813SSteffen Sagert $renderer->doc .= '</div>' . DOKU_LF; 11985220f43Ssaggi-dw } 12085220f43Ssaggi-dw $renderer->doc .= '</div>' . DOKU_LF; 121c78eb039Ssaggi-dw parent::$direction = 'tl-' . $this->getConf('direction');//Reset direction 12285220f43Ssaggi-dw break; 12385220f43Ssaggi-dw } 12485220f43Ssaggi-dw return true; 12585220f43Ssaggi-dw } 12685220f43Ssaggi-dw return false; 12785220f43Ssaggi-dw } 12885220f43Ssaggi-dw} 129