| 1 |
<?php
|
| 2 |
// $Id: countdown.module,v 1.5.2.1 2008/07/25 16:12:52 deekayen Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Count to, or from, a specified date and display the output in a block
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Describe the module in the HTML frontend
|
| 11 |
*
|
| 12 |
* @param string $section
|
| 13 |
* @return string
|
| 14 |
*/
|
| 15 |
function countdown_help($path, $arg) {
|
| 16 |
$output = '';
|
| 17 |
switch ($path) {
|
| 18 |
case 'admin/help#countdown':
|
| 19 |
$output = t("Don't forget to configure the event name and date in Administer/blocks/Countdown configure");
|
| 20 |
break;
|
| 21 |
}
|
| 22 |
return $output;
|
| 23 |
}
|
| 24 |
|
| 25 |
/**
|
| 26 |
* Do all the block stuff
|
| 27 |
*
|
| 28 |
* @param string $op
|
| 29 |
* @param integer $delta
|
| 30 |
* @return string or array
|
| 31 |
*/
|
| 32 |
function countdown_block($op = 'list', $delta = 0, $edit = array()) {
|
| 33 |
switch ($op) {
|
| 34 |
case 'list':
|
| 35 |
$blocks[0]['info'] = 'Countdown';
|
| 36 |
return $blocks;
|
| 37 |
break;
|
| 38 |
|
| 39 |
case 'configure':
|
| 40 |
$form['countdown_event_name'] = array(
|
| 41 |
'#type' => 'textfield',
|
| 42 |
'#title' => t('Event Name'),
|
| 43 |
'#default_value' => variable_get('countdown_event_name', ''),
|
| 44 |
'#size' => 30,
|
| 45 |
'#maxlength' => 200,
|
| 46 |
'#description' => t("Event name you're counting to or from."),
|
| 47 |
'#required' => TRUE
|
| 48 |
);
|
| 49 |
$form['countdown_url'] = array(
|
| 50 |
'#type' => 'textfield',
|
| 51 |
'#title' => t('Event URL'),
|
| 52 |
'#default_value' => variable_get('countdown_url', ''),
|
| 53 |
'#size' => 30,
|
| 54 |
'#maxlength' => 200,
|
| 55 |
'#description' => t("Turn the event description into a link to more information about the event."),
|
| 56 |
'#required' => FALSE
|
| 57 |
);
|
| 58 |
|
| 59 |
$form['countdown_accuracy'] = array(
|
| 60 |
'#type' => 'radios',
|
| 61 |
'#title' => t('Accuracy'),
|
| 62 |
'#default_value' => variable_get('countdown_accuracy', 'd'),
|
| 63 |
'#options' => array('d' => t('days'), 'h' => t('hours'), 'm' => t('minutes'), 's' => 'seconds'),
|
| 64 |
'#description' => t('Select the smallest amount of detail to display. For example, selecting "days" will display only days, selecting "hours" will display the number of days and hours.')
|
| 65 |
);
|
| 66 |
|
| 67 |
$time = time();
|
| 68 |
$timestamp = variable_get('countdown_timestamp', $time);
|
| 69 |
|
| 70 |
$form['target_time'] = array(
|
| 71 |
'#type' => 'fieldset',
|
| 72 |
'#title' => t('Target date/time'),
|
| 73 |
'#collapsible' => TRUE,
|
| 74 |
'#collapsed' => FALSE,
|
| 75 |
'#description' => t('Select a date relative to the server time: %s', array('%s' => format_date($time)))
|
| 76 |
);
|
| 77 |
|
| 78 |
for ($years = array(), $i = 1970; $i < 2032; $years[$i] = $i, $i++);
|
| 79 |
$form['target_time']['year'] = array(
|
| 80 |
'#type' => 'select',
|
| 81 |
'#title' => t('Year'),
|
| 82 |
'#default_value' => (int)date('Y', $timestamp),
|
| 83 |
'#options' => $years
|
| 84 |
);
|
| 85 |
unset($years);
|
| 86 |
|
| 87 |
$form['target_time']['month'] = array(
|
| 88 |
'#type' => 'select',
|
| 89 |
'#title' => t('Month'),
|
| 90 |
'#default_value' => (int)date('n', $timestamp),
|
| 91 |
'#options' => array(1 => t('January'), 2 => t('February'), 3 => t('March'), 4 => t('April'),
|
| 92 |
5 => t('May'), 6 => t('June'), 7 => t('July'), 8 => t('August'),
|
| 93 |
9 => t('September'), 10 => t('October'), 11 => t('November'), 12 => t('December'))
|
| 94 |
);
|
| 95 |
|
| 96 |
for ($month_days = array(), $i = 1; $i < 32; $month_days[$i] = $i, $i++);
|
| 97 |
$form['target_time']['day'] = array(
|
| 98 |
'#type' => 'select',
|
| 99 |
'#title' => t('Day'),
|
| 100 |
'#default_value' => (int)date('j', $timestamp),
|
| 101 |
'#options' => $month_days
|
| 102 |
);
|
| 103 |
unset($month_days);
|
| 104 |
|
| 105 |
for ($hrs = array(), $i = 0; $i < 24; $hrs[] = $i, $i++);
|
| 106 |
$form['target_time']['hour'] = array(
|
| 107 |
'#type' => 'select',
|
| 108 |
'#title' => t('Hour'),
|
| 109 |
'#default_value' => (int)date('G', $timestamp),
|
| 110 |
'#options' => $hrs
|
| 111 |
);
|
| 112 |
unset($hrs);
|
| 113 |
|
| 114 |
for ($mins = array(), $i = 0; $i < 60; $mins[] = $i, $i++);
|
| 115 |
$form['target_time']['min'] = array(
|
| 116 |
'#type' => 'select',
|
| 117 |
'#title' => t('Minute'),
|
| 118 |
'#default_value' => (int)date('i', $timestamp),
|
| 119 |
'#options' => $mins
|
| 120 |
);
|
| 121 |
$form['target_time']['sec'] = array(
|
| 122 |
'#type' => 'select',
|
| 123 |
'#title' => t('Seconds'),
|
| 124 |
'#default_value' => (int)date('s', $timestamp),
|
| 125 |
'#options' => $mins
|
| 126 |
);
|
| 127 |
|
| 128 |
return $form;
|
| 129 |
break;
|
| 130 |
|
| 131 |
case 'save':
|
| 132 |
variable_set('countdown_event_name', $edit['countdown_event_name']);
|
| 133 |
variable_set('countdown_url', $edit['countdown_url']);
|
| 134 |
variable_set('countdown_accuracy', $edit['countdown_accuracy']);
|
| 135 |
variable_set('countdown_timestamp', mktime((int)$edit['hour'], (int)$edit['min'], (int)$edit['sec'], (int)$edit['month'], (int)$edit['day'], (int)$edit['year']));
|
| 136 |
|
| 137 |
case 'view':
|
| 138 |
if (user_access('access content')) {
|
| 139 |
$block['subject'] = variable_get('countdown_block_title', t('Countdown'));
|
| 140 |
$block['content'] = theme('countdown');
|
| 141 |
return $block;
|
| 142 |
}
|
| 143 |
break;
|
| 144 |
}
|
| 145 |
}
|
| 146 |
|
| 147 |
/**
|
| 148 |
* Implementation of hook_theme().
|
| 149 |
*
|
| 150 |
* Theme function for similar block
|
| 151 |
*/
|
| 152 |
function countdown_theme() {
|
| 153 |
return array(
|
| 154 |
'countdown' => array(
|
| 155 |
'template' => 'countdown',
|
| 156 |
)
|
| 157 |
);
|
| 158 |
}
|