/[drupal]/contributions/modules/taxonomy_filter/taxonomy_filter.theme.inc
ViewVC logotype

Contents of /contributions/modules/taxonomy_filter/taxonomy_filter.theme.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Sat Jul 25 23:39:02 2009 UTC (4 months ago) by solotandem
Branch: MAIN
CVS Tags: DRUPAL-6--1-1, HEAD
Changes since 1.4: +6 -3 lines
File MIME type: text/x-php
#458618: Knocks out right sidebar in theme
1 <?php
2 // $Id: taxonomy_filter.theme.inc,v 1.4 2009/05/17 04:22:46 solotandem Exp $
3
4 /**
5 * @file
6 * Include file for Taxonomy Filter theming functions.
7 */
8
9 /**
10 * Render a breadcrumb style list of select and remove links to current search
11 * criteria.
12 *
13 * @param array $terms taxonomy term objects associated with the current url.
14 * @param array $block_info block information.
15 * @return string $output html output.
16 */
17 function theme_taxonomy_filter_block_current_content($terms, $block_info) {
18 $output = '';
19 $links = array();
20 foreach ($terms as $term) {
21 $item = array();
22 $item['tid'] = $term->tid;
23 $item['title'] = $term->vocab_name . ' : ' . $term->name;
24 $item['link_attributes']['title'] = $term->name;
25 $item['item_attributes']['class'] = array('li-inline');
26 $links[] = theme('taxonomy_filter_current_item', $item, $block_info);
27 }
28 $output = implode('<li class="li-inline li-separator">›</li>', $links); // Use '›' instead of '>'.
29
30 return $output;
31 }
32
33 /**
34 * Process variables for taxonomy-filter-item.tpl.php.
35 *
36 * Process term ids in the order selected by user.
37 * Display two links:
38 * 1) All tids up to and including this tid (a "select" criteria link),
39 * 2) All tids except this tid (a "remove" criteria link saved to post_link).
40 */
41 function template_preprocess_taxonomy_filter_current_item(&$variables) {
42 // Extract basic information.
43 $link_tids = $variables['block_info']['url_tids'];
44 $depth = $variables['block_info']['url_depth'];
45
46 // Make code easier to read.
47 $link = $variables['item']['link_attributes'];
48
49 // Do the select criteria link.
50 if (!isset($link['href'])) {
51 $tids = _taxonomy_filter_tids_upto($link_tids, $variables['item']['tid']);
52 $path = _taxonomy_filter_format_path($tids, $depth, NULL);
53 if ($path != '') {
54 $link['href'] = $path;
55 }
56 }
57 $name = $variables['item']['title'];
58 $variables['link'] = theme('taxonomy_filter_link', $name, $link);
59
60 // Add a remove criteria link (except on last tid).
61 $tids = array_diff($link_tids, array($variables['item']['tid']));
62 if (count($tids) > 0) {
63 $name = 'remove';
64 $path = _taxonomy_filter_format_path($tids, $depth, NULL);
65 $link['href'] = $path;
66 if ($link['title']) {
67 $link['title'] = 'Remove ' . $link['title'];
68 }
69 $link['super'] = true;
70 $variables['post_link'] = theme('taxonomy_filter_link', $name, $link);
71 }
72
73 // Set list item attributes.
74 if (isset($variables['item']['item_attributes']['class'])) {
75 $variables['class'] = implode(' ', $variables['item']['item_attributes']['class']);
76 }
77 if (isset($variables['item']['item_attributes']['style'])) {
78 $variables['style'] = implode('; ', $variables['item']['item_attributes']['style']);
79 }
80 }
81
82 /**
83 * Render links to allow the user to refine the current search criteria.
84 *
85 * @param array $sections vocabulary and term lists to refine the current url.
86 * @param array $block_info block information.
87 * @return string $output html output.
88 */
89 function theme_taxonomy_filter_block_content($sections, $block_info) {
90 drupal_add_css(drupal_get_path('module', 'taxonomy_filter') .'/taxonomy_filter.css');
91 $output = '';
92 foreach ($sections as $section) {
93 if ((/*isset($section['items']) &&*/ count($section['items']) >= 0) || isset($section['content'])) {
94 $output .= theme('taxonomy_filter_section', $section, $block_info);
95 }
96 }
97 return $output;
98 }
99
100 /**
101 * Process variables for taxonomy-filter-section.tpl.php.
102 */
103 function template_preprocess_taxonomy_filter_section(&$variables) {
104 if ($variables['section']['info']['module'] == 'tf_context') {
105 // Context menu has another level to the arrays for parents, children, related and toplevel.
106 // All other menu templates are similar to the default "static" (as it is called in 5.x) list.
107 return;
108 }
109
110 $items = $variables['section']['items'];
111 $is_list = (count($items) > 0);
112 $section_info = $variables['section']['info'];
113 $block_info = $variables['block_info'];
114
115 if (isset($variables['section']['content'])) {
116 $variables['content'] = $variables['section']['content'];
117 }
118 else {
119 $content = '';
120 if ($is_list) {
121 foreach ($items as $item) {
122 $content .= theme('taxonomy_filter_item', $item, $section_info, $block_info);
123 }
124 }
125 $variables['content'] = $content;
126 }
127 $variables['title'] = $variables['section']['title'];
128 $variables['is_list'] = $is_list;
129 if (is_array($variables['section']['info']['class'])) {
130 $variables['class'] = implode(' ', $variables['section']['info']['class']);
131 }
132 }
133
134 /**
135 * Process variables for taxonomy-filter-item.tpl.php.
136 */
137 function template_preprocess_taxonomy_filter_item(&$variables) {
138 $link_attributes = array();
139 $link_tids = $variables['item']['info']['link_tids'];
140 // TODO: depth handling
141 // $depth = isset($variables['section_info']['link_depth']) ? $variables['section_info']['link_depth'] : NULL;
142 $depth = isset($variables['section_info']['section_settings']['depth']) ? $variables['section_info']['section_settings']['depth'] : NULL;
143 if (isset($variables['item']['link_attributes']['href'])) {
144 $link_attributes['href'] = $variables['item']['link_attributes']['href'];
145 }
146 else {
147 $path = _taxonomy_filter_format_path($link_tids, $depth, NULL);
148 if ($path != '') {
149 $link_attributes['href'] = $path;
150 }
151 }
152 if (isset($variables['item']['link_attributes']['class'])) {
153 $link_attributes['class'] = $variables['item']['link_attributes']['class'];
154 }
155 if (isset($variables['item']['link_attributes']['title'])) {
156 $link_attributes['title'] = $variables['item']['link_attributes']['title'];
157 }
158 $name = $variables['item']['title'];
159 $variables['link'] = theme('taxonomy_filter_link', $name, $link_attributes);
160 if (isset($variables['item']['item_attributes']['class'])) {
161 $variables['class'] = implode(' ', $variables['item']['item_attributes']['class']);
162 }
163 }
164
165 /**
166 * Render a taxonomy filter link.
167 *
168 * @param string $name link display text.
169 * @param array $attributes html attributes.
170 * @return string html output.
171 */
172 function theme_taxonomy_filter_link($name, $attributes) {
173 if ($name) {
174 if (isset($attributes['class']) && is_array($attributes['class'])) {
175 $attributes['class'] = implode(' ', $attributes['class']);
176 }
177 if (isset($attributes['href'])) {
178 if (isset($attributes['super'])) {
179 unset($attributes['super']);
180 $output = '<a'. drupal_attributes($attributes) . '>' . $name . '</a>';
181 $output = '&nbsp;<sup>['. $output . ']</sup>&nbsp;';
182 }
183 else {
184 $output = '<a'. drupal_attributes($attributes) . '>' . $name . '</a>';
185 }
186 }
187 else {
188 $output = '<span'. drupal_attributes($attributes) .'>'. $name .'</span>';
189 }
190 return $output;
191 }
192 }
193
194 /**
195 * Render a list of available taxonomy filter menu templates.
196 *
197 * @param array $form form elements.
198 * @return string html output.
199 */
200 function theme_taxonomy_filter_admin_list_form_templates($form) {
201 $rows = array();
202 foreach (element_children($form) as $key) {
203 $template = &$form[$key];
204 $row = array();
205 $row[] = drupal_render($template['name']);
206 $row[] = drupal_render($template['desc']);
207 $row[] = drupal_render($template['module']);
208 $row[] = array('data' => $template['status']['#value'], 'class' => 'status');
209 $rows[] = array('data' => $row, 'class' => $template['status']['#class']);
210 }
211 $header = array(t('Name'), t('Description'), t('Module'), t('Status'));
212
213 $output = theme('table', $header, $rows);
214
215 return $output;
216 }
217
218 /**
219 * Render a list of configured taxonomy filter menus.
220 *
221 * @param array $form form elements.
222 * @return string html output.
223 */
224 function theme_taxonomy_filter_admin_list_form_menus($form) {
225 $css_path = drupal_get_path('module', 'taxonomy_filter') .'/taxonomy-filter-admin.css';
226 drupal_add_css($css_path, 'module', 'all', FALSE);
227
228 $rows = array();
229 foreach (element_children($form) as $key) {
230 $menu = &$form[$key];
231 $row = array();
232 $row[] = drupal_render($menu['name']);
233 $row[] = drupal_render($menu['template']);
234 $row[] = drupal_render($menu['edit']);
235 $row[] = drupal_render($menu['delete']);
236 $row[] = drupal_render($menu['vocabs']);
237 $rows[] = array('data' => $row, 'class' => $menu['status']['#class']);
238 }
239
240 $header = array(t('Name'), t('Template'), array('data' => t('Operations'), 'colspan' => 2), t('Vocabs used on')); //, t('Module status'));
241
242 $output = theme('table', $header, $rows);
243
244 return $output;
245 }
246
247 /**
248 * Render an editable list of taxonomy filter menu to vocabulary mappings.
249 *
250 * @param array $form form elements.
251 * @return string html output.
252 */
253 function theme_taxonomy_filter_admin_mappings_table($form) {
254 $mappings = variable_get('taxonomy_filter_mappings', array()); // TODO Duplicates call in form builder.
255 $vids = array_keys($mappings);
256
257 $rows = array();
258
259 $header1 = '<tr>';
260 $header1 .= _theme_table_cell(t('The filter menu for:'), true);
261 $header1 .= _theme_table_cell(
262 array(
263 'data' => t('uses:'),
264 'colspan' => 2,
265 ), true);
266 $header1 .= _theme_table_cell(
267 array(
268 'data' => t('and appears on term listings from:'),
269 ), true);
270 $header1 .= '</tr>';
271
272 $header = array('Vocabulary', 'Refine Criteria', ' Current Criteria', 'Vocabularies', 'Operations');
273 foreach ($vids as $row_vid) {
274 $vocab = &$form['vocab'. $row_vid]; // TODO Are the '&' references needed???
275 $vocab_name = drupal_render($vocab);
276
277 $row = array();
278 $row[] = $vocab_name;
279
280 $menu = &$form['refine_menu'. $row_vid]; // TODO Are the '&' references needed???
281 $row[] = drupal_render($menu);
282
283 $menu = &$form['current_menu'. $row_vid]; // TODO Are the '&' references needed???
284 $row[] = drupal_render($menu);
285
286 $menu = $form['vocabs'. $row_vid];
287 $row[] = drupal_render($menu);
288
289 $menu = $form['edit'. $row_vid];
290 $row[] = drupal_render($menu);
291
292 $rows[] = array('data' => $row);
293 }
294
295 $table_output = theme('table', $header, $rows);
296 $table_output = str_replace("<thead>", "<thead>$header1\n", $table_output);
297
298 return $table_output;
299 }

  ViewVC Help
Powered by ViewVC 1.1.2