1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
 * Dynamic style sheet loader.
 */
function alt_media_styles($conditions = array()) {
  global $theme, $theme_key, $base_path;
  
  // Set directories to check.
  $check_dirs = array(path_to_theme() .'/styles');
  // Check if we are currently in a sub-theme .
  if ($theme != $theme_key) {
    $check_dirs[] = path_to_theme() ."/$theme_key/styles";
  }
  
  foreach ($check_dirs as $check_dir) {  
    // Get all the default styles in $check_dir.
    foreach (glob("$styles_dir/*.css") as $file) {
      $component = basename($file, '.css');
      // $component overwrites matching values set previously.
      // Makes cascading possible from sub-theme to the base theme.
      $css_queue[$component] = $file;
    }
  }
  
  // Setup IE styles.
  $ie_styles = '';
  
  foreach ($css_queue as $component => $file) {
    $media = isset($conditions[$component]['media']) ? $conditions[$component]['media'] : 'all';
    $preprocess = isset($conditions[$component]['media']) ? $conditions[$component]['preprocess'] : TRUE;
    $ie_cc = isset($conditions[$component]['IE condition']) ? $conditions[$component]['IE condition'] : FALSE;
    
    if ($ie_cc) {
      $ie_styles .= "<!--[$ie_cc]>\n<style type=\"text/css\" media=\"$media\">@import \"$base_path$file\";</style>\n<![endif]-->";
    }
    else {
      drupal_add_css($file, 'theme', $media, $preprocess);
    }
  }
  
  // Return stored styles.
  return array('styles' => drupal_add_css(), 'IE styles' => $ie_styles);
}