Added missing modules, including some as submodules.
[yaffs-website] / web / modules / contrib / advagg / advagg_mod / advagg_mod.advagg.inc
1 <?php
2
3 /**
4  * @file
5  * Advanced CSS/JS aggregation modifier module.
6  */
7
8 /**
9  * Implements hook_advagg_css_contents_alter().
10  *
11  * Used to run strings inside of quotes of the content attribute through the t
12  * function.
13  *
14  * @see \Drupal\Core\Asset\CssOptimizer::processCss
15  */
16 function advagg_mod_advagg_css_contents_alter(&$data, $css_asset) {
17   $config = \Drupal::config('advagg_mod.settings');
18   if (!$config->get('css_translate')) {
19     return;
20   }
21
22   // Code taken from \Drupal\Core\Asset\CssOptimizer::processCss().
23   // Regexp to match double quoted strings.
24   $double_quot = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"';
25   // Regexp to match single quoted strings.
26   $single_quot = "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'";
27   // Extract all content inside of quotes.
28   $css_content_pattern = "/content:.*?($double_quot|$single_quot|(?:\\;|\\})).*?(?:\\;|\\})/";
29
30   // Run strings inside of quotes of the content attribute through the t
31   // function.
32   $data = preg_replace_callback($css_content_pattern, 'advagg_mod_advagg_css_content_t_replace_callback', $data);
33 }
34
35 /**
36  * Run preg matches through the t() function.
37  *
38  * @param array $matches
39  *   Array of matches from preg_replace_callback().
40  *
41  * @return string
42  *   Replaced String.
43  */
44 function advagg_mod_advagg_css_content_t_replace_callback(array $matches) {
45   // Skip if equal to ; or }.
46   if ($matches[1] === ';' || $matches[1] === '}') {
47     return $matches[0];
48   }
49   // Remove quotes for t function.
50   $before = substr($matches[1], 1, -1);
51   // Only run if it contains A-Za-z.
52   if (!preg_match('/[A-Za-z]/', $before)) {
53     return $matches[0];
54   }
55   // Only run if it contains characters other than unicode.
56   $css_unicode_pattern = '/\\\\[0-9a-fA-F]{1,6}(?:\\r\\n|[ \\t\\r\\n\\f])?/';
57   $unicode_removed = preg_replace($css_unicode_pattern, '', $before);
58   if (empty($unicode_removed)) {
59     return $matches[0];
60   }
61
62   // Run t function.
63   // @ignore sniffer_semantics_functioncall_notliteralstring
64   $after = (string) t($before);
65   // Put back.
66   return str_replace($before, $after, $matches[0]);
67 }