1*85220f43Ssaggi-dw<?php 2*85220f43Ssaggi-dw/** 3*85220f43Ssaggi-dw * DokuWiki Plugin dwtimeline (Syntax Component) 4*85220f43Ssaggi-dw * 5*85220f43Ssaggi-dw * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6*85220f43Ssaggi-dw * @author saggi <saggi@gmx.de> 7*85220f43Ssaggi-dw */ 8*85220f43Ssaggi-dwclass syntax_plugin_dwtimeline_timeline extends \dokuwiki\Extension\SyntaxPlugin 9*85220f43Ssaggi-dw{ 10*85220f43Ssaggi-dw protected $box_open = false; 11*85220f43Ssaggi-dw 12*85220f43Ssaggi-dw /** @inheritDoc */ 13*85220f43Ssaggi-dw public function getType() 14*85220f43Ssaggi-dw { 15*85220f43Ssaggi-dw return 'substition'; 16*85220f43Ssaggi-dw } 17*85220f43Ssaggi-dw 18*85220f43Ssaggi-dw /** @inheritDoc */ 19*85220f43Ssaggi-dw public function getPType() 20*85220f43Ssaggi-dw { 21*85220f43Ssaggi-dw return 'stack'; 22*85220f43Ssaggi-dw } 23*85220f43Ssaggi-dw 24*85220f43Ssaggi-dw /** @inheritDoc */ 25*85220f43Ssaggi-dw public function getSort() 26*85220f43Ssaggi-dw { 27*85220f43Ssaggi-dw return 180; 28*85220f43Ssaggi-dw } 29*85220f43Ssaggi-dw 30*85220f43Ssaggi-dw /** 31*85220f43Ssaggi-dw * @return array Things that may be inside the syntax 32*85220f43Ssaggi-dw */ 33*85220f43Ssaggi-dw function getAllowedTypes() { 34*85220f43Ssaggi-dw return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); 35*85220f43Ssaggi-dw } 36*85220f43Ssaggi-dw 37*85220f43Ssaggi-dw /** 38*85220f43Ssaggi-dw * Set the EntryPattern 39*85220f43Ssaggi-dw * @param type $mode 40*85220f43Ssaggi-dw */ 41*85220f43Ssaggi-dw public function connectTo($mode) 42*85220f43Ssaggi-dw { 43*85220f43Ssaggi-dw $this->Lexer->addEntryPattern('<dwtimeline\b.*?>',$mode,'plugin_dwtimeline_timeline');/* (?=.*?</dwtimeline\b.*?>) */ 44*85220f43Ssaggi-dw } 45*85220f43Ssaggi-dw 46*85220f43Ssaggi-dw /** 47*85220f43Ssaggi-dw * Set the ExitPattern 48*85220f43Ssaggi-dw */ 49*85220f43Ssaggi-dw public function postConnect() 50*85220f43Ssaggi-dw { 51*85220f43Ssaggi-dw $this->Lexer->addExitPattern('</dwtimeline\b.*?>', 'plugin_dwtimeline_timeline'); 52*85220f43Ssaggi-dw } 53*85220f43Ssaggi-dw 54*85220f43Ssaggi-dw /** 55*85220f43Ssaggi-dw * Handle the match 56*85220f43Ssaggi-dw * @param type $match 57*85220f43Ssaggi-dw * @param type $state 58*85220f43Ssaggi-dw * @param type $pos 59*85220f43Ssaggi-dw * @param Doku_Handler $handler 60*85220f43Ssaggi-dw * @return type 61*85220f43Ssaggi-dw */ 62*85220f43Ssaggi-dw public function handle($match, $state, $pos, Doku_Handler $handler) 63*85220f43Ssaggi-dw { 64*85220f43Ssaggi-dw $data = []; 65*85220f43Ssaggi-dw switch ($state) { 66*85220f43Ssaggi-dw case DOKU_LEXER_ENTER : 67*85220f43Ssaggi-dw $match = trim(substr($match, 11,-1));// returns match between <dwtimeline(11) and >(-1) 68*85220f43Ssaggi-dw $data = helper_plugin_dwtimeline::getTitleMatches($match); 69*85220f43Ssaggi-dw return array($state,$data); 70*85220f43Ssaggi-dw 71*85220f43Ssaggi-dw case DOKU_LEXER_UNMATCHED : 72*85220f43Ssaggi-dw return array ($state,$match); 73*85220f43Ssaggi-dw case DOKU_LEXER_EXIT : 74*85220f43Ssaggi-dw $match = trim(substr($match, 12,-1));//returns match between </dwtimeline(12) and >(-1) 75*85220f43Ssaggi-dw $data = helper_plugin_dwtimeline::getTitleMatches($match); 76*85220f43Ssaggi-dw return array($state,$data); 77*85220f43Ssaggi-dw } 78*85220f43Ssaggi-dw return array(); 79*85220f43Ssaggi-dw } 80*85220f43Ssaggi-dw 81*85220f43Ssaggi-dw /** 82*85220f43Ssaggi-dw * Render Function 83*85220f43Ssaggi-dw * @param type $mode 84*85220f43Ssaggi-dw * @param Doku_Renderer $renderer 85*85220f43Ssaggi-dw * @param type $data 86*85220f43Ssaggi-dw * @return boolean 87*85220f43Ssaggi-dw */ 88*85220f43Ssaggi-dw public function render($mode, Doku_Renderer $renderer, $data) 89*85220f43Ssaggi-dw { 90*85220f43Ssaggi-dw if ($mode == 'xhtml') { 91*85220f43Ssaggi-dw global $direction; 92*85220f43Ssaggi-dw if (!$direction) {$direction=$this->getConf('direction');} 93*85220f43Ssaggi-dw list($state,$indata) = $data; 94*85220f43Ssaggi-dw switch ($state) { 95*85220f43Ssaggi-dw case DOKU_LEXER_ENTER : 96*85220f43Ssaggi-dw $renderer->doc .= '<div class="timeline">'. DOKU_LF; 97*85220f43Ssaggi-dw if ($indata['title'] or $indata['description']) { 98*85220f43Ssaggi-dw $renderer->doc .= '<div class="container top">'. DOKU_LF; 99*85220f43Ssaggi-dw $renderer->doc .= '<div class="content">'. DOKU_LF; 100*85220f43Ssaggi-dw if ($indata['title']) {$renderer->doc .= '<h2>'.$indata['title'].'</h2>'. DOKU_LF;} 101*85220f43Ssaggi-dw if ($indata['description']) {$renderer->doc .= '<p>'.$indata['description'].'</p>'. DOKU_LF;} 102*85220f43Ssaggi-dw $renderer->doc .= '</div>'. DOKU_LF; 103*85220f43Ssaggi-dw $renderer->doc .= '</div>'. DOKU_LF; 104*85220f43Ssaggi-dw } 105*85220f43Ssaggi-dw break; 106*85220f43Ssaggi-dw case DOKU_LEXER_UNMATCHED : 107*85220f43Ssaggi-dw $renderer->doc .= $renderer->_xmlEntities($indata); 108*85220f43Ssaggi-dw break; 109*85220f43Ssaggi-dw case DOKU_LEXER_EXIT : 110*85220f43Ssaggi-dw if ($indata['title'] or $indata['description']) { 111*85220f43Ssaggi-dw $renderer->doc .= '<div class="container bottom">'. DOKU_LF; 112*85220f43Ssaggi-dw $renderer->doc .= '<div class="content">'. DOKU_LF; 113*85220f43Ssaggi-dw if ($indata['title']) {$renderer->doc .= '<h2>'.$indata['title'].'</h2>'. DOKU_LF;} 114*85220f43Ssaggi-dw if ($indata['description']) {$renderer->doc .= '<p>'.$indata['description'].'</p>'. DOKU_LF;} 115*85220f43Ssaggi-dw $renderer->doc .= '</div>'. DOKU_LF; 116*85220f43Ssaggi-dw $renderer->doc .= '</div>'. DOKU_LF; 117*85220f43Ssaggi-dw } 118*85220f43Ssaggi-dw $renderer->doc .= '</div>'. DOKU_LF; 119*85220f43Ssaggi-dw $direction=$this->getConf('direction');//Reset direction 120*85220f43Ssaggi-dw break; 121*85220f43Ssaggi-dw } 122*85220f43Ssaggi-dw return true; 123*85220f43Ssaggi-dw } 124*85220f43Ssaggi-dw return false; 125*85220f43Ssaggi-dw } 126*85220f43Ssaggi-dw 127*85220f43Ssaggi-dw} 128*85220f43Ssaggi-dw 129