You are here

function auto_username_configuration in Automatic User Names 6

Same name and namespace in other branches
  1. 5 auto_username.module \auto_username_configuration()
1 string reference to 'auto_username_configuration'
auto_username_menu in ./auto_username.module
Implementation of hook_menu().

File

./auto_username.module, line 32

Code

function auto_username_configuration() {

  // Always run before pathauto
  if (module_exists('pathauto')) {
    $weight = db_result(db_query("SELECT weight FROM {system} WHERE name='auto_username'"));

    // update the weight in the system table
    db_query("UPDATE {system} SET weight=" . ($weight + 1) . " WHERE name='pathauto'");
  }
  $form = array();

  // Other module configuration.
  $form['aun_general_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('General settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );

  // The basic pattern.  Always supports PHP, as there's little value in not doing so.
  $form['aun_general_settings']['aun_pattern'] = array(
    '#type' => 'textarea',
    '#title' => t('Pattern for username'),
    '#description' => t('Enter the pattern for usernames.  You may use any of the tokens listed below.'),
    '#default_value' => variable_get('aun_pattern', ''),
  );
  $form['aun_general_settings']['token_help'] = array(
    '#title' => t('Replacement patterns'),
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('Note that profile fields that are not present in the user registration form will get replaced with an empty string when the account is created.  That is rarely desirable.  Also, values such as the user id are not available yet on user creation, so using them is not advisable.'),
  );
  $form['aun_general_settings']['token_help']['help'] = array(
    '#value' => theme('token_help', 'user'),
  );

  // Other module configuration.
  $form['aun_other_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Other settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['aun_other_settings']['aun_php'] = array(
    '#type' => 'checkbox',
    '#title' => t('Evaluate PHP in pattern.'),
    '#description' => t('If this box is checked, the pattern will be executed as PHP code after token substitution has taken place.  You must surround the PHP code in <?php and ?> tags.  Token replacement will take place before PHP code execution.  That means you can place tokens into the PHP code where you want that value to appear literally.'),
    '#default_value' => variable_get('aun_php', 0),
  );
  $form['aun_other_settings']['aun_update_on_edit'] = array(
    '#type' => 'checkbox',
    '#title' => t('Update on user edit'),
    '#description' => t('If this box is checked, the username will be reset any time the user\'s profile is updated.  That can help to enforce a username format, but may result in a user\'s login name changing unexpectedly.  It is best used in conjunction with an alternative login mechanism, such as OpenID or an e-mail address.'),
    '#default_value' => variable_get('aun_update_on_edit', 1),
  );
  $form['aun_other_settings']['aun_reduce_ascii'] = array(
    '#type' => 'checkbox',
    '#title' => t('Reduce strings to letters and numbers from ASCII-96'),
    '#default_value' => variable_get('aun_reduce_ascii', 0),
    '#description' => t('Filters the new username to only letters and numbers found in the ASCII-96 set.'),
  );
  $form['aun_other_settings']['aun_replace_whitespace'] = array(
    '#type' => 'checkbox',
    '#title' => t('Replace whitespace with separator.'),
    '#default_value' => variable_get('aun_replace_whitespace', 0),
    '#description' => t('Replace all whitespace in tokens with the separator character specified below.  Note that this will affect the tokens themselves, not the pattern specified above.  To avoid spaces entirely, ensure that the pattern above contains no spaces.'),
  );
  $form['aun_other_settings']['aun_separator'] = array(
    '#type' => 'textfield',
    '#title' => t('Separator'),
    '#description' => t('This value will be used in place of selected punctuation characters (see below).'),
    '#default_value' => variable_get('aun_separator', '-'),
  );
  $options = array(
    AUN_PUNCTUATION_REMOVE => t('Remove'),
    AUN_PUNCTUATION_REPLACE => t('Replace by separator'),
    AUN_PUNCTUATION_DO_NOTHING => t('No action (do not replace)'),
  );
  $form['punctuation'] = array(
    '#type' => 'fieldset',
    '#title' => t('Punctuation settings'),
    '#description' => t('The following replacement rules will be applied to each token.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  foreach (auto_username_punctuation_chars() as $name => $details) {
    $form['punctuation']['aun_punctuation_' . $name] = array(
      '#type' => 'select',
      '#title' => $details['name'],
      '#default_value' => variable_get('aun_punctuation_' . $name, AUN_PUNCTUATION_REMOVE),
      '#options' => $options,
    );
  }
  return system_settings_form($form);
}