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