1<?php 2 3/** 4 * @license See LICENSE file 5 * @author Jaap de Haan <jaap.dehaan@color-of-code.de> 6 */ 7 8// must be run within DokuWiki 9if (!defined('DOKU_INC')) { 10 die(); 11} 12 13// See help: https://www.dokuwiki.org/devel:syntax_plugins 14 15class syntax_plugin_bpmnio_bpmnio extends DokuWiki_Syntax_Plugin 16{ 17 18 public function getPType() 19 { 20 return 'block'; 21 } 22 23 public function getType() 24 { 25 return 'protected'; 26 } 27 28 public function getSort() 29 { 30 return 0; 31 } 32 33 public function connectTo($mode) 34 { 35 $this->Lexer->addEntryPattern('<bpmnio.*?>(?=.*?</bpmnio>)', $mode, 'plugin_bpmnio_bpmnio'); 36 } 37 38 public function postConnect() 39 { 40 $this->Lexer->addExitPattern('</bpmnio>', 'plugin_bpmnio_bpmnio'); 41 } 42 43 public function handle($match, $state, $pos, Doku_Handler $handler) 44 { 45 if ($state == DOKU_LEXER_UNMATCHED) { 46 $match = base64_encode($match); 47 } 48 return array($match, $state); 49 } 50 51 public function render($mode, Doku_Renderer $renderer, $data) 52 { 53 list($match, $state) = $data; 54 55 if (is_a($renderer, 'renderer_plugin_dw2pdf')) { 56 if ($state == DOKU_LEXER_EXIT) { 57 $renderer->doc .= <<<HTML 58 <div class="plugin-bpmnio"> 59 <a href="https://github.com/Color-Of-Code/dokuwiki-plugin-bpmnio/issues/4">DW2PDF support missing: Help wanted</a> 60 </div> 61 HTML; 62 } 63 return true; 64 } 65 66 if ($mode == 'xhtml' || $mode == 'odt') { 67 switch ($state) { 68 case DOKU_LEXER_ENTER: 69 preg_match('/<bpmnio type="(\w+)">/', $match, $type); 70 $type = $type[1] ?? 'bpmn'; 71 $bpmnid = uniqid('__' . $type . '_js_'); 72 $renderer->doc .= <<<HTML 73 <div class="plugin-bpmnio" id="{$bpmnid}"> 74 <textarea class="bpmn_js_data"> 75 HTML; 76 break; 77 78 case DOKU_LEXER_UNMATCHED: 79 $renderer->doc .= trim($match); 80 break; 81 case DOKU_LEXER_EXIT: 82 $renderer->doc .= <<<HTML 83 </textarea> 84 <div class="bpmn_js_container"></div> 85 </div> 86 HTML; 87 break; 88 } 89 return true; 90 } 91 return false; 92 } 93} 94