diff --git a/classes/local/controllers/maintenance_static_page_generator.php b/classes/local/controllers/maintenance_static_page_generator.php index 75abc12..ed9cf7c 100644 --- a/classes/local/controllers/maintenance_static_page_generator.php +++ b/classes/local/controllers/maintenance_static_page_generator.php @@ -83,6 +83,7 @@ public function generate() { $this->update_link_favicon(); $this->update_images(); $this->remove_configured_css_selectors(); + $this->update_inline_background_images(); $html = $this->dom->saveHTML(); if (trim($html) == '') { @@ -218,6 +219,23 @@ private function update_images() { } } + /** + * Fetch and fixes all inline background images. + */ + private function update_inline_background_images() { + $xpath = new \DOMXPath($this->dom); + $elements = $xpath->query("//*[@style]"); + + foreach ($elements as $element) { + $style = $element->getAttribute("style"); + preg_match('/(?<=background-image)\s*:\s*url\s*\(\s*(\S+)\s*\);/', $style, $matches); + if (isset($matches[1])) { + $updated = preg_replace("/(?<=background-image)\s*:\s*url\s*\(\s*(\S+)\s*\);/", ': url(' . $this->io->generate_file_url($matches[1]) . '); ', $style); + $element->setAttribute('style', $updated); + } + } + } + /** * Remove from DOM the CSS selectores defined in the plugin settings. */