| 1 |
<?php |
<?php |
| 2 |
// $Id: taxonomy_context.module,v 1.82.4.4 2009/10/02 17:57:49 nancyw Exp $ |
// $Id: taxonomy_context.module,v 1.82.4.5 2009/10/02 20:11:15 nancyw Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 50 |
* Implementation of hook_init(). |
* Implementation of hook_init(). |
| 51 |
*/ |
*/ |
| 52 |
function taxonomy_context_init() { |
function taxonomy_context_init() { |
| 53 |
static $taxonomy_context_css_inserted = FALSE; |
if (variable_get('taxonomy_context_use_style', 0)) { |
|
if (variable_get('taxonomy_context_use_style', 1) && !$taxonomy_context_css_inserted) { |
|
| 54 |
drupal_add_css(drupal_get_path('module', 'taxonomy_context') . '/taxonomy_context.css'); |
drupal_add_css(drupal_get_path('module', 'taxonomy_context') . '/taxonomy_context.css'); |
|
$taxonomy_context_css_inserted = TRUE; |
|
| 55 |
} |
} |
| 56 |
|
|
| 57 |
// Helper function for when i18ntaxonomy module is not installed. |
// Helper function for when i18ntaxonomy module is not installed. |
| 382 |
* Menu callback: display a vocabulary's page. |
* Menu callback: display a vocabulary's page. |
| 383 |
*/ |
*/ |
| 384 |
function taxonomy_context_vocabulary_page() { |
function taxonomy_context_vocabulary_page() { |
|
|
|
| 385 |
$vid = arg(2); |
$vid = arg(2); |
| 386 |
if (empty($vid)) { |
if (empty($vid)) { |
| 387 |
$vocabularies = taxonomy_get_vocabularies(); |
$vocabularies = taxonomy_get_vocabularies(); |
| 393 |
$vocabularies = array(); |
$vocabularies = array(); |
| 394 |
$vocabularies[] = taxonomy_vocabulary_load($vid); |
$vocabularies[] = taxonomy_vocabulary_load($vid); |
| 395 |
} |
} |
| 396 |
|
|
| 397 |
|
$output = '<div id="taxonomy-context-overview">'; |
| 398 |
foreach ($vocabularies as $vocabulary) { |
foreach ($vocabularies as $vocabulary) { |
| 399 |
taxonomy_context_load('vocabulary', $vocabulary); |
taxonomy_context_load('vocabulary', $vocabulary); |
| 400 |
$vocabulary = taxonomy_context_prepare($vocabulary, FALSE); |
$vocabulary = taxonomy_context_prepare($vocabulary, FALSE); |
| 401 |
$vocabulary->links = module_invoke_all('link', 'vocabulary', $vocabulary); |
$vocabulary->links = module_invoke_all('link', 'vocabulary', $vocabulary); |
| 402 |
|
$show_count = variable_get('taxonomy_context_count_nodes', 0); |
| 403 |
|
|
| 404 |
if (module_exists('i18n') && module_exists('translation')) { |
if (module_exists('i18n') && module_exists('translation')) { |
| 405 |
$result = db_query("SELECT * FROM {term_data} WHERE vid = %d AND language = '%s'", $vocabulary->vid, _i18n_get_lang()); |
$result = db_query("SELECT * FROM {term_data} WHERE vid = %d AND language = '%s'", $vocabulary->vid, _i18n_get_lang()); |
| 409 |
} |
} |
| 410 |
} |
} |
| 411 |
else { |
else { |
| 412 |
$vocabulary->terms = taxonomy_get_tree($vocabulary->vid, 0, -1, 1); |
$vocabulary->terms = taxonomy_get_tree($vocabulary->vid, 0, -1, variable_get('taxonomy_context_max_depth', 1)); |
| 413 |
} |
} |
| 414 |
if (count($vocabulary->terms)) { |
if (count($vocabulary->terms)) { |
| 415 |
foreach (array_keys($vocabulary->terms) as $key) { |
foreach (array_keys($vocabulary->terms) as $key) { |
| 416 |
|
if ($show_count) { |
| 417 |
|
$vocabulary->terms[$key]->name .= ' (' . taxonomy_term_count_nodes($vocabulary->terms[$key]->tid) . ')'; |
| 418 |
|
} |
| 419 |
$vocabulary->terms[$key]->description = node_teaser($vocabulary->terms[$key]->description); |
$vocabulary->terms[$key]->description = node_teaser($vocabulary->terms[$key]->description); |
| 420 |
// Load the term to ensure it gets a format assigned. |
// Load the term to ensure it gets a format assigned. |
| 421 |
taxonomy_context_load('term', $vocabulary->terms[$key]); |
taxonomy_context_load('term', $vocabulary->terms[$key]); |
| 431 |
} |
} |
| 432 |
} |
} |
| 433 |
|
|
| 434 |
return $output; |
return $output . '</div>'; |
| 435 |
} |
} |
| 436 |
|
|
| 437 |
/** |
/** |
| 595 |
} |
} |
| 596 |
|
|
| 597 |
function taxonomy_context_admin_settings() { |
function taxonomy_context_admin_settings() { |
| 598 |
|
// We need the CSS here. |
| 599 |
|
drupal_add_css(drupal_get_path('module', 'taxonomy_context') . '/taxonomy_context.css'); |
| 600 |
|
|
| 601 |
$form = array(); |
$form = array(); |
| 602 |
|
|
| 603 |
$form['general_settings'] = array( |
$form['general_settings'] = array( |
| 630 |
'#description' => t('Show listings of subterms (sub-categories) for current term.'), |
'#description' => t('Show listings of subterms (sub-categories) for current term.'), |
| 631 |
); |
); |
| 632 |
|
|
| 633 |
|
$form['general_settings']['taxonomy_context_max_depth'] = array( |
| 634 |
|
'#type' => 'textfield', |
| 635 |
|
'#title' => t('Maximum term depth for overview'), |
| 636 |
|
'#default_value' => variable_get('taxonomy_context_max_depth', 1), |
| 637 |
|
'#size' => 8, |
| 638 |
|
'#description' => t('This is how deep in the hierarchy to show terms on the overview ("menu") page. A value of 1 show only the highest level.'), |
| 639 |
|
); |
| 640 |
|
|
| 641 |
$form['general_settings']['taxonomy_context_node_block'] = array( |
$form['general_settings']['taxonomy_context_node_block'] = array( |
| 642 |
'#type' => 'radios', |
'#type' => 'radios', |
| 643 |
'#title' => t('Show nodes in block'), |
'#title' => t('Show nodes in block'), |
| 654 |
'#description' => t('Do you want items on the menu expanded or collapsed by default?'), |
'#description' => t('Do you want items on the menu expanded or collapsed by default?'), |
| 655 |
); |
); |
| 656 |
|
|
| 657 |
|
$form['general_settings']['taxonomy_context_count_nodes'] = array( |
| 658 |
|
'#type' => 'radios', |
| 659 |
|
'#title' => t('Show node count on overview page'), |
| 660 |
|
'#default_value' => variable_get('taxonomy_context_count_nodes', 0), |
| 661 |
|
'#options' => array(t('Disabled'), t('Enabled')), |
| 662 |
|
'#description' => t('Show the number of nodes tagged with each term. For example: term-name (nnn)'), |
| 663 |
|
); |
| 664 |
|
|
| 665 |
$form['general_settings']['taxonomy_context_block_count_nodes'] = array( |
$form['general_settings']['taxonomy_context_block_count_nodes'] = array( |
| 666 |
'#type' => 'radios', |
'#type' => 'radios', |
| 667 |
'#title' => t('Show count nodes in block items'), |
'#title' => t('Show count nodes in block items'), |
| 764 |
*/ |
*/ |
| 765 |
function theme_taxonomy_context_vocabulary_list($vocabulary) { |
function theme_taxonomy_context_vocabulary_list($vocabulary) { |
| 766 |
$output = '<h3 class="title">' . l($vocabulary->name, "taxonomy/vocabulary/$vocabulary->vid") . "</h3>\n"; |
$output = '<h3 class="title">' . l($vocabulary->name, "taxonomy/vocabulary/$vocabulary->vid") . "</h3>\n"; |
| 767 |
$output .= "<ul>\n"; |
$items = array(); |
| 768 |
foreach ($vocabulary->terms as $term) { |
foreach ($vocabulary->terms as $term) { |
| 769 |
$output .= ' <li class="vocabulary-list">' . l($term->name, taxonomy_term_path($term)) . "</li>\n"; |
// Indent child terms. |
| 770 |
|
$items[] = array( |
| 771 |
|
'data' => str_repeat("—", $term->depth) .' '. l($term->name, taxonomy_term_path($term)), |
| 772 |
|
'class' => 'vocabulary-list depth-'. $term->depth, |
| 773 |
|
); |
| 774 |
} |
} |
| 775 |
$output .= "</ul>\n"; |
$output .= theme('item_list', $items); |
| 776 |
return $output; |
return $output; |
| 777 |
} |
} |
| 778 |
|
|