You are here

function maintenance_exempt_form_system_site_maintenance_mode_alter in Maintenance Exempt 7

Same name and namespace in other branches
  1. 8 maintenance_exempt.module \maintenance_exempt_form_system_site_maintenance_mode_alter()

Implements hook_form_FORM_ID_alter().

File

./maintenance_exempt.module, line 46
Allow exemption of maintenance mode based on either certain set IP addresses or matching a set query string value.

Code

function maintenance_exempt_form_system_site_maintenance_mode_alter(&$form, &$form_state) {
  $form['maintenance_exempt_by_url'] = array(
    '#type' => 'fieldset',
    '#title' => t('Set Exemption by URL'),
    '#weight' => 1,
    '#collapsible' => TRUE,
    '#collapsed' => variable_get('maintenance_exempt_urls', '') ? FALSE : TRUE,
  );
  $form['maintenance_exempt_by_url']['maintenance_exempt_urls'] = array(
    '#type' => 'textarea',
    '#title' => t('Exempt URLs'),
    '#default_value' => variable_get('maintenance_exempt_urls'),
    '#description' => t('Enter a newline-separated list of URLs addresses who should be exempt from maintenance mode. For example "/api/get_info/'),
  );
  $form['maintenance_exempt_by_ip'] = array(
    '#type' => 'fieldset',
    '#title' => t('Set Exemption by IP'),
    '#weight' => 2,
    '#collapsible' => TRUE,
    '#collapsed' => variable_get('maintenance_exempt_ips', '') ? FALSE : TRUE,
  );
  $form['maintenance_exempt_by_ip']['maintenance_exempt_ips'] = array(
    '#type' => 'textarea',
    '#title' => t('Exempt IPs'),
    '#default_value' => variable_get('maintenance_exempt_ips'),
    '#description' => t('Enter a newline-separated list of IP addresses who should be exempt from maintenance mode. !cidr_notation is allowed.', array(
      '!cidr_notation' => l(t('CIDR Notation'), 'http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing'),
    )),
    '#suffix' => t('Your current IP address is %current', array(
      '%current' => ip_address(),
    )),
  );
  $form['maintenance_exempt_by_query_string'] = array(
    '#type' => 'fieldset',
    '#title' => t('Set Exemption by query string'),
    '#weight' => 3,
    '#collapsible' => TRUE,
    '#collapsed' => variable_get('maintenance_exempt_query_key', '') ? FALSE : TRUE,
  );
  $form['maintenance_exempt_by_query_string']['maintenance_exempt_query_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Exempt query string'),
    '#default_value' => variable_get('maintenance_exempt_query_key'),
    '#description' => t('Enter a string which can be used as a variable in the !query_string to exempt a visitor from maintenance mode. !current_url', array(
      '!query_string' => l(t('query string'), 'http://en.wikipedia.org/wiki/Query_string'),
      '!current_url' => variable_get('maintenance_exempt_query_key', '') ? "<br /><br />" . l('Hyperlink to exempt a visitor', '', array(
        'query' => array(
          variable_get('maintenance_exempt_query_key', '') => '',
        ),
      )) : '',
    )),
  );
  $form['#submit'][] = 'maintenance_exempt_form_system_site_maintenance_mode_submit';
}