| 1 |
<?php
|
| 2 |
// $Id: taxonomy_html.module,v 1.28.2.2 2006/12/18 12:40:11 goba Exp $
|
| 3 |
|
| 4 |
function taxonomy_html_menu($may_cache) {
|
| 5 |
$items = array();
|
| 6 |
if ($may_cache) {
|
| 7 |
$items[] = array(
|
| 8 |
'path' => 'taxonomy_html', 'title' => t('categories'),
|
| 9 |
'callback' => 'taxonomy_html_page',
|
| 10 |
'access' => user_access('access content'),
|
| 11 |
'type' => MENU_SUGGESTED_ITEM
|
| 12 |
);
|
| 13 |
$items[] = array(
|
| 14 |
'path' => 'admin/settings/taxonomy_html',
|
| 15 |
'title' => t('Taxonomy HTML'),
|
| 16 |
'description' => t('Specify omitted vocabularies and other settings.'),
|
| 17 |
'callback' => 'drupal_get_form',
|
| 18 |
'callback arguments' => 'taxonomy_html_admin_settings',
|
| 19 |
'access' => user_access('administer site configuration'),
|
| 20 |
'type' => MENU_NORMAL_ITEM,
|
| 21 |
);
|
| 22 |
}
|
| 23 |
return $items;
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Implementation of hook_block().
|
| 28 |
*/
|
| 29 |
function taxonomy_html_block($op = 'list', $delta = 0) {
|
| 30 |
if ($op == 'list') {
|
| 31 |
$blocks = array();
|
| 32 |
$vocabularies = taxonomy_html_get_vocabularies();
|
| 33 |
foreach ($vocabularies as $vid => $vocab) {
|
| 34 |
$blocks[$vocab->vid]['info'] = t('@vocabulary term block', array('@vocabulary' => $vocab->name));
|
| 35 |
}
|
| 36 |
return $blocks;
|
| 37 |
}
|
| 38 |
elseif (($op == 'view') && ($vocab = taxonomy_get_vocabulary($delta))) {
|
| 39 |
$data['subject'] = check_plain($vocab->name);
|
| 40 |
$data['content'] = taxonomy_html_vocab_horiz($vocab);
|
| 41 |
return $data;
|
| 42 |
}
|
| 43 |
}
|
| 44 |
|
| 45 |
function taxonomy_html_page($type = '') {
|
| 46 |
drupal_set_title(variable_get("taxonomy_html_overview_title", t("Categories")));
|
| 47 |
$columns = variable_get('taxonomy_html_overview_columns', 2);
|
| 48 |
$vocabularies = taxonomy_html_get_vocabularies();
|
| 49 |
$output = '<table id="taxonomy-html">';
|
| 50 |
$cellwidth = round(100 / $columns). '%';
|
| 51 |
foreach ($vocabularies as $n => $vocab) {
|
| 52 |
if ($n % $columns == 0) {
|
| 53 |
$output .= '<tr>';
|
| 54 |
}
|
| 55 |
$output .= '<td width="'. $cellwidth .'"><h3>'. $vocab->name ."</h3>\n". taxonomy_html_vocab_horiz($vocab, $type). "</td>\n";
|
| 56 |
if (($n % $columns) == ($columns - 1)) {
|
| 57 |
$output .= "</tr>\n";
|
| 58 |
}
|
| 59 |
}
|
| 60 |
// Close last row if not closed already
|
| 61 |
if (($n % $columns) != ($columns - 1)) {
|
| 62 |
$output .= "</tr>\n";
|
| 63 |
}
|
| 64 |
$output .= '</table>';
|
| 65 |
return $output;
|
| 66 |
}
|
| 67 |
|
| 68 |
function taxonomy_html_get_vocabularies($type = NULL) {
|
| 69 |
$allvocabularies = taxonomy_get_vocabularies($type);
|
| 70 |
$omitted = variable_get('taxonomy_html_overview_vocab', array()); //omit undesired vocabularies from listing
|
| 71 |
foreach ($omitted as $val) {
|
| 72 |
unset($allvocabularies[$val]);
|
| 73 |
}
|
| 74 |
$allvocabularies = array_merge(array(), $allvocabularies);
|
| 75 |
return $allvocabularies;
|
| 76 |
}
|
| 77 |
|
| 78 |
|
| 79 |
function taxonomy_html_vocab_horiz($vocabulary, $type = '') {
|
| 80 |
$lastdepth = 0;
|
| 81 |
$output = '';
|
| 82 |
$tree = taxonomy_get_tree($vocabulary->vid);
|
| 83 |
foreach ($tree as $index => $term) {
|
| 84 |
|
| 85 |
$showcounts = variable_get('taxonomy_html_show_node_count', 0);
|
| 86 |
$term->count = taxonomy_term_count_nodes($term->tid);
|
| 87 |
$class = @($tree[$index+1]->depth > $term->depth ? 'expanded' : 'leaf');
|
| 88 |
|
| 89 |
if ($term->depth > $lastdepth) {
|
| 90 |
$output .= "<ul>\n";
|
| 91 |
}
|
| 92 |
elseif ($term->depth < $lastdepth) {
|
| 93 |
$output .= str_repeat("</li></ul></li>\n", ($lastdepth - $term->depth));
|
| 94 |
}
|
| 95 |
elseif ($output != '') {
|
| 96 |
$output .= "</li>\n";
|
| 97 |
}
|
| 98 |
|
| 99 |
if ($term->count) {
|
| 100 |
$output .= '<li class="' . $class . '">' . l($term->name .($showcounts ? ' ('. $term->count .')' : ''), 'taxonomy/term/' . $term->tid . ($type == 'feed' ? '/feed' : ''), ($showcounts ? array("title" => format_plural($term->count, '1 item', '%count items')) : array()));
|
| 101 |
}
|
| 102 |
else {
|
| 103 |
if (variable_get('taxonomy_html_show_empty_terms', 0) == 0) {
|
| 104 |
$output .= '<li class="' . $class . '">'. $term->name;
|
| 105 |
}
|
| 106 |
}
|
| 107 |
|
| 108 |
$lastdepth = $term->depth;
|
| 109 |
}
|
| 110 |
if ($lastdepth > 0) {
|
| 111 |
$output .= str_repeat("</li></ul></li>\n", $lastdepth);
|
| 112 |
}
|
| 113 |
return '<ul class="menu">' . $output . '</ul>';
|
| 114 |
}
|
| 115 |
|
| 116 |
function taxonomy_html_admin_settings() {
|
| 117 |
$form = array();
|
| 118 |
$vocabularies = taxonomy_get_vocabularies();
|
| 119 |
foreach ($vocabularies as $vocabulary) {
|
| 120 |
$select[$vocabulary->vid] = $vocabulary->name;
|
| 121 |
}
|
| 122 |
$form["taxonomy_html_overview_vocab"] = array(
|
| 123 |
'#type' => 'select',
|
| 124 |
'#title' => t("Omitted vocabularies"),
|
| 125 |
'#default_value' => variable_get("taxonomy_html_overview_vocab", array()),
|
| 126 |
'#options' => $select,
|
| 127 |
'#description' => t("Select vocabularies which should be <strong>omitted</strong> from listings."),
|
| 128 |
'#extra' => "",
|
| 129 |
'#multiple' => 1,
|
| 130 |
);
|
| 131 |
$form["taxonomy_html_overview_title"] = array(
|
| 132 |
'#type' => 'textfield',
|
| 133 |
'#title' => t("Overview title"),
|
| 134 |
'#default_value' => variable_get("taxonomy_html_overview_title", t("Categories")),
|
| 135 |
'#size' => 35,
|
| 136 |
'#maxlength' => 255,
|
| 137 |
'#description' => t("Title of the overview page."),
|
| 138 |
);
|
| 139 |
$form['taxonomy_html_overview_columns'] = array(
|
| 140 |
'#type' => 'select',
|
| 141 |
'#title' => t("Overview columns"),
|
| 142 |
'#default_value' => variable_get("taxonomy_html_overview_columns", "2"),
|
| 143 |
'#options' => array("1" => "1", "2" => "2", "3" => "3", "4" => "4", "5" => "5", "6" => "6"),
|
| 144 |
'#description' => t("Number of vocabularies per row on the overview page."),
|
| 145 |
);
|
| 146 |
$form['taxonomy_html_show_node_count'] = array(
|
| 147 |
'#type' => 'radios',
|
| 148 |
'#title' => t('Show node counts in links'),
|
| 149 |
'#default_value' => variable_get('taxonomy_html_show_node_count', 0),
|
| 150 |
'#options' => array(t('Disabled'), t('Enabled')),
|
| 151 |
'#description' => t('Show counts of nodes associated with taxonomy terms.')
|
| 152 |
);
|
| 153 |
$form['taxonomy_html_show_empty_terms'] = array(
|
| 154 |
'#type' => 'radios',
|
| 155 |
'#title' => t('Show empty terms'),
|
| 156 |
'#default_value' => variable_get('taxonomy_html_show_empty_terms', 0),
|
| 157 |
'#options' => array(t('Show empty terms'), t('Do not show empty terms')),
|
| 158 |
'#description' => t('Show terms that do not have any associated nodes.')
|
| 159 |
);
|
| 160 |
return system_settings_form($form);
|
| 161 |
}
|