You are here

function environment_indicator_init in Environment Indicator 6

Same name and namespace in other branches
  1. 7 environment_indicator.module \environment_indicator_init()

Implementation of hook_init().

File

./environment_indicator.module, line 61
Adds a coloured strip to the side of the site informing the user which environment they are in (Development, Staging Production etc).

Code

function environment_indicator_init() {
  if (!user_access('access environment indicator') || !variable_get('environment_indicator_enabled', 1)) {
    return;
  }

  // Do not show the indicator on select pages.
  $off_pages = variable_get('environment_indicator_suppress_pages', "imagecrop/*\n");
  $path = drupal_get_path_alias($_GET['q']);

  // Compare with the internal and path alias (if any).
  $page_match = drupal_match_path($path, $off_pages);
  if ($path != $_GET['q']) {
    $page_match = $page_match || drupal_match_path($_GET['q'], $off_pages);
  }
  if ($page_match) {
    return;
  }
  $path = drupal_get_path('module', 'environment_indicator');
  drupal_add_css($path . '/environment_indicator.css', 'module', 'all', FALSE);

  // Performance: Defer execution.
  drupal_add_js($path . '/environment_indicator.min.js', 'module', 'header', TRUE);

  //drupal_add_js($path .'/environment_indicator.js', 'module', 'header', TRUE);
  if ($setting = variable_get('environment_indicator_margin', 1)) {
    $settings['margin'] = check_plain($setting);
  }
  if ($setting = variable_get('environment_indicator_position', 'left')) {
    $settings['position'] = check_plain($setting);
  }
  if ($setting = variable_get('environment_indicator_text', 'ENVIRONMENT INDICATOR')) {
    $settings['text'] = check_plain($setting);
  }
  if ($setting = variable_get('environment_indicator_color', '#d00c0c')) {
    $settings['color'] = check_plain($setting);
  }
  drupal_add_js(array(
    'environment_indicator' => $settings,
  ), 'setting');
}