Implements hook_css_alter().

1 call to advagg_relocate_css_alter()
advagg_relocate_load_stylesheet_external dans advagg_relocate/advagg_relocate.module
Convert external @import statements to be local.

Fichier

advagg_relocate/advagg_relocate.module, line 179

Code

function advagg_relocate_css_alter(&$css) {
    if (!module_exists('advagg') || !advagg_enabled()) {
        return;
    }
    $aggregate_settings = advagg_current_hooks_hash_array();
    // Check external css setting.
    if (empty($aggregate_settings['variables']['advagg_relocate_css_inline_external'])) {
        return;
    }
    // Handle fonts.
    $replacements = array();
    foreach ($css as $key => &$values) {
        if ($values['type'] !== 'external') {
            continue;
        }
        if (!advagg_relocate_check_domain_of_font_url($key, $aggregate_settings)) {
            continue;
        }
        module_load_include('advagg.inc', 'advagg_relocate');
        $font_faces = advagg_relocate_get_remote_font_data($key, $aggregate_settings);
        if (empty($font_faces)) {
            continue;
        }
        $new_css = advagg_relocate_font_face_parser($font_faces);
        $values['data'] = $new_css;
        $values['type'] = 'inline';
        // Add DNS information for font domains.
        $parse = @parse_url($key);
        if (strpos($parse['host'], 'fonts.googleapis.com') !== FALSE) {
            // Add fonts.gstatic.com when fonts.googleapis.com is added.
            $values['dns_prefetch'] = 'https://fonts.gstatic.com/#crossorigin';
            $values['preload'] = 'https://fonts.gstatic.com/#crossorigin';
        }
        // Move this css to the top.
        if (module_exists('advagg_mod') && $aggregate_settings['variables']['advagg_mod_css_adjust_sort_external']) {
            $values['group'] = CSS_SYSTEM - 1;
            $values['weight'] = -50000;
            $values['movable'] = FALSE;
        }
        // Do not move this css to the bottom.
        if (module_exists('advagg_mod') && $aggregate_settings['variables']['advagg_mod_css_adjust_sort_inline']) {
            $values['movable'] = FALSE;
        }
        $replacements[basename($key)] = $key;
    }
    if (!empty($replacements)) {
        $css = advagg_relocate_key_rename($css, $replacements);
    }
}