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 public function getPType() 18 { 19 return 'block'; 20 } 21 22 public function getType() 23 { 24 return 'protected'; 25 } 26 27 public function getSort() 28 { 29 return 0; 30 } 31 32 public function connectTo($mode) 33 { 34 $this->Lexer->addEntryPattern('<bpmnio.*?>(?=.*?</bpmnio>)', $mode, 'plugin_bpmnio_bpmnio'); 35 } 36 37 public function postConnect() 38 { 39 $this->Lexer->addExitPattern('</bpmnio>', 'plugin_bpmnio_bpmnio'); 40 } 41 42 public function handle($match, $state, $pos, Doku_Handler $handler) 43 { 44 $posStart = $pos; 45 $posEnd = $pos + strlen($match); 46 47 if ($state == DOKU_LEXER_UNMATCHED) { 48 $match = base64_encode(trim($match)); 49 } 50 return array($match, $state, $posStart, $posEnd); 51 } 52 53 public function render($mode, Doku_Renderer $renderer, $data) 54 { 55 list($match, $state, $posStart, $posEnd) = $data; 56 57 if (is_a($renderer, 'renderer_plugin_dw2pdf')) { 58 if ($state == DOKU_LEXER_EXIT) { 59 $renderer->doc .= <<<HTML 60 <div class="plugin-bpmnio"> 61 <a href="https://github.com/Color-Of-Code/dokuwiki-plugin-bpmnio/issues/4">DW2PDF support missing: Help wanted</a> 62 </div> 63 HTML; 64 } 65 return true; 66 } 67 68 if ($mode == 'xhtml' || $mode == 'odt') { 69 switch ($state) { 70 case DOKU_LEXER_ENTER: 71 preg_match('/<bpmnio type="(\w+)">/', $match, $type); 72 $type = $type[1] ?? 'bpmn'; 73 $bpmnid = uniqid('__' . $type . '_js_'); 74 $renderer->doc .= <<<HTML 75 <div class="plugin-bpmnio" id="{$bpmnid}"> 76 HTML; 77 break; 78 79 case DOKU_LEXER_UNMATCHED: 80 $renderer->doc .= <<<HTML 81 <div class="bpmn_js_data"> 82 {$match} 83 </div> 84 HTML; 85 86 $class = $this->_startSectionEdit($renderer, $posStart); 87 $renderer->doc .= <<<HTML 88 <div class="bpmn_js_canvas {$class}"> 89 <div class="bpmn_js_container {$class}"></div> 90 </div> 91 HTML; 92 $this->_finishSectionEdit($renderer, $posEnd); 93 break; 94 95 case DOKU_LEXER_EXIT: 96 $renderer->doc .= '</div>'; 97 break; 98 } 99 return true; 100 } 101 return false; 102 } 103 104 private function _startSectionEdit(Doku_Renderer $renderer, $pos) 105 { 106 $sectionEditData = ['target' => 'plugin_bpmnio']; 107 if (!defined('SEC_EDIT_PATTERN')) { 108 // backwards-compatibility for Frusterick Manners (2017-02-19) 109 $sectionEditData = 'plugin_bpmnio'; 110 } 111 return $renderer->startSectionEdit($pos, $sectionEditData); 112 } 113 114 private function _finishSectionEdit(Doku_Renderer $renderer, $pos) 115 { 116 $renderer->finishSectionEdit($pos); 117 } 118} 119