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 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12class syntax_plugin_dwtimeline_timeline extends \dokuwiki\Extension\SyntaxPlugin 13{ 14 15 /** @inheritDoc */ 16 public function getType() 17 { 18 return 'substition'; 19 } 20 21 /** @inheritDoc */ 22 public function getPType() 23 { 24 return 'stack'; 25 } 26 27 /** @inheritDoc */ 28 public function getSort() 29 { 30 return 320; 31 } 32 33 /** 34 * @return array Things that may be inside the syntax 35 */ 36 function getAllowedTypes() { 37 return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); 38 } 39 40 /** 41 * Set the EntryPattern 42 * @param type $mode 43 */ 44 public function connectTo($mode) 45 { 46 $this->Lexer->addEntryPattern('<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 type $match 60 * @param type $state 61 * @param type $pos 62 * @param Doku_Handler $handler 63 * @return type 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 = helper_plugin_dwtimeline::getTitleMatches($match); 74 return array($state,$data); 75 case DOKU_LEXER_UNMATCHED : 76 return array ($state,$match); 77 case DOKU_LEXER_EXIT : 78 $match = trim(substr($match, 12,-1));//returns match between </dwtimeline(12) and >(-1) 79 $data = helper_plugin_dwtimeline::getTitleMatches($match); 80 return array($state,$data); 81 } 82 return array(); 83 } 84 85 /** 86 * Render Function 87 * @param type $mode 88 * @param Doku_Renderer $renderer 89 * @param type $data 90 * @return boolean 91 */ 92 public function render($mode, Doku_Renderer $renderer, $data) 93 { 94 if ($mode == 'xhtml') { 95 global $direction; 96 if (!$direction) {$direction=$this->getConf('direction');} 97 list($state,$indata) = $data; 98 switch ($state) { 99 case DOKU_LEXER_ENTER : 100 if ($indata['align'] === 'horz'){$renderer->doc .= '<div class="timeline-'.$indata['align'].'-line"></div>'. DOKU_LF;}; 101 $renderer->doc .= '<div class="timeline-'.$indata['align'].'">'. DOKU_LF; 102 if (isset($indata['title']) or isset($indata['description'])) { 103 $renderer->doc .= '<div class="container-'.$indata['align'].' top">'. DOKU_LF; 104 $renderer->doc .= '<div class="content">'. DOKU_LF; 105 if (isset($indata['title'])) {$renderer->doc .= '<div class="tltitle">'.$indata['title'].'</div>'. DOKU_LF;} 106 if (isset($indata['description'])) {$renderer->doc .= '<p>'.$indata['description'].'</p>'. DOKU_LF;} 107 $renderer->doc .= '</div>'. DOKU_LF; 108 $renderer->doc .= '</div>'. DOKU_LF; 109 } 110 break; 111 case DOKU_LEXER_UNMATCHED : 112 $renderer->doc .= $renderer->cdata($indata); 113 break; 114 case DOKU_LEXER_EXIT : 115 if (isset($indata['title']) or isset($indata['description'])) { 116 $renderer->doc .= '<div class="container-'.$indata['align'].' bottom">'. DOKU_LF; 117 $renderer->doc .= '<div class="content">'. DOKU_LF; 118 if (isset($indata['title'])) {$renderer->doc .= '<div class="tltitle">'.$indata['title'].'</div>'. DOKU_LF;} 119 if (isset($indata['description'])) {$renderer->doc .= '<p>'.$indata['description'].'</p>'. DOKU_LF;} 120 $renderer->doc .= '</div>'. DOKU_LF; 121 $renderer->doc .= '</div>'. DOKU_LF; 122 } 123 $renderer->doc .= '</div>'. DOKU_LF; 124 $direction=$this->getConf('direction');//Reset direction 125 break; 126 } 127 return true; 128 } 129 return false; 130 } 131 132} 133 134