($value)
| 792 | } |
| 793 | |
| 794 | private static function sanitizeFooterHtml($value): string |
| 795 | { |
| 796 | $html = trim((string)$value); |
| 797 | if ($html === '') { |
| 798 | return ''; |
| 799 | } |
| 800 | |
| 801 | $html = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/', ' ', $html); |
| 802 | $html = substr((string)$html, 0, 2000); |
| 803 | |
| 804 | if (!class_exists(\DOMDocument::class)) { |
| 805 | $text = strip_tags($html); |
| 806 | $text = preg_replace('/\s+/', ' ', (string)$text); |
| 807 | return trim($text); |
| 808 | } |
| 809 | |
| 810 | $previous = libxml_use_internal_errors(true); |
| 811 | $doc = new \DOMDocument('1.0', 'UTF-8'); |
| 812 | $loaded = $doc->loadHTML( |
| 813 | '<?xml encoding="UTF-8"><div>' . $html . '</div>', |
| 814 | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD |
| 815 | ); |
| 816 | libxml_clear_errors(); |
| 817 | libxml_use_internal_errors($previous); |
| 818 | |
| 819 | if (!$loaded) { |
| 820 | $text = strip_tags($html); |
| 821 | $text = preg_replace('/\s+/', ' ', (string)$text); |
| 822 | return trim($text); |
| 823 | } |
| 824 | |
| 825 | $wrapper = $doc->getElementsByTagName('div')->item(0); |
| 826 | if (!$wrapper) { |
| 827 | return ''; |
| 828 | } |
| 829 | |
| 830 | self::sanitizeFooterNode($wrapper, $doc); |
| 831 | |
| 832 | $out = ''; |
| 833 | foreach (iterator_to_array($wrapper->childNodes) as $child) { |
| 834 | $out .= $doc->saveHTML($child); |
| 835 | } |
| 836 | |
| 837 | return trim($out); |
| 838 | } |
| 839 | |
| 840 | private static function sanitizeFooterNode(\DOMNode $node, \DOMDocument $doc): void |
| 841 | { |
no test coverage detected