You are here

function shurly_settings_form in ShURLy 6

Same name and namespace in other branches
  1. 7 shurly.admin.inc \shurly_settings_form()

Settings form

1 string reference to 'shurly_settings_form'
shurly_menu in ./shurly.module
Implementation of hook_menu()

File

./shurly.admin.inc, line 11
Administration pages for the Htaccess module.

Code

function shurly_settings_form($form_state) {
  global $base_url;
  drupal_add_js('misc/jquery.js', 'core', 'header');
  $form['shurly_url'] = array(
    '#type' => 'fieldset',
    '#title' => t('Base URL'),
    '#description' => t('If you want to use a dedicated url for the short URL\'s, enter below that short base URL to be used.'),
  );
  $form['shurly_url']['shurly_base'] = array(
    '#type' => 'textfield',
    '#description' => t('Default is the base URL of the Drupal installation.'),
    '#default_value' => variable_get('shurly_base', $base_url),
    '#required' => TRUE,
  );
  $form['shurly_restrictions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Restrictions'),
    '#description' => t('Restrict short URL targets. Be aware of the fact, that the localhost, local network and unresolvable restriction are resolving the given address by staging a DNS request, which can significantly <strong>slow down the short URL creation</strong>!'),
  );
  $form['shurly_restrictions']['shurly_forbid_localhost'] = array(
    '#type' => 'checkbox',
    '#title' => t('Forbid localhost'),
    '#description' => t('Do not allow creation of short URLs targeting localhost addresses.'),
    '#default_value' => variable_get('shurly_forbid_localhost', FALSE),
  );
  $form['shurly_restrictions']['shurly_forbid_private_ips'] = array(
    '#type' => 'checkbox',
    '#title' => t('Forbid private IP ranges'),
    '#description' => t('Do not allow creation of short URLs targeting private IP ranges.'),
    '#default_value' => variable_get('shurly_forbid_private_ips', FALSE),
  );
  $form['shurly_restrictions']['shurly_forbid_unresolvable_hosts'] = array(
    '#type' => 'checkbox',
    '#title' => t('Forbid unresolvable hostnames'),
    '#description' => t('Do not allow creation of short URLs targeting host addresses that cannot be resolved.'),
    '#default_value' => variable_get('shurly_forbid_unresolvable_hosts', FALSE),
  );
  $form['shurly_restrictions']['shurly_forbid_ips'] = array(
    '#type' => 'checkbox',
    '#title' => t('Forbid direct IP redirects'),
    '#description' => t('Do not allow creation of short URLs containing an IP address instead of a human readable hostname.'),
    '#default_value' => variable_get('shurly_forbid_ips', FALSE),
  );
  $form['shurly_restrictions']['shurly_forbid_custom'] = array(
    '#type' => 'checkbox',
    '#title' => t('Forbid URL target by custom pattern'),
    '#description' => t('Define a custom pattern (RegEx) to forbid some kind of target URLs.'),
    '#default_value' => variable_get('shurly_forbid_custom', FALSE),
    '#attributes' => array(
      'onchange' => "jQuery('#shurly_custom_restriction_container').toggle();",
    ),
  );
  $form['shurly_restrictions']['shurly_custom_restriction'] = array(
    '#type' => 'textfield',
    '#title' => t('Custom pattern'),
    '#description' => t('PERL regular expression defining a forbidden URL pattern.'),
    '#default_value' => variable_get('shurly_custom_restriction', FALSE),
    '#prefix' => '<div id="shurly_custom_restriction_container"' . (variable_get('shurly_forbid_custom', FALSE) ? '>' : ' style="display: none;">'),
    '#suffix' => '</div>',
  );
  $form['shurly_throttle'] = array(
    '#type' => 'fieldset',
    '#title' => t('Rate limiting'),
    '#tree' => TRUE,
    '#description' => t('Limit requests by IP address. Leave blank for no rate limiting.<br /><strong>Note:</strong> Only roles with the \'Create short URLs\' permission are listed here. Change that permission <a href="!url">here</a>.', array(
      '!url' => url('admin/user/permissions', array(
        'fragment' => 'module-shurly',
      )),
    )),
  );
  $saved = variable_get('shurly_throttle', array());
  foreach (user_roles(FALSE, 'Create short URLs') as $rid => $name) {
    $form['shurly_throttle'][$rid] = array(
      '#type' => 'fieldset',
      '#title' => $name,
      '#tree' => TRUE,
    );
    $form['shurly_throttle'][$rid]['rate'] = array(
      '#type' => 'textfield',
      '#size' => '3',
      '#prefix' => '<div class="container-inline">',
      '#field_suffix' => ' ' . t('requests'),
      '#default_value' => $saved[$rid]['rate'],
    );
    $form['shurly_throttle'][$rid]['time'] = array(
      '#type' => 'textfield',
      '#size' => '3',
      '#field_prefix' => t('within'),
      '#field_suffix' => ' ' . t('minutes'),
      '#default_value' => $saved[$rid]['time'],
      '#suffix' => '</div>',
    );
    $form['shurly_throttle'][$rid]['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight'),
      '#default_value' => isset($saved[$rid]['weight']) ? $saved[$rid]['weight'] : 0,
      '#description' => t('Order of this role when considering a user with multiple roles. A user\'s lightest role will take precedence.'),
    );
  }
  return system_settings_form($form);
}