ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilAccessibilityDocumentsContainsHtmlValidator.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
10 private $text;
11
16 public function __construct(string $text)
17 {
18 $this->text = $text;
19 }
20
24 public function isValid() : bool
25 {
26 if (!preg_match('/<[^>]+?>/', $this->text)) {
27 return false;
28 }
29
30 try {
31 $dom = new DOMDocument();
32 if (!$dom->loadHTML($this->text)) {
33 return false;
34 }
35
36 $iter = new RecursiveIteratorIterator(
37 new ilHtmlDomNodeIterator($dom),
38 RecursiveIteratorIterator::SELF_FIRST
39 );
40 foreach ($iter as $element) {
42 if (in_array(strtolower($element->nodeName), ['body'])) {
43 continue;
44 }
45
46 if ($element->nodeType === XML_ELEMENT_NODE) {
47 return true;
48 }
49 }
50
51 return false;
52 } catch (Exception $e) {
53 return false;
54 } catch (Throwable $e) {
55 return false;
56 }
57 }
58}
An exception for terminatinating execution or to throw for unit testing.
__construct(string $text)
ilAccessibilityDocumentsContainsHtmlValidator constructor.
Class ilHtmlDomNodeIterator.