Move regexps to a separate method #179.

This commit is contained in:
Mikhail Golenkov
2020-02-10 11:12:14 +11:00
parent 26baaf9993
commit 7ad82886d7

View File

@@ -138,6 +138,17 @@ class maintenance_static_page_generator {
}
}
/**
* Retrieves all URLs from file content using regular expressions.
*
* @param string $contents Content of the file
* @return array Array of all matches in multi-dimensional array
*/
public function get_urls_from_stylesheet($contents) {
preg_match_all('#url\([\'"]?(?!data:)([^\'"\)]+)#', $contents, $matches);
return $matches;
}
/**
* Checks for urls inside filename.
*
@@ -148,9 +159,8 @@ class maintenance_static_page_generator {
global $CFG;
$contents = file_get_contents($filename);
if (!preg_match_all('#url\([\'"]?(?!data:)([^\'"\)]+)#', $contents, $matches)) {
return;
}
$matches = $this->get_urls_from_stylesheet($contents);
foreach ($matches[1] as $originalurl) {
// Allow incomplete URLs in CSS, assume it is from moodle root.
if (maintenance_static_page_io::is_url($originalurl)) {