ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTermsOfServiceDocumentsContainsHtmlValidator.php
Go to the documentation of this file.
1 <?php
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 }
__construct(string $text)
ilTermsOfServiceDocumentsContainsHtmlValidator constructor.
Class ilHtmlDomNodeIterator.