| 1 |
<?php
|
| 2 |
// $Id: taxonomy_dhtml.module,v 1.68 2008/12/11 15:44:07 darthclue Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_theme()
|
| 6 |
*/
|
| 7 |
function taxonomy_dhtml_theme() {
|
| 8 |
return array(
|
| 9 |
'taxonomy_dhtml_admin' => array(
|
| 10 |
'arguments' => array('form' => array()),
|
| 11 |
),
|
| 12 |
);
|
| 13 |
}
|
| 14 |
|
| 15 |
/**
|
| 16 |
* Implementation of hook_block()
|
| 17 |
*/
|
| 18 |
function taxonomy_dhtml_block($op = "list", $delta = 0) {
|
| 19 |
if($op == "list") {
|
| 20 |
$vocabularies = taxonomy_dhtml_get_vocabularies(TRUE);
|
| 21 |
foreach ($vocabularies as $vocabulary) {
|
| 22 |
$blocks[$vocabulary->vid]["info"] = 'Taxonomy DHTML: '. $vocabulary->name;
|
| 23 |
}
|
| 24 |
return $blocks;
|
| 25 |
}
|
| 26 |
elseif ($op == 'view') {
|
| 27 |
if (user_access("access content")) {
|
| 28 |
$vocabularies = taxonomy_dhtml_get_vocabularies(TRUE);
|
| 29 |
$block["subject"]= t($vocabularies[$delta]->name);
|
| 30 |
$block["content"]= menu_tree_output(taxonomy_dhtml_vocab_vert($vocabularies[$delta]->vid));
|
| 31 |
return $block;
|
| 32 |
}
|
| 33 |
}
|
| 34 |
}
|
| 35 |
|
| 36 |
/**
|
| 37 |
* TODO: Review comments from the original code ...
|
| 38 |
* TODO: recipe.module and node_aggregator did use $type to filter results to their own node type. no longer supported (but should be)
|
| 39 |
*/
|
| 40 |
function taxonomy_dhtml_vocab_vert($vocabulary_id, $op = NULL) {
|
| 41 |
$tree = taxonomy_get_tree($vocabulary_id);
|
| 42 |
$taxonomy_menu = array();
|
| 43 |
foreach ($tree as $term) {
|
| 44 |
if ($term->parents[0]==0) {
|
| 45 |
$taxonomy_menu[$term->name] = taxonomy_dhtml_process_term($term,taxonomy_dhtml_get_depth($term->vid));
|
| 46 |
}
|
| 47 |
}
|
| 48 |
return $taxonomy_menu;
|
| 49 |
}
|
| 50 |
|
| 51 |
/**
|
| 52 |
* Retrieve term data recursively
|
| 53 |
*
|
| 54 |
* @param term
|
| 55 |
* The term to process. Expected structure is a single term from the array returned by taxonomy_get_tree.
|
| 56 |
*
|
| 57 |
* @param depth
|
| 58 |
* The depth at which we are processing. We stop recursion if this is zero.
|
| 59 |
*/
|
| 60 |
function taxonomy_dhtml_process_term($term, $depth) {
|
| 61 |
switch ($depth) {
|
| 62 |
case 0:
|
| 63 |
$url = "taxonomy/term/$term->tid";
|
| 64 |
break;
|
| 65 |
case 10:
|
| 66 |
$url = "taxonomy/term/$term->tid/all";
|
| 67 |
break;
|
| 68 |
default:
|
| 69 |
$url = "taxonomy/term/$term->tid/$depth";
|
| 70 |
}
|
| 71 |
|
| 72 |
$count = taxonomy_dhtml_term_count_nodes($term, $depth);
|
| 73 |
$out = '';
|
| 74 |
if ($count) {
|
| 75 |
$out .= " ($count)";
|
| 76 |
}
|
| 77 |
$taxonomy_menu = array('link' => array('href' => $url, 'title' => $term->name . $out, 'expanded' => 1));
|
| 78 |
if ($depth>0) {
|
| 79 |
if ($tree = taxonomy_get_children($term->tid,$term->vid)) {
|
| 80 |
$taxonomy_menu['below'] = array();
|
| 81 |
foreach ($tree as $child) {
|
| 82 |
$taxonomy_menu['below'][$child->name] = taxonomy_dhtml_process_term($child, $depth-1);
|
| 83 |
}
|
| 84 |
}
|
| 85 |
}
|
| 86 |
return $taxonomy_menu;
|
| 87 |
}
|
| 88 |
|
| 89 |
/**
|
| 90 |
* Implementation of hook_menu().
|
| 91 |
*/
|
| 92 |
function taxonomy_dhtml_menu() {
|
| 93 |
global $user;
|
| 94 |
$items['admin/settings/taxonomy_dhtml'] = array(
|
| 95 |
'title' => 'Taxonomy DHTML',
|
| 96 |
'description' => t('Manage settings for taxonomy DHTML.'),
|
| 97 |
'page callback' => 'drupal_get_form',
|
| 98 |
'page arguments' => array('taxonomy_dhtml_admin'),
|
| 99 |
'access arguments' => array('administer taxonomy'),
|
| 100 |
'file' => 'taxonomy_dhtml.admin.inc',
|
| 101 |
);
|
| 102 |
return $items;
|
| 103 |
}
|
| 104 |
|
| 105 |
/**
|
| 106 |
* Implementation of hook_help().
|
| 107 |
*/
|
| 108 |
function taxonomy_dhtml_help($path, $arg) {
|
| 109 |
switch ($path) {
|
| 110 |
case 'admin/modules#description':
|
| 111 |
return '<p>'. t("A user interface for taxonomy featuring a collapsible list.") .'</p>';
|
| 112 |
case 'admin/help#taxonomy_dhtml':
|
| 113 |
case 'admin/settings/taxonomy_dhtml':
|
| 114 |
$output = '<p>';
|
| 115 |
$output .= "This module provides a DHTML representation of this site's taxonomy. ". l("Blocks", "admin/build/block"). " are also provided for each vocabulary.";
|
| 116 |
return $output;
|
| 117 |
}
|
| 118 |
}
|
| 119 |
|
| 120 |
/**
|
| 121 |
* Return the number of items (noi) to display for the provided vocabulary id.
|
| 122 |
*
|
| 123 |
* @param vid
|
| 124 |
* The vocabulary id to get noi data for.
|
| 125 |
*/
|
| 126 |
function taxonomy_dhtml_get_noi($vid) {
|
| 127 |
$noi_return = 25;
|
| 128 |
$result = db_query("SELECT v.vid, v.noi FROM {taxonomy_dhtml} v WHERE v.vid = '%s'", $vid);
|
| 129 |
while ($noi_row = db_fetch_object($result)) {
|
| 130 |
$noi_return = $noi_row->noi;
|
| 131 |
}
|
| 132 |
|
| 133 |
return $noi_return;
|
| 134 |
}
|
| 135 |
|
| 136 |
/**
|
| 137 |
* Rewrite of taxonomy_get_vocabularies to allow us to pull in additional information from the taxonomy_dhtml table.
|
| 138 |
*
|
| 139 |
* @param exposed
|
| 140 |
* If TRUE, we only return vocabularies that are set for exposure with a number of items to display greater than 0.
|
| 141 |
*/
|
| 142 |
function taxonomy_dhtml_get_vocabularies($exposed = FALSE) {
|
| 143 |
if ($exposed) {
|
| 144 |
$result = db_query(db_rewrite_sql('SELECT v.*, t.noi, t.depth, t.expblock FROM {vocabulary} v LEFT JOIN {taxonomy_dhtml} t ON v.vid = t.vid WHERE t.expblock=1 AND t.noi>0 ORDER BY v.weight, v.name', 'v', 'vid'));
|
| 145 |
}
|
| 146 |
else {
|
| 147 |
$result = db_query(db_rewrite_sql('SELECT v.*, t.noi, t.depth, t.expblock FROM {vocabulary} v LEFT JOIN {taxonomy_dhtml} t ON v.vid = t.vid ORDER BY v.weight, v.name', 'v', 'vid'));
|
| 148 |
}
|
| 149 |
|
| 150 |
$vocabularies = array();
|
| 151 |
$node_types = array();
|
| 152 |
while ($voc = db_fetch_object($result)) {
|
| 153 |
$vocabularies[$voc->vid] = $voc;
|
| 154 |
}
|
| 155 |
|
| 156 |
return $vocabularies;
|
| 157 |
}
|
| 158 |
|
| 159 |
/**
|
| 160 |
* Retrieve term count recursively
|
| 161 |
* Rewrite of taxonomy_term_count_nodes to allow us to eliminate children from the count.
|
| 162 |
*
|
| 163 |
* @param term
|
| 164 |
* The term to process. Expected structure is a single term from the array returned by taxonomy_get_tree.
|
| 165 |
*
|
| 166 |
* @param depth
|
| 167 |
* The depth at which we are processing. We stop recursion if this is zero.
|
| 168 |
*/
|
| 169 |
function taxonomy_dhtml_term_count_nodes($term, $depth) {
|
| 170 |
$count = 0;
|
| 171 |
$result = db_query(db_rewrite_sql('SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 AND t.tid = %d GROUP BY t.tid'), $term->tid);
|
| 172 |
while ($terms = db_fetch_object($result)) {
|
| 173 |
$count = $terms->c;
|
| 174 |
}
|
| 175 |
if ($depth>0) {
|
| 176 |
$tree = taxonomy_get_children($term->tid,$term->vid);
|
| 177 |
foreach ($tree as $child) {
|
| 178 |
$count += taxonomy_dhtml_term_count_nodes($child, $depth-1);
|
| 179 |
}
|
| 180 |
}
|
| 181 |
return $count;
|
| 182 |
}
|
| 183 |
|
| 184 |
/**
|
| 185 |
* Retrieve the depth for a specific vocab.
|
| 186 |
*
|
| 187 |
* @param vid
|
| 188 |
* The vocabulary id to return the depth for.
|
| 189 |
*/
|
| 190 |
function taxonomy_dhtml_get_depth($vid) {
|
| 191 |
$result = db_query('SELECT t.depth FROM {taxonomy_dhtml} t WHERE t.vid = %d', $vid);
|
| 192 |
|
| 193 |
$voc = db_fetch_object($result);
|
| 194 |
|
| 195 |
return $voc->depth;
|
| 196 |
}
|