Transforms all CSS files into inline CSS.

Paramètres

array $css: CSS array.

int $file_limit: The number of files to inline; 0 means no limit.

int $size_limit: The number of bytes to inline; 0 means no limit.

Voir aussi

advagg_get_css_aggregate_contents()

drupal_build_css_cache()

1 call to advagg_mod_inline_css()
_advagg_mod_pre_render_styles dans advagg_mod/advagg_mod.module
A #pre_render callback to inline all CSS on this page.

Fichier

advagg_mod/advagg_mod.module, line 3308

Code

function advagg_mod_inline_css(array &$css, $file_limit = 0, $size_limit = 0) {
    $aggregate_settings = advagg_current_hooks_hash_array();
    $optimize = TRUE;
    module_load_include('inc', 'advagg', 'advagg');
    $count = 0;
    $size = 0;
    foreach ($css as &$values) {
        // Only process files.
        if ($values['type'] !== 'file') {
            continue;
        }
        $file = $values['data'];
        if (file_exists($file)) {
            if (!empty($file_limit) && $count > $file_limit) {
                break;
            }
            $contents = advagg_load_css_stylesheet($file, $optimize, $aggregate_settings);
            // Allow other modules to modify this files contents.
            // Call hook_advagg_get_css_file_contents_alter().
            drupal_alter('advagg_get_css_file_contents', $contents, $file, $aggregate_settings);
            // Per the W3C specification at
            // http://www.w3.org/TR/REC-CSS2/cascade.html#at-import, @import rules
            // must proceed any other style, so we move those to the top.
            $regexp = '/@import[^;]+;/i';
            preg_match_all($regexp, $contents, $matches);
            $contents = preg_replace($regexp, '', $contents);
            $contents = implode('', $matches[0]) . $contents;
            $size += strlen($contents);
            if (!empty($size_limit) && $size > $size_limit) {
                break;
            }
            $values['data'] = $contents;
            $values['type'] = 'inline';
            $count++;
        }
    }
    unset($values);
}