From c56430e0ac3f119b7826bd0112b4cb1ecc491099 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 24 Apr 2025 16:40:03 +0200 Subject: [PATCH 1/3] fix(export): images missing in exported Knowledge Base PDF --- inc/knowbaseitem.class.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/inc/knowbaseitem.class.php b/inc/knowbaseitem.class.php index 5447797..25464b0 100644 --- a/inc/knowbaseitem.class.php +++ b/inc/knowbaseitem.class.php @@ -77,12 +77,18 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item) 'UTF-8', ))); - $answer - = Toolbox::stripTags(Glpi\Toolbox\Sanitizer::unsanitize(html_entity_decode( - $item->getField('answer'), - ENT_QUOTES, - 'UTF-8', - ))); + $answer = Glpi\Toolbox\Sanitizer::unsanitize(Html::entity_decode_deep($item->getField('answer'))); + $answer = preg_replace('#data:image/[^;]+;base64,#', '@', $answer); + + preg_match_all('/]*src=[\'"]([^\'"]*docid=([0-9]*))[^>]*>/', $answer, $res, PREG_SET_ORDER); + + foreach ($res as $img) { + $docimg = new Document(); + $docimg->getFromDB((int) $img[2]); + + $path = ''; + $answer = str_replace($img[0], $path, $answer); + } $pdf->setColumnsSize(100); From 0122bd5a3a9bc5b40325d3db9f8ac03c4e4a27c5 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 24 Apr 2025 16:49:42 +0200 Subject: [PATCH 2/3] Update CHANGELOg.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc1e1c0..d31ee31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [UNRELEASE] +- Fix missing images in exported Knowledge Base PDFs + ## [4.0.1] - 2025-03-10 ### Added From d78db985fea76c496e0dac4149921143786d5c77 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Fri, 25 Apr 2025 13:52:55 +0200 Subject: [PATCH 3/3] resize img --- inc/knowbaseitem.class.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/inc/knowbaseitem.class.php b/inc/knowbaseitem.class.php index 25464b0..c3e01a7 100644 --- a/inc/knowbaseitem.class.php +++ b/inc/knowbaseitem.class.php @@ -85,8 +85,13 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item) foreach ($res as $img) { $docimg = new Document(); $docimg->getFromDB((int) $img[2]); + $width = null; - $path = ''; + if (preg_match('/\bwidth=["\']?(\d+)/i', $img[0], $match_width)) { + $width = $match_width[1]; + } + + $path = ''; $answer = str_replace($img[0], $path, $answer); }