| 1 |
<?php |
<?php |
| 2 |
// $Id: taxonomy_context.module,v 1.82.4.5 2009/10/02 20:11:15 nancyw Exp $ |
// $Id: taxonomy_context.module,v 1.82.4.6 2009/10/02 22:25:36 nancyw Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 233 |
*/ |
*/ |
| 234 |
function taxonomy_context_form_alter(&$form, &$form_state, $form_id) { |
function taxonomy_context_form_alter(&$form, &$form_state, $form_id) { |
| 235 |
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) { |
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) { |
| 236 |
$options = array(t('Disabled'), t('Enabled')); |
$options = $endis; |
| 237 |
$form['taxonomy_context'] = array('#type' => 'fieldset', '#title' => t('Taxonomy context'), '#weight' => 0); |
$form['taxonomy_context'] = array('#type' => 'fieldset', '#title' => t('Taxonomy context'), '#weight' => 0); |
| 238 |
$form['taxonomy_context']['taxonomy_context_inline'] = array( |
$form['taxonomy_context']['taxonomy_context_inline'] = array( |
| 239 |
'#type' => 'radios', |
'#type' => 'radios', |
| 599 |
drupal_add_css(drupal_get_path('module', 'taxonomy_context') . '/taxonomy_context.css'); |
drupal_add_css(drupal_get_path('module', 'taxonomy_context') . '/taxonomy_context.css'); |
| 600 |
|
|
| 601 |
$form = array(); |
$form = array(); |
| 602 |
|
$endis = array(t('Disabled'), t('Enabled')); |
| 603 |
|
|
| 604 |
$form['general_settings'] = array( |
$form['general_settings'] = array( |
| 605 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 611 |
'#type' => 'radios', |
'#type' => 'radios', |
| 612 |
'#title' => t('Use style for term and subterm display'), |
'#title' => t('Use style for term and subterm display'), |
| 613 |
'#default_value' => variable_get('taxonomy_context_use_style', 0), |
'#default_value' => variable_get('taxonomy_context_use_style', 0), |
| 614 |
'#options' => array(t('Disabled'), t('Enabled')), |
'#options' => $endis, |
| 615 |
'#description' => t('Include style declaration to clean up display of taxonomy info. Disable this option if you wish to do this instead through editing theme .css files.'), |
'#description' => t('Include style declaration to clean up display of taxonomy info. Disable this option if you wish to do this instead through editing theme .css files.'), |
| 616 |
); |
); |
| 617 |
|
|
| 619 |
'#type' => 'radios', |
'#type' => 'radios', |
| 620 |
'#title' => t('Show term info'), |
'#title' => t('Show term info'), |
| 621 |
'#default_value' => variable_get('taxonomy_context_show_term', 1), |
'#default_value' => variable_get('taxonomy_context_show_term', 1), |
| 622 |
'#options' => array(t('Disabled'), t('Enabled')), |
'#options' => $endis, |
| 623 |
'#description' => t('Show additional information about current term (from description).'), |
'#description' => t('Show additional information about current term (from description).'), |
| 624 |
); |
); |
| 625 |
|
|
| 627 |
'#type' => 'radios', |
'#type' => 'radios', |
| 628 |
'#title' => t('Show subterm info'), |
'#title' => t('Show subterm info'), |
| 629 |
'#default_value' => variable_get('taxonomy_context_show_subterms', 1), |
'#default_value' => variable_get('taxonomy_context_show_subterms', 1), |
| 630 |
'#options' => array(t('Disabled'), t('Enabled')), |
'#options' => $endis, |
| 631 |
'#description' => t('Show listings of subterms (sub-categories) for current term.'), |
'#description' => t('Show listings of subterms (sub-categories) for current term.'), |
| 632 |
); |
); |
| 633 |
|
|
| 634 |
|
$form['general_settings']['taxonomy_context_subterm_indent'] = array( |
| 635 |
|
'#type' => 'textfield', |
| 636 |
|
'#title' => t('Subterm indent character'), |
| 637 |
|
'#default_value' => variable_get('taxonomy_context_subterm_indent', '—'), |
| 638 |
|
'#size' => 32, |
| 639 |
|
'#description' => t('Subterms will be indented to show hierarchy; this is what is used to show the indentation. It will be repeated for each level of depth.'), |
| 640 |
|
); |
| 641 |
|
|
| 642 |
$form['general_settings']['taxonomy_context_max_depth'] = array( |
$form['general_settings']['taxonomy_context_max_depth'] = array( |
| 643 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 644 |
'#title' => t('Maximum term depth for overview'), |
'#title' => t('Maximum term depth for overview'), |
| 646 |
'#size' => 8, |
'#size' => 8, |
| 647 |
'#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.'), |
'#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.'), |
| 648 |
); |
); |
| 649 |
|
$num_titles = variable_get('taxonomy_context_show_titles', 0); |
| 650 |
|
$order = variable_get('taxonomy_context_show_order', 'n.title'); |
| 651 |
|
|
| 652 |
|
$form['general_settings']['titles'] = array( |
| 653 |
|
'#type' => 'fieldset', |
| 654 |
|
'#title' => t('Node title display'), |
| 655 |
|
'#collapsible' => TRUE, |
| 656 |
|
); |
| 657 |
|
|
| 658 |
|
$form['general_settings']['titles']['taxonomy_context_show_titles'] = array( |
| 659 |
|
'#type' => 'textfield', |
| 660 |
|
'#title' => t('Maximum titles to show for each term'), |
| 661 |
|
'#default_value' => variable_get('taxonomy_context_show_titles', 0), |
| 662 |
|
'#size' => 8, |
| 663 |
|
'#description' => t('This is how many node titles to show for each term on the overview ("menu") page. A value of 0 means don\'t show any.'), |
| 664 |
|
); |
| 665 |
|
|
| 666 |
|
$form['general_settings']['titles']['taxonomy_context_show_order'] = array( |
| 667 |
|
'#type' => 'radios', |
| 668 |
|
'#title' => t('Title order'), |
| 669 |
|
'#default_value' => variable_get('taxonomy_context_show_order', 'n.title'), |
| 670 |
|
'#options' => array( |
| 671 |
|
'n.title' => t('by title (ascending)'), |
| 672 |
|
'n.sticky DESC, n.created DESC' => t('by standard Drupal order (sticky, most recent)'), |
| 673 |
|
), |
| 674 |
|
'#description' => t('In what order do you wish to show the titles? This may also affect which titles are shown if there are more than the limit above.'), |
| 675 |
|
); |
| 676 |
|
|
| 677 |
$form['general_settings']['taxonomy_context_node_block'] = array( |
$form['general_settings']['taxonomy_context_node_block'] = array( |
| 678 |
'#type' => 'radios', |
'#type' => 'radios', |
| 694 |
'#type' => 'radios', |
'#type' => 'radios', |
| 695 |
'#title' => t('Show node count on overview page'), |
'#title' => t('Show node count on overview page'), |
| 696 |
'#default_value' => variable_get('taxonomy_context_count_nodes', 0), |
'#default_value' => variable_get('taxonomy_context_count_nodes', 0), |
| 697 |
'#options' => array(t('Disabled'), t('Enabled')), |
'#options' => $endis, |
| 698 |
'#description' => t('Show the number of nodes tagged with each term. For example: term-name (nnn)'), |
'#description' => t('Show the number of nodes tagged with each term. For example: term-name (nnn)'), |
| 699 |
); |
); |
| 700 |
|
|
| 702 |
'#type' => 'radios', |
'#type' => 'radios', |
| 703 |
'#title' => t('Show count nodes in block items'), |
'#title' => t('Show count nodes in block items'), |
| 704 |
'#default_value' => variable_get('taxonomy_context_block_count_nodes', TAXONOMY_CONTEXT_BLOCK_COUNT_NODES_FALSE), |
'#default_value' => variable_get('taxonomy_context_block_count_nodes', TAXONOMY_CONTEXT_BLOCK_COUNT_NODES_FALSE), |
| 705 |
'#options' => array(t('Disabled'), t('Enabled')), |
'#options' => $endis, |
| 706 |
'#description' => t('Show count nodes in block after items. Example: term (nnn)'), |
'#description' => t('Show count nodes in block after items. Example: term (nnn)'), |
| 707 |
); |
); |
| 708 |
|
|
| 757 |
* Theme a term output. |
* Theme a term output. |
| 758 |
*/ |
*/ |
| 759 |
function theme_taxonomy_context_term($term) { |
function theme_taxonomy_context_term($term) { |
| 760 |
|
$indent_char = variable_get('taxonomy_context_subterm_indent', '—'); |
| 761 |
$type = $term->subterm ? 'subterm' : 'term'; |
$type = $term->subterm ? 'subterm' : 'term'; |
| 762 |
$output = "<div class=\"$type-container\">\n <div class=\"$type\">\n"; |
$output = "<div class=\"$type-container\">\n <div class=\"$type\">\n"; |
| 763 |
|
$indent = str_repeat($indent_char, $term->depth) .' '; |
| 764 |
if ($term->subterm) { |
if ($term->subterm) { |
| 765 |
$name = taxonomy_image_display($term->tid, NULL, NULL, array('wrapper' => TRUE)) . tt("taxonomy:term:$term->tid:name", $term->name, NULL, TRUE); |
$name = taxonomy_image_display($term->tid, NULL, NULL, array('wrapper' => TRUE)) . tt("taxonomy:term:$term->tid:name", $term->name, NULL, TRUE); |
| 766 |
$output .= '<h2 class="title">' . l($name, taxonomy_term_path($term), array('html' => TRUE)) . "</h2>\n"; |
$output .= '<h2 class="title">' . $indent . l($name, taxonomy_term_path($term), array('html' => TRUE)) . "</h2>\n"; |
| 767 |
} |
} |
| 768 |
$term->description = tt("taxonomy:term:$term->tid:description", $term->description, NULL, FALSE); |
$term->description = tt("taxonomy:term:$term->tid:description", $term->description, NULL, FALSE); |
| 769 |
$output .= '<div class="' . ($term->teaser ? 'teaser' : 'description') .'">' . $term->description . '</div>'; |
$output .= '<div class="' . ($term->teaser ? 'teaser' : 'description') .'">' . $term->description . '</div>'; |
| 770 |
if ($term->links) { |
if ($term->links) { |
| 771 |
$output .= '<div class="links">'. theme('links', $term->links) . "</div>\n"; |
$output .= '<div class="links">'. theme('links', $term->links) . "</div>\n"; |
| 772 |
} |
} |
| 773 |
|
if ($node_list = _taxonomy_context_get_titles($term->tid)) { |
| 774 |
|
$output .= theme('item_list', $node_list); |
| 775 |
|
} |
| 776 |
$output .= " </div>\n"; |
$output .= " </div>\n"; |
| 777 |
$output .= "</div>\n"; |
$output .= "</div>\n"; |
| 778 |
return $output; |
return $output; |
| 801 |
} |
} |
| 802 |
|
|
| 803 |
/** |
/** |
| 804 |
|
* Get a list of titles for nodes that use a term. |
| 805 |
|
*/ |
| 806 |
|
function _taxonomy_context_get_titles($tid) { |
| 807 |
|
$num_titles = variable_get('taxonomy_context_show_titles', 0); |
| 808 |
|
$order = variable_get('taxonomy_context_show_order', 'n.title'); |
| 809 |
|
$node_list = array(); |
| 810 |
|
$query = "SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid WHERE tn.tid = %d AND n.status = 1 ORDER BY $order LIMIT %d"; |
| 811 |
|
$args = array($tid, $num_titles); |
| 812 |
|
$result = db_query($query, $args); |
| 813 |
|
while ($node = db_fetch_object($result)) { |
| 814 |
|
$node_list[] = array( |
| 815 |
|
'data' => l($node->title, 'node/'. $node->nid, array('attributes' => array('title' => t('View this content')))), |
| 816 |
|
'class' => 'vocabulary-list-node', |
| 817 |
|
); |
| 818 |
|
} |
| 819 |
|
return $node_list; |
| 820 |
|
} |
| 821 |
|
|
| 822 |
|
/** |
| 823 |
* Theme a list of vocabulary and term links. |
* Theme a list of vocabulary and term links. |
| 824 |
*/ |
*/ |
| 825 |
function theme_taxonomy_context_vocabulary_list($vocabulary) { |
function theme_taxonomy_context_vocabulary_list($vocabulary) { |
| 826 |
$output = '<h3 class="title">' . l($vocabulary->name, "taxonomy/vocabulary/$vocabulary->vid") . "</h3>\n"; |
$indent_char = variable_get('taxonomy_context_subterm_indent', '—'); |
| 827 |
|
$output = '<div class="vocabulary-list-'. $vocabulary->vid .'">'; |
| 828 |
|
$output .= '<h3 class="title">' . l($vocabulary->name, "taxonomy/vocabulary/$vocabulary->vid") . "</h3>\n"; |
| 829 |
$items = array(); |
$items = array(); |
| 830 |
foreach ($vocabulary->terms as $term) { |
foreach ($vocabulary->terms as $term) { |
| 831 |
// Indent child terms. |
// Indent child terms. |
| 832 |
|
$indent = str_repeat($indent_char, $term->depth) .' '; |
| 833 |
|
$node_list = array(); |
| 834 |
$items[] = array( |
$items[] = array( |
| 835 |
'data' => str_repeat("—", $term->depth) .' '. l($term->name, taxonomy_term_path($term)), |
'data' => $indent . l($term->name, taxonomy_term_path($term)), |
| 836 |
|
'children' => _taxonomy_context_get_titles($term->tid), |
| 837 |
'class' => 'vocabulary-list depth-'. $term->depth, |
'class' => 'vocabulary-list depth-'. $term->depth, |
| 838 |
); |
); |
| 839 |
|
|
| 840 |
} |
} |
| 841 |
$output .= theme('item_list', $items); |
$output .= theme('item_list', $items); |
| 842 |
return $output; |
return $output .'</div>'; |
| 843 |
} |
} |
| 844 |
|
|
| 845 |
/** |
/** |