You are here

mcd.countdown.inc in Maintenance Countdown 6

Same filename and directory in other branches
  1. 7 mcd.countdown.inc

This file will be processed if time is set

File

mcd.countdown.inc
View source
<?php

/**
 * @file
 * This file will be processed if time is set
 */

/**
 * Implementation of hook_theme_registry_alter().
 *
 * Make drupal to use maintenance-countdown-page.tpl.php in
 * maintenance mode if timer is set
 *
 * @param $theme_registry
 * The entire cache of theme registry information, post-processing.
 */
function mcd_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'mcd');
  $theme_registry['maintenance_page']['template'] = 'maintenance-countdown-page';
  $theme_registry['maintenance_page']['path'] = $path;
}

/**
 * Generate the jQuery output
 */
function mcd_js_countdown() {

  //  get stoptime like 1315776380
  $stoptime = variable_get('mcd_stoptime', NULL);
  $mcd_message = variable_get('mcd_time_up_message', FALSE);
  $mcd_reload = variable_get('mcd_reload_button', 0);

  //  jQuery script for countdown initialization
  $output = "jQuery(document).ready(function(\$) {\$('#countdown_dashboard').countDown({targetDate: {";
  $output .= "'day': " . format_date($stoptime, 'custom', 'j') . ", ";
  $output .= "'month': " . format_date($stoptime, 'custom', 'n') . ", ";
  $output .= "'year': " . format_date($stoptime, 'custom', 'Y') . ", ";
  $output .= "'hour': " . format_date($stoptime, 'custom', 'G') . ", ";
  $output .= "'min': " . format_date($stoptime, 'custom', 'i') . ", ";
  $output .= "'sec': " . format_date($stoptime, 'custom', 's') . ", ";
  $output .= "'utc': '" . format_date($stoptime, 'custom', 'O') . "'";
  $output .= "}";
  if ($mcd_message || $mcd_reload != 1) {
    $output .= ", onComplete: function() {";

    //  slide down 'time is up' message or 'Reload' button
    if ($mcd_message || $mcd_reload == 0) {
      $output .= " \$('#complete_message').slideDown();";
    }
    if ($mcd_reload == 2) {
      $output .= " setTimeout(function() {location.reload();}, 15000)";
    }
    $output .= "}";
  }

  // close countDown
  $output .= "});";

  //  reload current page by clicking 'Reload' button
  if (variable_get('mcd_reload_button', 0) == 0) {
    $output .= " \$('#page_reload').click(function() {location.reload()});";
  }
  $output .= "";

  // close function
  $output .= "});";
  return $output;
}

/**
 * Add some variables for maintenance-coundown-page.tpl.php file.
 *
 * To add or override something you can use the same
 * TEMPLATE_preprocess_maintenance_page function  in your theme
 * template.php file.
 *
 * @param $variables
 *  New and updated variables for maintenance-coundown-page.tpl.php file.
 */
function mcd_preprocess_maintenance_page(&$variables) {
  $path = drupal_get_path('module', 'mcd');

  //  unset regions
  unset($variables['left']);
  unset($variables['right']);

  //  add theme css
  $variables['styles'] = drupal_add_css($path . '/styles/' . variable_get('mcd_page_themes', 'light') . '.css', 'theme', 'all');
  $css = drupal_add_css();

  //  we don't need all modules css
  unset($css['all']['module']);
  $variables['styles'] = drupal_get_css($css);

  //  we need jquery 1.4.1+ to make it work
  $variables['scripts'] = drupal_add_js($path . '/js/jquery-1.4.1.min.js', 'module', 'header', FALSE, TRUE, FALSE);
  $variables['scripts'] = drupal_add_js($path . '/js/jquery.lwtCountdown-1.0-min.js', 'module', 'header', FALSE, TRUE, FALSE);
  $variables['scripts'] = drupal_add_js(mcd_js_countdown(), 'inline');

  //  we don't need core js for this page
  $js = drupal_add_js(NULL, NULL, 'header');
  unset($js['core']);
  $variables['scripts'] = drupal_get_js('header', $js);
  $variables['time_up_message'] = variable_get('mcd_time_up_message', FALSE);
  if (variable_get('mcd_reload_button', 0) == 0) {
    $variables['reload_button'] = l(t('♻ Reload'), $_GET['q'], array(
      'attributes' => array(
        'id' => 'page_reload',
        'title' => t('Reload this page'),
      ),
    ));
  }
  else {
    $variables['reload_button'] = FALSE;
  }
}

Functions

Namesort descending Description
mcd_js_countdown Generate the jQuery output
mcd_preprocess_maintenance_page Add some variables for maintenance-coundown-page.tpl.php file.
mcd_theme_registry_alter Implementation of hook_theme_registry_alter().