CSS wildcard mechanism

  1. function _phptemplate_page($vars, $suggestions) {
  2.   // CSS Files
  3.   $css = array(
  4.     'admin/*' => 'admin',
  5.     'node/add/portfolio-entry' => 'add-portfolio',
  6.   );
  7.   $newcss = array();
  8.   $wildcars = array();
  9.   foreach ($css as $match => $file) {
  10.     if (strpos($match, '*') == strlen($match) - 1) {
  11.       unset($css[$match]);
  12.       $wildcards[substr($match, 0, -2)] = $file;
  13.     }
  14.   }
  15.   foreach ($suggestions as $suggestion) {
  16.     $suggestion = substr($suggestion, 5);
  17.     if (isset($css[$_GET['q']])) {
  18.       drupal_add_css(path_to_theme() .'/style-'. $css[$_GET['q']] .'.css', 'theme');
  19.     }
  20.     foreach ($wildcards as $match => $file) {
  21.       if (strpos($suggestion, $match) === 0) {
  22.         drupal_add_css(path_to_theme() .'/style-'. $file .'.css', 'theme');
  23.       }
  24.     }
  25.   }
  26.   $vars['styles'] = drupal_get_css();
  27.   return _phptemplate_default('page', $vars, $suggestions);
  28. }