name . '__' . $display->id; $themes[] = $hook . '__' . $display->id; $themes[] = $hook . '__' . preg_replace('/[^a-z0-9]/', '_', strtolower($view->tag)); if ($display->id != $display->display_plugin) { $themes[] = $hook . '__' . $view->name . '__' . $display->display_plugin; $themes[] = $hook . '__' . $display->display_plugin; } } $themes[] = $hook . '__' . $view->name; $themes[] = $hook; return $themes; } /** * Preprocess the primary theme implementation for a view. */ function template_preprocess_views_view(&$vars) { global $base_path; $view = $vars['view']; $vars['rows'] = !empty($view->result) || !empty($view->style_plugin->definition['even empty']) ? $view->style_plugin->render($view->result) : ''; $vars['css_name'] = views_css_safe($view->name); $vars['name'] = $view->name; $vars['display_id'] = $view->current_display; // Basic classes $vars['classes_array'] = array(); $vars['classes_array'][] = 'view'; $vars['classes_array'][] = 'view-' . views_css_safe($vars['name']); $vars['classes_array'][] = 'view-id-' . $vars['name']; $vars['classes_array'][] = 'view-display-id-' . $vars['display_id']; $css_class = $view->display_handler->get_option('css_class'); if (!empty($css_class)) { $vars['css_class'] = preg_replace('/[^a-zA-Z0-9- ]/', '-', $css_class); $vars['classes_array'][] = $vars['css_class']; } $empty = empty($vars['rows']); $vars['header'] = $view->display_handler->render_area('header', $empty); $vars['footer'] = $view->display_handler->render_area('footer', $empty); if ($empty) { $vars['empty'] = $view->display_handler->render_area('empty'); } $vars['exposed'] = !empty($view->exposed_widgets) ? $view->exposed_widgets : ''; $vars['more'] = $view->display_handler->render_more_link(); $vars['feed_icon'] = !empty($view->feed_icon) ? $view->feed_icon : ''; $vars['pager'] = ''; if ($view->display_handler->render_pager()) { $exposed_input = isset($view->exposed_data_raw) ? $view->exposed_data_raw : NULL; $vars['pager'] = $view->query->render_pager($exposed_input); } $vars['attachment_before'] = !empty($view->attachment_before) ? $view->attachment_before : ''; $vars['attachment_after'] = !empty($view->attachment_after) ? $view->attachment_after : ''; // if administrator, add some links. These used to be tabs, but this is better. if (user_access('administer views') && module_exists('views_ui') && empty($view->hide_admin_links) && !variable_get('views_no_hover_links', FALSE)) { $vars['admin_links_raw'] = array( array( 'title' => t('Edit view'), 'alt' => t("Edit this view"), 'href' => "admin/build/views/edit/$view->name", 'fragment' => 'views-tab-' . $view->current_display, 'query' => drupal_get_destination(), ), ); drupal_alter('views_admin_links', $vars['admin_links_raw'], $view); $vars['admin_links'] = theme('links', $vars['admin_links_raw']); } else { $vars['admin_links'] = ''; $vars['admin_links_raw'] = array(); } // Our JavaScript needs to have some means to find the HTML belonging to this // view. // // It is true that the DIV wrapper has classes denoting the name of the view // and its display ID, but this is not enough to unequivocally match a view // with its HTML, because one view may appear several times on the page. So // we set up a running counter, $dom_id, to issue a "unique" identifier for // each view. This identifier is written to both Drupal.settings and the DIV // wrapper. static $dom_id = 1; $vars['dom_id'] = !empty($view->dom_id) ? $view->dom_id : $dom_id++; $vars['classes_array'][] = 'view-dom-id-' . $vars['dom_id']; // If using AJAX, send identifying data about this view. if ($view->use_ajax) { $settings = array( 'views' => array( 'ajax_path' => url('views/ajax'), 'ajaxViews' => array( array( 'view_name' => $view->name, 'view_display_id' => $view->current_display, 'view_args' => check_plain(implode('/', $view->args)), 'view_path' => check_plain($_GET['q']), // Pass through URL to ensure we get e.g. language prefixes. // 'view_base_path' => isset($view->display['page']) ? substr(url($view->display['page']->display_options['path']), strlen($base_path)) : '', 'view_base_path' => $view->get_path(), 'view_dom_id' => $vars['dom_id'], // To fit multiple views on a page, the programmer may have // overridden the display's pager_element. 'pager_element' => isset($view->query->pager) ? $view->query->pager->get_pager_id() : 0, ), ), ), ); drupal_add_js($settings, 'setting'); views_add_js('ajax_view'); } // Flatten the classes to a string for the template file. $vars['classes'] = implode(' ', $vars['classes_array']); } /** * Preprocess theme function to print a single record from a row, with fields */ function template_preprocess_views_view_fields(&$vars) { $view = $vars['view']; // Loop through the fields for this view. $inline = FALSE; $vars['fields'] = array(); // ensure it's at least an empty array. foreach ($view->field as $id => $field) { // render this even if set to exclude so it can be used elsewhere. $field_output = $view->style_plugin->get_field($view->row_index, $id); $empty = $field_output !== 0 && empty($field_output); if (empty($field->options['exclude']) && (!$empty || (empty($field->options['hide_empty']) && empty($vars['options']['hide_empty'])))) { $object = new stdClass(); $object->handler = &$view->field[$id]; $object->element_type = $object->handler->element_type(TRUE); if ($object->element_type) { $class = ''; if ($object->handler->options['element_default_classes']) { $class = 'field-content'; } if ($classes = $object->handler->element_classes()) { if ($class) { $class .= ' '; } $class .= $classes; } $field_output = '<' . $object->element_type . ' class="' . $class . '">' . $field_output . '' . $object->element_type . '>'; } // Protect ourself somewhat for backward compatibility. This will prevent // old templates from producing invalid HTML when no element type is selected. if (empty($object->element_type)) { $object->element_type = 'span'; } $object->content = $field_output; if (isset($view->field[$id]->field_alias) && isset($vars['row']->{$view->field[$id]->field_alias})) { $object->raw = $vars['row']->{$view->field[$id]->field_alias}; } else { $object->raw = NULL; // make sure it exists to reduce NOTICE } if (!empty($vars['options']['separator']) && $inline && $object->inline && $object->content) { $object->separator = filter_xss_admin($vars['options']['separator']); } $object->class = views_css_safe($id); $object->inline = !empty($vars['options']['inline'][$id]); $inline = $object->inline; $object->inline_html = $object->handler->element_wrapper_type(TRUE, TRUE); if ($object->inline_html === '') { $object->inline_html = $object->inline ? 'span' : 'div'; } // Set up the wrapper HTML. $object->wrapper_prefix = ''; $object->wrapper_suffix = ''; if ($object->inline_html) { $class = ''; if ($object->handler->options['element_default_classes']) { $class = "views-field views-field-" . $object->class; } if ($classes = $object->handler->element_wrapper_classes()) { if ($class) { $class .= ' '; } $class .= $classes; } $object->wrapper_prefix = '<' . $object->inline_html; if ($class) { $object->wrapper_prefix .= ' class="' . $class . '"'; } $object->wrapper_prefix .= '>'; $object->wrapper_suffix = '' . $object->inline_html . '>'; } // Set up the label for the value and the HTML to make it easier // on the template. $object->label = check_plain($view->field[$id]->label()); $object->label_html = ''; $object->element_label_type = $object->handler->element_label_type(TRUE); if ($object->element_label_type && $object->label) { $class = ''; if ($object->handler->options['element_default_classes']) { $class = 'views-label-' . $object->class; } $element_label_class = $object->handler->element_label_classes(); if ($element_label_class) { if ($class) { $class .= ' '; } $class .= $element_label_class; } $object->label_html = '<' . $object->element_label_type . ' class="' . $class . '">'; $object->label_html .= $object->label; if ($object->handler->options['element_label_colon']) { $object->label_html .= ': '; } $object->label_html .= '' . $object->element_label_type . '>'; } $vars['fields'][$id] = $object; } } } /** * Display a single views field. * * Interesting bits of info: * $field->field_alias says what the raw value in $row will be. Reach it like * this: @code { $row->{$field->field_alias} @endcode */ function theme_views_view_field($view, $field, $row) { // Reference safe for PHP 4: return $view->field[$field->options['id']]->advanced_render($row); } /** * Process a single field within a view. * * This preprocess function isn't normally run, as a function is used by * default, for performance. However, by creating a template, this * preprocess should get picked up. */ function template_preprocess_views_view_field(&$vars) { $vars['output'] = $vars['field']->advanced_render($vars['row']); } /** * Preprocess theme function to print a single record from a row, with fields */ function template_preprocess_views_view_summary(&$vars) { $view = $vars['view']; $argument = $view->argument[$view->build_info['summary_level']]; $url_options = array(); if (!empty($view->exposed_raw_input)) { $url_options['query'] = $view->exposed_raw_input; } $vars['classes'] = array(); foreach ($vars['rows'] as $id => $row) { $vars['rows'][$id]->link = $argument->summary_name($row); $args = $view->args; $args[$argument->position] = $argument->summary_argument($row); $base_path = NULL; if (!empty($argument->options['style_options']['base_path'])) { $base_path = $argument->options['style_options']['base_path']; } $vars['rows'][$id]->url = url($view->get_url($args, $base_path), $url_options); $vars['rows'][$id]->count = intval($row->{$argument->count_alias}); if ($vars['rows'][$id]->url == base_path() . $_GET['q'] || $vars['rows'][$id]->url == base_path() . drupal_get_path_alias($_GET['q'])) { $vars['classes'][$id] = 'active'; } } } /** * Template preprocess theme function to print summary basically * unformatted. */ function template_preprocess_views_view_summary_unformatted(&$vars) { $view = $vars['view']; $argument = $view->argument[$view->build_info['summary_level']]; $vars['classes'] = array(); $url_options = array(); if (!empty($view->exposed_raw_input)) { $url_options['query'] = $view->exposed_raw_input; } $count = 0; foreach ($vars['rows'] as $id => $row) { // only false on first time: if ($count++) { $vars['rows'][$id]->separator = filter_xss_admin($vars['options']['separator']); } $vars['rows'][$id]->link = $argument->summary_name($row); $args = $view->args; $args[$argument->position] = $argument->summary_argument($row); $base_path = NULL; if (!empty($argument->options['style_options']['base_path'])) { $base_path = $argument->options['style_options']['base_path']; } $vars['rows'][$id]->url = url($view->get_url($args, $base_path), $url_options); $vars['rows'][$id]->count = intval($row->{$argument->count_alias}); if ($vars['rows'][$id]->url == base_path() . $_GET['q'] || $vars['rows'][$id]->url == base_path() . drupal_get_path_alias($_GET['q'])) { $vars['classes'][$id] = 'active'; } } } /** * Display a view as a table style. */ function template_preprocess_views_view_table(&$vars) { $view = $vars['view']; // We need the raw data for this grouping, which is passed in as $vars['rows']. // However, the template also needs to use for the rendered fields. We // therefore swap the raw data out to a new variable and reset $vars['rows'] // so that it can get rebuilt. // Store rows so that they may be used by further preprocess functions. $result = $vars['result'] = $vars['rows']; $vars['rows'] = array(); $vars['field_classes'] = array(); $options = $view->style_plugin->options; $handler = $view->style_plugin; $fields = &$view->field; $columns = $handler->sanitize_columns($options['columns'], $fields); $active = !empty($handler->active) ? $handler->active : ''; $order = !empty($handler->order) ? $handler->order : 'asc'; $query = tablesort_get_querystring(); if ($query) { $query = '&' . $query; } $header = array(); // Fields must be rendered in order as of Views 2.3, so we will pre-render // everything. $renders = $handler->render_fields($result); foreach ($columns as $field => $column) { // Create a second variable so we can easily find what fields we have and what the // CSS classes should be. $vars['fields'][$field] = views_css_safe($field); if ($active == $field) { $vars['fields'][$field] .= ' active'; } // render the header labels if ($field == $column && empty($fields[$field]->options['exclude'])) { $label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : ''); if (empty($options['info'][$field]['sortable']) || !$fields[$field]->click_sortable()) { $vars['header'][$field] = $label; } else { $initial = !empty($options['info'][$field]['default_sort_order']) ? $options['info'][$field]['default_sort_order'] : 'asc'; if ($active == $field) { $initial = ($order == 'asc') ? 'desc' : 'asc'; } $title = t('sort by @s', array('@s' => $label)); if ($active == $field) { $label .= theme('tablesort_indicator', $initial); } $link_options = array( 'html' => true, 'attributes' => array('title' => $title), 'query' => 'order=' . urlencode($field) . '&sort=' . $initial . $query, ); $vars['header'][$field] = l($label, $_GET['q'], $link_options); } $vars['header_classes'][$field] = ''; // Set up the header label class. if ($fields[$field]->options['element_default_classes']) { $vars['header_classes'][$field] .= "views-field views-field-" . $vars['fields'][$field]; } $class = $fields[$field]->element_label_classes(); if ($class) { if ($vars['header_classes'][$field]) { $vars['header_classes'][$field] .= ' '; } $vars['header_classes'][$field] .= $class; } // Add a header label wrapper if one was selected. if ($vars['header'][$field]) { $element_label_type = $fields[$field]->element_label_type(TRUE, TRUE); if ($element_label_type) { $vars['header'][$field] = '<' . $element_label_type . '>' . $vars['header'][$field] . '' . $element_label_type . '>'; } } } // Add a CSS align class to each field if one was set if (!empty($options['info'][$field]['align'])) { $vars['fields'][$field] .= ' ' . views_css_safe($options['info'][$field]['align']); } // Render each field into its appropriate column. foreach ($result as $num => $row) { // Add field classes $vars['field_classes'][$field][$num] = ''; if ($fields[$field]->options['element_default_classes']) { $vars['field_classes'][$field][$num] = "views-field views-field-" . $vars['fields'][$field]; } if ($classes = $fields[$field]->element_classes()) { if ($vars['field_classes'][$field][$num]) { $vars['field_classes'][$field][$num] .= ' '; } $vars['field_classes'][$field][$num] .= $classes; } if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) { $field_output = $renders[$num][$field]; $element_type = $fields[$field]->element_type(TRUE, TRUE); if ($element_type) { $field_output = '<' . $element_type . '>' . $field_output . '' . $element_type . '>'; } // Don't bother with separators and stuff if the field does not show up. if (empty($field_output) && !empty($vars['rows'][$num][$column])) { continue; } // Place the field into the column, along with an optional separator. if (!empty($vars['rows'][$num][$column])) { if (!empty($options['info'][$column]['separator'])) { $vars['rows'][$num][$column] .= filter_xss_admin($options['info'][$column]['separator']); } } else { $vars['rows'][$num][$column] = ''; } $vars['rows'][$num][$column] .= $field_output; } } } $count = 0; foreach ($vars['rows'] as $num => $row) { $vars['row_classes'][$num][] = ($count++ % 2 == 0) ? 'odd' : 'even'; if ($row_class = $handler->get_row_class($num)) { $vars['row_classes'][$num][] = $row_class; } } $vars['row_classes'][0][] = 'views-row-first'; $vars['row_classes'][count($vars['row_classes']) - 1][] = 'views-row-last'; $vars['class'] = 'views-table'; if (!empty($options['sticky'])) { drupal_add_js('misc/tableheader.js'); $vars['class'] .= " sticky-enabled"; } $vars['class'] .= ' cols-' . count($vars['header']); $vars['attributes'] = ''; if (!empty($handler->options['summary'])) { $vars['attributes'] = drupal_attributes(array('summary' => $handler->options['summary'])); } } /** * Display a view as a grid style. */ function template_preprocess_views_view_grid(&$vars) { $view = $vars['view']; $result = $view->result; $options = $view->style_plugin->options; $handler = $view->style_plugin; $columns = $options['columns']; $rows = array(); $row_indexes = array(); if ($options['alignment'] == 'horizontal') { $row = array(); $col_count = 0; $row_count = 0; $count = 0; foreach ($vars['rows'] as $row_index => $item) { $count++; $row[] = $item; $row_indexes[$row_count][$col_count] = $row_index; $col_count++; if ($count % $columns == 0) { $rows[] = $row; $row = array(); $col_count = 0; $row_count++; } } if ($row) { // Fill up the last line only if it's configured, but this is default. if (!empty($handler->options['fill_single_line']) || count($rows)) { for ($i = 0; $i < ($columns - $col_count); $i++) { $row[] = ''; } } $rows[] = $row; } } else { $num_rows = floor(count($vars['rows']) / $columns); // The remainders are the 'odd' columns that are slightly longer. $remainders = count($vars['rows']) % $columns; $row = 0; $col = 0; foreach ($vars['rows'] as $count => $item) { $rows[$row][$col] = $item; $row_indexes[$row][$col] = $count; $row++; if (!$remainders && $row == $num_rows) { $row = 0; $col++; } else if ($remainders && $row == $num_rows + 1) { $row = 0; $col++; $remainders--; } } for ($i = 0; $i < count($rows[0]); $i++) { // This should be string so that's okay :) if (!isset($rows[count($rows) - 1][$i])) { $rows[count($rows) - 1][$i] = ''; } } } // Apply the row classes foreach ($rows as $row_number => $row) { $row_classes = array(); $row_classes[] = 'row-' . ($row_number + 1); if ($row_number == 0) { $row_classes[] = 'row-first'; } if (count($rows) == ($row_number + 1)) { $row_classes[] = 'row-last'; } $vars['row_classes'][$row_number] = implode(' ', $row_classes); foreach ($rows[$row_number] as $column_number => $item) { $column_classes = array(); $column_classes[] = 'col-'. ($column_number + 1); if ($column_number == 0) { $column_classes[] = 'col-first'; } elseif (count($rows[$row_number]) == ($column_number + 1)) { $column_classes[] = 'col-last'; } if (isset($row_indexes[$row_number][$column_number]) && $column_class = $view->style_plugin->get_row_class($row_indexes[$row_number][$column_number])) { $column_classes[] = $column_class; } $vars['column_classes'][$row_number][$column_number] = implode(' ', $column_classes); } } $vars['rows'] = $rows; $vars['class'] = 'views-view-grid col-' . $columns; $vars['attributes'] = ''; if (!empty($handler->options['summary'])) { $vars['attributes'] = drupal_attributes(array('summary' => $handler->options['summary'])); } } /** * Display the simple view of rows one after another */ function template_preprocess_views_view_unformatted(&$vars) { $view = $vars['view']; $rows = $vars['rows']; $vars['classes'] = array(); // Set up striping values. $count = 0; $max = count($rows); foreach ($rows as $id => $row) { $count++; $row_classes = array(); $row_classes[] = 'views-row'; $row_classes[] = 'views-row-' . $count; $row_classes[] = 'views-row-' . ($count % 2 ? 'odd' : 'even'); if ($count == 1) { $row_classes[] = 'views-row-first'; } if ($count == $max) { $row_classes[] = 'views-row-last'; } if ($row_class = $view->style_plugin->get_row_class($id)) { $row_classes[] = $row_class; } // Flatten the classes to a string for each row for the template file. $vars['classes'][$id] = implode(' ', $row_classes); } } /** * Display the view as an HTML list element */ function template_preprocess_views_view_list(&$vars) { $handler = $vars['view']->style_plugin; $vars['class'] = views_css_safe($handler->options['class']); $vars['wrapper_class'] = views_css_safe($handler->options['wrapper_class']); $vars['wrapper_prefix'] = ''; $vars['wrapper_suffix'] = ''; $vars['list_type_prefix'] = '<' . $handler->options['type'] . '>'; $vars['list_type_suffix'] = '' . $handler->options['type'] . '>'; if ($vars['wrapper_class']) { $vars['wrapper_prefix'] = '