drupal_load_stylesheet_content

Versions
7
drupal_load_stylesheet_content($contents, $optimize = FALSE)

Process the contents of a stylesheet for aggregation.

Parameters

$contents The contents of the stylesheet.

$optimize (optional) Boolean whether CSS contents should be minified. Defaults to FALSE.

Return value

Contents of the stylesheet including the imported stylesheets.

▾ 2 functions call drupal_load_stylesheet_content()

drupal_get_css in includes/common.inc
Returns a themed representation of all stylesheets that should be attached to the page.
drupal_load_stylesheet in includes/common.inc
Loads the stylesheet and resolves all @import commands.

Code

includes/common.inc, line 3475

<?php
function drupal_load_stylesheet_content($contents, $optimize = FALSE) {
  // Remove multiple charset declarations for standards compliance (and fixing Safari problems).
  $contents = preg_replace('/^@charset\s+[\'"](\S*)\b[\'"];/i', '', $contents);

  if ($optimize) {
    // Perform some safe CSS optimizations.
    $contents = preg_replace('{
      (?<=\\\\\*/)([^/\*]+/\*)([^\*/]+\*/)  # Add a backslash also at the end ie-mac hack comment, so the next pass will not touch it.
                                            # The added backshlash does not affect the effectiveness of the hack.
      }x', '\1\\\\\2', $contents);
    $contents = preg_replace('<
      \s*([@{}:;,]|\)\s|\s\()\s* |          # Remove whitespace around separators, but keep space around parentheses.
      /\*[^*\\\\]*\*+([^/*][^*]*\*+)*/ |    # Remove comments that are not CSS hacks.
      >x', '\1', $contents);
  }

  // Replaces @import commands with the actual stylesheet content.
  // This happens recursively but omits external files.
  $contents = preg_replace_callback('/@import\s*(?:url\()?[\'"]?(?![a-z]+:)([^\'"\()]+)[\'"]?\)?;/', '_drupal_load_stylesheet', $contents);
  return $contents;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.