• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

theme/theme.inc

Go to the documentation of this file.
00001 <?php
00002 
00020 function _views_theme_functions($hook, $view, $display = NULL) {
00021   $themes = array();
00022 
00023   if ($display) {
00024     $themes[] = $hook . '__' . $view->name . '__' . $display->id;
00025     $themes[] = $hook . '__' . $display->id;
00026     $themes[] = $hook . '__' . preg_replace('/[^a-z0-9]/', '_', strtolower($view->tag));
00027 
00028     // Add theme suggestions foreach single tag.
00029     foreach (drupal_explode_tags($view->tag) as $tag) {
00030       $themes[] = $hook . '__' . preg_replace('/[^a-z0-9]/', '_', strtolower($tag));
00031     }
00032 
00033     if ($display->id != $display->display_plugin) {
00034       $themes[] = $hook . '__' . $view->name . '__' . $display->display_plugin;
00035       $themes[] = $hook . '__' . $display->display_plugin;
00036     }
00037   }
00038   $themes[] = $hook . '__' . $view->name;
00039   $themes[] = $hook;
00040   return $themes;
00041 }
00042 
00046 function template_preprocess_views_view(&$vars) {
00047   global $base_path;
00048 
00049   $view = $vars['view'];
00050 
00051   $vars['rows']       = (!empty($view->result) || $view->style_plugin->even_empty()) ? $view->style_plugin->render($view->result) : '';
00052 
00053   $vars['css_name']   = drupal_clean_css_identifier($view->name);
00054   $vars['name']       = $view->name;
00055   $vars['display_id'] = $view->current_display;
00056 
00057   // Basic classes
00058   $vars['classes_array'] = array();
00059   $vars['classes_array'][] = 'view';
00060   $vars['classes_array'][] = 'view-' . drupal_clean_css_identifier($vars['name']);
00061   $vars['classes_array'][] = 'view-id-' . $vars['name'];
00062   $vars['classes_array'][] = 'view-display-id-' . $vars['display_id'];
00063 
00064   $css_class = $view->display_handler->get_option('css_class');
00065   if (!empty($css_class)) {
00066     $vars['css_class'] = preg_replace('/[^a-zA-Z0-9- ]/', '-', $css_class);
00067     $vars['classes_array'][] = $vars['css_class'];
00068   }
00069 
00070   $empty = empty($vars['rows']);
00071 
00072   $vars['header'] = $view->display_handler->render_area('header', $empty);
00073   $vars['footer'] = $view->display_handler->render_area('footer', $empty);
00074   if ($empty) {
00075     $vars['empty'] = $view->display_handler->render_area('empty');
00076   }
00077 
00078   $vars['exposed']    = !empty($view->exposed_widgets) ? $view->exposed_widgets : '';
00079   $vars['more']       = $view->display_handler->render_more_link();
00080   $vars['feed_icon']  = !empty($view->feed_icon) ? $view->feed_icon : '';
00081 
00082   $vars['pager']      = '';
00083 
00084   // @todo: Figure out whether this belongs into views_ui_preprocess_views_view.
00085   // Render title for the admin preview.
00086   $vars['title'] = !empty($view->views_ui_context) ? filter_xss_admin($view->get_title()) : '';
00087 
00088   if ($view->display_handler->render_pager()) {
00089     $exposed_input = isset($view->exposed_raw_input) ? $view->exposed_raw_input : NULL;
00090     $vars['pager']      = $view->query->render_pager($exposed_input);
00091   }
00092 
00093   $vars['attachment_before'] = !empty($view->attachment_before) ? $view->attachment_before : '';
00094   $vars['attachment_after'] = !empty($view->attachment_after) ? $view->attachment_after : '';
00095 
00096   // Add contextual links to the view. We need to attach them to the dummy
00097   // $view_array variable, since contextual_preprocess() requires that they be
00098   // attached to an array (not an object) in order to process them. For our
00099   // purposes, it doesn't matter what we attach them to, since once they are
00100   // processed by contextual_preprocess() they will appear in the $title_suffix
00101   // variable (which we will then render in views-view.tpl.php).
00102   views_add_contextual_links($vars['view_array'], 'view', $view, $view->current_display);
00103 
00104   // Attachments are always updated with the outer view, never by themselves,
00105   // so they do not have dom ids.
00106   if (empty($view->is_attachment)) {
00107     // Our JavaScript needs to have some means to find the HTML belonging to this
00108     // view.
00109     //
00110     // It is true that the DIV wrapper has classes denoting the name of the view
00111     // and its display ID, but this is not enough to unequivocally match a view
00112     // with its HTML, because one view may appear several times on the page. So
00113     // we set up a hash with the current time, $dom_id, to issue a "unique" identifier for
00114     // each view. This identifier is written to both Drupal.settings and the DIV
00115     // wrapper.
00116     $vars['dom_id'] = !empty($view->dom_id) ? $view->dom_id : md5($view->name . REQUEST_TIME . rand());
00117     $vars['classes_array'][] = 'view-dom-id-' . $vars['dom_id'];
00118   }
00119 
00120   // If using AJAX, send identifying data about this view.
00121   if ($view->use_ajax && empty($view->is_attachment) && empty($view->live_preview)) {
00122     $settings = array(
00123       'views' => array(
00124         'ajax_path' => url('views/ajax'),
00125         'ajaxViews' => array(
00126           'views_dom_id:' . $vars['dom_id'] => array(
00127             'view_name' => $view->name,
00128             'view_display_id' => $view->current_display,
00129             'view_args' => check_plain(implode('/', $view->args)),
00130             'view_path' => check_plain($_GET['q']),
00131             // Pass through URL to ensure we get e.g. language prefixes.
00132 //            'view_base_path' => isset($view->display['page']) ? substr(url($view->display['page']->display_options['path']), strlen($base_path)) : '',
00133             'view_base_path' => $view->get_path(),
00134             'view_dom_id' => $vars['dom_id'],
00135             // To fit multiple views on a page, the programmer may have
00136             // overridden the display's pager_element.
00137             'pager_element' => isset($view->query->pager) ? $view->query->pager->get_pager_id() : 0,
00138           ),
00139         ),
00140       ),
00141     );
00142 
00143     drupal_add_js($settings, 'setting');
00144     views_add_js('ajax_view');
00145   }
00146 
00147   // If form fields were found in the View, reformat the View output as a form.
00148   if (views_view_has_form_elements($view)) {
00149     $output = !empty($vars['rows']) ? $vars['rows'] : $vars['empty'];
00150     $form = drupal_get_form(views_form_id($view), $view, $output);
00151     // The form is requesting that all non-essential views elements be hidden,
00152     // usually because the rendered step is not a view result.
00153     if ($form['show_view_elements']['#value'] == FALSE) {
00154       $vars['header'] = '';
00155       $vars['exposed'] = '';
00156       $vars['pager'] = '';
00157       $vars['footer'] = '';
00158       $vars['more'] = '';
00159       $vars['feed_icon'] = '';
00160     }
00161     $vars['rows'] = $form;
00162   }
00163 }
00164 
00168 function template_process_views_view(&$vars) {
00169   if (is_array($vars['rows'])) {
00170     $vars['rows'] = drupal_render($vars['rows']);
00171   }
00172 
00173   // Flatten the classes to a string for the template file.
00174   $vars['classes'] = implode(' ', $vars['classes_array']);
00175 }
00176 
00180 function template_preprocess_views_view_fields(&$vars) {
00181   $view = $vars['view'];
00182 
00183   // Loop through the fields for this view.
00184   $previous_inline = FALSE;
00185   $vars['fields'] = array(); // ensure it's at least an empty array.
00186   foreach ($view->field as $id => $field) {
00187     // render this even if set to exclude so it can be used elsewhere.
00188     $field_output = $view->style_plugin->get_field($view->row_index, $id);
00189     $empty = $field_output !== 0 && empty($field_output);
00190     if (empty($field->options['exclude']) && (!$empty || (empty($field->options['hide_empty']) && empty($vars['options']['hide_empty'])))) {
00191       $object = new stdClass();
00192       $object->handler = &$view->field[$id];
00193       $object->inline = !empty($vars['options']['inline'][$id]);
00194 
00195       $object->element_type = $object->handler->element_type(TRUE, !$vars['options']['default_field_elements'], $object->inline);
00196       if ($object->element_type) {
00197         $class = '';
00198         if ($object->handler->options['element_default_classes']) {
00199           $class = 'field-content';
00200         }
00201 
00202         if ($classes = $object->handler->element_classes($view->row_index)) {
00203           if ($class) {
00204             $class .= ' ';
00205           }
00206           $class .=  $classes;
00207         }
00208 
00209         $pre = '<' . $object->element_type;
00210         if ($class) {
00211           $pre .= ' class="' . $class . '"';
00212         }
00213         $field_output = $pre . '>' . $field_output . '</' . $object->element_type . '>';
00214       }
00215 
00216       // Protect ourself somewhat for backward compatibility. This will prevent
00217       // old templates from producing invalid HTML when no element type is selected.
00218       if (empty($object->element_type)) {
00219         $object->element_type = 'span';
00220       }
00221 
00222       $object->content = $field_output;
00223       if (isset($view->field[$id]->field_alias) && isset($vars['row']->{$view->field[$id]->field_alias})) {
00224         $object->raw = $vars['row']->{$view->field[$id]->field_alias};
00225       }
00226       else {
00227         $object->raw = NULL; // make sure it exists to reduce NOTICE
00228       }
00229 
00230       if (!empty($vars['options']['separator']) && $previous_inline && $object->inline && $object->content) {
00231         $object->separator = filter_xss_admin($vars['options']['separator']);
00232       }
00233 
00234       $object->class = drupal_clean_css_identifier($id);
00235 
00236       $previous_inline = $object->inline;
00237       $object->inline_html = $object->handler->element_wrapper_type(TRUE, TRUE);
00238       if ($object->inline_html === '' && $vars['options']['default_field_elements']) {
00239         $object->inline_html = $object->inline ? 'span' : 'div';
00240       }
00241 
00242       // Set up the wrapper HTML.
00243       $object->wrapper_prefix = '';
00244       $object->wrapper_suffix = '';
00245 
00246       if ($object->inline_html) {
00247         $class = '';
00248         if ($object->handler->options['element_default_classes']) {
00249           $class = "views-field views-field-" . $object->class;
00250         }
00251 
00252         if ($classes = $object->handler->element_wrapper_classes($view->row_index)) {
00253           if ($class) {
00254             $class .= ' ';
00255           }
00256           $class .= $classes;
00257         }
00258 
00259         $object->wrapper_prefix = '<' . $object->inline_html;
00260         if ($class) {
00261           $object->wrapper_prefix .= ' class="' . $class . '"';
00262         }
00263         $object->wrapper_prefix .= '>';
00264         $object->wrapper_suffix = '</' . $object->inline_html . '>';
00265       }
00266 
00267       // Set up the label for the value and the HTML to make it easier
00268       // on the template.
00269       $object->label = check_plain($view->field[$id]->label());
00270       $object->label_html = '';
00271       if ($object->label) {
00272         $object->label_html .= $object->label;
00273         if ($object->handler->options['element_label_colon']) {
00274           $object->label_html .= ': ';
00275         }
00276 
00277         $object->element_label_type = $object->handler->element_label_type(TRUE, !$vars['options']['default_field_elements']);
00278         if ($object->element_label_type) {
00279           $class = '';
00280           if ($object->handler->options['element_default_classes']) {
00281             $class = 'views-label views-label-' . $object->class;
00282           }
00283 
00284           $element_label_class = $object->handler->element_label_classes($view->row_index);
00285           if ($element_label_class) {
00286             if ($class) {
00287               $class .= ' ';
00288             }
00289 
00290             $class .= $element_label_class;
00291           }
00292 
00293           $pre = '<' . $object->element_label_type;
00294           if ($class) {
00295             $pre .= ' class="' . $class . '"';
00296           }
00297           $pre .= '>';
00298 
00299           $object->label_html = $pre . $object->label_html . '</' . $object->element_label_type . '>';
00300         }
00301       }
00302 
00303       $vars['fields'][$id] = $object;
00304     }
00305   }
00306 
00307 }
00308 
00312 function theme_views_view_grouping($vars) {
00313   $view = $vars['view'];
00314   $title = $vars['title'];
00315   $content = $vars['content'];
00316 
00317   $output = '<div class="view-grouping">';
00318   $output .= '<div class="view-grouping-header">' . $title . '</div>';
00319   $output .= '<div class="view-grouping-content">' . $content . '</div>' ;
00320   $output .= '</div>';
00321 
00322   return $output;
00323 }
00324 
00328 function template_preprocess_views_view_grouping(&$vars) {
00329   $vars['content'] = $vars['view']->style_plugin->render_grouping_sets($vars['rows'], $vars['grouping_level']);
00330 }
00331 
00339 function theme_views_view_field($vars) {
00340   $view = $vars['view'];
00341   $field = $vars['field'];
00342   $row = $vars['row'];
00343   return $vars['output'];
00344 }
00345 
00353 function template_preprocess_views_view_field(&$vars) {
00354   $vars['output'] = $vars['field']->advanced_render($vars['row']);
00355 }
00356 
00360 function template_preprocess_views_view_summary(&$vars) {
00361   $view     = $vars['view'];
00362   $argument = $view->argument[$view->build_info['summary_level']];
00363   $vars['row_classes'] = array();
00364 
00365   $url_options = array();
00366 
00367   if (!empty($view->exposed_raw_input)) {
00368     $url_options['query'] = $view->exposed_raw_input;
00369   }
00370 
00371   $active_urls = drupal_map_assoc(array(
00372     url($_GET['q'], array('alias' => TRUE)), // force system path
00373     url($_GET['q']), // could be an alias
00374   ));
00375 
00376   // Collect all arguments foreach row, to be able to alter them for example by the validator.
00377   // This is not done per single argument value, because this could cause performance problems.
00378   $row_args = array();
00379 
00380   foreach ($vars['rows'] as $id => $row) {
00381     $row_args[$id] = $argument->summary_argument($row);
00382   }
00383   $argument->process_summary_arguments($row_args);
00384 
00385   foreach ($vars['rows'] as $id => $row) {
00386     $vars['row_classes'][$id] = '';
00387 
00388     $vars['rows'][$id]->link = $argument->summary_name($row);
00389     $args = $view->args;
00390     $args[$argument->position] = $row_args[$id];
00391 
00392     $base_path = NULL;
00393     if (!empty($argument->options['summary_options']['base_path'])) {
00394       $base_path = $argument->options['summary_options']['base_path'];
00395     }
00396     $vars['rows'][$id]->url = url($view->get_url($args, $base_path), $url_options);
00397     $vars['rows'][$id]->count = intval($row->{$argument->count_alias});
00398     if (isset($active_urls[$vars['rows'][$id]->url])) {
00399       $vars['row_classes'][$id] = 'active';
00400     }
00401   }
00402 }
00403 
00408 function template_preprocess_views_view_summary_unformatted(&$vars) {
00409   $view     = $vars['view'];
00410   $argument = $view->argument[$view->build_info['summary_level']];
00411   $vars['row_classes'] = array();
00412 
00413   $url_options = array();
00414 
00415   if (!empty($view->exposed_raw_input)) {
00416     $url_options['query'] = $view->exposed_raw_input;
00417   }
00418 
00419   $count = 0;
00420   $active_urls = drupal_map_assoc(array(
00421     url($_GET['q'], array('alias' => TRUE)), // force system path
00422     url($_GET['q']), // could be an alias
00423   ));
00424 
00425   // Collect all arguments foreach row, to be able to alter them for example by the validator.
00426   // This is not done per single argument value, because this could cause performance problems.
00427   $row_args = array();
00428   foreach ($vars['rows'] as $id => $row) {
00429     $row_args[$id] = $argument->summary_argument($row);
00430   }
00431   $argument->process_summary_arguments($row_args);
00432 
00433   foreach ($vars['rows'] as $id => $row) {
00434     // only false on first time:
00435     if ($count++) {
00436       $vars['rows'][$id]->separator = filter_xss_admin($vars['options']['separator']);
00437     }
00438     $vars['rows'][$id]->link = $argument->summary_name($row);
00439     $args = $view->args;
00440     $args[$argument->position] = $row_args[$id];
00441 
00442     $base_path = NULL;
00443     if (!empty($argument->options['summary_options']['base_path'])) {
00444       $base_path = $argument->options['summary_options']['base_path'];
00445     }
00446     $vars['rows'][$id]->url = url($view->get_url($args, $base_path), $url_options);
00447     $vars['rows'][$id]->count = intval($row->{$argument->count_alias});
00448     if (isset($active_urls[$vars['rows'][$id]->url])) {
00449       $vars['row_classes'][$id] = 'active';
00450     }
00451   }
00452 }
00453 
00457 function template_preprocess_views_view_table(&$vars) {
00458   $view     = $vars['view'];
00459 
00460   // We need the raw data for this grouping, which is passed in as $vars['rows'].
00461   // However, the template also needs to use for the rendered fields.  We
00462   // therefore swap the raw data out to a new variable and reset $vars['rows']
00463   // so that it can get rebuilt.
00464   // Store rows so that they may be used by further preprocess functions.
00465   $result   = $vars['result'] = $vars['rows'];
00466   $vars['rows'] = array();
00467   $vars['field_classes'] = array();
00468   $vars['header'] = array();
00469 
00470   $options  = $view->style_plugin->options;
00471   $handler  = $view->style_plugin;
00472 
00473   $fields   = &$view->field;
00474   $columns  = $handler->sanitize_columns($options['columns'], $fields);
00475 
00476   $active   = !empty($handler->active) ? $handler->active : '';
00477   $order    = !empty($handler->order) ? $handler->order : 'asc';
00478 
00479   $query    = tablesort_get_query_parameters();
00480   if (isset($view->exposed_raw_input)) {
00481     $query += $view->exposed_raw_input;
00482   }
00483 
00484   // Fields must be rendered in order as of Views 2.3, so we will pre-render
00485   // everything.
00486   $renders = $handler->render_fields($result);
00487 
00488   foreach ($columns as $field => $column) {
00489     // Create a second variable so we can easily find what fields we have and what the
00490     // CSS classes should be.
00491     $vars['fields'][$field] = drupal_clean_css_identifier($field);
00492     if ($active == $field) {
00493       $vars['fields'][$field] .= ' active';
00494     }
00495 
00496     // render the header labels
00497     if ($field == $column && empty($fields[$field]->options['exclude'])) {
00498       $label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : '');
00499       if (empty($options['info'][$field]['sortable']) || !$fields[$field]->click_sortable()) {
00500         $vars['header'][$field] = $label;
00501       }
00502       else {
00503         $initial = !empty($options['info'][$field]['default_sort_order']) ? $options['info'][$field]['default_sort_order'] : 'asc';
00504 
00505         if ($active == $field) {
00506           $initial = ($order == 'asc') ? 'desc' : 'asc';
00507         }
00508 
00509         $title = t('sort by @s', array('@s' => $label));
00510         if ($active == $field) {
00511           $label .= theme('tablesort_indicator', array('style' => $initial));
00512         }
00513 
00514         $query['order'] = $field;
00515         $query['sort'] = $initial;
00516         $link_options = array(
00517           'html' => TRUE,
00518           'attributes' => array('title' => $title),
00519           'query' => $query,
00520         );
00521         $vars['header'][$field] = l($label, $_GET['q'], $link_options);
00522       }
00523 
00524       $vars['header_classes'][$field] = '';
00525       // Set up the header label class.
00526       if ($fields[$field]->options['element_default_classes']) {
00527         $vars['header_classes'][$field] .= "views-field views-field-" . $vars['fields'][$field];
00528       }
00529       $class = $fields[$field]->element_label_classes(0);
00530       if ($class) {
00531         if ($vars['header_classes'][$field]) {
00532           $vars['header_classes'][$field] .= ' ';
00533         }
00534         $vars['header_classes'][$field] .= $class;
00535       }
00536 
00537       // Add a header label wrapper if one was selected.
00538       if ($vars['header'][$field]) {
00539         $element_label_type = $fields[$field]->element_label_type(TRUE, TRUE);
00540         if ($element_label_type) {
00541           $vars['header'][$field] = '<' . $element_label_type . '>' . $vars['header'][$field] . '</' . $element_label_type . '>';
00542         }
00543       }
00544 
00545     }
00546 
00547     // Add a CSS align class to each field if one was set
00548     if (!empty($options['info'][$field]['align'])) {
00549       $vars['fields'][$field] .= ' ' . drupal_clean_css_identifier($options['info'][$field]['align']);
00550     }
00551 
00552     // Render each field into its appropriate column.
00553     foreach ($result as $num => $row) {
00554       // Add field classes
00555       $vars['field_classes'][$field][$num] = '';
00556       if ($fields[$field]->options['element_default_classes']) {
00557         $vars['field_classes'][$field][$num] = "views-field views-field-" . $vars['fields'][$field];
00558       }
00559       if ($classes = $fields[$field]->element_classes($num)) {
00560         if ($vars['field_classes'][$field][$num]) {
00561           $vars['field_classes'][$field][$num] .= ' ';
00562         }
00563 
00564         $vars['field_classes'][$field][$num] .= $classes;
00565       }
00566       $vars['field_attributes'][$field][$num] = array();
00567 
00568       if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) {
00569         $field_output = $renders[$num][$field];
00570         $element_type = $fields[$field]->element_type(TRUE, TRUE);
00571         if ($element_type) {
00572           $field_output = '<' . $element_type . '>' . $field_output . '</' . $element_type . '>';
00573         }
00574 
00575         // Don't bother with separators and stuff if the field does not show up.
00576         if (empty($field_output) && !empty($vars['rows'][$num][$column])) {
00577           continue;
00578         }
00579 
00580         // Place the field into the column, along with an optional separator.
00581         if (!empty($vars['rows'][$num][$column])) {
00582           if (!empty($options['info'][$column]['separator'])) {
00583             $vars['rows'][$num][$column] .= filter_xss_admin($options['info'][$column]['separator']);
00584           }
00585         }
00586         else {
00587           $vars['rows'][$num][$column] = '';
00588         }
00589 
00590         $vars['rows'][$num][$column] .= $field_output;
00591       }
00592     }
00593 
00594     // Remove columns if the option is hide empty column is checked and the field is not empty.
00595     if (!empty($options['info'][$field]['empty_column'])) {
00596       $empty = TRUE;
00597       foreach ($vars['rows'] as $num => $columns) {
00598         $empty &= empty($columns[$column]);
00599       }
00600       if ($empty) {
00601         foreach ($vars['rows'] as $num => &$columns) {
00602           unset($columns[$column]);
00603           unset($vars['header'][$column]);
00604         }
00605       }
00606     }
00607   }
00608 
00609   $count = 0;
00610   foreach ($vars['rows'] as $num => $row) {
00611     $vars['row_classes'][$num][] = ($count++ % 2 == 0) ? 'odd' : 'even';
00612     if ($row_class = $handler->get_row_class($num)) {
00613       $vars['row_classes'][$num][] = $row_class;
00614     }
00615   }
00616 
00617   $vars['row_classes'][0][] = 'views-row-first';
00618   $vars['row_classes'][count($vars['row_classes']) - 1][] = 'views-row-last';
00619 
00620   $vars['classes_array'] = array('views-table');
00621   if (empty($vars['rows']) && !empty($options['empty_table'])) {
00622     $vars['rows'][0][0] = $view->display_handler->render_area('empty');
00623     // Calculate the amounts of rows with output.
00624     $vars['field_attributes'][0][0]['colspan'] = count($vars['header']);
00625     $vars['field_classes'][0][0] = 'views-empty';
00626   }
00627 
00628 
00629   if (!empty($options['sticky'])) {
00630     drupal_add_js('misc/tableheader.js');
00631     $vars['classes_array'][] = "sticky-enabled";
00632   }
00633   $vars['classes_array'][] = 'cols-'. count($vars['header']);
00634 
00635   if (!empty($handler->options['summary'])) {
00636     $vars['attributes_array'] = array('summary' => $handler->options['summary']);
00637   }
00638 }
00639 
00643 function template_preprocess_views_view_grid(&$vars) {
00644   $view     = $vars['view'];
00645   $result   = $view->result;
00646   $options  = $view->style_plugin->options;
00647   $handler  = $view->style_plugin;
00648 
00649   $columns  = $options['columns'];
00650 
00651   $rows = array();
00652   $row_indexes = array();
00653 
00654   if ($options['alignment'] == 'horizontal') {
00655     $row = array();
00656     $col_count = 0;
00657     $row_count = 0;
00658     $count = 0;
00659     foreach ($vars['rows'] as $row_index => $item) {
00660       $count++;
00661       $row[] = $item;
00662       $row_indexes[$row_count][$col_count] = $row_index;
00663       $col_count++;
00664       if ($count % $columns == 0) {
00665         $rows[] = $row;
00666         $row = array();
00667         $col_count = 0;
00668         $row_count++;
00669       }
00670     }
00671     if ($row) {
00672       // Fill up the last line only if it's configured, but this is default.
00673       if (!empty($handler->options['fill_single_line']) || count($rows)) {
00674         for ($i = 0; $i < ($columns - $col_count); $i++) {
00675           $row[] = '';
00676         }
00677       }
00678       $rows[] = $row;
00679     }
00680   }
00681   else {
00682     $num_rows = floor(count($vars['rows']) / $columns);
00683     // The remainders are the 'odd' columns that are slightly longer.
00684     $remainders = count($vars['rows']) % $columns;
00685     $row = 0;
00686     $col = 0;
00687     foreach ($vars['rows'] as $count => $item) {
00688       $rows[$row][$col] = $item;
00689       $row_indexes[$row][$col] = $count;
00690       $row++;
00691 
00692       if (!$remainders && $row == $num_rows) {
00693         $row = 0;
00694         $col++;
00695       }
00696       elseif ($remainders && $row == $num_rows + 1) {
00697         $row = 0;
00698         $col++;
00699         $remainders--;
00700       }
00701     }
00702     for ($i = 0; $i < count($rows[0]); $i++) {
00703       // This should be string so that's okay :)
00704       if (!isset($rows[count($rows) - 1][$i])) {
00705         $rows[count($rows) - 1][$i] = '';
00706       }
00707     }
00708   }
00709 
00710   // Apply the row classes
00711   foreach ($rows as $row_number => $row) {
00712     $row_classes = array();
00713     $row_classes[] =  'row-' . ($row_number + 1);
00714     if ($row_number == 0) {
00715       $row_classes[] =  'row-first';
00716     }
00717     if (count($rows) == ($row_number + 1)) {
00718       $row_classes[] =  'row-last';
00719     }
00720     $vars['row_classes'][$row_number] = implode(' ', $row_classes);
00721     foreach ($rows[$row_number] as $column_number => $item) {
00722       $column_classes = array();
00723       $column_classes[] = 'col-'. ($column_number + 1);
00724       if ($column_number == 0) {
00725         $column_classes[] = 'col-first';
00726       }
00727       elseif (count($rows[$row_number]) == ($column_number + 1)) {
00728         $column_classes[] = 'col-last';
00729       }
00730       if (isset($row_indexes[$row_number][$column_number]) && $column_class = $view->style_plugin->get_row_class($row_indexes[$row_number][$column_number])) {
00731         $column_classes[] = $column_class;
00732       }
00733       $vars['column_classes'][$row_number][$column_number] = implode(' ', $column_classes);
00734     }
00735   }
00736   $vars['rows'] = $rows;
00737   $vars['class'] = 'views-view-grid cols-' . $columns;
00738   if (!empty($handler->options['summary'])) {
00739     $vars['attributes_array'] = array('summary' => $handler->options['summary']);
00740   }
00741 }
00742 
00746 function template_preprocess_views_view_unformatted(&$vars) {
00747   $view = $vars['view'];
00748   $rows = $vars['rows'];
00749 
00750   $vars['classes_array'] = array();
00751   $vars['classes'] = array();
00752   // Set up striping values.
00753   $count = 0;
00754   $max = count($rows);
00755   foreach ($rows as $id => $row) {
00756     $count++;
00757     $vars['classes'][$id][] = 'views-row';
00758     $vars['classes'][$id][] = 'views-row-' . $count;
00759     $vars['classes'][$id][] = 'views-row-' . ($count % 2 ? 'odd' : 'even');
00760     if ($count == 1) {
00761       $vars['classes'][$id][] = 'views-row-first';
00762     }
00763     if ($count == $max) {
00764       $vars['classes'][$id][] = 'views-row-last';
00765     }
00766 
00767     if ($row_class = $view->style_plugin->get_row_class($id)) {
00768       $vars['classes'][$id][] = $row_class;
00769     }
00770 
00771     // Flatten the classes to a string for each row for the template file.
00772     $vars['classes_array'][$id] = implode(' ', $vars['classes'][$id]);
00773   }
00774 }
00775 
00779 function template_preprocess_views_view_list(&$vars) {
00780   $handler  = $vars['view']->style_plugin;
00781 
00782   $class = explode(' ', $handler->options['class']);
00783   $class = array_map('views_clean_css_identifier', $class);
00784 
00785   $wrapper_class = explode(' ', $handler->options['wrapper_class']);
00786   $wrapper_class = array_map('views_clean_css_identifier', $wrapper_class);
00787 
00788   $vars['class'] = implode(' ', $class);
00789   $vars['wrapper_class'] = implode(' ', $wrapper_class);
00790   $vars['wrapper_prefix'] = '';
00791   $vars['wrapper_suffix'] = '';
00792   $vars['list_type_prefix'] = '<' . $handler->options['type'] . '>';
00793   $vars['list_type_suffix'] = '</' . $handler->options['type'] . '>';
00794   if ($vars['wrapper_class']) {
00795     $vars['wrapper_prefix'] = '<div class="' . $vars['wrapper_class'] . '">';
00796     $vars['wrapper_suffix'] = '</div>';
00797   }
00798 
00799   if ($vars['class']) {
00800     $vars['list_type_prefix'] = '<' . $handler->options['type'] . ' class="' . $vars['class'] . '">';
00801   }
00802   template_preprocess_views_view_unformatted($vars);
00803 }
00804 
00808 function template_preprocess_views_view_rss(&$vars) {
00809   global $base_url;
00810   global $language;
00811 
00812   $view     = &$vars['view'];
00813   $options  = &$vars['options'];
00814   $items    = &$vars['rows'];
00815 
00816   $style    = &$view->style_plugin;
00817 
00818   // The RSS 2.0 "spec" doesn't indicate HTML can be used in the description.
00819   // We strip all HTML tags, but need to prevent double encoding from properly
00820   // escaped source data (such as &amp becoming &amp;amp;).
00821   $vars['description'] = check_plain(decode_entities(strip_tags($options['description'])));
00822 
00823   if ($view->display_handler->get_option('sitename_title')) {
00824     $title = variable_get('site_name', 'Drupal');
00825     if ($slogan = variable_get('site_slogan', '')) {
00826       $title .= ' - ' . $slogan;
00827     }
00828   }
00829   else {
00830     $title = $view->get_title();
00831   }
00832   $vars['title'] = check_plain($title);
00833 
00834   // Figure out which display which has a path we're using for this feed. If there isn't
00835   // one, use the global $base_url
00836   $link_display_id = $view->display_handler->get_link_display();
00837   if ($link_display_id && !empty($view->display[$link_display_id])) {
00838     $path = $view->display[$link_display_id]->handler->get_path();
00839   }
00840 
00841   if ($path) {
00842     $path = $view->get_url(NULL, $path);
00843     $url_options = array('absolute' => TRUE);
00844     if (!empty($view->exposed_raw_input)) {
00845       $url_options['query'] = $view->exposed_raw_input;
00846     }
00847 
00848     // Compare the link to the default home page; if it's the default home page, just use $base_url.
00849     if ($path == variable_get('site_frontpage', 'node')) {
00850       $path = '';
00851     }
00852 
00853     $vars['link'] = check_url(url($path, $url_options));
00854   }
00855 
00856   $vars['langcode'] = check_plain($language->language);
00857   $vars['namespaces'] = drupal_attributes($style->namespaces);
00858   $vars['items'] = $items;
00859   $vars['channel_elements'] = format_xml_elements($style->channel_elements);
00860 
00861   // During live preview we don't want to output the header since the contents
00862   // of the feed are being displayed inside a normal HTML page.
00863   if (empty($vars['view']->live_preview)) {
00864     drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
00865   }
00866 }
00867 
00871 function template_preprocess_views_view_row_rss(&$vars) {
00872   $view     = &$vars['view'];
00873   $options  = &$vars['options'];
00874   $item     = &$vars['row'];
00875 
00876   $vars['title'] = check_plain($item->title);
00877   $vars['link'] = check_url($item->link);
00878   $vars['description'] = check_plain($item->description);
00879   $vars['item_elements'] = empty($item->elements) ? '' : format_xml_elements($item->elements);
00880 }
00881 
00885 function template_preprocess_views_exposed_form(&$vars) {
00886   $form = &$vars['form'];
00887 
00888   // Put all single checkboxes together in the last spot.
00889   $checkboxes = '';
00890 
00891   if (!empty($form['q'])) {
00892     $vars['q'] = drupal_render($form['q']);
00893   }
00894 
00895   $vars['widgets'] = array();
00896   foreach ($form['#info'] as $id => $info) {
00897     // Set aside checkboxes.
00898     if (isset($form[$info['value']]['#type']) && $form[$info['value']]['#type'] == 'checkbox') {
00899       $checkboxes .= drupal_render($form[$info['value']]);
00900       continue;
00901     }
00902     $widget = new stdClass;
00903     // set up defaults so that there's always something there.
00904     $widget->label = $widget->operator = $widget->widget = NULL;
00905 
00906     $widget->id = isset($form[$info['value']]['#id']) ? $form[$info['value']]['#id'] : '';
00907     if (!empty($info['label'])) {
00908       $widget->label = $info['label'];
00909     }
00910     if (!empty($info['operator'])) {
00911       $widget->operator = drupal_render($form[$info['operator']]);
00912     }
00913     $widget->widget = drupal_render($form[$info['value']]);
00914     $vars['widgets'][$id] = $widget;
00915   }
00916 
00917   // Wrap up all the checkboxes we set aside into a widget.
00918   if ($checkboxes) {
00919     $widget = new stdClass;
00920     // set up defaults so that there's always something there.
00921     $widget->label = $widget->operator = $widget->widget = NULL;
00922     $widget->id = 'checkboxes';
00923     $widget->widget = $checkboxes;
00924     $vars['widgets']['checkboxes'] = $widget;
00925   }
00926 
00927   if (isset($form['sort_by'])) {
00928     $vars['sort_by'] = drupal_render($form['sort_by']);
00929     $vars['sort_order'] = drupal_render($form['sort_order']);
00930   }
00931   if (isset($form['items_per_page'])) {
00932     $vars['items_per_page'] = drupal_render($form['items_per_page']);
00933   }
00934   if (isset($form['offset'])) {
00935     $vars['offset'] = drupal_render($form['offset']);
00936   }
00937   if (isset($form['reset'])) {
00938     $vars['reset_button'] = drupal_render($form['reset']);
00939   }
00940   // This includes the submit button.
00941   $vars['button'] = drupal_render_children($form);
00942 }
00943 
00947 function theme_views_form_views_form($variables) {
00948   $form = $variables['form'];
00949 
00950   // Placeholders and their substitutions (usually rendered form elements).
00951   $search = array();
00952   $replace = array();
00953 
00954   // Add in substitutions provided by the form.
00955   foreach ($form['#substitutions']['#value'] as $substitution) {
00956     $field_name = $substitution['field_name'];
00957     $row_id = $substitution['row_id'];
00958 
00959     $search[] = $substitution['placeholder'];
00960     $replace[] = isset($form[$field_name][$row_id]) ? drupal_render($form[$field_name][$row_id]) : '';
00961   }
00962   // Add in substitutions from hook_views_form_substitutions().
00963   $substitutions = module_invoke_all('views_form_substitutions');
00964   foreach ($substitutions as $placeholder => $substitution) {
00965     $search[] = $placeholder;
00966     $replace[] = $substitution;
00967   }
00968 
00969   // Apply substitutions to the rendered output.
00970   $form['output']['#markup'] = str_replace($search, $replace, $form['output']['#markup']);
00971 
00972   // Render and add remaining form fields.
00973   return drupal_render_children($form);
00974 }
00975 
00976 function theme_views_mini_pager($vars) {
00977   global $pager_page_array, $pager_total;
00978 
00979   $tags = $vars['tags'];
00980   $element = $vars['element'];
00981   $parameters = $vars['parameters'];
00982   $quantity = $vars['quantity'];
00983 
00984   // Calculate various markers within this pager piece:
00985   // Middle is used to "center" pages around the current page.
00986   $pager_middle = ceil($quantity / 2);
00987   // current is the page we are currently paged to
00988   $pager_current = $pager_page_array[$element] + 1;
00989   // max is the maximum page number
00990   $pager_max = $pager_total[$element];
00991   // End of marker calculations.
00992 
00993 
00994 
00995   if ($pager_total[$element] > 1) {
00996 
00997     $li_previous = theme('pager_previous',
00998       array(
00999         'text' => (isset($tags[1]) ? $tags[1] : t('‹‹')),
01000         'element' => $element,
01001         'interval' => 1,
01002         'parameters' => $parameters,
01003       )
01004     );
01005     if (empty($li_previous)) {
01006       $li_previous = "&nbsp;";
01007     }
01008 
01009     $li_next = theme('pager_next',
01010       array(
01011         'text' => (isset($tags[3]) ? $tags[3] : t('››')),
01012         'element' => $element,
01013         'interval' => 1,
01014         'parameters' => $parameters,
01015       )
01016     );
01017 
01018     if (empty($li_next)) {
01019       $li_next = "&nbsp;";
01020     }
01021 
01022     $items[] = array(
01023       'class' => array('pager-previous'),
01024       'data' => $li_previous,
01025     );
01026 
01027     $items[] = array(
01028       'class' => array('pager-current'),
01029       'data' => t('@current of @max', array('@current' => $pager_current, '@max' => $pager_max)),
01030     );
01031 
01032     $items[] = array(
01033       'class' => array('pager-next'),
01034       'data' => $li_next,
01035     );
01036     return theme('item_list',
01037       array(
01038         'items' => $items,
01039         'title' => NULL,
01040         'type' => 'ul',
01041         'attributes' => array('class' => array('pager')),
01042       )
01043     );
01044   }
01045 }
01046 
01050 function theme_views_container($variables) {
01051   $element = $variables['element'];
01052   return '<div' . drupal_attributes($element['#attributes']) . '>' . $element['#children'] . '</div>';
01053 }
01054 

Generated on Sun Feb 26 2012 12:52:52 for Views by  doxygen 1.7.1