Skip to content

Instantly share code, notes, and snippets.

@eiriksm
Created July 27, 2014 16:01
Show Gist options
  • Save eiriksm/d0e8ff026205d6bdd2f0 to your computer and use it in GitHub Desktop.
Save eiriksm/d0e8ff026205d6bdd2f0 to your computer and use it in GitHub Desktop.
<?php
$style = '';
foreach($styles as $stylesheet) {
if (strpos($stylesheet['data'], 'system/system.menus.css') > 0) {
// Skip this one, at least for my theme.
continue;
}
// The following are nicked from Drupal core.
$contents = drupal_load_stylesheet($stylesheet['data'], TRUE);
// Build the base URL of this CSS file: start with the full URL.
$css_base_url = file_create_url($stylesheet['data']);
// Move to the parent.
$css_base_url = substr($css_base_url, 0, strrpos($css_base_url, '/'));
// Simplify to a relative URL if the stylesheet URL starts with the
// base URL of the website.
if (substr($css_base_url, 0, strlen($GLOBALS['base_root'])) == $GLOBALS['base_root']) {
$css_base_url = substr($css_base_url, strlen($GLOBALS['base_root']));
}
_drupal_build_css_path(NULL, $css_base_url . '/');
// Anchor all paths in the CSS with its base URL, ignoring external and absolute paths.
$style .= preg_replace_callback('/url\(\s*[\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\s*\)/i', '_drupal_build_css_path', $contents);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment