You are here

function theme_countdown_block in Countdown 5

1 theme call to theme_countdown_block()
countdown_block in ./countdown.module
Do all the block stuff

File

./countdown.module, line 145

Code

function theme_countdown_block() {
  $time = time();
  $difference = variable_get('countdown_timestamp', $time) - $time;
  if ($difference < 0) {
    $passed = 1;
    $difference = abs($difference);
  }
  else {
    $passed = 0;
  }
  $accuracy = variable_get('countdown_accuracy', 'd');
  $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);
  $block = '';
  $block .= t('%i days', array(
    '%i' => $days_left,
  ));
  if ($accuracy == 'h' || $accuracy == 'm' || $accuracy == 's') {
    $block .= t(', %i hours', array(
      '%i' => $hrs_left,
    ));
  }
  if ($accuracy == 'm' || $accuracy == 's') {
    $block .= t(', %i minutes', array(
      '%i' => $min_left,
    ));
  }
  if ($accuracy == 's') {
    $block .= t(', %i seconds', array(
      '%i' => $secs_left,
    ));
  }
  $event_name = variable_get('countdown_event_name', '');
  $url = variable_get('countdown_url', '');
  $event_name = empty($url) || $url == 'http://' ? $event_name : l($event_name, $url, NULL, NULL, NULL, TRUE);
  $block .= t($passed ? ' since !s.' : ' until !s.', array(
    '!s' => $event_name,
  ));
  if ($accuracy != 'd') {
    $path = drupal_get_path('module', 'countdown');
    drupal_add_js($path . '/countdown.js');
    $block .= <<<___EOS___
<script type="text/javascript"><!--
  init_countdown('{<span class="php-variable">$accuracy</span>}');
// --></script>
___EOS___;
  }
  return $block;
}