Fix issue with namespaces for DOM

This commit is contained in:
Andy Dixon
2025-10-09 17:19:55 +01:00
committed by GitHub
parent d39d344be2
commit 40cc6b8c66
+6 -2
View File
@@ -295,14 +295,18 @@ class CMSController
// Load the HTML content from the file // Load the HTML content from the file
$htmlContent = file_get_contents($filePath); $htmlContent = file_get_contents($filePath);
if ($htmlContent === false) {
$htmlContent = file_get_contents($this->documentRoot . ltrim($filePath, '/'));
}
// Initialize a new DOMDocument object // Initialize a new DOMDocument object
$dom = new DOMDocument(); $dom = new \DOMDocument();
// Suppress warnings that might occur due to malformed HTML // Suppress warnings that might occur due to malformed HTML
@$dom->loadHTML($htmlContent); @$dom->loadHTML($htmlContent);
// Find all elements with the class "editable" // Find all elements with the class "editable"
$xpath = new DOMXPath($dom); $xpath = new \DOMXPath($dom);
$editableElements = $xpath->query('//*[contains(@class, "editable")]'); $editableElements = $xpath->query('//*[contains(@class, "editable")]');
// Return true if there are any elements with the "editable" class // Return true if there are any elements with the "editable" class