From 6777fdb193fb9db01243082b4181ef7637c4ac91 Mon Sep 17 00:00:00 2001 From: Steven Wittens Date: Fri, 21 Oct 2005 11:12:46 +0000 Subject: - #26583: Make forum taxonomy links redirect to forums rather than taxonomy pages. --- modules/taxonomy/taxonomy.module | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'modules/taxonomy/taxonomy.module') diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 7d5808ceb..d4c4431ff 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -30,18 +30,26 @@ function taxonomy_link($type, $node = NULL) { if (array_key_exists('taxonomy', $node)) { foreach ($node->taxonomy as $tid) { $term = taxonomy_get_term($tid); - $links[] = l($term->name, 'taxonomy/term/'. $term->tid); + $links[] = l($term->name, taxonomy_term_path($term)); } } else { foreach (taxonomy_node_get_terms($node->nid) as $term) { - $links[] = l($term->name, 'taxonomy/term/'. $term->tid); + $links[] = l($term->name, taxonomy_term_path($term)); } } return $links; } } +function taxonomy_term_path($term) { + $vocabulary = taxonomy_get_vocabulary($term->vid); + if ($vocabulary->module != 'taxonomy' && $path = module_invoke($vocabulary->module, 'term_path', $term)) { + return $path; + } + return 'taxonomy/term/'. $term->tid; +} + /** * Implementation of hook_menu(). */ @@ -866,16 +874,20 @@ function taxonomy_get_term_by_name($name) { * Return the vocabulary object matching a vocabulary ID. */ function taxonomy_get_vocabulary($vid) { - $result = db_query('SELECT v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE v.vid = %d ORDER BY v.weight, v.name', $vid); - $node_types = array(); - while ($voc = db_fetch_object($result)) { - $node_types[] = $voc->type; - unset($voc->type); - $voc->nodes = $node_types; - $vocabulary = $voc; + static $vocabularies = array(); + + if (!array_key_exists($vid, $vocabularies)) { + $result = db_query('SELECT v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE v.vid = %d ORDER BY v.weight, v.name', $vid); + $node_types = array(); + while ($voc = db_fetch_object($result)) { + $node_types[] = $voc->type; + unset($voc->type); + $voc->nodes = $node_types; + $vocabularies[$vid] = $voc; + } } - return $vocabulary; + return $vocabularies[$vid]; } /** -- cgit v1.2.3