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_milestone extends \dokuwiki\Extension\SyntaxPlugin 13{ 14 /** @inheritDoc */ 15 public function getType() 16 { 17 return 'substition'; 18 } 19 20 /** @inheritDoc */ 21 public function getPType() 22 { 23 return 'stack'; 24 } 25 26 /** @inheritDoc */ 27 public function getSort() 28 { 29 return 320; 30 } 31 32 /** 33 * @return array Things that may be inside the syntax 34 */ 35 function getAllowedTypes() { 36 return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); 37 } 38 39 /** 40 * Set the EntryPattern 41 * @param type $mode 42 */ 43 public function connectTo($mode) 44 { 45 $this->Lexer->addEntryPattern('<milestone\b.*?>',$mode,'plugin_dwtimeline_milestone'); 46 } 47 48 /** 49 * Set the ExitPattern 50 */ 51 public function postConnect() 52 { 53 $this->Lexer->addExitPattern('</milestone>', 'plugin_dwtimeline_milestone'); 54 } 55 56 /** 57 * Handle the match 58 * @param type $match 59 * @param type $state 60 * @param type $pos 61 * @param Doku_Handler $handler 62 * @return type 63 */ 64 public function handle($match, $state, $pos, Doku_Handler $handler) 65 { 66 $data = []; 67 switch ($state) { 68 case DOKU_LEXER_ENTER : 69 $match = trim(substr($match, 10,-1));// returns match between <milestone(10) and >(-1) 70 $data = helper_plugin_dwtimeline::getTitleMatches($match, 'title'); 71 global $align; 72 $data['align'] = $align; 73 return array($state,$data); 74 case DOKU_LEXER_UNMATCHED : 75 return array($state,$match); 76 case DOKU_LEXER_EXIT : 77 return array($state,''); 78 } 79 return array(); 80 } 81 82 /** 83 * Render Function 84 * @param type $mode 85 * @param Doku_Renderer $renderer 86 * @param type $data 87 * @return boolean 88 */ 89 public function render($mode, Doku_Renderer $renderer, $data) 90 { 91 if ($mode == 'xhtml') { 92 93 global $direction; 94 if (!$direction) {$direction=$this->getConf('direction');} 95 list($state,$indata) = $data; 96 switch ($state) { 97 case DOKU_LEXER_ENTER : 98 $renderer->doc .= '<div class="container-'.$indata['align'].' '.$direction.'"'.$indata['data'].$indata['backcolor'].'>'. DOKU_LF; 99 $renderer->doc .= '<div class="content">'. DOKU_LF; 100 if (isset($indata['title'])) { 101 if (isset($indata['link'])) { 102 $renderer->doc .= '<div class="mstitle">'.$this->render_text('[['.$indata['link'].'|'.$indata['title'].']]').'</div>'. DOKU_LF; 103 } else { 104 $renderer->doc .= '<div class="mstitle">'.$indata['title'].'</div>'. DOKU_LF; 105 } 106 } 107 if (isset($indata['description'])) {$renderer->doc .= '<div class="msdesc">'.$indata['description'].'</div>'. DOKU_LF;} 108 break; 109 110 case DOKU_LEXER_UNMATCHED : 111 $renderer->doc .= $renderer->cdata($indata); 112 break; 113 case DOKU_LEXER_EXIT : 114 $renderer->doc .= '</div>'. DOKU_LF; 115 $renderer->doc .= '</div>'. DOKU_LF; 116 $direction = helper_plugin_dwtimeline::getDirection($direction); 117 break; 118 } 119 return true; 120 } 121 return false; 122 } 123 124} 125 126