Loads the stylesheet and resolves all @import commands.

Loads a stylesheet and replaces @import commands with the contents of the imported file. Use this instead of file_get_contents when processing stylesheets.

The returned contents are compressed removing white space and comments only when CSS aggregation is enabled. This optimization will not apply for color.module enabled themes with CSS aggregation turned off.

Paramètres

string $file: Name of the stylesheet to be processed.

bool $optimize: Defines if CSS contents should be compressed or not.

array $aggregate_settings: Array of settings.

Return value

string Contents of the stylesheet, including any resolved @import commands.

5 calls to advagg_load_css_stylesheet()
AdvAggCascadingStylesheetsTestCase::testRenderFile dans tests/advagg.test
Tests rendering the stylesheets.
advagg_advagg_get_info_on_files_alter dans ./advagg.advagg.inc
Implements hook_advagg_get_info_on_files_alter().
advagg_get_css_aggregate_contents dans ./advagg.missing.inc
Given a list of files, grab their contents and glue it into one big string.
advagg_mod_inline_css dans advagg_mod/advagg_mod.module
Transforms all CSS files into inline CSS.
advagg_relocate_admin_list_files_with_import dans advagg_relocate/advagg_relocate.admin.inc
Check all CSS files, see if any contains an @import that is external.

Fichier

./advagg.inc, line 1633

Code

function advagg_load_css_stylesheet($file, $optimize = TRUE, array $aggregate_settings = array(), $contents = '') {
    $old_base_path = $GLOBALS['base_path'];
    // Change context to that of when this aggregate was created.
    advagg_context_switch($aggregate_settings, 0);
    // Get the stylesheets contents.
    $contents = advagg_load_stylesheet($file, $optimize, TRUE, $contents);
    // Resolve public:// if needed.
    if (!advagg_is_external($file) && file_uri_scheme($file)) {
        $file = advagg_get_relative_path($file);
    }
    // Get the parent directory of this file, relative to the Drupal root.
    $css_base_url = substr($file, 0, strrpos($file, '/'));
    // Handle split css files.
    list($css_path) = advagg_get_root_files_dir();
    $parts_path = (advagg_s3fs_evaluate_no_rewrite_cssjs(FALSE) ? $css_path[0] : $css_path[1]) . '/parts/';
    $url_parts = strpos($css_base_url, $parts_path);
    // If this CSS file is actually a part of a previously split larger CSS file,
    // don't use it to construct relative paths within the CSS file for
    // 'url(...)' bits.
    if ($url_parts !== FALSE) {
        $css_base_url = substr($css_base_url, $url_parts + strlen($parts_path));
    }
    // Replace the old base path with the one that was passed in.
    if (advagg_is_external($css_base_url) || variable_get('advagg_skip_file_create_url_inside_css', ADVAGG_SKIP_FILE_CREATE_URL_INSIDE_CSS)) {
        $pos = strpos($css_base_url, $old_base_path);
        if ($pos !== FALSE) {
            $parsed_url = parse_url($css_base_url);
            if (!empty($parsed_url['path'])) {
                // Remove any double slash in path.
                $parsed_url['path'] = str_replace('//', '/', $parsed_url['path']);
                // Get newly recalculated position.
                $pos = strpos($parsed_url['path'], $old_base_path);
                // Replace.
                if (strpos($parsed_url['path'], '/') !== 0 && $old_base_path === '/') {
                    // Special case if going to a subdir.
                    $parsed_url['path'] = $GLOBALS['base_path'] . $parsed_url['path'];
                }
                else {
                    $parsed_url['path'] = substr_replace($parsed_url['path'], $GLOBALS['base_path'], $pos, strlen($old_base_path));
                }
                $css_base_url = advagg_glue_url($parsed_url);
            }
        }
    }
    _advagg_build_css_path(array(), $css_base_url . '/', $aggregate_settings);
    // Anchor all paths in the CSS with its base URL, ignoring external,
    // absolute paths, and urls that start with # or %23 (SVG).
    $contents = preg_replace_callback('%url\\(\\s*+[\'"]?+(?![a-z]++:|/|\\#|\\%23+)([^\'"\\)]++)[\'"]?+\\s*+\\)%i', '_advagg_build_css_path', $contents);
    // Change context back.
    advagg_context_switch($aggregate_settings, 1);
    // Return the stylesheets contents.
    return $contents;
}