You are here

function pathauto_admin_settings in Pathauto 5.2

Same name and namespace in other branches
  1. 5 pathauto.module \pathauto_admin_settings()
  2. 6 pathauto.admin.inc \pathauto_admin_settings()

Form builder; Configure the Pathauto system.

See also

system_settings_form()

1 string reference to 'pathauto_admin_settings'
pathauto_menu in ./pathauto.module
Implementation of hook_menu().

File

./pathauto.module, line 418
Main file for the Pathauto module, which automatically generates aliases for content.

Code

function pathauto_admin_settings() {
  _pathauto_include();

  // Make sure they have token
  if (!function_exists('token_get_list')) {
    drupal_set_message(t('It appears that the <a href="@token_link">Token module</a> is not installed. Please ensure that you have it installed so that Pathauto can work properly. You may need to disable Pathauto and re-enable it to get Token enabled.', array(
      '@token_link' => 'http://drupal.org/project/token',
    )), 'error');
    return;
  }

  // Default words to ignore
  $ignore_words = array(
    'a',
    'an',
    'as',
    'at',
    'before',
    'but',
    'by',
    'for',
    'from',
    'is',
    'in',
    'into',
    'like',
    'of',
    'off',
    'on',
    'onto',
    'per',
    'since',
    'than',
    'the',
    'this',
    'that',
    'to',
    'up',
    'via',
    'with',
  );

  // Generate the form - settings applying to all patterns first
  $group_weight = -20;
  $form['general'] = array(
    '#type' => 'fieldset',
    '#weight' => $group_weight,
    '#title' => t('General settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $group_weight++;
  $form['general']['pathauto_verbose'] = array(
    '#type' => 'checkbox',
    '#title' => t('Verbose'),
    '#default_value' => variable_get('pathauto_verbose', FALSE),
    '#description' => t('Display alias changes (except during bulk updates).'),
  );
  $form['general']['pathauto_separator'] = array(
    '#type' => 'textfield',
    '#title' => t('Separator'),
    '#size' => 1,
    '#maxlength' => 1,
    '#default_value' => variable_get('pathauto_separator', '-'),
    '#description' => t('Character used to separate words in titles. This will replace any spaces and punctuation characters. Using a space or + character can cause unexpected results.'),
  );
  $form['general']['pathauto_case'] = array(
    '#type' => 'radios',
    '#title' => t('Character case'),
    '#default_value' => variable_get('pathauto_case', 1),
    '#options' => array(
      t('Leave case the same as source token values.'),
      t('Change to lower case'),
    ),
  );
  $form['general']['pathauto_max_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum alias length'),
    '#size' => 3,
    '#maxlength' => 3,
    '#default_value' => variable_get('pathauto_max_length', 100),
    '#description' => t('Maximum length of aliases to generate. 100 is recommended. See <a href="@pathauto-help">Pathauto help</a> for details.', array(
      '@pathauto-help' => url('admin/help/pathauto'),
    )),
  );
  $form['general']['pathauto_max_component_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum component length'),
    '#size' => 3,
    '#maxlength' => 3,
    '#default_value' => variable_get('pathauto_max_component_length', 100),
    '#description' => t('Maximum text length of any component in the alias (e.g., [title]). 100 is recommended. See <a href="@pathauto-help">Pathauto help</a> for details.', array(
      '@pathauto-help' => url('admin/help/pathauto'),
    )),
  );
  $form['general']['pathauto_max_bulk_update'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum number of objects to alias in a bulk update'),
    '#size' => 4,
    '#maxlength' => 4,
    '#default_value' => variable_get('pathauto_max_bulk_update', 50),
    '#description' => t('Maximum number of objects of a given type which should be aliased during a bulk update. The default is 50 and the recommended number depends on the speed of your server. If bulk updates "time out" or result in a "white screen" then reduce the number.'),
  );
  $actions = array(
    t('Do nothing. Leave the old alias intact.'),
    t('Create a new alias. Leave the existing alias functioning.'),
    t('Create a new alias. Delete the old alias.'),
  );
  if (function_exists('path_redirect_save')) {
    $actions[] = t('Create a new alias. Redirect from old alias.');
  }
  elseif (variable_get('pathauto_update_action', 2) == 3) {

    // the redirect action is selected, but path_redirect is not enabled
    // let's set the variable back to the default
    variable_set('pathauto_update_action', 2);
  }
  $form['general']['pathauto_update_action'] = array(
    '#type' => 'radios',
    '#title' => t('Update action'),
    '#default_value' => variable_get('pathauto_update_action', 2),
    '#options' => $actions,
    '#description' => t('What should pathauto do when updating an existing content item which already has an alias?'),
  );
  $disable_transliteration = TRUE;
  $path = drupal_get_path('module', 'pathauto');
  $transliteration_help = t('When a pattern includes certain characters (such as those with accents) should Pathauto attempt to transliterate them into the ASCII-96 alphabet? Transliteration is determined by the i18n-ascii.txt file in the Pathauto directory. <strong>This option is disabled on your site because you do not have an i18n-ascii.txt file in the Pathauto directory.</strong>');
  if (is_file($path . '/i18n-ascii.txt')) {
    $disable_transliteration = FALSE;
    $transliteration_help = t('When a pattern includes certain characters (such as those with accents) should Pathauto attempt to transliterate them into the ASCII-96 alphabet? Transliteration is determined by the i18n-ascii.txt file in the Pathauto directory.');
  }
  else {

    // Perhaps they've removed the file, set the transliterate option to FALSE
    variable_set('pathauto_transliterate', FALSE);
  }
  $form['general']['pathauto_transliterate'] = array(
    '#type' => 'checkbox',
    '#title' => t('Transliterate prior to creating alias'),
    '#default_value' => variable_get('pathauto_transliterate', FALSE),
    '#description' => $transliteration_help,
    '#disabled' => $disable_transliteration,
  );
  $form['general']['pathauto_reduce_ascii'] = array(
    '#type' => 'checkbox',
    '#title' => t('Reduce strings to letters and numbers from ASCII-96'),
    '#default_value' => variable_get('pathauto_reduce_ascii', FALSE),
    '#description' => t('Filters the new alias to only letters and numbers found in the ASCII-96 set.'),
  );
  $form['general']['pathauto_ignore_words'] = array(
    '#type' => 'textarea',
    '#title' => t('Strings to Remove'),
    '#default_value' => variable_get('pathauto_ignore_words', implode(',', $ignore_words)),
    '#description' => t('Words to strip out of the URL alias, separated by commas. Do not place punctuation in here and do not use WYSIWYG editors on this field.'),
  );
  $form['punctuation'] = array(
    '#type' => 'fieldset',
    '#weight' => $group_weight,
    '#title' => t('Punctuation settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $group_weight++;
  $punctuation = pathauto_punctuation_chars();
  foreach ($punctuation as $name => $details) {
    $form['punctuation']['pathauto_punctuation_' . $name] = array(
      '#type' => 'select',
      '#title' => $details['name'],
      '#default_value' => variable_get('pathauto_punctuation_' . $name, 0),
      '#options' => array(
        '0' => t('Remove'),
        '1' => t('Replace by separator'),
        '2' => t('No action (do not replace)'),
      ),
    );
  }

  // Call the hook on all modules - an array of 'settings' objects is returned
  $all_settings = module_invoke_all('pathauto', 'settings');
  $modulelist = '';
  $indexcount = 0;
  foreach ($all_settings as $settings) {
    $items = '';
    $module = $settings->module;
    $modulelist[] = $module;
    $patterndescr = $settings->patterndescr;
    $patterndefault = $settings->patterndefault;
    $groupheader = $settings->groupheader;
    $supportsfeeds = isset($settings->supportsfeeds) ? $settings->supportsfeeds : NULL;
    variable_set('pathauto_' . $module . '_supportsfeeds', $supportsfeeds);
    $form[$module] = array(
      '#type' => 'fieldset',
      '#title' => $groupheader,
      '#weight' => $group_weight,
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $group_weight++;

    // Prompt for the default pattern for this module
    $variable = 'pathauto_' . $module . '_pattern';
    $description = '';
    if (!count($_POST)) {
      $error = _pathauto_check_pattern(variable_get($variable, $patterndefault), $settings->token_type);
      if ($error) {
        $form[$module]['#collapsed'] = FALSE;
        $description = $error;
      }
    }
    $form[$module][$variable] = array(
      '#type' => 'textfield',
      '#title' => $patterndescr,
      '#default_value' => variable_get($variable, $patterndefault),
      '#description' => $description,
      '#size' => 65,
      '#maxlength' => 1280,
    );

    // If the module supports a set of specialized patterns, set
    // them up here
    if (isset($settings->patternitems)) {
      foreach ($settings->patternitems as $itemname => $itemlabel) {
        $variable = 'pathauto_' . $module . '_' . $itemname . '_pattern';
        $description = '';
        if (!count($_POST)) {
          $error = _pathauto_check_pattern(variable_get($variable, $patterndefault), $settings->token_type);
          if ($error) {
            $form[$module]['#collapsed'] = FALSE;
            $description = $error;
          }
        }
        $form[$module][$variable] = array(
          '#type' => 'textfield',
          '#title' => $itemlabel,
          '#default_value' => variable_get($variable, ''),
          '#description' => $description,
          '#size' => 65,
          '#maxlength' => 1280,
        );
      }
    }

    // Display the user documentation of placeholders supported by
    // this module, as a description on the last pattern
    $doc = "<dl>\n";
    foreach ($settings->placeholders as $name => $description) {
      $doc .= '<dt>' . $name . '</dt>';
      $doc .= '<dd>' . $description . '</dd>';
    }
    $doc .= "</dl>\n";
    $form[$module]['token_help'] = array(
      '#title' => t('Replacement patterns'),
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#description' => t('Use -raw replacements for text to avoid problems with HTML entities.'),
    );
    $form[$module]['token_help']['help'] = array(
      '#value' => $doc,
    );

    // If the module supports bulk updates, offer the update action here
    if ($settings->bulkname) {
      $variable = 'pathauto_' . $module . '_bulkupdate';
      if (variable_get($variable, FALSE)) {
        variable_set($variable, FALSE);
        $function = $module . '_pathauto_bulkupdate';
        call_user_func($function);
      }
      $form[$module][$variable] = array(
        '#type' => 'checkbox',
        '#title' => $settings->bulkname,
        '#default_value' => FALSE,
        '#description' => $settings->bulkdescr,
      );
    }

    // If the module supports feeds, offer to generate aliases for them
    if ($supportsfeeds) {
      $variable = 'pathauto_' . $module . '_applytofeeds';
      $current = variable_get($variable, $supportsfeeds);

      // This checks for the old style from 2.0 and earlier. TODO: At some point we can drop that.
      if (is_numeric($current)) {
        $current = $supportsfeeds;
      }
      $form[$module][$variable] = array(
        '#type' => 'textfield',
        '#title' => t('Internal feed alias text (leave blank to disable)'),
        '#size' => 65,
        '#maxlength' => 1280,
        '#default_value' => $current,
        '#description' => t('The text to use for aliases for RSS feeds. Examples are "feed" and "0/feed".'),
      );
    }
  }
  if (isset($do_index_bulkupdate) && $do_index_bulkupdate) {
    drupal_set_message(format_plural($indexcount, 'Bulk generation of index aliases completed, one alias generated.', 'Bulk generation of index aliases completed, @count aliases generated.'));
  }

  // Keep track of which modules currently support pathauto
  variable_set('pathauto_modulelist', $modulelist);
  return system_settings_form($form);
}