You are here

function taxonomy_redirect_default_term_path in Taxonomy Redirect 6

Same name and namespace in other branches
  1. 5 taxonomy_redirect.module \taxonomy_redirect_default_term_path()

Builds the default taxonomy_redirect term path. Can be overridden by the creation of a taxonomy_redirect_custom_term_path function

1 call to taxonomy_redirect_default_term_path()
taxonomy_redirect_term_path in ./taxonomy_redirect.module
Implementation of hook_term_path() from the taxonomy module.

File

./taxonomy_redirect.module, line 571

Code

function taxonomy_redirect_default_term_path($term, $path, $separator = NULL, $remove_text = NULL, $path_case = 'No transform') {
  $parents = taxonomy_get_parents_all($term->tid);
  $parents = array_reverse($parents);

  // Remove the child term from the array
  array_pop($parents);
  $parent_path = '';
  $parent_names = '';
  $parent_ids = '';
  foreach ($parents as $parent) {
    $parent_names = $parent_names ? $parent_names . '/' . $parent->name : $parent->name;
    $parent_ids = $parent_ids ? $parent_ids . '/' . $parent->tid : $parent->tid;
  }
  $path = t($path, array(
    '!tid' => $term->tid,
    '!name' => $term->name,
    '!parent_names' => $parent_names,
    '!parent_ids' => $parent_ids,
  ));

  // Remove text if necessary
  $text = array_filter(preg_split("/\n|\r/", $remove_text), 'taxonomy_redirect_filter_empty_lines');
  if (count($text) != 0) {
    $path = str_replace($text, "", $path);
  }

  // Replace separators if necessary.
  if ($separator || $separator === '0') {
    $path = str_replace(array(
      ' ',
      '+',
    ), $separator, $path);
  }

  // Change case if necessary
  switch ($path_case) {
    case 'No transform':
      break;
    case 'Uppercase':
      $path = strtoupper($path);
      break;
    case 'Lowercase':
      $path = strtolower($path);
      break;
  }

  // Remove any multiple slashes - They may have been created by !parent_names or !parent_ids being empty.
  while (strpos($path, '//') !== FALSE) {
    $path = str_replace('//', '/', $path);
  }

  // remove any leading slashes, they will break the url() and l() functions
  while (strpos($path, '/') === 0) {
    $path = substr($path, 1);
  }
  return $path;
}