From be7db52eec415279ff2847aa3557dbc89c18003c Mon Sep 17 00:00:00 2001 From: jknapp Date: Sun, 26 Jan 2025 12:30:03 -0800 Subject: [PATCH] Update DOM crawler to resolver PHP warning --- libs/shortcode.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/shortcode.php b/libs/shortcode.php index 0906c87..c60d94d 100644 --- a/libs/shortcode.php +++ b/libs/shortcode.php @@ -5,8 +5,9 @@ function fwembed_parse_html($url = null) { throw new ValueError("Missing URL"); } $html = null; + libxml_use_internal_errors(true); $dom = new DOMDocument(); - @$dom->loadHTML(file_get_contents($url)); + @$dom->loadHTML(loadHTML5(file_get_contents($url)), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $dom->documentURI = $url; $divs = $dom->getElementsByTagName('div'); foreach ($divs as $div) { @@ -43,9 +44,14 @@ function fwembed_parse_html($url = null) { $html = $html . '
' . $productHTML . '
'; } } + libxml_clear_errors(); return $html; } +function loadHTML5($html) { + return '' . $html . ''; +} + function fwembed_shortcode( $atts ) { $options = get_option( 'fourthwall_settings_name' ); $value = isset( $options['fourth_url'] ) ? $options['fourth_url'] : 'https://fourthwall.com';