| 1 |
<?php |
<?php |
| 2 |
// $Id: taxonomy_menu.inc,v 1.2.2.1 2008/09/08 19:37:23 afief Exp $ |
// $Id: taxonomy_menu.inc,v 1.2.2.2 2008/09/09 11:54:04 afief Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @author Jonathan Chaffer <jchaffer@structureinteractive.com> |
* @author Jonathan Chaffer <jchaffer@structureinteractive.com> |
| 161 |
'weight' => $vocab->weight |
'weight' => $vocab->weight |
| 162 |
); |
); |
| 163 |
|
|
| 164 |
$tree = taxonomy_get_tree($vocab->vid); |
//use helper function so it does not pull the tree from the cache. Issue #339672 |
| 165 |
|
$tree = _taxonomy_menu_taxonomy_get_tree($vocab->vid); |
| 166 |
$old_depth = -1; |
$old_depth = -1; |
| 167 |
$old_path = $path; |
$old_path = $path; |
| 168 |
|
|
| 329 |
// If no content found, return a "error" message |
// If no content found, return a "error" message |
| 330 |
return empty($output) ? t('No content for this category.') : $output; |
return empty($output) ? t('No content for this category.') : $output; |
| 331 |
} |
} |
| 332 |
|
|
| 333 |
|
/** |
| 334 |
|
* Helper function to retrieve the terms while avoiding the cache |
| 335 |
|
* |
| 336 |
|
* Issue #339672 |
| 337 |
|
* |
| 338 |
|
* @param <type> $vid |
| 339 |
|
* @param <type> $parent |
| 340 |
|
* @param <type> $depth |
| 341 |
|
* @param <type> $max_depth |
| 342 |
|
* @return <type> |
| 343 |
|
*/ |
| 344 |
|
function _taxonomy_menu_taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL) { |
| 345 |
|
|
| 346 |
|
$depth++; |
| 347 |
|
|
| 348 |
|
//** Removed from taxonomy_get_tree version START |
| 349 |
|
// We cache trees, so it's not CPU-intensive to call get_tree() on a term |
| 350 |
|
// and its children, too. |
| 351 |
|
//if (!isset($children[$vid])) { |
| 352 |
|
//** Removed from taxonomy_get_tree version END |
| 353 |
|
$children[$vid] = array(); |
| 354 |
|
|
| 355 |
|
$result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid); |
| 356 |
|
while ($term = db_fetch_object($result)) { |
| 357 |
|
$children[$vid][$term->parent][] = $term->tid; |
| 358 |
|
$parents[$vid][$term->tid][] = $term->parent; |
| 359 |
|
$terms[$vid][$term->tid] = $term; |
| 360 |
|
} |
| 361 |
|
//** Removed from taxonomy_get_tree version START |
| 362 |
|
//} |
| 363 |
|
//** Removed from taxonomy_get_tree version END |
| 364 |
|
|
| 365 |
|
$max_depth = (is_null($max_depth)) ? count($children[$vid]) : $max_depth; |
| 366 |
|
$tree = array(); |
| 367 |
|
if (!empty($children[$vid][$parent])) { |
| 368 |
|
foreach ($children[$vid][$parent] as $child) { |
| 369 |
|
if ($max_depth > $depth) { |
| 370 |
|
$term = drupal_clone($terms[$vid][$child]); |
| 371 |
|
$term->depth = $depth; |
| 372 |
|
// The "parent" attribute is not useful, as it would show one parent only. |
| 373 |
|
unset($term->parent); |
| 374 |
|
$term->parents = $parents[$vid][$child]; |
| 375 |
|
$tree[] = $term; |
| 376 |
|
|
| 377 |
|
if (!empty($children[$vid][$child])) { |
| 378 |
|
$tree = array_merge($tree, taxonomy_get_tree($vid, $child, $depth, $max_depth)); |
| 379 |
|
} |
| 380 |
|
} |
| 381 |
|
} |
| 382 |
|
} |
| 383 |
|
|
| 384 |
|
return $tree; |
| 385 |
|
} |
| 386 |
|
|