function advagg_relocate_load_stylesheet_external in Advanced CSS/JS Aggregation 7.2
Convert external @import statements to be local.
Parameters
array $matches: Array of matched items from preg_replace_callback().
Return value
string Contents of the import statement or new import statement.
1 string reference to 'advagg_relocate_load_stylesheet_external'
- advagg_relocate_css_post_alter in advagg_relocate/
advagg_relocate.module - Alter the css array.
File
- advagg_relocate/
advagg_relocate.module, line 1189 - Advanced aggregation relocate module.
Code
function advagg_relocate_load_stylesheet_external(array $matches) {
// Build css array.
$css = array(
$matches[1] => array(
'type' => 'external',
'data' => $matches[1],
),
);
// Recursively pull in imported fonts.
advagg_relocate_css_alter($css);
// Remove '../' segments where possible.
$values = reset($css);
if ($values['type'] !== 'inline') {
$last = '';
$url = $values['data'];
while ($url != $last) {
$last = $url;
$url = preg_replace('`(^|/)(?!\\.\\./)([^/]+)/\\.\\./`', '$1', $url);
}
// Build css array.
$css = array(
$url => array(
'type' => $values['type'],
'data' => $url,
),
);
}
// Recursively pull in external references.
advagg_relocate_css_post_alter($css);
$values = reset($css);
$key = key($css);
if ($values['type'] === 'inline') {
return "/* Contents of {$key} */\n{$values['data']}";
}
else {
if (!advagg_is_external($values['data'])) {
$dir = variable_get('advagg_relocate_directory', ADVAGG_RELOCATE_DIRECTORY);
$path = advagg_get_relative_path($dir) . '/';
$values['data'] = str_replace($path, '', $values['data']);
}
return "@import \"{$values['data']}\";";
}
}