ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilWebDAVMountInstructionsDocumentsContainsHtmlValidator.php
Go to the documentation of this file.
1<?php
2
3
5{
7 private $text;
8
13 public function __construct(string $purified_html_content)
14 {
15 $this->text = $purified_html_content;
16 }
17
21 public function isValid() : bool
22 {
23 if (!preg_match('/<[^>]+?>/', $this->text)) {
24 return false;
25 }
26
27 try {
28 $dom = new DOMDocument();
29 if (!$dom->loadHTML($this->text)) {
30 return false;
31 }
32
33 $iter = new RecursiveIteratorIterator(
34 new ilHtmlDomNodeIterator($dom),
35 RecursiveIteratorIterator::SELF_FIRST
36 );
37 foreach ($iter as $element) {
39 if (in_array(strtolower($element->nodeName), ['body'])) {
40 continue;
41 }
42
43 if ($element->nodeType === XML_ELEMENT_NODE) {
44 return true;
45 }
46 }
47 } catch (Exception $e) {
48 return false;
49 } catch (Throwable $e) {
50 return false;
51 }
52 }
53}
An exception for terminatinating execution or to throw for unit testing.
Class ilHtmlDomNodeIterator.
__construct(string $purified_html_content)
ilWebDAVMountInstructionsDocumentsContainsHtmlValidator constructor.