You are here

function countdown_countdown_build in Countdown 7.2

Countdown build callback.

Parameters

$plugin: The plugin definition.

$countdown_options: The array of options from the countdown box plugin.

Return value

A build array.

1 string reference to 'countdown_countdown_build'
countdown.inc in plugins/countdown/countdown.inc

File

plugins/countdown/countdown.inc, line 35

Code

function countdown_countdown_build($plugin, $countdown_options) {
  $output = '';
  $time = time();
  $difference = $countdown_options['countdown_target_timestamp'] - $time;
  if ($difference < 0) {
    $passed = 1;
    $difference = abs($difference);
  }
  else {
    $passed = 0;
  }
  $accuracy = date_granularity_precision($countdown_options['countdown_elements']);
  $days_left = floor($difference / 60 / 60 / 24);
  $hrs_left = floor(($difference - $days_left * 60 * 60 * 24) / 60 / 60);
  $min_left = floor(($difference - $days_left * 60 * 60 * 24 - $hrs_left * 60 * 60) / 60);
  $secs_left = floor($difference - $days_left * 60 * 60 * 24 - $hrs_left * 60 * 60 - $min_left * 60);
  $output .= format_plural($days_left, '1 day', '@count days');
  if ($accuracy == 'hour' || $accuracy == 'minute' || $accuracy == 'second') {
    $output .= format_plural($hrs_left, ', 1 hour', ', @count hours');
  }
  if ($accuracy == 'minute' || $accuracy == 'second') {
    $output .= format_plural($min_left, ', 1 minute', ', @count minutes');
  }
  if ($accuracy == 'second') {
    $output .= format_plural($secs_left, ', 1 second', ', @count seconds');
  }
  $event_name = $countdown_options['event_name'];
  $url = $countdown_options['event_url'];
  $event_name = empty($url) || $url == 'http://' ? $event_name : l($event_name, $url, array(
    'absolute' => TRUE,
  ));
  $output .= t($passed ? ' since !s.' : ' until !s.', array(
    '!s' => $event_name,
  ));
  if ($accuracy != 'd') {
    $path = $plugin['path'] . '/countdown';
    drupal_add_js($path . '/countdown.js');
    $output .= <<<___EOS___
<script type="text/javascript"><!--
  init_countdown('{<span class="php-variable">$accuracy</span>}');
// --></script>
___EOS___;
  }
  return $output;
}