You are here

function pathauto_clean_alias in Pathauto 7

Same name and namespace in other branches
  1. 6.2 pathauto.inc \pathauto_clean_alias()
  2. 6 pathauto.inc \pathauto_clean_alias()

Clean up an URL alias.

Performs the following alterations:

  • Trim duplicate, leading, and trailing back-slashes.
  • Trim duplicate, leading, and trailing separators.
  • Shorten to a desired length and logical position based on word boundaries.

Parameters

string $alias: A string with the URL alias to clean up.

Return value

string The cleaned URL alias.

2 calls to pathauto_clean_alias()
PathautoUnitTestCase::testCleanAlias in ./pathauto.test
Test pathauto_clean_alias().
pathauto_create_alias in ./pathauto.inc
Apply patterns to create an alias.

File

./pathauto.inc, line 301
Miscellaneous functions for Pathauto.

Code

function pathauto_clean_alias($alias) {
  $cache =& drupal_static(__FUNCTION__);
  if (!isset($cache)) {
    $cache = array(
      'maxlength' => min(variable_get('pathauto_max_length', 100), _pathauto_get_schema_alias_maxlength()),
    );
  }
  $output = $alias;

  // Trim duplicate, leading, and trailing separators. Do this before cleaning
  // backslashes since a pattern like "[token1]/[token2]-[token3]/[token4]"
  // could end up like "value1/-/value2" and if backslashes were cleaned first
  // this would result in a duplicate blackslash.
  $output = _pathauto_clean_separators($output);

  // Trim duplicate, leading, and trailing backslashes.
  $output = _pathauto_clean_separators($output, '/');

  // Shorten to a logical place based on word boundaries.
  $output = truncate_utf8($output, $cache['maxlength'], TRUE);
  return $output;
}