You are here

function css_injector_init in CSS Injector 7.2

Same name and namespace in other branches
  1. 6 css_injector.module \css_injector_init()
  2. 7 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 132
css_injector.module

Code

function css_injector_init() {

  // load all the rules
  ctools_include('export');
  $rules = ctools_export_load_object('css_injector_rule');
  foreach ($rules as $name => $rule) {

    // check if the rule actually exists in the db... required if files exist w/o db entry
    if (!isset($rule->crid)) {
      continue;
    }

    // check if the rule is disabled in the ctools UI, if so skip it
    if (isset($rule->disabled) && $rule->disabled == TRUE) {
      continue;
    }

    // check the page visibility settings
    if (_css_injector_visibility_pages($rule) == FALSE) {
      continue;
    }

    // add the css
    $code = $rule->inline == 1 ? $rule->css : _css_injector_rule_path($rule->crid);
    drupal_add_css($code, array(
      'type' => $rule->inline == 1 ? 'inline' : 'file',
      'media' => $rule->media,
      // this group has the highest weight
      'group' => CSS_THEME,
      'every_page' => FALSE,
      // safe guard to ensure inline files are never preprocessed
      'preprocess' => $rule->inline == 1 ? FALSE : $rule->preprocess,
      // since we're trying to give the administrator complete control, we'll
      // move JS that this module has added to a high weight, higher even than
      // the theme's CSS files. Currently the weight is 200 + the crid, which is
      // currently higher than Bartik's CSS.
      'weight' => 200 + $rule->crid,
    ));
  }
}