| 1 |
<?php
|
| 2 |
// $Id: theme.inc,v 1.83 2009/09/21 21:40:27 merlinofchaos Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file theme.inc
|
| 6 |
*
|
| 7 |
* An array of preprocessors to fill variables for templates and helper
|
| 8 |
* functions to make theming easier.
|
| 9 |
*/
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Provide a full array of possible themes to try for a given hook.
|
| 13 |
*
|
| 14 |
* @param $hook
|
| 15 |
* The hook to use. This is the base theme/template name.
|
| 16 |
* @param $view
|
| 17 |
* The view being rendered.
|
| 18 |
* @param $display
|
| 19 |
* The display being rendered, if applicable.
|
| 20 |
*/
|
| 21 |
function _views_theme_functions($hook, $view, $display = NULL) {
|
| 22 |
$themes = array();
|
| 23 |
|
| 24 |
if ($display) {
|
| 25 |
$themes[] = $hook . '__' . $view->name . '__' . $display->id;
|
| 26 |
$themes[] = $hook . '__' . $display->id;
|
| 27 |
$themes[] = $hook . '__' . preg_replace('/[^a-z0-9]/', '-', strtolower($view->tag));
|
| 28 |
if ($display->id != $display->display_plugin) {
|
| 29 |
$themes[] = $hook . '__' . $view->name . '__' . $display->display_plugin;
|
| 30 |
$themes[] = $hook . '__' . $display->display_plugin;
|
| 31 |
}
|
| 32 |
}
|
| 33 |
$themes[] = $hook . '__' . $view->name;
|
| 34 |
$themes[] = $hook;
|
| 35 |
return $themes;
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Preprocess the primary theme implementation for a view.
|
| 40 |
*/
|
| 41 |
function template_preprocess_views_view(&$vars) {
|
| 42 |
global $base_path;
|
| 43 |
|
| 44 |
$view = $vars['view'];
|
| 45 |
|
| 46 |
$vars['rows'] = !empty($view->result) || !empty($view->style_plugin->definition['even empty']) ? $view->style_plugin->render($view->result) : '';
|
| 47 |
|
| 48 |
$vars['css_name'] = views_css_safe($view->name);
|
| 49 |
$vars['name'] = $view->name;
|
| 50 |
$vars['display_id'] = $view->current_display;
|
| 51 |
|
| 52 |
if (!$vars['rows']) {
|
| 53 |
$vars['empty'] = $view->display_handler->render_empty();
|
| 54 |
if (!$view->display_handler->get_option('header_empty')) {
|
| 55 |
$vars['header'] = '';
|
| 56 |
}
|
| 57 |
if (!$view->display_handler->get_option('footer_empty')) {
|
| 58 |
$vars['footer'] = '';
|
| 59 |
}
|
| 60 |
}
|
| 61 |
else {
|
| 62 |
$vars['empty'] = '';
|
| 63 |
$header = TRUE;
|
| 64 |
}
|
| 65 |
|
| 66 |
$vars['exposed'] = !empty($view->exposed_widgets) ? $view->exposed_widgets : '';
|
| 67 |
if (!isset($vars['header'])) {
|
| 68 |
$vars['header'] = $view->display_handler->render_header();
|
| 69 |
}
|
| 70 |
if (!isset($vars['footer'])) {
|
| 71 |
$vars['footer'] = $view->display_handler->render_footer();
|
| 72 |
}
|
| 73 |
$vars['more'] = $view->display_handler->render_more_link();
|
| 74 |
$vars['feed_icon'] = !empty($view->feed_icon) ? $view->feed_icon : '';
|
| 75 |
|
| 76 |
$vars['attachment_before'] = !empty($view->attachment_before) ? $view->attachment_before : '';
|
| 77 |
$vars['attachment_after'] = !empty($view->attachment_after) ? $view->attachment_after : '';
|
| 78 |
|
| 79 |
$vars['pager'] = '';
|
| 80 |
|
| 81 |
$exposed_input = isset($view->exposed_data_raw) ? $view->exposed_data_raw : NULL;
|
| 82 |
if (!empty($view->pager['use_pager'])) {
|
| 83 |
$pager_type = ($view->pager['use_pager'] === 'mini' ? 'views_mini_pager' : 'pager');
|
| 84 |
$pager_theme = views_theme_functions($pager_type, $view, $view->display_handler->display);
|
| 85 |
$vars['pager'] = theme($pager_theme, $exposed_input, $view->pager['items_per_page'], $view->pager['element']);
|
| 86 |
}
|
| 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'),
|
| 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 |
array(
|
| 99 |
'title' => t('Export'),
|
| 100 |
'alt' => t("Export this view"),
|
| 101 |
'href' => "admin/build/views/export/$view->name",
|
| 102 |
),
|
| 103 |
array(
|
| 104 |
'title' => t('Clone'),
|
| 105 |
'alt' => t("Create a copy of this view"),
|
| 106 |
'href' => "admin/build/views/clone/$view->name",
|
| 107 |
),
|
| 108 |
);
|
| 109 |
|
| 110 |
drupal_alter('views_admin_links', $vars['admin_links_raw'], $view);
|
| 111 |
$vars['admin_links'] = theme('links', $vars['admin_links_raw']);
|
| 112 |
}
|
| 113 |
else {
|
| 114 |
$vars['admin_links'] = '';
|
| 115 |
$vars['admin_links_raw'] = array();
|
| 116 |
}
|
| 117 |
views_add_css('views');
|
| 118 |
|
| 119 |
// Our JavaScript needs to have some means to find the HTML belonging to this
|
| 120 |
// view.
|
| 121 |
//
|
| 122 |
// It is true that the DIV wrapper has classes denoting the name of the view
|
| 123 |
// and its display ID, but this is not enough to unequivocally match a view
|
| 124 |
// with its HTML, because one view may appear several times on the page. So
|
| 125 |
// we set up a running counter, $dom_id, to issue a "unique" identifier for
|
| 126 |
// each view. This identifier is written to both Drupal.settings and the DIV
|
| 127 |
// wrapper.
|
| 128 |
static $dom_id = 1;
|
| 129 |
$vars['dom_id'] = !empty($view->dom_id) ? $view->dom_id : $dom_id++;
|
| 130 |
|
| 131 |
// If using AJAX, send identifying data about this view.
|
| 132 |
if ($view->use_ajax) {
|
| 133 |
$settings = array(
|
| 134 |
'views' => array(
|
| 135 |
'ajax_path' => url('views/ajax'),
|
| 136 |
'ajaxViews' => array(
|
| 137 |
array(
|
| 138 |
'view_name' => $view->name,
|
| 139 |
'view_display_id' => $view->current_display,
|
| 140 |
'view_args' => implode('/', $view->args),
|
| 141 |
'view_path' => $_GET['q'],
|
| 142 |
// Pass through URL to ensure we get e.g. language prefixes.
|
| 143 |
// 'view_base_path' => isset($view->display['page']) ? substr(url($view->display['page']->display_options['path']), strlen($base_path)) : '',
|
| 144 |
'view_base_path' => $view->get_path(),
|
| 145 |
'view_dom_id' => $vars['dom_id'],
|
| 146 |
// To fit multiple views on a page, the programmer may have
|
| 147 |
// overridden the display's pager_element.
|
| 148 |
'pager_element' => $view->pager['element'],
|
| 149 |
),
|
| 150 |
),
|
| 151 |
),
|
| 152 |
);
|
| 153 |
|
| 154 |
drupal_add_js($settings, 'setting');
|
| 155 |
views_add_js('ajax_view');
|
| 156 |
}
|
| 157 |
}
|
| 158 |
|
| 159 |
/**
|
| 160 |
* Preprocess theme function to print a single record from a row, with fields
|
| 161 |
*/
|
| 162 |
function template_preprocess_views_view_fields(&$vars) {
|
| 163 |
$view = $vars['view'];
|
| 164 |
|
| 165 |
// Loop through the fields for this view.
|
| 166 |
$inline = FALSE;
|
| 167 |
$vars['fields'] = array(); // ensure it's at least an empty array.
|
| 168 |
foreach ($view->field as $id => $field) {
|
| 169 |
// render this even if set to exclude so it can be used elsewhere.
|
| 170 |
$field_output = $view->field[$id]->theme($vars['row']);
|
| 171 |
$empty = $field_output !== 0 && empty($field_output);
|
| 172 |
if (empty($field->options['exclude']) && (!$empty || empty($field->options['hide_empty']))) {
|
| 173 |
$object = new stdClass();
|
| 174 |
|
| 175 |
$object->content = $field_output;
|
| 176 |
if (isset($view->field[$id]->field_alias) && isset($vars['row']->{$view->field[$id]->field_alias})) {
|
| 177 |
$object->raw = $vars['row']->{$view->field[$id]->field_alias};
|
| 178 |
}
|
| 179 |
else {
|
| 180 |
$object->raw = NULL; // make sure it exists to reduce NOTICE
|
| 181 |
}
|
| 182 |
$object->inline = !empty($vars['options']['inline'][$id]);
|
| 183 |
$object->inline_html = $object->inline ? 'span' : 'div';
|
| 184 |
if (!empty($vars['options']['separator']) && $inline && $object->inline && $object->content) {
|
| 185 |
$object->separator = filter_xss_admin($vars['options']['separator']);
|
| 186 |
}
|
| 187 |
|
| 188 |
$inline = $object->inline;
|
| 189 |
|
| 190 |
$object->handler = &$view->field[$id];
|
| 191 |
$object->element_type = $object->handler->element_type();
|
| 192 |
|
| 193 |
$object->class = views_css_safe($id);
|
| 194 |
$object->label = check_plain($view->field[$id]->label());
|
| 195 |
$vars['fields'][$id] = $object;
|
| 196 |
}
|
| 197 |
}
|
| 198 |
|
| 199 |
}
|
| 200 |
|
| 201 |
/**
|
| 202 |
* Display a single views field.
|
| 203 |
*
|
| 204 |
* Interesting bits of info:
|
| 205 |
* $field->field_alias says what the raw value in $row will be. Reach it like
|
| 206 |
* this: @code { $row->{$field->field_alias} @endcode
|
| 207 |
*/
|
| 208 |
function theme_views_view_field($view, $field, $row) {
|
| 209 |
return $field->advanced_render($row);
|
| 210 |
}
|
| 211 |
|
| 212 |
/**
|
| 213 |
* Process a single field within a view.
|
| 214 |
*
|
| 215 |
* This preprocess function isn't normally run, as a function is used by
|
| 216 |
* default, for performance. However, by creating a template, this
|
| 217 |
* preprocess should get picked up.
|
| 218 |
*/
|
| 219 |
function template_preprocess_views_view_field(&$vars) {
|
| 220 |
$vars['output'] = $vars['field']->advanced_render($vars['row']);
|
| 221 |
}
|
| 222 |
|
| 223 |
/**
|
| 224 |
* Preprocess theme function to print a single record from a row, with fields
|
| 225 |
*/
|
| 226 |
function template_preprocess_views_view_summary(&$vars) {
|
| 227 |
$view = $vars['view'];
|
| 228 |
$argument = $view->argument[$view->build_info['summary_level']];
|
| 229 |
|
| 230 |
$url_options = array();
|
| 231 |
|
| 232 |
if (!empty($view->exposed_raw_input)) {
|
| 233 |
$url_options['query'] = $view->exposed_raw_input;
|
| 234 |
}
|
| 235 |
foreach ($vars['rows'] as $id => $row) {
|
| 236 |
$vars['rows'][$id]->link = $argument->summary_name($row);
|
| 237 |
$args = $view->args;
|
| 238 |
$args[$argument->position] = $argument->summary_argument($row);
|
| 239 |
|
| 240 |
$vars['rows'][$id]->url = url($view->get_url($args), $url_options);
|
| 241 |
$vars['rows'][$id]->count = intval($row->{$argument->count_alias});
|
| 242 |
}
|
| 243 |
}
|
| 244 |
|
| 245 |
/**
|
| 246 |
* Template preprocess theme function to print summary basically
|
| 247 |
* unformatted.
|
| 248 |
*/
|
| 249 |
function template_preprocess_views_view_summary_unformatted(&$vars) {
|
| 250 |
$view = $vars['view'];
|
| 251 |
$argument = $view->argument[$view->build_info['summary_level']];
|
| 252 |
|
| 253 |
$url_options = array();
|
| 254 |
|
| 255 |
if (!empty($view->exposed_raw_input)) {
|
| 256 |
$url_options['query'] = $view->exposed_raw_input;
|
| 257 |
}
|
| 258 |
|
| 259 |
$count = 0;
|
| 260 |
foreach ($vars['rows'] as $id => $row) {
|
| 261 |
// only false on first time:
|
| 262 |
if ($count++) {
|
| 263 |
$vars['rows'][$id]->separator = filter_xss_admin($vars['options']['separator']);
|
| 264 |
}
|
| 265 |
$vars['rows'][$id]->link = $argument->summary_name($row);
|
| 266 |
$args = $view->args;
|
| 267 |
$args[$argument->position] = $argument->summary_argument($row);
|
| 268 |
|
| 269 |
$vars['rows'][$id]->url = url($view->get_url($args), $url_options);
|
| 270 |
$vars['rows'][$id]->count = intval($row->{$argument->count_alias});
|
| 271 |
}
|
| 272 |
}
|
| 273 |
|
| 274 |
/**
|
| 275 |
* Display a view as a table style.
|
| 276 |
*/
|
| 277 |
function template_preprocess_views_view_table(&$vars) {
|
| 278 |
$view = $vars['view'];
|
| 279 |
|
| 280 |
// We need the raw data for this grouping, which is passed in as $vars['rows'].
|
| 281 |
// However, the template also needs to use for the rendered fields. We
|
| 282 |
// therefore swap the raw data out to a new variable and reset $vars['rows']
|
| 283 |
// so that it can get rebuilt.
|
| 284 |
// Store rows so that they may be used by further preprocess functions.
|
| 285 |
$result = $vars['result'] = $vars['rows'];
|
| 286 |
$vars['rows'] = array();
|
| 287 |
|
| 288 |
$options = $view->style_plugin->options;
|
| 289 |
$handler = $view->style_plugin;
|
| 290 |
|
| 291 |
$fields = &$view->field;
|
| 292 |
$columns = $handler->sanitize_columns($options['columns'], $fields);
|
| 293 |
|
| 294 |
$active = !empty($handler->active) ? $handler->active : '';
|
| 295 |
$order = !empty($handler->order) ? $handler->order : 'asc';
|
| 296 |
|
| 297 |
$query = tablesort_get_querystring();
|
| 298 |
if ($query) {
|
| 299 |
$query = '&' . $query;
|
| 300 |
}
|
| 301 |
|
| 302 |
// Fields must be rendered in order as of Views 2.3, so we will pre-render
|
| 303 |
// everything.
|
| 304 |
$renders = array();
|
| 305 |
$view->row_index = 0;
|
| 306 |
$keys = array_keys($view->field);
|
| 307 |
foreach ($result as $count => $row) {
|
| 308 |
foreach ($keys as $id) {
|
| 309 |
$renders[$count][$id] = $view->field[$id]->theme($row);
|
| 310 |
}
|
| 311 |
$view->row_index = $count;
|
| 312 |
}
|
| 313 |
unset($view->row_index);
|
| 314 |
|
| 315 |
foreach ($columns as $field => $column) {
|
| 316 |
// render the header labels
|
| 317 |
if ($field == $column && empty($fields[$field]->options['exclude'])) {
|
| 318 |
$label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : '');
|
| 319 |
if (empty($options['info'][$field]['sortable']) || !$fields[$field]->click_sortable()) {
|
| 320 |
$vars['header'][$field] = $label;
|
| 321 |
}
|
| 322 |
else {
|
| 323 |
// @todo -- make this a setting
|
| 324 |
$initial = 'asc';
|
| 325 |
|
| 326 |
if ($active == $field && $order == 'asc') {
|
| 327 |
$initial = 'desc';
|
| 328 |
}
|
| 329 |
|
| 330 |
$title = t('sort by @s', array('@s' => $label));
|
| 331 |
if ($active == $field) {
|
| 332 |
$label .= theme('tablesort_indicator', $initial);
|
| 333 |
}
|
| 334 |
$link_options = array(
|
| 335 |
'html' => true,
|
| 336 |
'attributes' => array('title' => $title),
|
| 337 |
'query' => 'order=' . urlencode($field) . '&sort=' . $initial . $query,
|
| 338 |
);
|
| 339 |
$vars['header'][$field] = l($label, $_GET['q'], $link_options);
|
| 340 |
}
|
| 341 |
}
|
| 342 |
|
| 343 |
// Create a second variable so we can easily find what fields we have and what the
|
| 344 |
// CSS classes should be.
|
| 345 |
$vars['fields'][$field] = views_css_safe($field);
|
| 346 |
if ($active == $field) {
|
| 347 |
$vars['fields'][$field] .= ' active';
|
| 348 |
}
|
| 349 |
|
| 350 |
// Render each field into its appropriate column.
|
| 351 |
foreach ($result as $num => $row) {
|
| 352 |
if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) {
|
| 353 |
$field_output = $renders[$num][$field];
|
| 354 |
|
| 355 |
if (!isset($vars['rows'][$num][$column])) {
|
| 356 |
$vars['rows'][$num][$column] = '';
|
| 357 |
}
|
| 358 |
|
| 359 |
// Don't bother with separators and stuff if the field does not show up.
|
| 360 |
if ($field_output === '') {
|
| 361 |
continue;
|
| 362 |
}
|
| 363 |
|
| 364 |
// Place the field into the column, along with an optional separator.
|
| 365 |
if ($vars['rows'][$num][$column] !== '') {
|
| 366 |
if (!empty($options['info'][$column]['separator'])) {
|
| 367 |
$vars['rows'][$num][$column] .= filter_xss_admin($options['info'][$column]['separator']);
|
| 368 |
}
|
| 369 |
}
|
| 370 |
|
| 371 |
$vars['rows'][$num][$column] .= $field_output;
|
| 372 |
}
|
| 373 |
}
|
| 374 |
}
|
| 375 |
|
| 376 |
foreach ($vars['rows'] as $num => $row) {
|
| 377 |
$vars['row_classes'][$num][] = ($num % 2 == 0) ? 'odd' : 'even';
|
| 378 |
}
|
| 379 |
|
| 380 |
$vars['row_classes'][0][] = 'views-row-first';
|
| 381 |
$vars['row_classes'][count($vars['row_classes']) - 1][] = 'views-row-last';
|
| 382 |
|
| 383 |
$vars['class'] = 'views-table';
|
| 384 |
if (!empty($options['sticky'])) {
|
| 385 |
drupal_add_js('misc/tableheader.js');
|
| 386 |
$vars['class'] .= " sticky-enabled";
|
| 387 |
}
|
| 388 |
}
|
| 389 |
|
| 390 |
/**
|
| 391 |
* Display a view as a grid style.
|
| 392 |
*/
|
| 393 |
function template_preprocess_views_view_grid(&$vars) {
|
| 394 |
$view = $vars['view'];
|
| 395 |
$result = $view->result;
|
| 396 |
$options = $view->style_plugin->options;
|
| 397 |
$handler = $view->style_plugin;
|
| 398 |
|
| 399 |
$columns = $options['columns'];
|
| 400 |
|
| 401 |
$rows = array();
|
| 402 |
|
| 403 |
if ($options['alignment'] == 'horizontal') {
|
| 404 |
$row = array();
|
| 405 |
$row_count = 0;
|
| 406 |
foreach ($vars['rows'] as $count => $item) {
|
| 407 |
$row[] = $item;
|
| 408 |
$row_count++;
|
| 409 |
if (($count + 1) % $columns == 0) {
|
| 410 |
$rows[] = $row;
|
| 411 |
$row = array();
|
| 412 |
$row_count = 0;
|
| 413 |
}
|
| 414 |
}
|
| 415 |
if ($row) {
|
| 416 |
// Fill up the last line.
|
| 417 |
for ($i = 0; $i < ($columns - $row_count); $i++) {
|
| 418 |
$row[] = '';
|
| 419 |
}
|
| 420 |
$rows[] = $row;
|
| 421 |
}
|
| 422 |
}
|
| 423 |
else {
|
| 424 |
$num_rows = floor(count($vars['rows']) / $columns);
|
| 425 |
// The remainders are the 'odd' columns that are slightly longer.
|
| 426 |
$remainders = count($vars['rows']) % $columns;
|
| 427 |
$row = 0;
|
| 428 |
$col = 0;
|
| 429 |
foreach ($vars['rows'] as $count => $item) {
|
| 430 |
$rows[$row][$col] = $item;
|
| 431 |
$row++;
|
| 432 |
|
| 433 |
if (!$remainders && $row == $num_rows) {
|
| 434 |
$row = 0;
|
| 435 |
$col++;
|
| 436 |
}
|
| 437 |
else if ($remainders && $row == $num_rows + 1) {
|
| 438 |
$row = 0;
|
| 439 |
$col++;
|
| 440 |
$remainders--;
|
| 441 |
}
|
| 442 |
}
|
| 443 |
for ($i = 0; $i < count($rows[0]); $i++) {
|
| 444 |
// This should be string so that's okay :)
|
| 445 |
if (!isset($rows[count($rows) - 1][$i])) {
|
| 446 |
$rows[count($rows) - 1][$i] = '';
|
| 447 |
}
|
| 448 |
}
|
| 449 |
}
|
| 450 |
$vars['rows'] = $rows;
|
| 451 |
}
|
| 452 |
|
| 453 |
/**
|
| 454 |
* Display the simple view of rows one after another
|
| 455 |
*/
|
| 456 |
function template_preprocess_views_view_unformatted(&$vars) {
|
| 457 |
$view = $vars['view'];
|
| 458 |
$rows = $vars['rows'];
|
| 459 |
|
| 460 |
$vars['classes'] = array();
|
| 461 |
// Set up striping values.
|
| 462 |
foreach ($rows as $id => $row) {
|
| 463 |
$vars['classes'][$id] = 'views-row';
|
| 464 |
$vars['classes'][$id] .= ' views-row-' . ($id + 1);
|
| 465 |
$vars['classes'][$id] .= ' views-row-' . ($id % 2 ? 'even' : 'odd');
|
| 466 |
if ($id == 0) {
|
| 467 |
$vars['classes'][$id] .= ' views-row-first';
|
| 468 |
}
|
| 469 |
}
|
| 470 |
$vars['classes'][$id] .= ' views-row-last';
|
| 471 |
}
|
| 472 |
|
| 473 |
/**
|
| 474 |
* Display the view as an HTML list element
|
| 475 |
*/
|
| 476 |
function template_preprocess_views_view_list(&$vars) {
|
| 477 |
template_preprocess_views_view_unformatted($vars);
|
| 478 |
}
|
| 479 |
|
| 480 |
/**
|
| 481 |
* Preprocess an RSS feed
|
| 482 |
*/
|
| 483 |
function template_preprocess_views_view_rss(&$vars) {
|
| 484 |
global $base_url;
|
| 485 |
global $language;
|
| 486 |
|
| 487 |
$view = &$vars['view'];
|
| 488 |
$options = &$vars['options'];
|
| 489 |
$items = &$vars['rows'];
|
| 490 |
|
| 491 |
$style = &$view->style_plugin;
|
| 492 |
|
| 493 |
if (!empty($options['mission_description'])) {
|
| 494 |
$description = variable_get('site_mission', '');
|
| 495 |
}
|
| 496 |
else {
|
| 497 |
$description = $options['description'];
|
| 498 |
}
|
| 499 |
// The RSS 2.0 "spec" doesn't indicate HTML can be used in the description.
|
| 500 |
// We strip all HTML tags, but need to prevent double encoding from properly
|
| 501 |
// escaped source data (such as & becoming &amp;).
|
| 502 |
$vars['description'] = check_plain(decode_entities(strip_tags($description)));
|
| 503 |
|
| 504 |
if ($view->display_handler->get_option('sitename_title')) {
|
| 505 |
$title = variable_get('site_name', 'Drupal');
|
| 506 |
if ($slogan = variable_get('site_slogan', '')) {
|
| 507 |
$title .= ' - ' . $slogan;
|
| 508 |
}
|
| 509 |
}
|
| 510 |
else {
|
| 511 |
$title = $view->get_title();
|
| 512 |
}
|
| 513 |
$vars['title'] = check_plain($title);
|
| 514 |
|
| 515 |
// Figure out which display which has a path we're using for this feed. If there isn't
|
| 516 |
// one, use the global $base_url
|
| 517 |
$link_display_id = $view->display_handler->get_link_display();
|
| 518 |
if ($link_display_id && !empty($view->display[$link_display_id])) {
|
| 519 |
$path = $view->display[$link_display_id]->handler->get_path();
|
| 520 |
}
|
| 521 |
|
| 522 |
if ($path) {
|
| 523 |
$path = $view->get_url(NULL, $path);
|
| 524 |
$url_options = array('absolute' => TRUE);
|
| 525 |
if (!empty($view->exposed_raw_input)) {
|
| 526 |
$url_options['query'] = $view->exposed_raw_input;
|
| 527 |
}
|
| 528 |
|
| 529 |
// Compare the link to the default home page; if it's the default home page, just use $base_url.
|
| 530 |
if ($path == variable_get('site_frontpage', 'node')) {
|
| 531 |
$path = '';
|
| 532 |
}
|
| 533 |
|
| 534 |
$vars['link'] = check_url(url($path, $url_options));
|
| 535 |
}
|
| 536 |
|
| 537 |
$vars['langcode'] = check_plain($language->language);
|
| 538 |
$vars['namespaces'] = drupal_attributes($style->namespaces);
|
| 539 |
$vars['items'] = $items;
|
| 540 |
$vars['channel_elements'] = format_xml_elements($style->channel_elements);
|
| 541 |
|
| 542 |
drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
|
| 543 |
}
|
| 544 |
|
| 545 |
/**
|
| 546 |
* Default theme function for all RSS rows.
|
| 547 |
*/
|
| 548 |
function template_preprocess_views_view_row_rss(&$vars) {
|
| 549 |
$view = &$vars['view'];
|
| 550 |
$options = &$vars['options'];
|
| 551 |
$item = &$vars['row'];
|
| 552 |
|
| 553 |
$vars['title'] = check_plain($item->title);
|
| 554 |
$vars['link'] = check_url($item->link);
|
| 555 |
$vars['description'] = check_plain($item->description);
|
| 556 |
$vars['item_elements'] = empty($item->elements) ? '' : format_xml_elements($item->elements);
|
| 557 |
}
|
| 558 |
|
| 559 |
/**
|
| 560 |
* Default theme function for all filter forms.
|
| 561 |
*/
|
| 562 |
function template_preprocess_views_exposed_form(&$vars) {
|
| 563 |
views_add_css('views');
|
| 564 |
$form = &$vars['form'];
|
| 565 |
|
| 566 |
// Put all single checkboxes together in the last spot.
|
| 567 |
$checkboxes = '';
|
| 568 |
|
| 569 |
if (!empty($form['q'])) {
|
| 570 |
$vars['q'] = drupal_render($form['q']);
|
| 571 |
}
|
| 572 |
|
| 573 |
$vars['widgets'] = array();
|
| 574 |
foreach ($form['#info'] as $id => $info) {
|
| 575 |
// Set aside checkboxes.
|
| 576 |
if (isset($form[$info['value']]['#type']) && $form[$info['value']]['#type'] == 'checkbox') {
|
| 577 |
$checkboxes .= drupal_render($form[$info['value']]);
|
| 578 |
continue;
|
| 579 |
}
|
| 580 |
$widget = new stdClass;
|
| 581 |
// set up defaults so that there's always something there.
|
| 582 |
$widget->label = $widget->operator = $widget->widget = NULL;
|
| 583 |
|
| 584 |
if (!empty($info['label'])) {
|
| 585 |
$widget->label = $info['label'];
|
| 586 |
}
|
| 587 |
if (!empty($info['operator'])) {
|
| 588 |
$widget->operator = drupal_render($form[$info['operator']]);
|
| 589 |
}
|
| 590 |
$widget->widget = drupal_render($form[$info['value']]);
|
| 591 |
$vars['widgets'][$id] = $widget;
|
| 592 |
}
|
| 593 |
|
| 594 |
// Wrap up all the checkboxes we set aside into a widget.
|
| 595 |
if ($checkboxes) {
|
| 596 |
$widget = new stdClass;
|
| 597 |
// set up defaults so that there's always something there.
|
| 598 |
$widget->label = $widget->operator = $widget->widget = NULL;
|
| 599 |
$widget->widget = $checkboxes;
|
| 600 |
$vars['widgets']['checkboxes'] = $widget;
|
| 601 |
}
|
| 602 |
|
| 603 |
// Don't render these:
|
| 604 |
unset($form['form_id']);
|
| 605 |
unset($form['form_build_id']);
|
| 606 |
unset($form['form_token']);
|
| 607 |
|
| 608 |
// This includes the submit button.
|
| 609 |
$vars['button'] = drupal_render($form);
|
| 610 |
}
|
| 611 |
|
| 612 |
function theme_views_mini_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
|
| 613 |
global $pager_page_array, $pager_total;
|
| 614 |
|
| 615 |
// Calculate various markers within this pager piece:
|
| 616 |
// Middle is used to "center" pages around the current page.
|
| 617 |
$pager_middle = ceil($quantity / 2);
|
| 618 |
// current is the page we are currently paged to
|
| 619 |
$pager_current = $pager_page_array[$element] + 1;
|
| 620 |
// max is the maximum page number
|
| 621 |
$pager_max = $pager_total[$element];
|
| 622 |
// End of marker calculations.
|
| 623 |
|
| 624 |
|
| 625 |
$li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('‹‹')), $limit, $element, 1, $parameters);
|
| 626 |
if (empty($li_previous)) {
|
| 627 |
$li_previous = " ";
|
| 628 |
}
|
| 629 |
|
| 630 |
$li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('››')), $limit, $element, 1, $parameters);
|
| 631 |
if (empty($li_next)) {
|
| 632 |
$li_next = " ";
|
| 633 |
}
|
| 634 |
|
| 635 |
if ($pager_total[$element] > 1) {
|
| 636 |
$items[] = array(
|
| 637 |
'class' => 'pager-previous',
|
| 638 |
'data' => $li_previous,
|
| 639 |
);
|
| 640 |
|
| 641 |
$items[] = array(
|
| 642 |
'class' => 'pager-current',
|
| 643 |
'data' => t('@current of @max', array('@current' => $pager_current, '@max' => $pager_max)),
|
| 644 |
);
|
| 645 |
|
| 646 |
$items[] = array(
|
| 647 |
'class' => 'pager-next',
|
| 648 |
'data' => $li_next,
|
| 649 |
);
|
| 650 |
return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
|
| 651 |
}
|
| 652 |
}
|
| 653 |
|
| 654 |
/**
|
| 655 |
* @defgroup views_templates Views' template files
|
| 656 |
* @{
|
| 657 |
* All views templates can be overridden with a variety of names, using
|
| 658 |
* the view, the display ID of the view, the display type of the view,
|
| 659 |
* or some combination thereof.
|
| 660 |
*
|
| 661 |
* For each view, there will be a minimum of two templates used. The first
|
| 662 |
* is used for all views: views-view.tpl.php.
|
| 663 |
*
|
| 664 |
* The second template is determined by the style selected for the view. Note
|
| 665 |
* that certain aspects of the view can also change which style is used; for
|
| 666 |
* example, arguments which provide a summary view might change the style to
|
| 667 |
* one of the special summary styles.
|
| 668 |
*
|
| 669 |
* The default style for all views is views-view-unformatted.tpl.php
|
| 670 |
*
|
| 671 |
* Many styles will then farm out the actual display of each row to a row
|
| 672 |
* style; the default row style is views-view-fields.tpl.php.
|
| 673 |
*
|
| 674 |
* Here is an example of all the templates that will be tried in the following
|
| 675 |
* case:
|
| 676 |
*
|
| 677 |
* View, named foobar. Style: unformatted. Row style: Fields. Display: Page.
|
| 678 |
*
|
| 679 |
* - views-view--foobar--page.tpl.php
|
| 680 |
* - views-view--page.tpl.php
|
| 681 |
* - views-view--foobar.tpl.php
|
| 682 |
* - views-view.tpl.php
|
| 683 |
*
|
| 684 |
* - views-view-unformatted--foobar--page.tpl.php
|
| 685 |
* - views-view-unformatted--page.tpl.php
|
| 686 |
* - views-view-unformatted--foobar.tpl.php
|
| 687 |
* - views-view-unformatted.tpl.php
|
| 688 |
*
|
| 689 |
* - views-view-fields--foobar--page.tpl.php
|
| 690 |
* - views-view-fields--page.tpl.php
|
| 691 |
* - views-view-fields--foobar.tpl.php
|
| 692 |
* - views-view-fields.tpl.php
|
| 693 |
*
|
| 694 |
* Important! When adding a new template to your theme, be sure to flush the
|
| 695 |
* theme registry cache!
|
| 696 |
*
|
| 697 |
* @see _views_theme_functions
|
| 698 |
* @}
|
| 699 |
*/
|