| 1 |
<?php |
<?php |
| 2 |
// $Id: taxonomy_context.module,v 1.82.4.7 2009/10/03 03:00:02 nancyw Exp $ |
// $Id: taxonomy_context.module,v 1.82.4.8 2009/10/03 18:47:10 nancyw Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 311 |
function taxonomy_context_get_context() { |
function taxonomy_context_get_context() { |
| 312 |
static $context; |
static $context; |
| 313 |
if (!isset($context)) { |
if (!isset($context)) { |
| 314 |
$context = array('tid' => NULL, 'root_tid' => NULL, 'nid' => NULL, "vid" => NULL); |
$context = array( |
| 315 |
|
'tid' => 0, |
| 316 |
|
'root_tid' => 0, |
| 317 |
|
'nid' => NULL, |
| 318 |
|
'vid' => NULL, |
| 319 |
|
'depth' => NULL, |
| 320 |
|
'term' => NULL, |
| 321 |
|
'parents' => array(), |
| 322 |
|
); |
| 323 |
$mode = arg(0); |
$mode = arg(0); |
| 324 |
switch ($mode) { |
switch ($mode) { |
| 325 |
// If the taxonomy_list module is also enabled, our path becomes "context/vocabulary". |
// If the taxonomy_list module is also enabled, our path becomes "context/vocabulary". |
| 327 |
case 'taxonomy': |
case 'taxonomy': |
| 328 |
switch (arg(1)) { |
switch (arg(1)) { |
| 329 |
case 'vocabulary': |
case 'vocabulary': |
|
$context['tid'] = 0; |
|
|
$context['root_tid'] = 0; |
|
| 330 |
$context['vid'] = ((int)arg(2)) ? arg(2) : 1; |
$context['vid'] = ((int)arg(2)) ? arg(2) : 1; |
| 331 |
break; |
break; |
| 332 |
case 'term': |
case 'term': |
| 333 |
$tidcurrs = preg_split('/[+ ,]/', arg(2)); |
$tidcurrs = preg_split('/[+ ,]/', arg(2)); |
| 334 |
$context['tid'] = $tidcurrs[0]; |
$tid = $context['tid'] = $tidcurrs[0]; |
| 335 |
$parents = taxonomy_get_parents_all($tid); |
$parents = $context['parents'] = taxonomy_get_parents_all($tid); |
| 336 |
// Note that list() is right to left, so it gets the last element. |
// Note that list() is right to left, so it gets the last element. |
| 337 |
list($top_parent) = $parents; |
list($top_parent) = $parents; |
| 338 |
$context['root_tid'] = $top_parent->tid; |
$context['root_tid'] = $top_parent->tid; |
| 339 |
$term = taxonomy_get_term($context['tid']); |
// Taxonomy_get_term does not supply depth. |
| 340 |
|
// The only way to get that is from a tree. |
| 341 |
|
$tree = taxonomy_get_tree($top_parent->vid); |
| 342 |
|
foreach ($tree as $index => $term) { |
| 343 |
|
if ($term->tid == $tid) { |
| 344 |
|
$context['depth'] = $term->depth; |
| 345 |
|
break; |
| 346 |
|
} |
| 347 |
|
} |
| 348 |
$context['vid'] = $term->vid; |
$context['vid'] = $term->vid; |
| 349 |
|
$context['term'] = $term; |
| 350 |
break; |
break; |
| 351 |
} |
} |
| 352 |
break; |
break; |
| 516 |
$context = taxonomy_context_get_context(); |
$context = taxonomy_context_get_context(); |
| 517 |
} |
} |
| 518 |
$parents = array(); |
$parents = array(); |
| 519 |
$parents_terms = array_reverse(taxonomy_get_parents_all($context->tid)); |
$parents_terms = array_reverse($context->parents); |
| 520 |
foreach ($parents_terms as $parent) { |
foreach ($parents_terms as $parent) { |
| 521 |
$parents[] = $parent->tid; |
$parents[] = $parent->tid; |
| 522 |
} |
} |