Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions classes/local/controllers/maintenance_static_page_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) == '') {
Expand Down Expand Up @@ -217,6 +218,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.
*/
Expand Down