You are here

function css_injector_init in CSS Injector 7

Same name and namespace in other branches
  1. 6 css_injector.module \css_injector_init()
  2. 7.2 css_injector.module \css_injector_init()

Implements hook_init(). Checks to see whether any CSS files should be added to the current page, based on rules configured by the site administrator.

File

./css_injector.module, line 47
Allows administrators to inject CSS into the page output based on configurable rules. Useful for adding simple CSS tweaks without modifying a site's official theme.

Code

function css_injector_init() {
  $css_rules = _css_injector_load_rule();
  foreach ($css_rules as $css_rule) {
    if (!isset($css_rule['enabled']) || $css_rule['enabled']) {
      if (_css_injector_evaluate_rule($css_rule)) {
        $file_uri = _css_injector_rule_uri($css_rule['crid']);
        $theme_rules = isset($css_rule['rule_themes']) ? unserialize($css_rule['rule_themes']) : '';
        global $theme;
        if (!is_array($theme_rules) || empty($theme_rules) || in_array($theme, $theme_rules, true)) {
          switch ($css_rule['media']) {
            case 'all':
            case 'screen':
            case 'print':
              drupal_add_css($file_uri, array(
                'type' => 'file',
                'group' => CSS_THEME,
                'media' => $css_rule['media'],
                'preprocess' => $css_rule['preprocess'],
              ));
              break;
            case 'IE 7':
            case 'IE 8':
            case 'IE 9':
              drupal_add_css($file_uri, array(
                'group' => CSS_THEME,
                'browsers' => array(
                  'IE' => $css_rule['media'],
                  '!IE' => FALSE,
                ),
                'preprocess' => $css_rule['preprocess'],
              ));
              break;
          }
        }
      }
    }
  }
}