| 1 |
<?php
|
| 2 |
// $Id: taxonomy_breadcrumb.inc,v 1.1 2009/01/12 02:19:26 mgn Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* helper functions for taxonomy_breadcrumb
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* This function overrides the core taxonomy_term_page. First, call the core
|
| 11 |
* taxonomy_term_page. Then, alter the breadcrumb trail. This module's
|
| 12 |
* hook_menu and a module weight greater than taxonomy's ensure this
|
| 13 |
* function gets called for the taxonomy/term path (the module weight is
|
| 14 |
* in the system table and is set in taxonomy_breadcrumb.install).
|
| 15 |
*/
|
| 16 |
function _taxonomy_breadcrumb_term_page($str_tids = '', $depth = 0, $op = 'page') {
|
| 17 |
// Include the .inc file with all helper functions
|
| 18 |
require_once drupal_get_path('module', 'taxonomy') .'/taxonomy.pages.inc';
|
| 19 |
|
| 20 |
// Call the core taxonomy_term_page function
|
| 21 |
$output = taxonomy_term_page($str_tids, $depth, $op);
|
| 22 |
|
| 23 |
// Use first term to generate breadcrumb trail
|
| 24 |
$terms = taxonomy_terms_parse_string($str_tids);
|
| 25 |
$breadcrumb = _taxonomy_breadcrumb_generate_breadcrumb($terms['tids'][0], TRUE);
|
| 26 |
drupal_set_breadcrumb($breadcrumb);
|
| 27 |
return $output;
|
| 28 |
}
|
| 29 |
|
| 30 |
/**
|
| 31 |
* Return lightest term for given node ($nid).
|
| 32 |
* Similar to taxonomy_node_get_terms, but only return the lightest term in the
|
| 33 |
* lightest vocab for the node.
|
| 34 |
*/
|
| 35 |
function _taxonomy_breadcrumb_node_get_lightest_term($nid) {
|
| 36 |
// We only want the first row of the result--this is the lightest term of the
|
| 37 |
// lightest vocab. This query should be the same as the query found in
|
| 38 |
// taxonomy_node_get_terms.
|
| 39 |
$result = db_query(db_rewrite_sql('SELECT t.* FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.nid = %d ORDER BY v.weight, t.weight, t.name', 't', 'tid'), $nid);
|
| 40 |
$term = db_fetch_object($result); // extract first row of query
|
| 41 |
return $term;
|
| 42 |
}
|
| 43 |
|
| 44 |
/**
|
| 45 |
* Return the administrator defined vocabulary path for a given vocabulary
|
| 46 |
* ($vid). If a path doesn't exist, NULL is returned.
|
| 47 |
*/
|
| 48 |
function _taxonomy_breadcrumb_get_vocabulary_path($vid) {
|
| 49 |
$result = db_query("SELECT path FROM {taxonomy_breadcrumb_vocabulary} WHERE vid = %d", $vid);
|
| 50 |
$path = NULL;
|
| 51 |
if ($row = db_fetch_array($result)) {
|
| 52 |
$path = $row['path'];
|
| 53 |
}
|
| 54 |
return $path;
|
| 55 |
}
|
| 56 |
|
| 57 |
/**
|
| 58 |
* Return the administrator defined term path for a given term ($tid).
|
| 59 |
* If a path doesn't exist, NULL is returned.
|
| 60 |
*/
|
| 61 |
function _taxonomy_breadcrumb_get_term_path($tid) {
|
| 62 |
$result = db_query("SELECT path FROM {taxonomy_breadcrumb_term} WHERE tid = %d", $tid);
|
| 63 |
$path = NULL;
|
| 64 |
if ($row = db_fetch_array($result)) {
|
| 65 |
$path = $row['path'];
|
| 66 |
}
|
| 67 |
return $path;
|
| 68 |
}
|
| 69 |
|
| 70 |
/**
|
| 71 |
* If the current drupal path (q=) is /node/nid, generate the breadcrumb trail
|
| 72 |
* based on nid.
|
| 73 |
*/
|
| 74 |
function _taxonomy_breadcrumb_generate_breadcrumb($tid, $is_term_page = FALSE) {
|
| 75 |
|
| 76 |
$term = taxonomy_get_term($tid);
|
| 77 |
|
| 78 |
// HOME breadcrumb generation
|
| 79 |
$home_text = variable_get('taxonomy_breadcrumb_home', '');
|
| 80 |
if ($home_text != '') {
|
| 81 |
$breadcrumb[] = l(t($home_text), NULL);
|
| 82 |
}
|
| 83 |
// VOCABULARY breadcrumb generation
|
| 84 |
$vocabulary_path = _taxonomy_breadcrumb_get_vocabulary_path($term->vid);
|
| 85 |
if ($vocabulary_path != NULL) {
|
| 86 |
$vocabulary = taxonomy_vocabulary_load($term->vid);
|
| 87 |
$breadcrumb[] = l(_taxonomy_breadcrumb_tt("taxonomy:vocabulary:$term->tid:name", $vocabulary->name), $vocabulary_path);
|
| 88 |
}
|
| 89 |
|
| 90 |
// TERM breadcrumb generation
|
| 91 |
$parent_terms = array_reverse(taxonomy_get_parents_all($tid));
|
| 92 |
foreach ($parent_terms as $parent_term) {
|
| 93 |
$term_path = _taxonomy_breadcrumb_get_term_path($parent_term->tid);
|
| 94 |
if ($term_path == NULL) {
|
| 95 |
$term_path = taxonomy_term_path(taxonomy_get_term($parent_term->tid));
|
| 96 |
}
|
| 97 |
// Do not create links to own self if we are on a taxonomy/term page.
|
| 98 |
if ($is_term_page && $parent_term->tid == $tid) {
|
| 99 |
$breadcrumb[] = _taxonomy_breadcrumb_tt("taxonomy:term:$parent_term->tid:name", $parent_term->name);
|
| 100 |
}
|
| 101 |
else {
|
| 102 |
$breadcrumb[] = l(_taxonomy_breadcrumb_tt("taxonomy:term:$parent_term->tid:name", $parent_term->name), $term_path);
|
| 103 |
}
|
| 104 |
}
|
| 105 |
|
| 106 |
// Remove current TERM from end of breadcrumb trail
|
| 107 |
if (!variable_get('taxonomy_breadcrumb_show_current_term', TRUE) && !is_null($breadcrumb)) {
|
| 108 |
array_pop($breadcrumb);
|
| 109 |
}
|
| 110 |
return $breadcrumb;
|
| 111 |
|
| 112 |
}
|
| 113 |
|
| 114 |
|
| 115 |
/**
|
| 116 |
* Helper function for when i18ntaxonomy module is not installed.
|
| 117 |
*/
|
| 118 |
|
| 119 |
function _taxonomy_breadcrumb_tt($string_id, $default, $language = NULL) {
|
| 120 |
|
| 121 |
return function_exists('tt') ? tt($string_id, $default, $language) : $default;
|
| 122 |
}
|