ILIAS  release_8 Revision v8.24
class.ilWebDAVMountInstructionsDocumentsContainsHtmlValidator.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5
23{
24 private string $text;
25
26 public function __construct(string $purified_html_content)
27 {
28 $this->text = $purified_html_content;
29 }
30
31 public function isValid(): bool
32 {
33 if (!preg_match('/<[^>]+?>/', $this->text)) {
34 return false;
35 }
36
37 try {
38 $dom = new DOMDocument();
39 if (!$dom->loadHTML($this->text)) {
40 return false;
41 }
42
43 $iter = new RecursiveIteratorIterator(
44 new ilHtmlDomNodeIterator($dom),
45 RecursiveIteratorIterator::SELF_FIRST
46 );
47 foreach ($iter as $element) {
49 if (strtolower($element->nodeName) === 'body') {
50 continue;
51 }
52
53 if ($element->nodeType === XML_ELEMENT_NODE) {
54 return true;
55 }
56 }
57 } catch (Exception|Throwable $e) {
58 return false;
59 }
60
61 return false;
62 }
63}
Class ilHtmlDomNodeIterator.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...