You are here

function pathauto_admin_settings in Pathauto 5

Same name and namespace in other branches
  1. 5.2 pathauto.module \pathauto_admin_settings()
  2. 6 pathauto.admin.inc \pathauto_admin_settings()
1 string reference to 'pathauto_admin_settings'
pathauto_menu in ./pathauto.module

File

./pathauto.module, line 39

Code

function pathauto_admin_settings() {

  // Restrict administration of this module
  if (!user_access('administer pathauto')) {
    $form["error"] = array(
      '#type' => 'item',
      '#title' => t('You are not authorized to access the pathauto settings.'),
    );
    return system_settings_form($form);
  }
  $output = '';

  // Check for any updates
  _pathauto_update();

  // 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.'),
  );
  $form["general"]["pathauto_quotes"] = array(
    '#type' => 'radios',
    '#title' => t('Quotation marks'),
    '#default_value' => variable_get('pathauto_quotes', 0),
    '#options' => array(
      t('Remove'),
      t('Replace by separator'),
    ),
  );
  $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_indexaliases"] = array(
    '#type' => 'checkbox',
    '#title' => t('Create index aliases'),
    '#default_value' => variable_get('pathauto_indexaliases', FALSE),
    '#description' => t('When a pattern generates a hierarchical alias (i.e., any alias containing a slash), generate aliases for each step of the hierarchy which can be used to list content within that hierarchy. For example, if a node alias "music/concert/beethoven" is created, also create an alias "music/concert" which will list all concert nodes, and an alias "music" which will list all music nodes.'),
  );

  // If requested, do a bulk generation of index aliases
  $do_index_bulkupdate = variable_get('pathauto_indexaliases_bulkupdate', FALSE);
  variable_set('pathauto_indexaliases_bulkupdate', FALSE);
  $form["general"]["pathauto_indexaliases_bulkupdate"] = array(
    '#type' => 'checkbox',
    '#title' => t('Bulk generate index aliases'),
    '#default_value' => FALSE,
    '#description' => t('Generate index aliases based on all pre-existing aliases.'),
  );
  $form["general"]["pathauto_update_action"] = array(
    '#type' => 'radios',
    '#title' => t('Update action'),
    '#default_value' => variable_get('pathauto_update_action', 2),
    '#options' => array(
      t('Do nothing, leaving the old alias intact'),
      t('Create a new alias in addition to the old alias'),
      t('Create a new alias, replacing the old one'),
    ),
    '#description' => t('What should pathauto do when updating an existing content item which already has an alias?'),
  );
  $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'),
  );

  // 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';
    $form[$module][$variable] = array(
      '#type' => 'textfield',
      '#title' => $patterndescr,
      '#default_value' => variable_get($variable, $patterndefault),
      '#size' => 65,
      '#maxlength' => variable_get('pathauto_max_length', 100),
    );

    // 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';
        $form[$module][$variable] = array(
          '#type' => 'textfield',
          '#title' => $itemlabel,
          '#default_value' => variable_get($variable, ''),
          '#size' => 65,
          '#maxlength' => variable_get('pathauto_max_length', 100),
        );
      }
    }

    // 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][$variable]["#description"] = $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,
      );
    }

    // Perform bulk updates of indexes for this module, if asked
    if ($do_index_bulkupdate) {
      $function = $module . '_pathauto_bulkupdate_indexes';
      if (is_callable($function)) {
        $indexcount += call_user_func($function);
      }
    }

    // If the module supports feeds, offer to generate aliases for them
    if ($supportsfeeds) {
      $variable = 'pathauto_' . $module . '_applytofeeds';
      $form[$module][$variable] = array(
        '#type' => 'checkbox',
        '#title' => t('Create feed aliases'),
        '#default_value' => variable_get($variable, FALSE),
        '#description' => t('Also generate aliases for RSS feeds.'),
      );
    }
  }
  if ($do_index_bulkupdate) {
    drupal_set_message(format_plural($indexcount, "Bulk update of index aliases completed, one alias generated.", "Bulk update 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);
}