1<?php 2 3/** 4 * @license See LICENSE file 5 * @author Jaap de Haan <jaap.dehaan@color-of-code.de> 6 */ 7 8// See help: https://www.dokuwiki.org/devel:syntax_plugins 9 10// The HTML structure generated by this syntax plugin is: 11// 12// <div class="plugin-bpmnio" id="__(bpmn|dmn)_js_<hash>"> 13// <div class="bpmn_js_data"> 14// ... base64 encoded xml 15// </div> 16// <div class="bpmn_js_canvas {$class}"> 17// <div class="bpmn_js_container">... rendered herein</div> 18// </div> 19// </div> 20 21 22class syntax_plugin_bpmnio_bpmnio extends DokuWiki_Syntax_Plugin 23{ 24 public function getPType() 25 { 26 return 'block'; 27 } 28 29 public function getType() 30 { 31 return 'protected'; 32 } 33 34 public function getSort() 35 { 36 return 0; 37 } 38 39 public function connectTo($mode) 40 { 41 $this->Lexer->addEntryPattern('<bpmnio.*?>(?=.*?</bpmnio>)', $mode, 'plugin_bpmnio_bpmnio'); 42 } 43 44 public function postConnect() 45 { 46 $this->Lexer->addExitPattern('</bpmnio>', 'plugin_bpmnio_bpmnio'); 47 } 48 49 public function handle($match, $state, $pos, Doku_Handler $handler) 50 { 51 $posStart = $pos; 52 $posEnd = $pos + strlen($match); 53 54 if ($state == DOKU_LEXER_UNMATCHED) { 55 $match = base64_encode($match); 56 } 57 return array($match, $state, $posStart, $posEnd); 58 } 59 60 public function render($mode, Doku_Renderer $renderer, $data) 61 { 62 list($match, $state, $posStart, $posEnd) = $data; 63 64 if (is_a($renderer, 'renderer_plugin_dw2pdf')) { 65 if ($state == DOKU_LEXER_EXIT) { 66 $renderer->doc .= <<<HTML 67 <div class="plugin-bpmnio"> 68 <a href="https://github.com/Color-Of-Code/dokuwiki-plugin-bpmnio/issues/4">DW2PDF support missing: Help wanted</a> 69 </div> 70 HTML; 71 } 72 return true; 73 } 74 75 if ($mode == 'xhtml' || $mode == 'odt') { 76 switch ($state) { 77 case DOKU_LEXER_ENTER: 78 preg_match('/<bpmnio type="(\w+)">/', $match, $type); 79 $type = $type[1] ?? 'bpmn'; 80 $bpmnid = uniqid("__{$type}_js_"); 81 $renderer->doc .= <<<HTML 82 <div class="plugin-bpmnio" id="{$bpmnid}"> 83 HTML; 84 break; 85 86 case DOKU_LEXER_UNMATCHED: 87 $renderer->doc .= <<<HTML 88 <div class="bpmn_js_data"> 89 {$match} 90 </div> 91 HTML; 92 93 $class = $this->_startSectionEdit($renderer, $posStart); 94 $renderer->doc .= <<<HTML 95 <div class="bpmn_js_canvas {$class}"> 96 <div class="bpmn_js_container"></div> 97 </div> 98 HTML; 99 $this->_finishSectionEdit($renderer, $posEnd); 100 break; 101 102 case DOKU_LEXER_EXIT: 103 $renderer->doc .= '</div>'; 104 break; 105 } 106 return true; 107 } 108 return false; 109 } 110 111 private function _startSectionEdit(Doku_Renderer $renderer, $pos) 112 { 113 $sectionEditData = ['target' => 'plugin_bpmnio']; 114 if (!defined('SEC_EDIT_PATTERN')) { 115 // backwards-compatibility for Frusterick Manners (2017-02-19) 116 $sectionEditData = 'plugin_bpmnio'; 117 } 118 return $renderer->startSectionEdit($pos, $sectionEditData); 119 } 120 121 private function _finishSectionEdit(Doku_Renderer $renderer, $pos) 122 { 123 $renderer->finishSectionEdit($pos); 124 } 125} 126