diff --git a/alpha/template.php b/alpha/template.php index a878078..4a3e3ea 100644 --- a/alpha/template.php +++ b/alpha/template.php @@ -323,6 +323,92 @@ function alpha_alpha_preprocess_block(&$vars) { } /** + * Implements hook_process_html(). + * + * Replaces stylesheets with color.module's recolored versions, like + * _color_html_alter() but for stylesheets with any media query (not just + * "all"). And for stylesheets added using Omega's non-standard method in + * .info files; css[global.css]. + * + * @see _color_html_alter() + */ +function alpha_alpha_process_html(&$vars) { + global $theme_key; + + // Hook into color.module. + if (module_exists('color')) { + + // Override stylesheets. + $color_paths = variable_get('color_' . $theme_key . '_stylesheets', array()); + if (!empty($color_paths)) { + $themes = list_themes(); + + // Replace theme stylesheets if there is a recolored file. + if (!empty($themes[$theme_key]->stylesheets)) { + foreach ($themes[$theme_key]->stylesheets as $paths) { + foreach ($paths as $base_filename => $old_path) { + + // This part is from _color_html_alter(). + + // Loop over the path array with recolored CSS files to find matching + // paths which could replace the non-recolored paths. + foreach ($color_paths as $color_path) { + // Color module currently requires unique file names to be used, + // which allows us to compare different file paths. + if (drupal_basename($old_path) == drupal_basename($color_path)) { + // Replace the path to the new css file. + // This keeps the order of the stylesheets intact. + $vars['css'][$old_path]['data'] = $color_path; + } + } + } + } + } + + // Replace the theme's omega-stylesheets if there is a recolored file. + if (!empty($themes[$theme_key]->info['css'])) { + foreach (array_keys($themes[$theme_key]->info['css']) as $filename) { + + // Loop over the paths of the recolored stylesheet files. + foreach ($color_paths as $color_path) { + + // Find recolored stylesheets with the same name as the + // omega-stylesheets. + if ($filename == drupal_basename($color_path)) { + + // Index all CSS files without their omega-layout prefixes. + if (!isset($index)) { + $index = array(); + foreach (array_keys($vars['css']) as $name) { + $data_css = explode('::', $name); + $key = array_pop($data_css); + $index[$key][] = $name; + } + } + + // Omega-stylesheets are always found in the theme's css + // directory. + $path = drupal_get_path('theme', $theme_key) . "/css/$filename"; + + // Replace all references to the omega-stylesheet with the + // recolored stylesheet. + if (!empty($index[$path])) { + foreach ($index[$path] as $css_path) { + $vars['css'][$css_path]['data'] = $color_path; + } + } + } + } + } + } + + // Build the styles variables. + $vars['styles'] = drupal_get_css($vars['css']); + } + } +} + +/** * Implements hook_preprocess_html(). */ function alpha_alpha_preprocess_html(&$vars) {