You are here

function theme_views_autorefresh in Views Hacks 6

Theme function for 'views_autorefresh'.

File

views_autorefresh/views_autorefresh.module, line 31

Code

function theme_views_autorefresh($interval, $ping = NULL, $incremental = NULL, $view = NULL) {
  if (empty($view)) {
    $view = views_get_current_view();
  }

  // Signal the view that we're incrementally auto-refreshing.
  if (!empty($incremental)) {
    $view->autorefresh['incremental'] = $incremental;
  }
  if (!empty($ping)) {
    $view->autorefresh['ping'] = $ping;
  }

  // Add the JavaScript settings.
  drupal_add_js(drupal_get_path('module', 'views_autorefresh') . '/views_autorefresh.js');
  drupal_add_js(array(
    'views_autorefresh' => array(
      $view->name => array(
        'interval' => $interval,
        'ping' => $ping,
        'incremental' => $incremental,
        'timestamp' => __views_autorefresh_get_timestamp($view),
      ),
    ),
  ), 'setting');
  $query_string = drupal_query_string_encode($_REQUEST, array_merge(array(
    'q',
    'pass',
  ), array_keys($_COOKIE)));
  $query[] = $query_string;
  $link = l('', $_GET['q'], array(
    'query' => count($query) ? implode('&', $query) : NULL,
  ));

  // Signal modules to add their own plugins.
  module_invoke_all('views_autorefresh_plugins', $view);
  return '<div class="auto-refresh">' . $link . '</div>';
}