You are here

environment_indicator.module in Environment Indicator 7

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

@author Tom Kirkpatrick (mrfelton), www.systemseed.com

File

environment_indicator.module
View source
<?php

/**
 * @file
 * Adds a coloured strip to the side of the site informing the user which
 * environment they are in (Development, Staging Production etc).
 *
 * @author Tom Kirkpatrick (mrfelton), www.systemseed.com
 */

/**
 * Implement hook_help().
 */
function environment_indicator_help($path, $arg) {
  switch ($path) {
    case 'admin/config/development/environment_indicator':
      return t('The Environment Indicator adds a coloured strip to the side of the site informing you which environment you\'re currently in (Development, Staging Production etc). Use the settings below to customize the appearance of the indicator. You may override these settings in your settings.php file in each of your environments.');
    case 'admin/help#environment_indicator':
      $output = '<p>' . t('The Environment Indicator adds a coloured strip to the side of the site informing you which environment you\'re currently in (Development, Staging Production etc') . '</p>';
      $output .= '<p>' . t('The Environment Indicator <a href="@settings">settings page</a> allows you to modify some elements of the indicator\'s behavior and appearance. Since the appearance of the indicator is dependent on your site theme, substantial customisations require modifications to your site\'s theme and CSS files.', array(
        '@settings' => url('admin/config/development/environment_indicator'),
      )) . '</p>';
      $output .= '<p>' . t('The Environment Indicator\'s visibility depends upon the permissions of the viewer. The <a href="@permissions">access environment indicator</a> permission must be enabled for a user role in order for users of that role to see the indicator.', array(
        '@permissions' => url('admin/people/permissions', array(
          'fragment' => 'module-environment_indicator',
        )),
      )) . '</p>';
      $output .= '<p>' . t('The settings for the Environment Indicator, such as the text to display and the color can be overridden for each of your specific environments in the site\'s settings.php file. This allows you to customise the indicator for each environment without needing to make any changes in the database. This means that the Environment Indicator will always display correctly when moving your site from development to staging to production. For example:') . '</p>';
      $output .= '<dl>';
      $output .= '<dt><em>environment_indicator_text</em></dt><dd>' . t('The text that will be displayed vertically down the indicator. e.g:<br/>$conf[\'environment_indicator_text\'] = \'STAGING SERVER\';') . '</dd></dt>';
      $output .= '<dt><em>environment_indicator_color</em></dt><dd>' . t('A valid css color. e.g:<br/>$conf[\'environment_indicator_color\'] = \'red\';') . '</dd></dt>';
      $output .= '<dt><em>environment_indicator_enabled</em></dt><dd>' . t('A boolean value indicating whether the Environment Indicator should be enabled or not. On your production environment, you should probably set this to FALSE. e.g:<br/>$conf[\'environment_indicator_enabled\'] = FALSE;') . '</dd></dt>';
      $output .= '</dl>';
      return $output;
  }
}

/**
 * Implement hook_permission().
 */
function environment_indicator_permission() {
  return array(
    'access environment indicator' => array(
      'title' => t('Access environment indicator'),
      'description' => t('View the environment indicator'),
    ),
  );
}

/**
 * Implement hook_menu().
 */
function environment_indicator_menu() {
  $items['admin/config/development/environment_indicator'] = array(
    'title' => 'Environment indicator',
    'description' => 'Adjust settings for the Environment Indicator.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'environment_indicator_settings',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'environment_indicator.admin.inc',
  );
  return $items;
}

/**
 * Implement hook_init().
 */
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/*\nmedia/browser");
  $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', array(
    'every_page' => TRUE,
  ));

  // Performance: Defer execution.
  drupal_add_js($path . '/environment_indicator.min.js');
  drupal_add_js($path . '/environment_indicator.js', array(
    'preprocess' => FALSE,
  ));
  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');
}

/**
 * Implements hook_overlay_child_initialize().
 */
function environment_indicator_overlay_child_initialize() {
  drupal_add_js(array(
    'environment_indicator' => array(
      'suppress' => 1,
    ),
  ), 'setting');
}