Skip to content

Commit

Permalink
fix: create custom temp directory for html purify serializer (openemr…
Browse files Browse the repository at this point in the history
…#7521)

* fix: create custom temp directory for html purify serializer

* make subdir in temporary_files_dir

* use constant instead of slash

* log mkdir error
  • Loading branch information
stephenwaite authored Jun 26, 2024
1 parent 2f4858f commit 1a20710
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Services/DocumentTemplates/DocumentTemplateRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use HTMLPurifier;
use HTMLPurifier_Config;
use RuntimeException;
use OpenEMR\Common\Logging\SystemLogger;
use OpenEMR\Services\VersionService;

require_once($GLOBALS['srcdir'] . '/appointments.inc.php');
Expand Down Expand Up @@ -109,7 +110,16 @@ public function doRender($template_id, $template_content = null, $json_data = nu
// purify html (and remove js)
$isLegacy = stripos($template, 'portal_version') === false;
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.SerializerPath', $GLOBALS['temporary_files_dir']);
$purifyTempFile = $GLOBALS['temporary_files_dir'] . DIRECTORY_SEPARATOR . 'htmlpurifier';
if (
!file_exists($purifyTempFile) &&
!is_dir($purifyTempFile)
) {
if (!mkdir($purifyTempFile)) {
(new SystemLogger())->error("Could not create directory ", [$purifyTempFile]);
}
}
$config->set('Cache.SerializerPath', $purifyTempFile);
$config->set('Core.Encoding', 'UTF-8');
$config->set('CSS.AllowedProperties', '*');
$purify = new HTMLPurifier($config);
Expand Down

0 comments on commit 1a20710

Please sign in to comment.