Further modules included.
[yaffs-website] / web / modules / contrib / advagg / advagg.advagg.inc
1 <?php
2
3 /**
4  * @file
5  * Advanced CSS/JS aggregation module.
6  *
7  * File used to store hook_advagg_* hooks.
8  */
9
10 /**
11  * Implements hook_advagg_scan_file_alter().
12  *
13  * Used to make sure the add/modify the file meta data saved in the database.
14  */
15 function advagg_advagg_scan_file_alter($file, &$data) {
16   // Capture hosts for DNS prefetching.
17   // Skip if not a css file.
18   if (empty($data['fileext']) || $data['fileext'] !== 'css') {
19     return;
20   }
21
22   // Get domain names in this css file.
23   $matches = [];
24   $pattern = '%url\(\s*+[\'"]?+(http:\/\/|https:\/\/|\/\/)([^\'"()\s]++)[\'"]?+\s*+\)%i';
25   preg_match_all($pattern, $data['contents'], $matches);
26   $urls = [];
27   if (!empty($matches[1])) {
28     foreach ($matches[1] as $key => $match) {
29       $parse = @parse_url($match . $matches[2][$key]);
30       if (!empty($parse['host']) && empty($urls[$parse['host']])) {
31         $urls[$parse['host']] = $parse['host'];
32       }
33     }
34     $urls = array_values($urls);
35   }
36   if (!empty($urls)) {
37     $data['dns_prefetch'] = $urls;
38   }
39 }