| 1 |
<?php |
<?php |
| 2 |
// $Id: taxonomy_breadcrumb.inc,v 1.1 2009/01/12 02:19:26 mgn Exp $ |
// $Id: $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 14 |
* in the system table and is set in taxonomy_breadcrumb.install). |
* in the system table and is set in taxonomy_breadcrumb.install). |
| 15 |
*/ |
*/ |
| 16 |
function _taxonomy_breadcrumb_term_page($str_tids = '', $depth = 0, $op = 'page') { |
function _taxonomy_breadcrumb_term_page($str_tids = '', $depth = 0, $op = 'page') { |
| 17 |
// Include the .inc file with all helper functions |
static $callback = array(); |
| 18 |
require_once(drupal_get_path('module', 'taxonomy') .'/taxonomy.pages.inc'); |
if (empty($callback)) { |
| 19 |
|
$callback = variable_get('taxonomy_breadcrumb_override_callback', array() ); |
| 20 |
// Call the core taxonomy_term_page function |
if (!empty($callback)) { |
| 21 |
$output = taxonomy_term_page($str_tids, $depth, $op); |
$require_path = isset($callback['file path']) ? $callback['file path'] : drupal_get_path('module', $callback['module']); |
| 22 |
|
require_once($require_path .'/'. $callback['file']); |
| 23 |
|
} |
| 24 |
|
else { |
| 25 |
|
// Default to core taxonomy_term_page callback. |
| 26 |
|
// Include the .inc file with all helper functions. |
| 27 |
|
require_once(drupal_get_path('module', 'taxonomy') .'/taxonomy.pages.inc'); |
| 28 |
|
} |
| 29 |
|
} |
| 30 |
|
if (isset($callback['page callback'])) { |
| 31 |
|
$func = $callback['page callback']; |
| 32 |
|
// Assume that any function overriding the core taxonomy function would have the same parameters. |
| 33 |
|
$output = $func($str_tids, $depth, $op); |
| 34 |
|
} |
| 35 |
|
else { |
| 36 |
|
// Call the core taxonomy_term_page function. |
| 37 |
|
$output = taxonomy_term_page($str_tids, $depth, $op); |
| 38 |
|
} |
| 39 |
|
|
| 40 |
// Use first term to generate breadcrumb trail |
// Use first term to generate breadcrumb trail. |
| 41 |
$terms = taxonomy_terms_parse_string($str_tids); |
$terms = taxonomy_terms_parse_string($str_tids); |
| 42 |
$breadcrumb = _taxonomy_breadcrumb_generate_breadcrumb($terms['tids'][0], TRUE); |
$breadcrumb = _taxonomy_breadcrumb_generate_breadcrumb($terms['tids'][0], TRUE); |
| 43 |
drupal_set_breadcrumb($breadcrumb); |
drupal_set_breadcrumb($breadcrumb); |
| 50 |
* lightest vocab for the node. |
* lightest vocab for the node. |
| 51 |
*/ |
*/ |
| 52 |
function _taxonomy_breadcrumb_node_get_lightest_term($nid) { |
function _taxonomy_breadcrumb_node_get_lightest_term($nid) { |
| 53 |
// We only want the first row of the result--this is the lightest term of the |
|
| 54 |
// lightest vocab. This query should be the same as the query found in |
/* We only want the first row of the result--this is the lightest term of the |
| 55 |
// taxonomy_node_get_terms. |
* lightest vocab. This query should be the same as the query found in |
| 56 |
|
* taxonomy_node_get_terms. |
| 57 |
|
*/ |
| 58 |
$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); |
$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); |
| 59 |
$term = db_fetch_object($result); // extract first row of query |
// Extract the first row of query. |
| 60 |
|
$term = db_fetch_object($result); |
| 61 |
return $term; |
return $term; |
| 62 |
} |
} |
| 63 |
|
|
| 95 |
|
|
| 96 |
$term = taxonomy_get_term($tid); |
$term = taxonomy_get_term($tid); |
| 97 |
|
|
| 98 |
// HOME breadcrumb generation |
// Generate the HOME breadcrumb. |
| 99 |
$home_text = variable_get('taxonomy_breadcrumb_home', ''); |
$home_text = variable_get('taxonomy_breadcrumb_home', ''); |
| 100 |
if ($home_text != '') { |
if ($home_text != '') { |
| 101 |
$breadcrumb[] = l(t($home_text), NULL); |
$breadcrumb[] = l(t($home_text), NULL); |
| 102 |
} |
} |
| 103 |
// VOCABULARY breadcrumb generation |
// Generate the VOCABULARY breadcrumb. |
| 104 |
$vocabulary_path = _taxonomy_breadcrumb_get_vocabulary_path($term->vid); |
$vocabulary_path = _taxonomy_breadcrumb_get_vocabulary_path($term->vid); |
| 105 |
if ($vocabulary_path != NULL) { |
if ($vocabulary_path != NULL) { |
| 106 |
$vocabulary = taxonomy_vocabulary_load($term->vid); |
$vocabulary = taxonomy_vocabulary_load($term->vid); |
| 107 |
$breadcrumb[] = l(_taxonomy_breadcrumb_tt("taxonomy:vocabulary:$term->tid:name", $vocabulary->name), $vocabulary_path); |
$breadcrumb[] = l(_taxonomy_breadcrumb_tt("taxonomy:vocabulary:$term->tid:name", $vocabulary->name), $vocabulary_path); |
| 108 |
} |
} |
| 109 |
|
|
| 110 |
// TERM breadcrumb generation |
// Generate the TERM breadcrumb. |
| 111 |
$parent_terms = array_reverse(taxonomy_get_parents_all($tid)); |
$parent_terms = array_reverse(taxonomy_get_parents_all($tid)); |
| 112 |
foreach ($parent_terms as $parent_term) { |
foreach ($parent_terms as $parent_term) { |
| 113 |
$term_path = _taxonomy_breadcrumb_get_term_path($parent_term->tid); |
$term_path = _taxonomy_breadcrumb_get_term_path($parent_term->tid); |
| 123 |
} |
} |
| 124 |
} |
} |
| 125 |
|
|
| 126 |
// Remove current TERM from end of breadcrumb trail |
// Optionally remove the current TERM from end of breadcrumb trail. |
| 127 |
if (!variable_get('taxonomy_breadcrumb_show_current_term', TRUE) && !is_null($breadcrumb)) { |
if (!variable_get('taxonomy_breadcrumb_show_current_term', TRUE) && !is_null($breadcrumb)) { |
| 128 |
array_pop($breadcrumb); |
array_pop($breadcrumb); |
| 129 |
} |
} |
| 130 |
return $breadcrumb; |
return $breadcrumb; |
|
|
|
| 131 |
} |
} |
| 132 |
|
|
|
|
|
| 133 |
/** |
/** |
| 134 |
* Helper function for when i18ntaxonomy module is not installed. |
* Helper function for when i18ntaxonomy module is not installed. |
| 135 |
*/ |
*/ |
| 136 |
|
|
| 137 |
function _taxonomy_breadcrumb_tt($string_id, $default, $language = NULL) { |
function _taxonomy_breadcrumb_tt($string_id, $default, $language = NULL) { |
|
|
|
| 138 |
return function_exists('tt') ? tt($string_id, $default, $language) : $default; |
return function_exists('tt') ? tt($string_id, $default, $language) : $default; |
| 139 |
} |
} |