ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
HTMLPurifier.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\LegalDocuments;
22 
26 use Closure;
27 
29 {
31  private array $allowed_tags;
32  private string $cache_directory;
33 
36 
40  public function __construct(
41  ?array $allowed_tags = null,
42  ?string $cache_directory = null,
43  ?Closure $create_config = null
44  ) {
45  $this->cache_directory = $cache_directory ?? ilHtmlPurifierAbstractLibWrapper::_getCacheDirectory();
46  $this->allowed_tags = $allowed_tags ?? ilObjAdvancedEditing::_getUsedHTMLTags('textarea');
47  $this->create_config = $create_config ?? HTMLPurifier_Config::createDefault(...);
49  }
50 
52  {
53  $config = ($this->create_config)();
54  $config->set('HTML.DefinitionID', 'ilias termsofservice document');
55  $config->set('HTML.DefinitionRev', 1);
56  $config->set('HTML.TargetBlank', true);
57  $config->set('Cache.SerializerPath', $this->cache_directory);
58  $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
59 
60  $tags = $this->makeElementListTinyMceCompliant($this->allowed_tags);
61 
62  $tags[] = 'b';
63  $tags[] = 'i';
64 
65  $config->set('HTML.AllowedElements', $this->removeUnsupportedElements($tags));
66  $config->set('HTML.ForbiddenAttributes', 'div@style');
67 
68  if (($def = $config->maybeGetRawHTMLDefinition()) !== null) {
69  $def->addAttribute('a', 'target', 'Enum#_blank,_self,_target,_top');
70  }
71 
72  return $config;
73  }
74 }
__construct(?array $allowed_tags=null, ?string $cache_directory=null, ?Closure $create_config=null)
removeUnsupportedElements(array $elements)
Removes all unsupported elements.
__construct(VocabulariesInterface $vocabularies)
static _getUsedHTMLTags(string $a_module="")
Returns an array of all allowed HTML tags for text editing.