forked from berkes/tagadelic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtagadelic_taxonomy.module
More file actions
69 lines (56 loc) · 1.6 KB
/
Copy pathtagadelic_taxonomy.module
File metadata and controls
69 lines (56 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* @file tagadelic.module
* Library to build tagclouds.
* @author Bèr Kessels <ber@webschuur.com>
* @link http://berk.es
*/
/**
* Implements hook_menu().
* @see hook_menu()
*/
function tagadelic_taxonomy_menu() {
$items['tagadelic_taxonomy'] = array(
'title' => 'Tag Cloud',
'page callback' => 'tagadelic_taxonomy_cloud',
'access callback' => TRUE,
'expanded' => TRUE,
);
return $items;
}
/**
* Constructs a simple page.
*/
function tagadelic_taxonomy_cloud() {
$cloud = new TagadelicCloud("tagadalic_taxonomy");
foreach (tagadelic_taxonomy_get_tags(60) as $term) {
$tag = new TagadelicTag($term->tid, $term->name, $term->count);
$tag->set_link("taxonomy/term/{$term->tid}");
$cloud->add_tag($tag);
}
return theme("tagadelic_taxonomy_cloud", array("tags" => $cloud->get_tags()));
}
function tagadelic_taxonomy_theme($existing, $type, $theme, $path) {
return array(
"tagadelic_taxonomy_cloud" => array(
"variables" => array(
"tags" => array(),
"name" => "",
),
"path" => "{$path}/templates",
"template" => "tagadelic_taxonomy_cloud"
), // tagadelic_taxonomy_cloud
);
}
function tagadelic_taxonomy_get_tags($max_amount) {
$tags = array();
$query = db_select('taxonomy_index', 'i');
$alias = $query->leftjoin('taxonomy_term_data', 't', '%alias.tid = i.tid');
$query->addExpression('COUNT(i.nid)', 'count');
$query->addField($alias, 'tid');
$query->addField($alias, 'name');
$query->addField($alias, 'description');
$query->range(0, $max_amount)
->groupBy("i.tid");
return $query->execute();
}