You are here

function advagg_mod_advagg_css_content_t_replace_callback in Advanced CSS/JS Aggregation 8.2

Same name and namespace in other branches
  1. 7.2 advagg_mod/advagg_mod.advagg.inc \advagg_mod_advagg_css_content_t_replace_callback()

Run preg matches through the t() function.

Parameters

array $matches: Array of matches from preg_replace_callback().

Return value

string Replaced String.

1 string reference to 'advagg_mod_advagg_css_content_t_replace_callback'
advagg_mod_advagg_css_contents_alter in advagg_mod/advagg_mod.advagg.inc
Implements hook_advagg_css_contents_alter().

File

advagg_mod/advagg_mod.advagg.inc, line 44
Advanced CSS/JS aggregation modifier module.

Code

function advagg_mod_advagg_css_content_t_replace_callback(array $matches) {

  // Skip if equal to ; or }.
  if ($matches[1] === ';' || $matches[1] === '}') {
    return $matches[0];
  }

  // Remove quotes for t function.
  $before = substr($matches[1], 1, -1);

  // Only run if it contains A-Za-z.
  if (!preg_match('/[A-Za-z]/', $before)) {
    return $matches[0];
  }

  // Only run if it contains characters other than unicode.
  $css_unicode_pattern = '/\\\\[0-9a-fA-F]{1,6}(?:\\r\\n|[ \\t\\r\\n\\f])?/';
  $unicode_removed = preg_replace($css_unicode_pattern, '', $before);
  if (empty($unicode_removed)) {
    return $matches[0];
  }

  // Run t function.
  // @ignore sniffer_semantics_functioncall_notliteralstring
  $after = (string) t($before);

  // Put back.
  return str_replace($before, $after, $matches[0]);
}