You are here

function pathauto_clean_token_values in Pathauto 6

Same name and namespace in other branches
  1. 5.2 pathauto.inc \pathauto_clean_token_values()
  2. 6.2 pathauto.inc \pathauto_clean_token_values()
  3. 7 pathauto.inc \pathauto_clean_token_values()

Clean tokens so they are URL friendly.

Parameters

$full: An array of token values from token_get_values() that need to be "cleaned" for use in the URL.

Return value

An array of the cleaned tokens.

1 call to pathauto_clean_token_values()
pathauto_get_placeholders in ./pathauto.inc
Generalized function to get tokens across all Pathauto types.

File

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

Code

function pathauto_clean_token_values($full, $options = array()) {
  $replacements = array();
  foreach ($full->values as $key => $value) {
    $token = $full->tokens[$key];
    if (strpos($token, 'path') !== FALSE && is_array($value) && !empty($options['pathauto'])) {

      // If the token name contains 'path', the token value is an array, and
      // the 'pathauto' option was passed to token_get_values(), then the token
      // should have each segment cleaned, and then glued back together to
      // construct a value resembling an URL.
      $segments = array_map('pathauto_cleanstring', $value);
      $replacements[$token] = implode('/', $segments);
    }
    elseif (preg_match('/(path|alias|url|url-brief)(-raw)?$/', $token)) {

      // Token name matches an URL-type name and should be left raw.
      $replacements[$token] = $value;
    }
    else {

      // Token is not an URL, so it should have its value cleaned.
      $replacements[$token] = pathauto_cleanstring($value);
    }
  }
  return $replacements;
}