ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
HTMLPurifier.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\LegalDocuments;
22
25use HTMLPurifier_Config;
26use Closure;
27
29{
31 private readonly array $allowed_tags;
32 private readonly string $cache_directory;
33
35 private readonly Closure $create_config;
36
41 public function __construct(
42 ?array $allowed_tags = null,
43 ?string $cache_directory = null,
44 ?Closure $create_config = null
45 ) {
47 $this->allowed_tags = $allowed_tags ?? ilRTESettings::_getUsedHTMLTags('textarea');
48 $this->create_config = $create_config ?? HTMLPurifier_Config::createDefault(...);
50 }
51
52 protected function getPurifierConfigInstance(): HTMLPurifier_Config
53 {
54 $config = ($this->create_config)();
55 $config->set('HTML.DefinitionID', 'ilias termsofservice document');
56 $config->set('HTML.DefinitionRev', 1);
57 $config->set('HTML.TargetBlank', true);
58 $config->set('Cache.SerializerPath', $this->cache_directory);
59 $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
60
61 $tags = $this->makeElementListTinyMceCompliant($this->allowed_tags);
62
63 $tags[] = 'b';
64 $tags[] = 'i';
65
66 $config->set('HTML.AllowedElements', $this->removeUnsupportedElements($tags));
67 $config->set('HTML.ForbiddenAttributes', 'div@style');
68
69 if (($def = $config->maybeGetRawHTMLDefinition()) !== null) {
70 $def->addAttribute('a', 'target', 'Enum#_blank,_self,_target,_top');
71 }
72
73 return $config;
74 }
75}
__construct(?array $allowed_tags=null, ?string $cache_directory=null, ?Closure $create_config=null)
Abstract class wrapping the HTMLPurifier instance.
removeUnsupportedElements(array $elements)
Removes all unsupported elements.
static _getUsedHTMLTags(string $module='')
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc