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 400; 31 } 32 33 34 /** 35 * @return array Things that may be inside the syntax 36 */ 37 function getAllowedTypes() { 38 return array('plugin_dwtimeline_milestone'); 39 } 40 41 /** 42 * Set the EntryPattern 43 * @param type $mode 44 */ 45 public function connectTo($mode) 46 { 47 $this->Lexer->addEntryPattern('<dwtimeline\b.*?>(?=.*?</dwtimeline\b.*?>)',$mode,'plugin_dwtimeline_timeline'); 48 } 49 50 /** 51 * Set the ExitPattern 52 */ 53 public function postConnect() 54 { 55 $this->Lexer->addExitPattern('</dwtimeline\b.*?>', 'plugin_dwtimeline_timeline'); 56 } 57 58 /** 59 * Handle the match 60 * @param type $match 61 * @param type $state 62 * @param type $pos 63 * @param Doku_Handler $handler 64 * @return type 65 */ 66 public function handle($match, $state, $pos, Doku_Handler $handler) 67 { 68 $data = []; 69 switch ($state) { 70 case DOKU_LEXER_ENTER : 71 global $align; 72 $align = $this->getConf('align'); 73 $match = trim(substr($match, 11,-1));// returns match between <dwtimeline(11) and >(-1) 74 $data = helper_plugin_dwtimeline::getTitleMatches($match); 75 $align = $data['align']; 76 return array($state,$data); 77 case DOKU_LEXER_UNMATCHED : 78 return array ($state,$match); 79 case DOKU_LEXER_EXIT : 80 $match = trim(substr($match, 12,-1));//returns match between </dwtimeline(12) and >(-1) 81 $data = helper_plugin_dwtimeline::getTitleMatches($match); 82 return array($state,$data); 83 } 84 return array(); 85 } 86 87 /** 88 * Render Function 89 * @param type $mode 90 * @param Doku_Renderer $renderer 91 * @param type $data 92 * @return boolean 93 */ 94 public function render($mode, Doku_Renderer $renderer, $data) 95 { 96 if ($mode == 'xhtml') { 97 global $direction; 98 if (!$direction) {$direction='tl-'.$this->getConf('direction');} 99 list($state,$indata) = $data; 100 switch ($state) { 101 case DOKU_LEXER_ENTER : 102 $renderer->doc .= '<div class="dwtimeline">'. DOKU_LF; 103 if ($indata['align'] === 'horz'){$renderer->doc .= '<div class="timeline-'.$indata['align'].'-line"></div>'. DOKU_LF;}; 104 $renderer->doc .= '<div class="timeline-'.$indata['align'].'">'. DOKU_LF; 105 if (isset($indata['title']) or isset($indata['description'])) { 106 $renderer->doc .= '<div class="container-'.$indata['align'].' tl-top">'. DOKU_LF; 107 $renderer->doc .= '<div class="tlcontent">'. DOKU_LF; 108 if (isset($indata['title'])) {$renderer->doc .= '<div class="tltitle">'.$indata['title'].'</div>'. DOKU_LF;} 109 if (isset($indata['description'])) {$renderer->doc .= '<p>'. DOKU_LF.$indata['description']. DOKU_LF.'</p>'. DOKU_LF;} 110 $renderer->doc .= '</div>'. DOKU_LF; 111 $renderer->doc .= '</div>'. DOKU_LF; 112 } 113 break; 114 case DOKU_LEXER_UNMATCHED : 115 $renderer->doc .= $renderer->cdata($indata); 116 break; 117 case DOKU_LEXER_EXIT : 118 if (isset($indata['title']) or isset($indata['description'])) { 119 $renderer->doc .= '<div class="container-'.$indata['align'].' tl-bottom">'. DOKU_LF; 120 $renderer->doc .= '<div class="tlcontent">'. DOKU_LF; 121 if (isset($indata['title'])) {$renderer->doc .= '<div class="tltitle">'.$indata['title'].'</div>'. DOKU_LF;} 122 if (isset($indata['description'])) {$renderer->doc .= '<p>'.$indata['description'].'</p>'. DOKU_LF;} 123 $renderer->doc .= '</div>'. DOKU_LF; 124 $renderer->doc .= '</div>'. DOKU_LF; 125 $renderer->doc .= '</div>'. DOKU_LF; 126 } 127 $renderer->doc .= '</div>'. DOKU_LF; 128 $direction='tl-'.$this->getConf('direction');//Reset direction 129 break; 130 } 131 return true; 132 } 133 return false; 134 } 135 136} 137 138