MCPcopy Create free account
hub / github.com/error311/FileRise / sanitizeFooterHtml

Method sanitizeFooterHtml

src/FileRise/Domain/AdminModel.php:794–838  ·  view source on GitHub ↗
($value)

Source from the content-addressed store, hash-verified

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 {

Callers 3

buildPublicSubsetMethod · 0.95
updateConfigMethod · 0.95
getConfigMethod · 0.95

Calls 1

sanitizeFooterNodeMethod · 0.95

Tested by

no test coverage detected