From 7ad82886d718a06a849a97962298797ab3b86d4b Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Mon, 10 Feb 2020 11:12:14 +1100 Subject: [PATCH] Move regexps to a separate method #179. --- .../maintenance_static_page_generator.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/classes/local/controllers/maintenance_static_page_generator.php b/classes/local/controllers/maintenance_static_page_generator.php index 6de8c25..d58e87b 100644 --- a/classes/local/controllers/maintenance_static_page_generator.php +++ b/classes/local/controllers/maintenance_static_page_generator.php @@ -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)) {