From 7b4ae4071345f00786ef970e0464f1bd8aef118d Mon Sep 17 00:00:00 2001 From: Jaap de Haan Date: Fri, 21 Mar 2025 18:40:44 +0100 Subject: [PATCH 1/4] feat: Make use of media file via src --- syntax/bpmnio.php | 68 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/syntax/bpmnio.php b/syntax/bpmnio.php index 8342dfb..9695663 100644 --- a/syntax/bpmnio.php +++ b/syntax/bpmnio.php @@ -18,7 +18,8 @@ // class syntax_plugin_bpmnio_bpmnio extends SyntaxPlugin { - public string $type = ''; // 'bpmn' or 'dmn' + protected string $type = ''; // 'bpmn' or 'dmn' + protected string $src = ''; // media file public function getPType() { @@ -49,27 +50,61 @@ public function handle($match, $state, $pos, Doku_Handler $handler) { switch ($state) { case DOKU_LEXER_ENTER: - $matched = ''; - preg_match('//', $match, $matched); - $this->type = $matched[1] ?? 'bpmn'; - return [$state, $this->type, '', $pos, '']; + $matched = []; + preg_match('/]+)>/', $match, $matched); + + $attrs = []; + if (!empty($matched[1])) { + $attrs = $this->buildAttributes($matched[1]); + } + + $this->type = $attrs['type'] ?? 'bpmn'; + $this->src = $attrs['src'] ?? ''; + + return [$state, $this->type, '', $pos, '', false]; case DOKU_LEXER_UNMATCHED: $posStart = $pos; $posEnd = $pos + strlen($match); - $match = base64_encode($match); - return [$state, $this->type, $match, $posStart, $posEnd]; + + $inline = empty($this->src); + if (!$inline) { + $match = $this->getMedia($this->src); + } + return [$state, $this->type, base64_encode($match), $posStart, $posEnd, $inline]; case DOKU_LEXER_EXIT: $this->type = ''; - return [$state, '', '', '', '']; + $this->src = ''; + return [$state, '', '', '', '', '', false]; } return []; } + private function buildAttributes($string) + { + $attrs = []; + preg_match_all('/(\w+)=["\'](.*?)["\']/', $string, $matches, PREG_SET_ORDER); + foreach ($matches as $match) { + $attrs[$match[1]] = $match[2]; + } + return $attrs; + } + + private function getMedia($src) + { + $file = mediaFN($src); + + if (!file_exists($file) || !is_readable($file)) { + return "Error: Cannot load file $src"; + } + + return file_get_contents($file); + } + public function render($mode, Doku_Renderer $renderer, $data) { - [$state, $type, $match, $posStart, $posEnd] = $data; + [$state, $type, $match, $posStart, $posEnd, $inline] = $data; if (is_a($renderer, 'renderer_plugin_dw2pdf')) { if ($state == DOKU_LEXER_EXIT) { @@ -99,16 +134,21 @@ public function render($mode, Doku_Renderer $renderer, $data) {$match} HTML; - - $target = "plugin_bpmnio_{$type}"; - $sectionEditData = ['target' => $target]; - $class = $renderer->startSectionEdit($posStart, $sectionEditData); + if ($inline) { + $target = "plugin_bpmnio_{$type}"; + $sectionEditData = ['target' => $target]; + $class = $renderer->startSectionEdit($posStart, $sectionEditData); + } else { + $class = ''; + } $renderer->doc .= <<
HTML; - $renderer->finishSectionEdit($posEnd); + if ($inline) { + $renderer->finishSectionEdit($posEnd); + } break; case DOKU_LEXER_EXIT: From 6ead846180afa9dc9e2b4a19baba417de65c05fc Mon Sep 17 00:00:00 2001 From: Jaap de Haan Date: Fri, 21 Mar 2025 18:53:54 +0100 Subject: [PATCH 2/4] fix: check acl --- syntax/bpmnio.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/syntax/bpmnio.php b/syntax/bpmnio.php index 9695663..795d18f 100644 --- a/syntax/bpmnio.php +++ b/syntax/bpmnio.php @@ -93,6 +93,10 @@ private function buildAttributes($string) private function getMedia($src) { + if (!auth_quickaclcheck($src) >= AUTH_READ) { + return "Error: Access denied for file $src"; + } + $file = mediaFN($src); if (!file_exists($file) || !is_readable($file)) { From 486bff3bb17442e49258bec802c08cbfafe913e8 Mon Sep 17 00:00:00 2001 From: Jaap de Haan Date: Fri, 28 Mar 2025 12:17:40 +0100 Subject: [PATCH 3/4] fix: acl and testing --- plugin.info.txt | 2 +- script/bpmnio_render.js | 6 ++++++ syntax/bpmnio.php | 10 +++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/plugin.info.txt b/plugin.info.txt index d9ccc58..7b1081e 100644 --- a/plugin.info.txt +++ b/plugin.info.txt @@ -1,7 +1,7 @@ base bpmnio author Jaap de Haan email ColorOfCode@googlemail.com -date 2025-03-21 +date 2025-03-28 name bpmnio desc Renders BPMN or DMN xml using the bpmn.io js library url http://www.dokuwiki.org/plugin:bpmnio diff --git a/script/bpmnio_render.js b/script/bpmnio_render.js index 308adc3..4df9244 100644 --- a/script/bpmnio_render.js +++ b/script/bpmnio_render.js @@ -131,6 +131,12 @@ function safeRender(tag, type, fn) { const data = root.find(dataId)[0]; const xml = extractXml(data.textContent); + if (xml.startsWith("Error:")) { + container.textContent = xml; + container.style.color = 'red'; + return; + } + fn(xml, container); } catch (err) { console.warn(err.message); diff --git a/syntax/bpmnio.php b/syntax/bpmnio.php index 795d18f..01962df 100644 --- a/syntax/bpmnio.php +++ b/syntax/bpmnio.php @@ -1,6 +1,7 @@ = AUTH_READ) { + global $ID; + + $id = (new MediaResolver($ID))->resolveId($src); + if (auth_quickaclcheck($id) < AUTH_READ) + { return "Error: Access denied for file $src"; } - $file = mediaFN($src); - + $file = mediaFN($id); if (!file_exists($file) || !is_readable($file)) { return "Error: Cannot load file $src"; } From 8c7d01d61e3ff96ce6de354ca04e99987efb92c4 Mon Sep 17 00:00:00 2001 From: Jaap de Haan Date: Fri, 28 Mar 2025 12:20:55 +0100 Subject: [PATCH 4/4] fix: format --- syntax/bpmnio.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/syntax/bpmnio.php b/syntax/bpmnio.php index 01962df..673dfb4 100644 --- a/syntax/bpmnio.php +++ b/syntax/bpmnio.php @@ -97,8 +97,7 @@ private function getMedia($src) global $ID; $id = (new MediaResolver($ID))->resolveId($src); - if (auth_quickaclcheck($id) < AUTH_READ) - { + if (auth_quickaclcheck($id) < AUTH_READ) { return "Error: Access denied for file $src"; }