1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * @file theme.inc |
---|
5 | * |
---|
6 | * An array of preprocessors to fill variables for templates and helper |
---|
7 | * functions to make theming easier. |
---|
8 | */ |
---|
9 | |
---|
10 | /** |
---|
11 | * Provide a full array of possible themes to try for a given hook. |
---|
12 | * |
---|
13 | * @param $hook |
---|
14 | * The hook to use. This is the base theme/template name. |
---|
15 | * @param $view |
---|
16 | * The view being rendered. |
---|
17 | * @param $display |
---|
18 | * The display being rendered, if applicable. |
---|
19 | */ |
---|
20 | function _views_theme_functions($hook, $view, $display = NULL) { |
---|
21 | $themes = array(); |
---|
22 | |
---|
23 | if ($display) { |
---|
24 | $themes[] = $hook . '__' . $view->name . '__' . $display->id; |
---|
25 | $themes[] = $hook . '__' . $display->id; |
---|
26 | $themes[] = $hook . '__' . preg_replace('/[^a-z0-9]/', '_', strtolower($view->tag)); |
---|
27 | if ($display->id != $display->display_plugin) { |
---|
28 | $themes[] = $hook . '__' . $view->name . '__' . $display->display_plugin; |
---|
29 | $themes[] = $hook . '__' . $display->display_plugin; |
---|
30 | } |
---|
31 | } |
---|
32 | $themes[] = $hook . '__' . $view->name; |
---|
33 | $themes[] = $hook; |
---|
34 | return $themes; |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * Preprocess the primary theme implementation for a view. |
---|
39 | */ |
---|
40 | function template_preprocess_views_view(&$vars) { |
---|
41 | global $base_path; |
---|
42 | |
---|
43 | $view = $vars['view']; |
---|
44 | |
---|
45 | $vars['rows'] = !empty($view->result) || $view->style_plugin->even_empty() ? $view->style_plugin->render($view->result) : ''; |
---|
46 | |
---|
47 | $vars['css_name'] = views_css_safe($view->name); |
---|
48 | $vars['name'] = $view->name; |
---|
49 | $vars['display_id'] = $view->current_display; |
---|
50 | |
---|
51 | // Basic classes |
---|
52 | $vars['css_class'] = ''; |
---|
53 | |
---|
54 | $vars['classes_array'] = array(); |
---|
55 | $vars['classes_array'][] = 'view'; |
---|
56 | $vars['classes_array'][] = 'view-' . views_css_safe($vars['name']); |
---|
57 | $vars['classes_array'][] = 'view-id-' . $vars['name']; |
---|
58 | $vars['classes_array'][] = 'view-display-id-' . $vars['display_id']; |
---|
59 | |
---|
60 | $css_class = $view->display_handler->get_option('css_class'); |
---|
61 | if (!empty($css_class)) { |
---|
62 | $vars['css_class'] = preg_replace('/[^a-zA-Z0-9- ]/', '-', $css_class); |
---|
63 | $vars['classes_array'][] = $vars['css_class']; |
---|
64 | } |
---|
65 | |
---|
66 | $empty = empty($vars['rows']); |
---|
67 | |
---|
68 | $vars['header'] = $view->display_handler->render_area('header', $empty); |
---|
69 | $vars['footer'] = $view->display_handler->render_area('footer', $empty); |
---|
70 | if ($empty) { |
---|
71 | $vars['empty'] = $view->display_handler->render_area('empty', $empty); |
---|
72 | } |
---|
73 | |
---|
74 | $vars['exposed'] = !empty($view->exposed_widgets) ? $view->exposed_widgets : ''; |
---|
75 | $vars['more'] = $view->display_handler->render_more_link(); |
---|
76 | $vars['feed_icon'] = !empty($view->feed_icon) ? $view->feed_icon : ''; |
---|
77 | |
---|
78 | $vars['pager'] = ''; |
---|
79 | |
---|
80 | if ($view->display_handler->render_pager()) { |
---|
81 | $exposed_input = isset($view->exposed_raw_input) ? $view->exposed_raw_input: NULL; |
---|
82 | $vars['pager'] = $view->query->render_pager($exposed_input); |
---|
83 | } |
---|
84 | |
---|
85 | $vars['attachment_before'] = !empty($view->attachment_before) ? $view->attachment_before : ''; |
---|
86 | $vars['attachment_after'] = !empty($view->attachment_after) ? $view->attachment_after : ''; |
---|
87 | |
---|
88 | // if administrator, add some links. These used to be tabs, but this is better. |
---|
89 | if (user_access('administer views') && module_exists('views_ui') && empty($view->hide_admin_links) && !variable_get('views_no_hover_links', FALSE)) { |
---|
90 | $vars['admin_links_raw'] = array( |
---|
91 | array( |
---|
92 | 'title' => t('Edit view'), |
---|
93 | 'alt' => t("Edit this view"), |
---|
94 | 'href' => "admin/build/views/edit/$view->name", |
---|
95 | 'fragment' => 'views-tab-' . $view->current_display, |
---|
96 | 'query' => drupal_get_destination(), |
---|
97 | ), |
---|
98 | ); |
---|
99 | |
---|
100 | drupal_alter('views_admin_links', $vars['admin_links_raw'], $view); |
---|
101 | $vars['admin_links'] = theme('links', $vars['admin_links_raw']); |
---|
102 | } |
---|
103 | else { |
---|
104 | $vars['admin_links'] = ''; |
---|
105 | $vars['admin_links_raw'] = array(); |
---|
106 | } |
---|
107 | |
---|
108 | // Our JavaScript needs to have some means to find the HTML belonging to this |
---|
109 | // view. |
---|
110 | // |
---|
111 | // It is true that the DIV wrapper has classes denoting the name of the view |
---|
112 | // and its display ID, but this is not enough to unequivocally match a view |
---|
113 | // with its HTML, because one view may appear several times on the page. So |
---|
114 | // we set up a hash with the current time, $dom_id, to issue a "unique" identifier for |
---|
115 | // each view. This identifier is written to both Drupal.settings and the DIV |
---|
116 | // wrapper. |
---|
117 | $vars['dom_id'] = !empty($view->dom_id) ? $view->dom_id : md5($view->name . time() . rand()); |
---|
118 | $vars['classes_array'][] = 'view-dom-id-' . $vars['dom_id']; |
---|
119 | |
---|
120 | // If using AJAX, send identifying data about this view. |
---|
121 | if ($view->use_ajax) { |
---|
122 | $settings = array( |
---|
123 | 'views' => array( |
---|
124 | 'ajax_path' => url('views/ajax'), |
---|
125 | 'ajaxViews' => array( |
---|
126 | 'views_dom_id:' . $vars['dom_id'] => array( |
---|
127 | 'view_name' => $view->name, |
---|
128 | 'view_display_id' => $view->current_display, |
---|
129 | 'view_args' => check_plain(implode('/', $view->args)), |
---|
130 | 'view_path' => check_plain($_GET['q']), |
---|
131 | // Pass through URL to ensure we get e.g. language prefixes. |
---|
132 | // 'view_base_path' => isset($view->display['page']) ? substr(url($view->display['page']->display_options['path']), strlen($base_path)) : '', |
---|
133 | 'view_base_path' => $view->get_path(), |
---|
134 | 'view_dom_id' => $vars['dom_id'], |
---|
135 | // To fit multiple views on a page, the programmer may have |
---|
136 | // overridden the display's pager_element. |
---|
137 | 'pager_element' => isset($view->query->pager) ? $view->query->pager->get_pager_id() : 0, |
---|
138 | ), |
---|
139 | ), |
---|
140 | ), |
---|
141 | ); |
---|
142 | |
---|
143 | drupal_add_js($settings, 'setting'); |
---|
144 | views_add_js('ajax_view'); |
---|
145 | } |
---|
146 | // Flatten the classes to a string for the template file. |
---|
147 | $vars['classes'] = implode(' ', $vars['classes_array']); |
---|
148 | |
---|
149 | // If form fields were found in the View, reformat the View output as a form. |
---|
150 | if (views_view_has_form_elements($view)) { |
---|
151 | $vars['rows'] = drupal_get_form(views_form_id($view), $view, $vars['rows']); |
---|
152 | // The form is requesting that all non-essential views elements be hidden, |
---|
153 | // usually because the rendered step is not a view result. |
---|
154 | if ($view->show_view_elements == FALSE) { |
---|
155 | $vars['header'] = ''; |
---|
156 | $vars['exposed'] = ''; |
---|
157 | $vars['pager'] = ''; |
---|
158 | $vars['footer'] = ''; |
---|
159 | $vars['more'] = ''; |
---|
160 | $vars['feed_icon'] = ''; |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | /** |
---|
166 | * Preprocess theme function to print a single record from a row, with fields |
---|
167 | */ |
---|
168 | function template_preprocess_views_view_fields(&$vars) { |
---|
169 | $view = $vars['view']; |
---|
170 | |
---|
171 | // Loop through the fields for this view. |
---|
172 | $previous_inline = FALSE; |
---|
173 | $vars['fields'] = array(); // ensure it's at least an empty array. |
---|
174 | foreach ($view->field as $id => $field) { |
---|
175 | // render this even if set to exclude so it can be used elsewhere. |
---|
176 | $field_output = $view->style_plugin->get_field($view->row_index, $id); |
---|
177 | $empty = $field_output !== 0 && empty($field_output); |
---|
178 | if (empty($field->options['exclude']) && (!$empty || (empty($field->options['hide_empty']) && empty($vars['options']['hide_empty'])))) { |
---|
179 | $object = new stdClass(); |
---|
180 | $object->handler = &$view->field[$id]; |
---|
181 | $object->inline = !empty($vars['options']['inline'][$id]); |
---|
182 | |
---|
183 | $object->element_type = $object->handler->element_type(TRUE, !$vars['options']['default_field_elements'], $object->inline); |
---|
184 | if ($object->element_type) { |
---|
185 | $class = ''; |
---|
186 | if ($object->handler->options['element_default_classes']) { |
---|
187 | $class = 'field-content'; |
---|
188 | } |
---|
189 | |
---|
190 | if ($classes = $object->handler->element_classes($view->row_index)) { |
---|
191 | if ($class) { |
---|
192 | $class .= ' '; |
---|
193 | } |
---|
194 | $class .= $classes; |
---|
195 | } |
---|
196 | |
---|
197 | $pre = '<' . $object->element_type; |
---|
198 | if ($class) { |
---|
199 | $pre .= ' class="' . $class . '"'; |
---|
200 | } |
---|
201 | $field_output = $pre . '>' . $field_output . '</' . $object->element_type . '>'; |
---|
202 | } |
---|
203 | |
---|
204 | // Protect ourself somewhat for backward compatibility. This will prevent |
---|
205 | // old templates from producing invalid HTML when no element type is selected. |
---|
206 | if (empty($object->element_type)) { |
---|
207 | $object->element_type = 'span'; |
---|
208 | } |
---|
209 | |
---|
210 | $object->content = $field_output; |
---|
211 | if (isset($view->field[$id]->field_alias) && isset($vars['row']->{$view->field[$id]->field_alias})) { |
---|
212 | $object->raw = $vars['row']->{$view->field[$id]->field_alias}; |
---|
213 | } |
---|
214 | else { |
---|
215 | $object->raw = NULL; // make sure it exists to reduce NOTICE |
---|
216 | } |
---|
217 | |
---|
218 | if (!empty($vars['options']['separator']) && $previous_inline && $object->inline && $object->content) { |
---|
219 | $object->separator = filter_xss_admin($vars['options']['separator']); |
---|
220 | } |
---|
221 | |
---|
222 | $object->class = views_css_safe($id); |
---|
223 | |
---|
224 | $previous_inline = $object->inline; |
---|
225 | $object->inline_html = $object->handler->element_wrapper_type(TRUE, TRUE); |
---|
226 | if ($object->inline_html === '' && $vars['options']['default_field_elements']) { |
---|
227 | $object->inline_html = $object->inline ? 'span' : 'div'; |
---|
228 | } |
---|
229 | |
---|
230 | // Set up the wrapper HTML. |
---|
231 | $object->wrapper_prefix = ''; |
---|
232 | $object->wrapper_suffix = ''; |
---|
233 | |
---|
234 | if ($object->inline_html) { |
---|
235 | $class = ''; |
---|
236 | if ($object->handler->options['element_default_classes']) { |
---|
237 | $class = "views-field views-field-" . $object->class; |
---|
238 | } |
---|
239 | |
---|
240 | if ($classes = $object->handler->element_wrapper_classes($view->row_index)) { |
---|
241 | if ($class) { |
---|
242 | $class .= ' '; |
---|
243 | } |
---|
244 | $class .= $classes; |
---|
245 | } |
---|
246 | |
---|
247 | $object->wrapper_prefix = '<' . $object->inline_html; |
---|
248 | if ($class) { |
---|
249 | $object->wrapper_prefix .= ' class="' . $class . '"'; |
---|
250 | } |
---|
251 | $object->wrapper_prefix .= '>'; |
---|
252 | $object->wrapper_suffix = '</' . $object->inline_html . '>'; |
---|
253 | } |
---|
254 | |
---|
255 | // Set up the label for the value and the HTML to make it easier |
---|
256 | // on the template. |
---|
257 | $object->label = check_plain($view->field[$id]->label()); |
---|
258 | $object->label_html = ''; |
---|
259 | if ($object->label) { |
---|
260 | $object->label_html .= $object->label; |
---|
261 | if ($object->handler->options['element_label_colon']) { |
---|
262 | $object->label_html .= ': '; |
---|
263 | } |
---|
264 | |
---|
265 | $object->element_label_type = $object->handler->element_label_type(TRUE, !$vars['options']['default_field_elements']); |
---|
266 | if ($object->element_label_type) { |
---|
267 | $class = ''; |
---|
268 | if ($object->handler->options['element_default_classes']) { |
---|
269 | $class = 'views-label views-label-' . $object->class; |
---|
270 | } |
---|
271 | |
---|
272 | $element_label_class = $object->handler->element_label_classes($view->row_index); |
---|
273 | if ($element_label_class) { |
---|
274 | if ($class) { |
---|
275 | $class .= ' '; |
---|
276 | } |
---|
277 | |
---|
278 | $class .= $element_label_class; |
---|
279 | } |
---|
280 | |
---|
281 | $pre = '<' . $object->element_label_type; |
---|
282 | if ($class) { |
---|
283 | $pre .= ' class="' . $class . '"'; |
---|
284 | } |
---|
285 | $pre .= '>'; |
---|
286 | |
---|
287 | $object->label_html = $pre . $object->label_html . '</' . $object->element_label_type . '>'; |
---|
288 | } |
---|
289 | } |
---|
290 | |
---|
291 | $vars['fields'][$id] = $object; |
---|
292 | } |
---|
293 | } |
---|
294 | |
---|
295 | } |
---|
296 | |
---|
297 | /** |
---|
298 | * Display a single views field. |
---|
299 | * |
---|
300 | * Interesting bits of info: |
---|
301 | * $field->field_alias says what the raw value in $row will be. Reach it like |
---|
302 | * this: @code { $row->{$field->field_alias} @endcode |
---|
303 | */ |
---|
304 | function theme_views_view_field($view, $field, $row) { |
---|
305 | // Reference safe for PHP 4: |
---|
306 | return $view->field[$field->options['id']]->advanced_render($row); |
---|
307 | } |
---|
308 | |
---|
309 | /** |
---|
310 | * Process a single field within a view. |
---|
311 | * |
---|
312 | * This preprocess function isn't normally run, as a function is used by |
---|
313 | * default, for performance. However, by creating a template, this |
---|
314 | * preprocess should get picked up. |
---|
315 | */ |
---|
316 | function template_preprocess_views_view_field(&$vars) { |
---|
317 | $vars['output'] = $vars['field']->advanced_render($vars['row']); |
---|
318 | } |
---|
319 | |
---|
320 | /** |
---|
321 | * Preprocess theme function to print a single record from a row, with fields |
---|
322 | */ |
---|
323 | function template_preprocess_views_view_summary(&$vars) { |
---|
324 | $view = $vars['view']; |
---|
325 | $argument = $view->argument[$view->build_info['summary_level']]; |
---|
326 | |
---|
327 | $url_options = array(); |
---|
328 | |
---|
329 | if (!empty($view->exposed_raw_input)) { |
---|
330 | $url_options['query'] = $view->exposed_raw_input; |
---|
331 | } |
---|
332 | $vars['classes'] = array(); |
---|
333 | foreach ($vars['rows'] as $id => $row) { |
---|
334 | $vars['rows'][$id]->link = $argument->summary_name($row); |
---|
335 | $args = $view->args; |
---|
336 | $args[$argument->position] = $argument->summary_argument($row); |
---|
337 | |
---|
338 | $base_path = NULL; |
---|
339 | if (!empty($argument->options['style_options']['base_path'])) { |
---|
340 | $base_path = $argument->options['style_options']['base_path']; |
---|
341 | } |
---|
342 | $vars['rows'][$id]->url = url($view->get_url($args, $base_path), $url_options); |
---|
343 | $vars['rows'][$id]->count = intval($row->{$argument->count_alias}); |
---|
344 | if ($vars['rows'][$id]->url == base_path() . $_GET['q'] || $vars['rows'][$id]->url == base_path() . drupal_get_path_alias($_GET['q'])) { |
---|
345 | $vars['classes'][$id] = 'active'; |
---|
346 | } |
---|
347 | } |
---|
348 | } |
---|
349 | |
---|
350 | /** |
---|
351 | * Template preprocess theme function to print summary basically |
---|
352 | * unformatted. |
---|
353 | */ |
---|
354 | function template_preprocess_views_view_summary_unformatted(&$vars) { |
---|
355 | $view = $vars['view']; |
---|
356 | $argument = $view->argument[$view->build_info['summary_level']]; |
---|
357 | $vars['classes'] = array(); |
---|
358 | |
---|
359 | $url_options = array(); |
---|
360 | |
---|
361 | if (!empty($view->exposed_raw_input)) { |
---|
362 | $url_options['query'] = $view->exposed_raw_input; |
---|
363 | } |
---|
364 | |
---|
365 | $count = 0; |
---|
366 | foreach ($vars['rows'] as $id => $row) { |
---|
367 | // only false on first time: |
---|
368 | if ($count++) { |
---|
369 | $vars['rows'][$id]->separator = filter_xss_admin($vars['options']['separator']); |
---|
370 | } |
---|
371 | $vars['rows'][$id]->link = $argument->summary_name($row); |
---|
372 | $args = $view->args; |
---|
373 | $args[$argument->position] = $argument->summary_argument($row); |
---|
374 | |
---|
375 | $base_path = NULL; |
---|
376 | if (!empty($argument->options['style_options']['base_path'])) { |
---|
377 | $base_path = $argument->options['style_options']['base_path']; |
---|
378 | } |
---|
379 | $vars['rows'][$id]->url = url($view->get_url($args, $base_path), $url_options); |
---|
380 | $vars['rows'][$id]->count = intval($row->{$argument->count_alias}); |
---|
381 | if ($vars['rows'][$id]->url == base_path() . $_GET['q'] || $vars['rows'][$id]->url == base_path() . drupal_get_path_alias($_GET['q'])) { |
---|
382 | $vars['classes'][$id] = 'active'; |
---|
383 | } |
---|
384 | } |
---|
385 | } |
---|
386 | |
---|
387 | /** |
---|
388 | * Display a view as a table style. |
---|
389 | */ |
---|
390 | function template_preprocess_views_view_table(&$vars) { |
---|
391 | $view = $vars['view']; |
---|
392 | |
---|
393 | // We need the raw data for this grouping, which is passed in as $vars['rows']. |
---|
394 | // However, the template also needs to use for the rendered fields. We |
---|
395 | // therefore swap the raw data out to a new variable and reset $vars['rows'] |
---|
396 | // so that it can get rebuilt. |
---|
397 | // Store rows so that they may be used by further preprocess functions. |
---|
398 | $result = $vars['result'] = $vars['rows']; |
---|
399 | $vars['rows'] = array(); |
---|
400 | $vars['field_classes'] = array(); |
---|
401 | $vars['header'] = array(); |
---|
402 | |
---|
403 | $options = $view->style_plugin->options; |
---|
404 | $handler = $view->style_plugin; |
---|
405 | |
---|
406 | $fields = &$view->field; |
---|
407 | $columns = $handler->sanitize_columns($options['columns'], $fields); |
---|
408 | |
---|
409 | $active = !empty($handler->active) ? $handler->active : ''; |
---|
410 | $order = !empty($handler->order) ? $handler->order : 'asc'; |
---|
411 | |
---|
412 | parse_str(tablesort_get_querystring(), $query); |
---|
413 | if (isset($view->exposed_raw_input)) { |
---|
414 | $query += $view->exposed_raw_input; |
---|
415 | } |
---|
416 | $query = empty($query) ? '' : '&' . http_build_query($query, '', '&'); |
---|
417 | |
---|
418 | // Fields must be rendered in order as of Views 2.3, so we will pre-render |
---|
419 | // everything. |
---|
420 | $renders = $handler->render_fields($result); |
---|
421 | |
---|
422 | foreach ($columns as $field => $column) { |
---|
423 | // Create a second variable so we can easily find what fields we have and what the |
---|
424 | // CSS classes should be. |
---|
425 | $vars['fields'][$field] = views_css_safe($field); |
---|
426 | if ($active == $field) { |
---|
427 | $vars['fields'][$field] .= ' active'; |
---|
428 | } |
---|
429 | |
---|
430 | // render the header labels |
---|
431 | if ($field == $column && empty($fields[$field]->options['exclude'])) { |
---|
432 | $label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : ''); |
---|
433 | if (empty($options['info'][$field]['sortable']) || !$fields[$field]->click_sortable()) { |
---|
434 | $vars['header'][$field] = $label; |
---|
435 | } |
---|
436 | else { |
---|
437 | $initial = !empty($options['info'][$field]['default_sort_order']) ? $options['info'][$field]['default_sort_order'] : 'asc'; |
---|
438 | |
---|
439 | if ($active == $field) { |
---|
440 | $initial = ($order == 'asc') ? 'desc' : 'asc'; |
---|
441 | } |
---|
442 | |
---|
443 | $title = t('sort by @s', array('@s' => $label)); |
---|
444 | if ($active == $field) { |
---|
445 | $label .= theme('tablesort_indicator', $initial); |
---|
446 | } |
---|
447 | $link_options = array( |
---|
448 | 'html' => true, |
---|
449 | 'attributes' => array('title' => $title), |
---|
450 | 'query' => 'order=' . urlencode($field) . '&sort=' . $initial . $query, |
---|
451 | ); |
---|
452 | $vars['header'][$field] = l($label, $_GET['q'], $link_options); |
---|
453 | } |
---|
454 | |
---|
455 | $vars['header_classes'][$field] = ''; |
---|
456 | // Set up the header label class. |
---|
457 | if ($fields[$field]->options['element_default_classes']) { |
---|
458 | $vars['header_classes'][$field] .= "views-field views-field-" . $vars['fields'][$field]; |
---|
459 | } |
---|
460 | $class = $fields[$field]->element_label_classes(0); |
---|
461 | if ($class) { |
---|
462 | if ($vars['header_classes'][$field]) { |
---|
463 | $vars['header_classes'][$field] .= ' '; |
---|
464 | } |
---|
465 | $vars['header_classes'][$field] .= $class; |
---|
466 | } |
---|
467 | |
---|
468 | // Add a header label wrapper if one was selected. |
---|
469 | if ($vars['header'][$field]) { |
---|
470 | $element_label_type = $fields[$field]->element_label_type(TRUE, TRUE); |
---|
471 | if ($element_label_type) { |
---|
472 | $vars['header'][$field] = '<' . $element_label_type . '>' . $vars['header'][$field] . '</' . $element_label_type . '>'; |
---|
473 | } |
---|
474 | } |
---|
475 | |
---|
476 | } |
---|
477 | |
---|
478 | // Add a CSS align class to each field if one was set |
---|
479 | if (!empty($options['info'][$field]['align'])) { |
---|
480 | $vars['fields'][$field] .= ' ' . views_css_safe($options['info'][$field]['align']); |
---|
481 | } |
---|
482 | |
---|
483 | // Render each field into its appropriate column. |
---|
484 | foreach ($result as $num => $row) { |
---|
485 | // Add field classes |
---|
486 | $vars['field_classes'][$field][$num] = ''; |
---|
487 | if ($fields[$field]->options['element_default_classes']) { |
---|
488 | $vars['field_classes'][$field][$num] = "views-field views-field-" . $vars['fields'][$field]; |
---|
489 | } |
---|
490 | if ($classes = $fields[$field]->element_classes($num)) { |
---|
491 | if ($vars['field_classes'][$field][$num]) { |
---|
492 | $vars['field_classes'][$field][$num] .= ' '; |
---|
493 | } |
---|
494 | |
---|
495 | $vars['field_classes'][$field][$num] .= $classes; |
---|
496 | } |
---|
497 | $vars['field_attributes'][$field][$num] = array(); |
---|
498 | |
---|
499 | if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) { |
---|
500 | $field_output = $renders[$num][$field]; |
---|
501 | $element_type = $fields[$field]->element_type(TRUE, TRUE); |
---|
502 | if ($element_type) { |
---|
503 | $field_output = '<' . $element_type . '>' . $field_output . '</' . $element_type . '>'; |
---|
504 | } |
---|
505 | |
---|
506 | // Don't bother with separators and stuff if the field does not show up. |
---|
507 | if (empty($field_output) && !empty($vars['rows'][$num][$column])) { |
---|
508 | continue; |
---|
509 | } |
---|
510 | |
---|
511 | // Place the field into the column, along with an optional separator. |
---|
512 | if (!empty($vars['rows'][$num][$column])) { |
---|
513 | if (!empty($options['info'][$column]['separator'])) { |
---|
514 | $vars['rows'][$num][$column] .= filter_xss_admin($options['info'][$column]['separator']); |
---|
515 | } |
---|
516 | } |
---|
517 | else { |
---|
518 | $vars['rows'][$num][$column] = ''; |
---|
519 | } |
---|
520 | |
---|
521 | $vars['rows'][$num][$column] .= $field_output; |
---|
522 | } |
---|
523 | } |
---|
524 | } |
---|
525 | |
---|
526 | $count = 0; |
---|
527 | foreach ($vars['rows'] as $num => $row) { |
---|
528 | $vars['row_classes'][$num][] = ($count++ % 2 == 0) ? 'odd' : 'even'; |
---|
529 | if ($row_class = $handler->get_row_class($num)) { |
---|
530 | $vars['row_classes'][$num][] = $row_class; |
---|
531 | } |
---|
532 | } |
---|
533 | |
---|
534 | $vars['row_classes'][0][] = 'views-row-first'; |
---|
535 | $vars['row_classes'][count($vars['row_classes']) - 1][] = 'views-row-last'; |
---|
536 | |
---|
537 | if (empty($vars['rows']) && !empty($options['empty_table'])) { |
---|
538 | $vars['rows'][0][0] = $view->display_handler->render_area('empty'); |
---|
539 | // Calculate the amounts of rows with output. |
---|
540 | $vars['field_attributes'][0][0]['colspan'] = count($vars['header']); |
---|
541 | } |
---|
542 | |
---|
543 | |
---|
544 | $vars['class'] = 'views-table'; |
---|
545 | if (!empty($options['sticky'])) { |
---|
546 | drupal_add_js('misc/tableheader.js'); |
---|
547 | $vars['class'] .= " sticky-enabled"; |
---|
548 | } |
---|
549 | $vars['class'] .= ' cols-' . count($vars['header']); |
---|
550 | |
---|
551 | $vars['attributes'] = ''; |
---|
552 | if (!empty($handler->options['summary'])) { |
---|
553 | $vars['attributes'] = drupal_attributes(array('summary' => $handler->options['summary'])); |
---|
554 | } |
---|
555 | } |
---|
556 | |
---|
557 | /** |
---|
558 | * Display a view as a grid style. |
---|
559 | */ |
---|
560 | function template_preprocess_views_view_grid(&$vars) { |
---|
561 | $view = $vars['view']; |
---|
562 | $result = $view->result; |
---|
563 | $options = $view->style_plugin->options; |
---|
564 | $handler = $view->style_plugin; |
---|
565 | |
---|
566 | $columns = $options['columns']; |
---|
567 | |
---|
568 | $rows = array(); |
---|
569 | $row_indexes = array(); |
---|
570 | |
---|
571 | if ($options['alignment'] == 'horizontal') { |
---|
572 | $row = array(); |
---|
573 | $col_count = 0; |
---|
574 | $row_count = 0; |
---|
575 | $count = 0; |
---|
576 | foreach ($vars['rows'] as $row_index => $item) { |
---|
577 | $count++; |
---|
578 | $row[] = $item; |
---|
579 | $row_indexes[$row_count][$col_count] = $row_index; |
---|
580 | $col_count++; |
---|
581 | if ($count % $columns == 0) { |
---|
582 | $rows[] = $row; |
---|
583 | $row = array(); |
---|
584 | $col_count = 0; |
---|
585 | $row_count++; |
---|
586 | } |
---|
587 | } |
---|
588 | if ($row) { |
---|
589 | // Fill up the last line only if it's configured, but this is default. |
---|
590 | if (!empty($handler->options['fill_single_line']) && count($rows)) { |
---|
591 | for ($i = 0; $i < ($columns - $col_count); $i++) { |
---|
592 | $row[] = ''; |
---|
593 | } |
---|
594 | } |
---|
595 | $rows[] = $row; |
---|
596 | } |
---|
597 | } |
---|
598 | else { |
---|
599 | $num_rows = floor(count($vars['rows']) / $columns); |
---|
600 | // The remainders are the 'odd' columns that are slightly longer. |
---|
601 | $remainders = count($vars['rows']) % $columns; |
---|
602 | $row = 0; |
---|
603 | $col = 0; |
---|
604 | foreach ($vars['rows'] as $count => $item) { |
---|
605 | $rows[$row][$col] = $item; |
---|
606 | $row_indexes[$row][$col] = $count; |
---|
607 | $row++; |
---|
608 | |
---|
609 | if (!$remainders && $row == $num_rows) { |
---|
610 | $row = 0; |
---|
611 | $col++; |
---|
612 | } |
---|
613 | else if ($remainders && $row == $num_rows + 1) { |
---|
614 | $row = 0; |
---|
615 | $col++; |
---|
616 | $remainders--; |
---|
617 | } |
---|
618 | } |
---|
619 | for ($i = 0; $i < count($rows[0]); $i++) { |
---|
620 | // This should be string so that's okay :) |
---|
621 | if (!isset($rows[count($rows) - 1][$i])) { |
---|
622 | $rows[count($rows) - 1][$i] = ''; |
---|
623 | } |
---|
624 | } |
---|
625 | } |
---|
626 | |
---|
627 | // Apply the row classes |
---|
628 | foreach ($rows as $row_number => $row) { |
---|
629 | $row_classes = array(); |
---|
630 | $row_classes[] = 'row-' . ($row_number + 1); |
---|
631 | if ($row_number == 0) { |
---|
632 | $row_classes[] = 'row-first'; |
---|
633 | } |
---|
634 | if (count($rows) == ($row_number + 1)) { |
---|
635 | $row_classes[] = 'row-last'; |
---|
636 | } |
---|
637 | $vars['row_classes'][$row_number] = implode(' ', $row_classes); |
---|
638 | foreach ($rows[$row_number] as $column_number => $item) { |
---|
639 | $column_classes = array(); |
---|
640 | $column_classes[] = 'col-'. ($column_number + 1); |
---|
641 | if ($column_number == 0) { |
---|
642 | $column_classes[] = 'col-first'; |
---|
643 | } |
---|
644 | elseif (count($rows[$row_number]) == ($column_number + 1)) { |
---|
645 | $column_classes[] = 'col-last'; |
---|
646 | } |
---|
647 | if (isset($row_indexes[$row_number][$column_number]) && $column_class = $view->style_plugin->get_row_class($row_indexes[$row_number][$column_number])) { |
---|
648 | $column_classes[] = $column_class; |
---|
649 | } |
---|
650 | $vars['column_classes'][$row_number][$column_number] = implode(' ', $column_classes); |
---|
651 | } |
---|
652 | } |
---|
653 | $vars['rows'] = $rows; |
---|
654 | $vars['class'] = 'views-view-grid col-' . $columns; |
---|
655 | $vars['attributes'] = ''; |
---|
656 | if (!empty($handler->options['summary'])) { |
---|
657 | $vars['attributes'] = drupal_attributes(array('summary' => $handler->options['summary'])); |
---|
658 | } |
---|
659 | } |
---|
660 | |
---|
661 | /** |
---|
662 | * Display the simple view of rows one after another |
---|
663 | */ |
---|
664 | function template_preprocess_views_view_unformatted(&$vars) { |
---|
665 | $view = $vars['view']; |
---|
666 | $rows = $vars['rows']; |
---|
667 | |
---|
668 | $vars['classes'] = array(); |
---|
669 | // Set up striping values. |
---|
670 | $count = 0; |
---|
671 | $max = count($rows); |
---|
672 | foreach ($rows as $id => $row) { |
---|
673 | $count++; |
---|
674 | $row_classes = array(); |
---|
675 | $row_classes[] = 'views-row'; |
---|
676 | $row_classes[] = 'views-row-' . $count; |
---|
677 | $row_classes[] = 'views-row-' . ($count % 2 ? 'odd' : 'even'); |
---|
678 | if ($count == 1) { |
---|
679 | $row_classes[] = 'views-row-first'; |
---|
680 | } |
---|
681 | if ($count == $max) { |
---|
682 | $row_classes[] = 'views-row-last'; |
---|
683 | } |
---|
684 | |
---|
685 | if ($row_class = $view->style_plugin->get_row_class($id)) { |
---|
686 | $row_classes[] = $row_class; |
---|
687 | } |
---|
688 | |
---|
689 | // Flatten the classes to a string for each row for the template file. |
---|
690 | $vars['classes'][$id] = implode(' ', $row_classes); |
---|
691 | } |
---|
692 | } |
---|
693 | |
---|
694 | /** |
---|
695 | * Display the view as an HTML list element |
---|
696 | */ |
---|
697 | function template_preprocess_views_view_list(&$vars) { |
---|
698 | $handler = $vars['view']->style_plugin; |
---|
699 | |
---|
700 | $vars['class'] = views_css_safe($handler->options['class']); |
---|
701 | $vars['wrapper_class'] = views_css_safe($handler->options['wrapper_class']); |
---|
702 | $vars['wrapper_prefix'] = ''; |
---|
703 | $vars['wrapper_suffix'] = ''; |
---|
704 | $vars['list_type_prefix'] = '<' . $handler->options['type'] . '>'; |
---|
705 | $vars['list_type_suffix'] = '</' . $handler->options['type'] . '>'; |
---|
706 | if ($vars['wrapper_class']) { |
---|
707 | $vars['wrapper_prefix'] = '<div class="' . $vars['wrapper_class'] . '">'; |
---|
708 | $vars['wrapper_suffix'] = '</div>'; |
---|
709 | } |
---|
710 | |
---|
711 | if ($vars['class']) { |
---|
712 | $vars['list_type_prefix'] = '<' . $handler->options['type'] . ' class="' . $vars['class'] . '">'; |
---|
713 | } |
---|
714 | template_preprocess_views_view_unformatted($vars); |
---|
715 | } |
---|
716 | |
---|
717 | /** |
---|
718 | * Preprocess an RSS feed |
---|
719 | */ |
---|
720 | function template_preprocess_views_view_rss(&$vars) { |
---|
721 | global $base_url; |
---|
722 | global $language; |
---|
723 | |
---|
724 | $view = &$vars['view']; |
---|
725 | $options = &$vars['options']; |
---|
726 | $items = &$vars['rows']; |
---|
727 | |
---|
728 | $style = &$view->style_plugin; |
---|
729 | |
---|
730 | if (!empty($options['mission_description'])) { |
---|
731 | $description = variable_get('site_mission', ''); |
---|
732 | } |
---|
733 | else { |
---|
734 | $description = $options['description']; |
---|
735 | } |
---|
736 | // The RSS 2.0 "spec" doesn't indicate HTML can be used in the description. |
---|
737 | // We strip all HTML tags, but need to prevent double encoding from properly |
---|
738 | // escaped source data (such as & becoming &amp;). |
---|
739 | $vars['description'] = check_plain(decode_entities(strip_tags($style->get_description()))); |
---|
740 | |
---|
741 | if ($view->display_handler->get_option('sitename_title')) { |
---|
742 | $title = variable_get('site_name', 'Drupal'); |
---|
743 | if ($slogan = variable_get('site_slogan', '')) { |
---|
744 | $title .= ' - ' . $slogan; |
---|
745 | } |
---|
746 | } |
---|
747 | else { |
---|
748 | $title = $view->get_title(); |
---|
749 | } |
---|
750 | $vars['title'] = check_plain($title); |
---|
751 | |
---|
752 | // Figure out which display which has a path we're using for this feed. If there isn't |
---|
753 | // one, use the global $base_url |
---|
754 | $link_display_id = $view->display_handler->get_link_display(); |
---|
755 | if ($link_display_id && !empty($view->display[$link_display_id])) { |
---|
756 | $path = $view->display[$link_display_id]->handler->get_path(); |
---|
757 | } |
---|
758 | |
---|
759 | if ($path) { |
---|
760 | $path = $view->get_url(NULL, $path); |
---|
761 | $url_options = array('absolute' => TRUE); |
---|
762 | if (!empty($view->exposed_raw_input)) { |
---|
763 | $url_options['query'] = $view->exposed_raw_input; |
---|
764 | } |
---|
765 | |
---|
766 | // Compare the link to the default home page; if it's the default home page, just use $base_url. |
---|
767 | if ($path == variable_get('site_frontpage', 'node')) { |
---|
768 | $path = ''; |
---|
769 | } |
---|
770 | |
---|
771 | $vars['link'] = check_url(url($path, $url_options)); |
---|
772 | } |
---|
773 | |
---|
774 | $vars['langcode'] = check_plain($language->language); |
---|
775 | $vars['namespaces'] = drupal_attributes($style->namespaces); |
---|
776 | $vars['items'] = $items; |
---|
777 | $vars['channel_elements'] = format_xml_elements($style->channel_elements); |
---|
778 | |
---|
779 | drupal_set_header('Content-Type: application/rss+xml; charset=utf-8'); |
---|
780 | } |
---|
781 | |
---|
782 | /** |
---|
783 | * Default theme function for all RSS rows. |
---|
784 | */ |
---|
785 | function template_preprocess_views_view_row_rss(&$vars) { |
---|
786 | $view = &$vars['view']; |
---|
787 | $options = &$vars['options']; |
---|
788 | $item = &$vars['row']; |
---|
789 | |
---|
790 | $vars['title'] = check_plain($item->title); |
---|
791 | $vars['link'] = check_url($item->link); |
---|
792 | $vars['description'] = check_plain($item->description); |
---|
793 | $vars['item_elements'] = empty($item->elements) ? '' : format_xml_elements($item->elements); |
---|
794 | } |
---|
795 | |
---|
796 | /** |
---|
797 | * Default theme function for all filter forms. |
---|
798 | */ |
---|
799 | function template_preprocess_views_exposed_form(&$vars) { |
---|
800 | $form = &$vars['form']; |
---|
801 | |
---|
802 | // Put all single checkboxes together in the last spot. |
---|
803 | $checkboxes = ''; |
---|
804 | |
---|
805 | if (!empty($form['q'])) { |
---|
806 | $vars['q'] = drupal_render($form['q']); |
---|
807 | } |
---|
808 | |
---|
809 | $vars['widgets'] = array(); |
---|
810 | foreach ($form['#info'] as $id => $info) { |
---|
811 | // Set aside checkboxes. |
---|
812 | if (isset($form[$info['value']]['#type']) && $form[$info['value']]['#type'] == 'checkbox') { |
---|
813 | $checkboxes .= drupal_render($form[$info['value']]); |
---|
814 | continue; |
---|
815 | } |
---|
816 | $widget = new stdClass; |
---|
817 | // set up defaults so that there's always something there. |
---|
818 | $widget->label = $widget->operator = $widget->widget = NULL; |
---|
819 | |
---|
820 | $widget->id = isset($form[$info['value']]['#id']) ? $form[$info['value']]['#id'] : ''; |
---|
821 | if (!empty($info['label'])) { |
---|
822 | $widget->label = $info['label']; |
---|
823 | } |
---|
824 | if (!empty($info['operator'])) { |
---|
825 | $widget->operator = drupal_render($form[$info['operator']]); |
---|
826 | } |
---|
827 | $widget->widget = drupal_render($form[$info['value']]); |
---|
828 | $vars['widgets'][$id] = $widget; |
---|
829 | } |
---|
830 | |
---|
831 | // Wrap up all the checkboxes we set aside into a widget. |
---|
832 | if ($checkboxes) { |
---|
833 | $widget = new stdClass; |
---|
834 | // set up defaults so that there's always something there. |
---|
835 | $widget->label = $widget->operator = $widget->widget = NULL; |
---|
836 | $widget->id = 'checkboxes'; |
---|
837 | $widget->widget = $checkboxes; |
---|
838 | $vars['widgets']['checkboxes'] = $widget; |
---|
839 | } |
---|
840 | |
---|
841 | // Don't render these: |
---|
842 | unset($form['form_id']); |
---|
843 | unset($form['form_build_id']); |
---|
844 | unset($form['form_token']); |
---|
845 | |
---|
846 | if (isset($form['sort_by'])) { |
---|
847 | $vars['sort_by'] = drupal_render($form['sort_by']); |
---|
848 | $vars['sort_order'] = drupal_render($form['sort_order']); |
---|
849 | } |
---|
850 | if (isset($form['items_per_page'])) { |
---|
851 | $vars['items_per_page'] = drupal_render($form['items_per_page']); |
---|
852 | } |
---|
853 | if (isset($form['offset'])) { |
---|
854 | $vars['offset'] = drupal_render($form['offset']); |
---|
855 | } |
---|
856 | if (isset($form['reset'])) { |
---|
857 | $vars['reset_button'] = drupal_render($form['reset']); |
---|
858 | } |
---|
859 | // This includes the submit button. |
---|
860 | $vars['button'] = drupal_render($form); |
---|
861 | } |
---|
862 | |
---|
863 | /** |
---|
864 | * Theme function for a View with form elements: replace the placeholders. |
---|
865 | */ |
---|
866 | function theme_views_form_views_form($form) { |
---|
867 | // Placeholders and their substitutions (usually rendered form elements). |
---|
868 | $search = array(); |
---|
869 | $replace = array(); |
---|
870 | |
---|
871 | // Add in substitutions provided by the form. |
---|
872 | foreach ($form['#substitutions']['#value'] as $substitution) { |
---|
873 | $field_name = $substitution['field_name']; |
---|
874 | $row_id = $substitution['row_id']; |
---|
875 | |
---|
876 | $search[] = $substitution['placeholder']; |
---|
877 | $replace[] = isset($form[$field_name][$row_id]) ? drupal_render($form[$field_name][$row_id]) : ''; |
---|
878 | } |
---|
879 | // Add in substitutions from hook_views_form_substitutions(). |
---|
880 | $substitutions = module_invoke_all('views_form_substitutions'); |
---|
881 | foreach ($substitutions as $placeholder => $substitution) { |
---|
882 | $search[] = $placeholder; |
---|
883 | $replace[] = $substitution; |
---|
884 | } |
---|
885 | |
---|
886 | // Apply substitutions to the rendered output. |
---|
887 | $form['output']['#value'] = str_replace($search, $replace, $form['output']['#value']); |
---|
888 | |
---|
889 | // Render and add remaining form fields. |
---|
890 | return drupal_render($form); |
---|
891 | } |
---|
892 | |
---|
893 | function theme_views_mini_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) { |
---|
894 | global $pager_page_array, $pager_total; |
---|
895 | |
---|
896 | // Calculate various markers within this pager piece: |
---|
897 | // Middle is used to "center" pages around the current page. |
---|
898 | $pager_middle = ceil($quantity / 2); |
---|
899 | // current is the page we are currently paged to |
---|
900 | $pager_current = $pager_page_array[$element] + 1; |
---|
901 | // max is the maximum page number |
---|
902 | $pager_max = $pager_total[$element]; |
---|
903 | // End of marker calculations. |
---|
904 | |
---|
905 | |
---|
906 | $li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('â¹â¹')), $limit, $element, 1, $parameters); |
---|
907 | if (empty($li_previous)) { |
---|
908 | $li_previous = " "; |
---|
909 | } |
---|
910 | |
---|
911 | $li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('âºâº')), $limit, $element, 1, $parameters); |
---|
912 | if (empty($li_next)) { |
---|
913 | $li_next = " "; |
---|
914 | } |
---|
915 | |
---|
916 | if ($pager_total[$element] > 1) { |
---|
917 | $items[] = array( |
---|
918 | 'class' => 'pager-previous', |
---|
919 | 'data' => $li_previous, |
---|
920 | ); |
---|
921 | |
---|
922 | $items[] = array( |
---|
923 | 'class' => 'pager-current', |
---|
924 | 'data' => t('@current of @max', array('@current' => $pager_current, '@max' => $pager_max)), |
---|
925 | ); |
---|
926 | |
---|
927 | $items[] = array( |
---|
928 | 'class' => 'pager-next', |
---|
929 | 'data' => $li_next, |
---|
930 | ); |
---|
931 | return theme('item_list', $items, NULL, 'ul', array('class' => 'pager')); |
---|
932 | } |
---|
933 | } |
---|
934 | |
---|
935 | /** |
---|
936 | * @defgroup views_templates Views' template files |
---|
937 | * @{ |
---|
938 | * All views templates can be overridden with a variety of names, using |
---|
939 | * the view, the display ID of the view, the display type of the view, |
---|
940 | * or some combination thereof. |
---|
941 | * |
---|
942 | * For each view, there will be a minimum of two templates used. The first |
---|
943 | * is used for all views: views-view.tpl.php. |
---|
944 | * |
---|
945 | * The second template is determined by the style selected for the view. Note |
---|
946 | * that certain aspects of the view can also change which style is used; for |
---|
947 | * example, arguments which provide a summary view might change the style to |
---|
948 | * one of the special summary styles. |
---|
949 | * |
---|
950 | * The default style for all views is views-view-unformatted.tpl.php |
---|
951 | * |
---|
952 | * Many styles will then farm out the actual display of each row to a row |
---|
953 | * style; the default row style is views-view-fields.tpl.php. |
---|
954 | * |
---|
955 | * Here is an example of all the templates that will be tried in the following |
---|
956 | * case: |
---|
957 | * |
---|
958 | * View, named foobar. Style: unformatted. Row style: Fields. Display: Page. |
---|
959 | * |
---|
960 | * - views-view--foobar--page.tpl.php |
---|
961 | * - views-view--page.tpl.php |
---|
962 | * - views-view--foobar.tpl.php |
---|
963 | * - views-view.tpl.php |
---|
964 | * |
---|
965 | * - views-view-unformatted--foobar--page.tpl.php |
---|
966 | * - views-view-unformatted--page.tpl.php |
---|
967 | * - views-view-unformatted--foobar.tpl.php |
---|
968 | * - views-view-unformatted.tpl.php |
---|
969 | * |
---|
970 | * - views-view-fields--foobar--page.tpl.php |
---|
971 | * - views-view-fields--page.tpl.php |
---|
972 | * - views-view-fields--foobar.tpl.php |
---|
973 | * - views-view-fields.tpl.php |
---|
974 | * |
---|
975 | * Important! When adding a new template to your theme, be sure to flush the |
---|
976 | * theme registry cache! |
---|
977 | * |
---|
978 | * @see _views_theme_functions |
---|
979 | * @} |
---|
980 | */ |
---|