-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvocabulary.module
More file actions
314 lines (279 loc) · 9.3 KB
/
vocabulary.module
File metadata and controls
314 lines (279 loc) · 9.3 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?php
include('vocabulary.taxonomy_menu.inc');
function vocabulary_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'vocabulary'),
);
}
/**
* Implementation of hook_ctools_plugin_directory().
*
* It simply tells panels where to find the .inc files that define various
* args, contexts, content_types. In this case the subdirectories of
* ctools_plugin_example/panels are used.
*/
function vocabulary_ctools_plugin_directory($module, $plugin) {
return "plugins/$plugin";
}
function vocabulary_menu() {
$items['taxonomy/%taxonomy_vocabulary'] = array(
'title callback' => 'vocabulary_page_title',
'title arguments' => array(1),
'page callback' => 'vocabulary_page',
'page arguments' => array(1),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['taxonomy/%taxonomy_vocabulary/view'] = array(
'title' => 'View',
'page callback' => 'vocabulary_page',
'page arguments' => array(1),
'access arguments' => array('access content'),
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$path = drupal_get_path('module', 'taxonomy');
$items['taxonomy/%taxonomy_vocabulary/edit'] = array(
'title' => 'Edit',
'page callback' => 'taxonomy_admin_vocabulary_edit',
'page arguments' => array(1),
'access arguments' => array('administer taxonomy'),
'type' => MENU_LOCAL_TASK,
'file' => 'taxonomy.admin.inc',
'file path' => $path,
'weight' => 5,
);
$items['taxonomy/%taxonomy_vocabulary/list'] = array(
'title' => 'List',
'page callback' => 'drupal_get_form',
'page arguments' => array('taxonomy_overview_terms', 1),
'access arguments' => array('administer taxonomy'),
'type' => MENU_LOCAL_TASK,
'file path' => $path,
'file' => 'taxonomy.admin.inc',
'weight' => 10,
);
return $items;
}
function vocabulary_page_title($vocabulary) {
return check_plain($vocabulary->name);
}
/* will not work, can't just target that path.
function vocabulary_path_alias_types() {
return array('taxonomy/%'=>t("Just vocabularies"));
}
*/
function vocabulary_page($vocabulary) {
drupal_set_title(check_plain($vocabulary->name));
$page = isset($_GET['page']) ? $_GET['page'] : 0;
$results = pager_query(db_rewrite_sql('SELECT t.*, h.parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), 50, 0, NULL, $vocabulary->vid);
$total_entries = db_query(db_rewrite_sql('SELECT count(*) FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d', 't', 'tid'), 50, 0, NULL, $vocabulary->vid);
while ($term = db_fetch_object($results)) {
$output .= "<h3 class='term-name'>".l($term->name,taxonomy_term_path($term))."</h3>"
. "<div class='term-description'>".filter_xss($term->description)."</div>";
}
if ($output) return $output . theme('pager', NULL, variable_get('default_nodes_main', 10));
else return t("No terms found.");
}
function vocabulary_form_taxonomy_form_vocabulary_alter(&$form, $form_state) {
if (arg(0) == 'taxonomy' && arg(2)=='edit') $form['#submit'][] = 'vocabulary_taxonomy_form_vocabulary';
}
function vocabulary_taxonomy_form_vocabulary($form, &$form_state) {
$form_state['values']['vid'];
$form_state['redirect'] = 'taxonomy/'.$form_state['values']['vid'];
return;
}
/* token stuff */
/*
* Implementation of hook_token_values
*/
function vocabulary_token_values($type, $object = NULL) {
$values = array();
switch ($type) {
case 'vocabulary':
$values['vid'] = $object->vid;
$values['vocab'] = check_plain($object->name);
$values['vocab-raw'] = $object->name;
break;
}
return $values;
}
/*
* Implementation of hook_token_list
*/
function vocabulary_token_list($type = 'all') {
$tokens = array();
if ($type == 'vocabulary' || $type == 'all') {
$tokens['vocabulary']['vid'] = t('Vocabulary vid.');
$tokens['vocabulary']['vocab-raw'] = t('Raw vocabulary name.');
$tokens['vocabulary']['vocab'] = t('Vocabulary name.');
}
return $tokens;
}
/*
* Pathauto stuff
*/
/*
* Implementation of hook_pathauto
*/
function vocabulary_pathauto($op) {
switch ($op) {
case 'settings':
$settings = array();
$settings['module'] = 'vocabulary';
$settings['token_type'] = 'vocabulary';
$settings['groupheader'] = t('Vocabulary path settings');
$settings['patterndefault'] = t('category/[vocab-raw]');
$patterns = token_get_list('vocabulary');
foreach ($patterns as $type => $pattern_set) {
if ($type != 'global') {
foreach ($pattern_set as $pattern => $description) {
$settings['placeholders']['['. $pattern .']'] = $description;
}
}
}
$settings['supportsfeeds'] = '0/feed';
$settings['bulkname'] = t('Bulk generate aliases for vocabularies that are not aliased');
$settings['bulkdescr'] = t('Generate aliases for all existing vocabularies which do not already have aliases.');
return (object) $settings;
default:
break;
}
}
/**
* Generate aliases for all nodes without aliases.
*/
function vocabulary_pathauto_bulkupdate() {
// From all node types, only attempt to update those with patterns
// If there's a default pattern we assume all types might be updated.
$pattern = trim(variable_get('pathauto_vocabulary_pattern', '')) ;
if (!$pattern) return;
$vocabularies = taxonomy_get_vocabularies();
$placeholders = array();
$count = 0;
foreach($vocabularies as $vocabulary) {
$placeholders = pathauto_get_placeholders('vocabulary', $vocabulary);
if (pathauto_create_alias('vocabulary', 'bulkupdate', $placeholders, "taxonomy/$vocabulary->vid", $vocabulary->vid)) {
$count++;
}
}
drupal_set_message(format_plural($count,
'Bulk generation of vocabularies completed, one alias generated.',
'Bulk generation of vocabularies completed, @count aliases generated.'));
}
/**
* Implementation of hook_taxonomy().
*/
function vocabulary_taxonomy($op, $type, $object = NULL) {
switch ($type) {
case 'vocabulary':
switch ($op) {
case 'insert':
case 'update':
_pathauto_include();
// Use the category info to automatically create an alias
$vocabulary = (object) $object;
if ($vocabulary->name) {
$placeholders = pathauto_get_placeholders('vocabulary', $vocabulary);
pathauto_create_alias('vocabulary', $op, $placeholders, "taxonomy/$vocabulary->vid", $vocabulary->vid);
}
break;
case 'delete':
// If the category is deleted, remove the path aliases
$vocabulary = (object) $object;
path_set_alias('taxonomy/'. $vocabulary->vid);
path_set_alias('taxonomy/'. $vocabulary->vid .'/0/feed');
break;
default:
break;
}
break;
default:
break;
}
}
/**
* Implementation of specially named hook_ctools_arguments().
*/
function vocabulary_ctools_arguments() {
return array(
'vocabulary' => array(
'title' => t("Vocabulary ID"),
// keyword to use for %substitution
'keyword' => 'vocabulary',
'description' => t('Creates a vocabulary from a vid or vocabulary name'),
'context' => 'vocabulary_context',
'default' => array('input_form' => 'vid'),
'settings form' => 'vocabulary_settings_form',
'placeholder form' => 'vocabulary_ctools_argument_placeholder',
),
);
}
/**
* Discover if this argument gives us the term we crave.
*/
function vocabulary_context($arg = NULL, $conf = NULL, $empty = FALSE) {
// If unset it wants a generic, unfilled context.
if ($empty) {
return ctools_context_create_empty('vocabulary');
}
switch ($conf['input_form']) {
case 'vid':
default:
if ($arg->vid) {
$vocabulary = $arg;
break;
}
if (!is_numeric($arg)) {
return FALSE;
}
$vocabulary = taxonomy_vocabulary_load($arg);
break;
case 'vocabulary':
if ($arg->vid) {
$vocabulary = $arg;
break;
}
$vid = db_result(db_query("SELECT vid from {vocabulary} where lower(name) = %s",lower($arg)));
$vocabulary = taxonomy_vocabulary_load($vid);
break;
}
if (empty($vocabulary)) {
return NULL;
}
$context = ctools_context_create('vocabulary', $vocabulary);
$context->original_argument = $arg;
return $context;
}
/**
* Settings form for the argument
*/
function vocabulary_settings_form(&$form, &$form_state, $conf) {
// @todo allow synonym use like Views does.
$form['settings']['input_form'] = array(
'#title' => t('Argument type'),
'#type' => 'radios',
'#options' => array('tid' => t('Vocabulary ID'), 'term' => t('Vocabulary name')),
'#default_value' => $conf['input_form'],
'#prefix' => '<div class="clear-block">',
'#suffix' => '</div>',
);
}
/**
* Form fragment to get an argument to convert a placeholder for preview.
*/
function vocabulary_ctools_argument_placeholder($conf) {
switch ($conf['input_form']) {
case 'vid':
default:
return array(
'#type' => 'textfield',
'#description' => t('Enter a vocabulary ID.'),
);
case 'vocabulary':
return array(
'#type' => 'textfield',
'#description' => t('Enter a vocabulary name.'),
);
}
}