1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Page callbacks for the taxonomy module, i18n remake.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Menu callback; displays all nodes associated with a term.
|
10
|
*
|
11
|
* @param $term
|
12
|
* The taxonomy term.
|
13
|
* @return
|
14
|
* The page content.
|
15
|
*/
|
16
|
function i18n_taxonomy_term_page($term) {
|
17
|
$term = i18n_taxonomy_localize_terms($term);
|
18
|
|
19
|
// Assign the term name as the page title.
|
20
|
drupal_set_title($term->name);
|
21
|
|
22
|
// Build breadcrumb based on the hierarchy of the term.
|
23
|
$current = (object) array(
|
24
|
'tid' => $term->tid,
|
25
|
);
|
26
|
// @todo This overrides any other possible breadcrumb and is a pure hard-coded
|
27
|
// presumption. Make this behavior configurable per vocabulary or term.
|
28
|
$breadcrumb = array();
|
29
|
while ($parents = taxonomy_get_parents($current->tid)) {
|
30
|
$parents = i18n_taxonomy_localize_terms($parents);
|
31
|
$current = array_shift($parents);
|
32
|
$breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
|
33
|
}
|
34
|
$breadcrumb[] = l(t('Home'), NULL);
|
35
|
$breadcrumb = array_reverse($breadcrumb);
|
36
|
drupal_set_breadcrumb($breadcrumb);
|
37
|
drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->name);
|
38
|
|
39
|
$build = array();
|
40
|
|
41
|
$build['term_heading'] = array(
|
42
|
'#prefix' => '<div class="term-listing-heading">',
|
43
|
'#suffix' => '</div>',
|
44
|
'term' => taxonomy_term_view($term, 'full'),
|
45
|
);
|
46
|
|
47
|
if ($nids = taxonomy_select_nodes($term->tid, TRUE, variable_get('default_nodes_main', 10))) {
|
48
|
$nodes = node_load_multiple($nids);
|
49
|
$build += node_view_multiple($nodes);
|
50
|
$build['pager'] = array(
|
51
|
'#theme' => 'pager',
|
52
|
'#weight' => 5,
|
53
|
);
|
54
|
}
|
55
|
else {
|
56
|
$build['no_content'] = array(
|
57
|
'#prefix' => '<p>',
|
58
|
'#markup' => t('There is currently no content classified with this term.'),
|
59
|
'#suffix' => '</p>',
|
60
|
);
|
61
|
}
|
62
|
return $build;
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* Render a taxonomy term page HTML output.
|
67
|
*
|
68
|
* @param $tids
|
69
|
* An array of term ids.
|
70
|
* @param $result
|
71
|
* A pager_query() result, such as that performed by taxonomy_select_nodes().
|
72
|
*
|
73
|
* @ingroup themeable
|
74
|
*/
|
75
|
function theme_i18n_taxonomy_term_page($tids, $result) {
|
76
|
drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css');
|
77
|
|
78
|
$output = '';
|
79
|
|
80
|
// Only display the description if we have a single term, to avoid clutter and confusion.
|
81
|
if (count($tids) == 1) {
|
82
|
$term = i18n_taxonomy_localize_terms(taxonomy_term_load($tids[0]));
|
83
|
// Check that a description is set.
|
84
|
if (!empty($term->description)) {
|
85
|
$output .= '<div class="taxonomy-term-description">';
|
86
|
$output .= filter_xss_admin($term->description);
|
87
|
$output .= '</div>';
|
88
|
}
|
89
|
}
|
90
|
|
91
|
$output .= taxonomy_render_nodes($result);
|
92
|
|
93
|
return $output;
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* Helper function for autocompletion. Replacement for taxonomy_autocomplete
|
98
|
*/
|
99
|
function i18n_taxonomy_autocomplete_field($field_name, $tags_typed = '') {
|
100
|
// Part of the criteria for the query come from the field's own settings.
|
101
|
$field = field_info_field($field_name);
|
102
|
$vids = array();
|
103
|
$vocabularies = taxonomy_vocabulary_get_names();
|
104
|
foreach ($field['settings']['allowed_values'] as $tree) {
|
105
|
$vids[] = $vocabularies[$tree['vocabulary']]->vid;
|
106
|
}
|
107
|
// This has been redirected from taxonomy module so we add current language and no language
|
108
|
// Because some of the vocabularies may not have language
|
109
|
$langcode = array(i18n_langcode(), LANGUAGE_NONE);
|
110
|
return _i18n_taxonomy_autocomplete($langcode, $vids, $tags_typed);
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* Helper function for autocompletion. Select by language
|
115
|
*/
|
116
|
function i18n_taxonomy_autocomplete_language($langcode, $vocabulary, $tags_typed = '') {
|
117
|
$vids = $vocabulary ? array($vocabulary->vid) : NULL;
|
118
|
return _i18n_taxonomy_autocomplete($langcode, $vids, $tags_typed);
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* Helper function for autocompletion
|
123
|
*/
|
124
|
function _i18n_taxonomy_autocomplete($langcode, $vids, $tags_typed = '') {
|
125
|
// The user enters a comma-separated list of tags. We only autocomplete the last tag.
|
126
|
$tags_typed = drupal_explode_tags($tags_typed);
|
127
|
$tag_last = drupal_strtolower(array_pop($tags_typed));
|
128
|
|
129
|
$matches = array();
|
130
|
if ($langcode && $tag_last != '') {
|
131
|
$query = db_select('taxonomy_term_data', 't')
|
132
|
->fields('t', array('tid', 'name'));
|
133
|
$query->addTag('translatable');
|
134
|
$query->addTag('term_access');
|
135
|
// Disable i18n_select for this query
|
136
|
$query->addTag('i18n_select');
|
137
|
// Add language condition
|
138
|
$query->condition('t.language', $langcode);
|
139
|
|
140
|
// Do not select already entered terms.
|
141
|
if (!empty($tags_typed)) {
|
142
|
$query->condition('t.name', $tags_typed, 'NOT IN');
|
143
|
}
|
144
|
// There may be vocabulary restrictions
|
145
|
if ($vids) {
|
146
|
$query->condition('t.vid', $vids);
|
147
|
}
|
148
|
// Select rows that match by term name.
|
149
|
$tags_return = $query
|
150
|
->condition('t.name', '%' . db_like($tag_last) . '%', 'LIKE')
|
151
|
->range(0, 10)
|
152
|
->execute()
|
153
|
->fetchAllKeyed();
|
154
|
|
155
|
$prefix = count($tags_typed) ? drupal_implode_tags($tags_typed) . ', ' : '';
|
156
|
|
157
|
$term_matches = array();
|
158
|
foreach ($tags_return as $tid => $name) {
|
159
|
$n = $name;
|
160
|
// Term names containing commas or quotes must be wrapped in quotes.
|
161
|
if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
|
162
|
$n = '"' . str_replace('"', '""', $name) . '"';
|
163
|
}
|
164
|
$term_matches[$prefix . $n] = check_plain($name);
|
165
|
}
|
166
|
}
|
167
|
|
168
|
drupal_json_output($term_matches);
|
169
|
}
|