185220f43Ssaggi-dw<?php 285220f43Ssaggi-dw/** 385220f43Ssaggi-dw * DokuWiki Plugin dwtimeline (Syntax Component) 485220f43Ssaggi-dw * 585220f43Ssaggi-dw * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 685220f43Ssaggi-dw * @author saggi <saggi@gmx.de> 785220f43Ssaggi-dw */ 84ff971beSsaggi-dw 9*4fa647deSsaggi-dwuse dokuwiki\plugin\dwtimeline\support\support; 104ff971beSsaggi-dw 1185220f43Ssaggi-dwclass syntax_plugin_dwtimeline_milestone extends \dokuwiki\Extension\SyntaxPlugin 1285220f43Ssaggi-dw{ 1385220f43Ssaggi-dw /** @inheritDoc */ 1485220f43Ssaggi-dw public function getType() 1585220f43Ssaggi-dw { 162ddb0813SSteffen Sagert return 'plugin_dwtimeline_milestone'; 1785220f43Ssaggi-dw } 1885220f43Ssaggi-dw 1985220f43Ssaggi-dw /** @inheritDoc */ 2085220f43Ssaggi-dw public function getPType() 2185220f43Ssaggi-dw { 2285220f43Ssaggi-dw return 'stack'; 2385220f43Ssaggi-dw } 2485220f43Ssaggi-dw 2585220f43Ssaggi-dw /** @inheritDoc */ 2685220f43Ssaggi-dw public function getSort() 2785220f43Ssaggi-dw { 282ddb0813SSteffen Sagert return 400; 292ddb0813SSteffen Sagert } 302ddb0813SSteffen Sagert 312ddb0813SSteffen Sagert function accepts($mode) { 322ddb0813SSteffen Sagert if ($mode == "plugin_dwtimeline_timeline") return true; 332ddb0813SSteffen Sagert return parent::accepts($mode); 3485220f43Ssaggi-dw } 3585220f43Ssaggi-dw 3685220f43Ssaggi-dw /** 3785220f43Ssaggi-dw * @return array Things that may be inside the syntax 3885220f43Ssaggi-dw */ 3985220f43Ssaggi-dw function getAllowedTypes() { 4085220f43Ssaggi-dw return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); 4185220f43Ssaggi-dw } 4285220f43Ssaggi-dw 4385220f43Ssaggi-dw /** 4485220f43Ssaggi-dw * Set the EntryPattern 45*4fa647deSsaggi-dw * @param string $mode 4685220f43Ssaggi-dw */ 4785220f43Ssaggi-dw public function connectTo($mode) 4885220f43Ssaggi-dw { 492ddb0813SSteffen Sagert $this->Lexer->addEntryPattern('<milestone\b.*?>(?=.*?</milestone>)',$mode,'plugin_dwtimeline_milestone'); 5008c5c745SSteffen Sagert } 5185220f43Ssaggi-dw 5285220f43Ssaggi-dw /** 5385220f43Ssaggi-dw * Set the ExitPattern 5485220f43Ssaggi-dw */ 5585220f43Ssaggi-dw public function postConnect() 5685220f43Ssaggi-dw { 5785220f43Ssaggi-dw $this->Lexer->addExitPattern('</milestone>', 'plugin_dwtimeline_milestone'); 5885220f43Ssaggi-dw } 5985220f43Ssaggi-dw 6085220f43Ssaggi-dw /** 6185220f43Ssaggi-dw * Handle the match 62*4fa647deSsaggi-dw * @param string $match The match of the syntax 63*4fa647deSsaggi-dw * @param int $state The state of the handler 64*4fa647deSsaggi-dw * @param int $pos The position in the document 65*4fa647deSsaggi-dw * @param Doku_Handler $handler The handler 66*4fa647deSsaggi-dw * @return array Data for the renderer 6785220f43Ssaggi-dw */ 6885220f43Ssaggi-dw public function handle($match, $state, $pos, Doku_Handler $handler) 6985220f43Ssaggi-dw { 7085220f43Ssaggi-dw $data = []; 7185220f43Ssaggi-dw switch ($state) { 7285220f43Ssaggi-dw case DOKU_LEXER_ENTER : 7385220f43Ssaggi-dw $match = trim(substr($match, 10,-1));// returns match between <milestone(10) and >(-1) 74*4fa647deSsaggi-dw $data = support::getTitleMatches($match, 'title'); 754ff971beSsaggi-dw global $align; 764ff971beSsaggi-dw $data['align'] = $align; 7785220f43Ssaggi-dw return array($state,$data); 7885220f43Ssaggi-dw case DOKU_LEXER_UNMATCHED : 7985220f43Ssaggi-dw return array($state,$match); 8085220f43Ssaggi-dw case DOKU_LEXER_EXIT : 8185220f43Ssaggi-dw return array($state,''); 8285220f43Ssaggi-dw } 8385220f43Ssaggi-dw return array(); 8485220f43Ssaggi-dw } 8585220f43Ssaggi-dw 8685220f43Ssaggi-dw /** 87*4fa647deSsaggi-dw * Create output 88*4fa647deSsaggi-dw * 89*4fa647deSsaggi-dw * @param string $mode string output format being rendered 90*4fa647deSsaggi-dw * @param Doku_Renderer $renderer the current renderer object 91*4fa647deSsaggi-dw * @param array $data data created by handler() 92*4fa647deSsaggi-dw * @return boolean rendered correctly? 9385220f43Ssaggi-dw */ 9485220f43Ssaggi-dw public function render($mode, Doku_Renderer $renderer, $data) 9585220f43Ssaggi-dw { 9685220f43Ssaggi-dw if ($mode == 'xhtml') { 9785220f43Ssaggi-dw global $direction; 9808c5c745SSteffen Sagert if (!$direction) {$direction='tl-'.$this->getConf('direction');} 9985220f43Ssaggi-dw list($state,$indata) = $data; 10085220f43Ssaggi-dw switch ($state) { 10185220f43Ssaggi-dw case DOKU_LEXER_ENTER : 1024ff971beSsaggi-dw $renderer->doc .= '<div class="container-'.$indata['align'].' '.$direction.'"'.$indata['data'].$indata['backcolor'].'>'. DOKU_LF; 10308c5c745SSteffen Sagert $renderer->doc .= '<div class="tlcontent">'. DOKU_LF; 1044ff971beSsaggi-dw if (isset($indata['title'])) { 1054ff971beSsaggi-dw if (isset($indata['link'])) { 1064ff971beSsaggi-dw $renderer->doc .= '<div class="mstitle">'.$this->render_text('[['.$indata['link'].'|'.$indata['title'].']]').'</div>'. DOKU_LF; 10785220f43Ssaggi-dw } else { 1084ff971beSsaggi-dw $renderer->doc .= '<div class="mstitle">'.$indata['title'].'</div>'. DOKU_LF; 10985220f43Ssaggi-dw } 11085220f43Ssaggi-dw } 1114ff971beSsaggi-dw if (isset($indata['description'])) {$renderer->doc .= '<div class="msdesc">'.$indata['description'].'</div>'. DOKU_LF;} 11285220f43Ssaggi-dw break; 11385220f43Ssaggi-dw case DOKU_LEXER_UNMATCHED : 1144ff971beSsaggi-dw $renderer->doc .= $renderer->cdata($indata); 11585220f43Ssaggi-dw break; 11685220f43Ssaggi-dw case DOKU_LEXER_EXIT : 11785220f43Ssaggi-dw $renderer->doc .= '</div>'. DOKU_LF; 11885220f43Ssaggi-dw $renderer->doc .= '</div>'. DOKU_LF; 119*4fa647deSsaggi-dw $direction = support::getDirection($direction); 12085220f43Ssaggi-dw break; 12185220f43Ssaggi-dw } 12285220f43Ssaggi-dw return true; 12385220f43Ssaggi-dw } 12485220f43Ssaggi-dw return false; 12585220f43Ssaggi-dw } 12685220f43Ssaggi-dw 12785220f43Ssaggi-dw} 12885220f43Ssaggi-dw 129