| 1 |
<?php |
<?php |
| 2 |
// $Id: taxonomy_context.module,v 1.82.4.11 2009/10/05 18:23:10 nancyw Exp $ |
// $Id: taxonomy_context.module,v 1.82.4.12 2009/10/12 19:48:59 nancyw Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 221 |
$links['administer_'. $type] = array( |
$links['administer_'. $type] = array( |
| 222 |
'title' => t('edit !object_name', array('!object_name' => $object->name)), |
'title' => t('edit !object_name', array('!object_name' => $object->name)), |
| 223 |
'href' => 'admin/content/taxonomy/edit/'. $type .'/'. $object->$keys[$type], |
'href' => 'admin/content/taxonomy/edit/'. $type .'/'. $object->$keys[$type], |
| 224 |
'attributes' => array('title' => t('Edit this !type.', array('!type' => $type))) |
'attributes' => array('title' => t('Edit this !type.', array('!type' => $type))), |
| 225 |
|
'query' => drupal_get_destination(), |
| 226 |
); |
); |
| 227 |
} |
} |
| 228 |
|
|
| 230 |
} |
} |
| 231 |
|
|
| 232 |
/** |
/** |
| 233 |
* Add links to a term or vocabulary. |
* Implementation of hook_link_alter(). |
| 234 |
|
* Remove current term from taxonomy links. |
| 235 |
*/ |
*/ |
| 236 |
function taxonomy_context_get_links($type, &$object, $teaser = FALSE) { |
function taxonomy_context_link_alter(&$links, $node) { |
| 237 |
$object->links = module_invoke_all('link', $type, $object, $teaser); |
// Only do this on taxonomy/term/xxx if we want it. |
| 238 |
|
if (arg(0) == 'taxonomy' && arg(1) == 'term' && variable_get('taxonomy_context_suppress_current', 0)) { |
| 239 |
|
$tid = arg(2); |
| 240 |
|
unset($links["taxonomy_term_$tid"]); |
| 241 |
|
} |
| 242 |
} |
} |
| 243 |
|
|
| 244 |
/** |
/** |
| 294 |
function taxonomy_context_load($type, &$object) { |
function taxonomy_context_load($type, &$object) { |
| 295 |
$keys = array('term' => 'tid', 'vocabulary' => 'vid'); |
$keys = array('term' => 'tid', 'vocabulary' => 'vid'); |
| 296 |
$object->format = db_result(db_query('SELECT format FROM {taxonomy_context_'. $type .'} WHERE '. $keys[$type] .' = %d', $object->$keys[$type])); |
$object->format = db_result(db_query('SELECT format FROM {taxonomy_context_'. $type .'} WHERE '. $keys[$type] .' = %d', $object->$keys[$type])); |
|
// Get links. |
|
|
taxonomy_context_get_links($type, $object); |
|
|
} |
|
| 297 |
|
|
| 298 |
/** |
// Add links to a term or vocabulary. |
| 299 |
* Implementation of hook_link_alter(). |
$object->links = module_invoke_all('link', $type, $object, $teaser); |
| 300 |
* Remove current term from taxonomy links. |
|
| 301 |
*/ |
// If we want related terms, add them to the object now. |
| 302 |
function taxonomy_context_link_alter(&$links, $node) { |
if ($type == 'term') { |
| 303 |
// Only do this on taxonomy/term/xxx if we want it. |
if (variable_get('taxonomy_context_show_related', 0)) { |
| 304 |
if (arg(0) == 'taxonomy' && arg(1) == 'term' && variable_get('taxonomy_context_suppress_current', 0)) { |
$object->related = taxonomy_get_related($object->tid, 'name'); |
| 305 |
$tid = arg(2); |
} |
| 306 |
unset($links["taxonomy_term_$tid"]); |
if (variable_get('taxonomy_context_show_synonyms', 0)) { |
| 307 |
|
$object->synonyms = taxonomy_get_synonyms($object->tid); |
| 308 |
|
} |
| 309 |
} |
} |
| 310 |
} |
} |
| 311 |
|
|
| 538 |
} |
} |
| 539 |
|
|
| 540 |
/** |
/** |
|
* Display subterms. |
|
|
*/ |
|
|
function theme_taxonomy_context_subterms($terms) { |
|
|
$output = ''; |
|
|
if (count($terms)) { |
|
|
foreach ($terms as $term) { |
|
|
taxonomy_context_load('term', $term); |
|
|
$term->subterm = TRUE; |
|
|
$term->teaser = isset($term->description) ? node_teaser($term->description, isset($term->format) ? $term->format : NULL) : ''; |
|
|
$term = taxonomy_context_prepare($term, TRUE); |
|
|
$term->links = module_invoke_all('link', 'term', $term); |
|
|
$output .= theme('taxonomy_context_term', $term); |
|
|
} |
|
|
} |
|
|
return $output; |
|
|
} |
|
|
|
|
|
/** |
|
| 541 |
* Return a menu tree for a vocabulary. |
* Return a menu tree for a vocabulary. |
| 542 |
*/ |
*/ |
| 543 |
function taxonomy_context_menu_tree($vid, $tid = NULL) { |
function taxonomy_context_menu_tree($vid, $tid = NULL) { |
| 678 |
*/ |
*/ |
| 679 |
function taxonomy_context_theme() { |
function taxonomy_context_theme() { |
| 680 |
return array( |
return array( |
| 681 |
|
'taxonomy_context_related' => array( |
| 682 |
|
'arguments' => array('term'), |
| 683 |
|
'file' => 'taxonomy_context.theme.inc', |
| 684 |
|
), |
| 685 |
|
'taxonomy_context_synonyms' => array( |
| 686 |
|
'arguments' => array('term'), |
| 687 |
|
'file' => 'taxonomy_context.theme.inc', |
| 688 |
|
), |
| 689 |
'taxonomy_context_subterms' => array( |
'taxonomy_context_subterms' => array( |
| 690 |
'arguments' => array('terms'), |
'arguments' => array('terms'), |
| 691 |
), |
'file' => 'taxonomy_context.theme.inc', |
| 692 |
|
), |
| 693 |
'taxonomy_context_term' => array( |
'taxonomy_context_term' => array( |
| 694 |
'arguments' => array('term'), |
'arguments' => array('term'), |
| 695 |
), |
'file' => 'taxonomy_context.theme.inc', |
| 696 |
|
), |
| 697 |
'taxonomy_context_vocabulary' => array( |
'taxonomy_context_vocabulary' => array( |
| 698 |
'arguments' => array('vocabulary'), |
'arguments' => array('vocabulary'), |
| 699 |
), |
'file' => 'taxonomy_context.theme.inc', |
| 700 |
|
), |
| 701 |
'taxonomy_context_vocabulary_list' => array( |
'taxonomy_context_vocabulary_list' => array( |
| 702 |
'arguments' => array('vocabulary'), |
'arguments' => array('vocabulary'), |
| 703 |
), |
'file' => 'taxonomy_context.theme.inc', |
| 704 |
); |
), |
| 705 |
} |
); |
|
|
|
|
/** |
|
|
* Theme a term output. |
|
|
*/ |
|
|
function theme_taxonomy_context_term($term) { |
|
|
$indent_char = variable_get('taxonomy_context_subterm_indent', '—'); |
|
|
$type = $term->subterm ? 'subterm' : 'term'; |
|
|
$output = "<div class=\"$type-container\">\n <div class=\"$type\">\n"; |
|
|
$indent = str_repeat($indent_char, $term->depth) .' '; |
|
|
$img = taxonomy_image_display($term->tid, NULL, NULL, array('wrapper' => TRUE)); |
|
|
$name = tt("taxonomy:term:$term->tid:name", $term->name, NULL, TRUE); |
|
|
$level = 2 + $term->subterm; |
|
|
$output .= '<h' . $level . ' class="title">' |
|
|
. $img |
|
|
. $indent |
|
|
. l($name, taxonomy_term_path($term)) |
|
|
. "</h$level>"; |
|
|
$term->description = tt("taxonomy:term:$term->tid:description", $term->description, NULL, FALSE); |
|
|
$output .= '<div class="' . ($term->teaser ? 'teaser' : 'description') .'">' . $term->description . '</div>'; |
|
|
if ($term->links) { |
|
|
$output .= '<div class="links">'. theme('links', $term->links) . "</div>\n"; |
|
|
} |
|
|
if ($node_list = _taxonomy_context_get_titles($term->tid)) { |
|
|
$output .= theme('item_list', $node_list); |
|
|
} |
|
|
$output .= " </div>\n"; |
|
|
$output .= "</div>\n"; |
|
|
return $output; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Theme a vocabulary output. |
|
|
*/ |
|
|
function theme_taxonomy_context_vocabulary($vocabulary) { |
|
|
$output .= "<div class=\"vocabulary-container\">\n"; |
|
|
$output .= " <div class=\"vocabulary\">\n"; |
|
|
$output .= ' <div class="description">' . $vocabulary->description . "</div>\n"; |
|
|
if ($vocabulary->links) { |
|
|
$output .= ' <div class="links">'. theme('links', $vocabulary->links) . "</div>\n"; |
|
|
} |
|
|
if ($vocabulary->terms && is_array($vocabulary->terms)) { |
|
|
foreach ($vocabulary->terms as $term) { |
|
|
$term->subterm = TRUE; |
|
|
$output .= theme('taxonomy_context_term', $term); |
|
|
} |
|
|
} |
|
|
$output .= " </div>\n"; |
|
|
$output .= "</div>\n"; |
|
|
|
|
|
return $output; |
|
| 706 |
} |
} |
| 707 |
|
|
| 708 |
/** |
/** |
| 725 |
} |
} |
| 726 |
|
|
| 727 |
/** |
/** |
|
* Theme a list of vocabulary and term links. |
|
|
*/ |
|
|
function theme_taxonomy_context_vocabulary_list($vocabulary) { |
|
|
$indent_char = variable_get('taxonomy_context_subterm_indent', '—'); |
|
|
$output = '<div class="vocabulary-list-'. $vocabulary->vid .'">'; |
|
|
$output .= '<h3 class="title">' . l($vocabulary->name, "taxonomy/vocabulary/$vocabulary->vid") . "</h3>\n"; |
|
|
$items = array(); |
|
|
foreach ($vocabulary->terms as $term) { |
|
|
// Indent child terms. |
|
|
$indent = str_repeat($indent_char, $term->depth) .' '; |
|
|
$node_list = array(); |
|
|
$indent = str_repeat($indent_char, $term->depth) .' '; |
|
|
$img = taxonomy_image_display($term->tid, NULL, NULL, array('wrapper' => TRUE)); |
|
|
$name = tt("taxonomy:term:$term->tid:name", $term->name, NULL, TRUE); |
|
|
$items[] = array( |
|
|
'data' => $img . $indent . l($name, taxonomy_term_path($term)), |
|
|
'children' => _taxonomy_context_get_titles($term->tid), |
|
|
'class' => 'vocabulary-list depth-'. $term->depth, |
|
|
); |
|
|
} |
|
|
$output .= theme('item_list', $items); |
|
|
return $output .'</div>'; |
|
|
} |
|
|
|
|
|
/** |
|
| 728 |
* Implementation of hook_views_post_view(). |
* Implementation of hook_views_post_view(). |
| 729 |
* Prevents from losing the breadcrumb. |
* Prevents from losing the breadcrumb. |
| 730 |
*/ |
*/ |