ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWebDAVMountInstructionsDocumentsContainsHtmlValidator.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public function __construct(private string $text)
24 {
25 }
26
27 public function isValid(): bool
28 {
29 if (!preg_match('/<[^>]+?>/', $this->text)) {
30 return false;
31 }
32
33 try {
34 $dom = new DOMDocument();
35 if (!$dom->loadHTML($this->text)) {
36 return false;
37 }
38
39 $iter = new RecursiveIteratorIterator(
40 new ilHtmlDomNodeIterator($dom),
41 RecursiveIteratorIterator::SELF_FIRST
42 );
43 foreach ($iter as $element) {
45 if (strtolower((string) $element->nodeName) === 'body') {
46 continue;
47 }
48
49 if ($element->nodeType === XML_ELEMENT_NODE) {
50 return true;
51 }
52 }
53 } catch (Exception|Throwable) {
54 return false;
55 }
56
57 return false;
58 }
59}
Class ilHtmlDomNodeIterator.