ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAccessibilityDocumentsContainsHtmlValidator.php
Go to the documentation of this file.
1<?php
2
23{
24 private string $text;
25
26 public function __construct(string $text)
27 {
28 $this->text = $text;
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 (in_array(strtolower($element->nodeName), ['body'])) {
50 continue;
51 }
52
53 if ($element->nodeType === XML_ELEMENT_NODE) {
54 return true;
55 }
56 }
57
58 return false;
59 } catch (Exception | Throwable $e) {
60 return false;
61 }
62 }
63}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilHtmlDomNodeIterator.