-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathtagadelic_taxonomy.module
160 lines (134 loc) · 4.15 KB
/
tagadelic_taxonomy.module
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
* @file tagadelic.module
* Library to build tagclouds.
* @author Bèr Kessels <[email protected]>
* @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',
'page arguments' => array('60'),
'access arguments' => array("access content"),
'expanded' => TRUE,
);
# Admin pages
$items['admin/structure/tagadelic_taxonomy'] = array(
'title' => 'Tag Cloud',
'page callback' => 'tagadelic_taxonomy_admin',
'access arguments' => array("administer site configuration"),
);
return $items;
}
/**
* Constructs a simple page.
* Callback from the menu.
*/
function tagadelic_taxonomy_cloud() {
return theme("tagadelic_taxonomy_cloud", array("tags" => tagadelic_taxonomy_get_cloud(60)));
}
function tagadelic_taxonomy_get_cloud($max_amount) {
drupal_add_css(drupal_get_path('module', 'tagadelic') . '/tagadelic.css');
$cloud = new TagadelicCloud("tagadalic_taxonomy");
foreach (tagadelic_taxonomy_tags_from_db($max_amount) as $term) {
$tag = new TagadelicTag($term->tid, $term->name, $term->count);
$tag->set_link("taxonomy/term/{$term->tid}");
$cloud->add_tag($tag);
}
# Because now here wer're returning an array, not HTML.
return $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_tags_from_db($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->orderBy('count', 'DESC');
foreach(variable_get("tagadelic_taxonomy_vocabularies", array()) as $vid => $state) {
if ($state != $vid) { //Disabled
$query->condition('t.vid', $vid, '<>');
}
}
$query->range(0, $max_amount)
->groupBy("i.tid");
return $query->execute();
}
/********************************************************************
* Admin pages methods *
*******************************************************************/
/**
* tagadelic_taxonomy_admin Renders admin page
*
* @returns String $html The Contents of the page, as HTML
*/
function tagadelic_taxonomy_admin() {
$html = "";
$form = drupal_get_form("tagadelic_taxonomy_admin_form");
$html .= drupal_render($form);
return $html;
}
function tagadelic_taxonomy_admin_form($form, &$form_state) {
$form = array();
$options = array();
foreach(taxonomy_get_vocabularies() as $vocabulary) {
$options[$vocabulary->vid] = $vocabulary->name;
}
$form["tagadelic_taxonomy_vocabularies"] = array(
"#type" => "checkboxes",
"#title" => "Vocabularies used in Tag Cloud",
"#options" => $options,
"#default_value" => variable_get('tagadelic_taxonomy_vocabularies', array()),
);
return system_settings_form($form);
}
/**
* Implementation of hook_block_info
*
* @returns array $blocks
*/
function tagadelic_taxonomy_block_info() {
return array(
'tagadelic_taxonomy' => array(
'info' => t('Tagadelic Tag cloud'),
'cache' => DRUPAL_NO_CACHE,
)
);
}
/**
* Implementation of hook_block_view
*
* @param String $delta name key for the block
*
* @return array $block renderable array of terms cloud
*/
function tagadelic_taxonomy_block_view($delta = '') {
$body = theme("tagadelic_taxonomy_cloud", array("tags" => tagadelic_taxonomy_get_cloud(12)));
$body .= l(t("More tags"), "tagadelic_taxonomy", array("attributes" => array("class" => array("more"))));
return array(
'subject' => t('Tag cloud'),
'content' => array(
'#type' => 'markup',
'#markup' => $body,
)
);
}