| 1 |
<?php |
<?php |
| 2 |
// $Id: countdown.module,v 1.3 2006/11/06 21:23:59 deekayen Exp $ |
// $Id: countdown.module,v 1.4 2007/01/15 23:34:37 deekayen Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Count to or from a specified date and display the output in a block |
* Count to or from a specified date and display the output in a block |
| 29 |
* @return string or array |
* @return string or array |
| 30 |
*/ |
*/ |
| 31 |
function countdown_block($op = 'list', $delta = 0, $edit = array()) { |
function countdown_block($op = 'list', $delta = 0, $edit = array()) { |
| 32 |
switch($op) { |
switch ($op) { |
| 33 |
case 'list': |
case 'list': |
| 34 |
$blocks[0]['info'] = 'Countdown'; |
$blocks[0]['info'] = 'Countdown'; |
| 35 |
return $blocks; |
return $blocks; |
| 65 |
'#description' => t('Select a date relative to the server time: %s', array('%s' => format_date($time))) |
'#description' => t('Select a date relative to the server time: %s', array('%s' => format_date($time))) |
| 66 |
); |
); |
| 67 |
|
|
| 68 |
for($years = array(), $i = 1970; $i < 2032; $years[$i] = $i, $i++); |
for ($years = array(), $i = 1970; $i < 2032; $years[$i] = $i, $i++); |
| 69 |
$form['target_time']['year'] = array( |
$form['target_time']['year'] = array( |
| 70 |
'#type' => 'select', |
'#type' => 'select', |
| 71 |
'#title' => t('Year'), |
'#title' => t('Year'), |
| 83 |
9 => t('September'), 10 => t('October'), 11 => t('November'), 12 => t('December')) |
9 => t('September'), 10 => t('October'), 11 => t('November'), 12 => t('December')) |
| 84 |
); |
); |
| 85 |
|
|
| 86 |
for($month_days = array(), $i = 1; $i < 32; $month_days[$i] = $i, $i++); |
for ($month_days = array(), $i = 1; $i < 32; $month_days[$i] = $i, $i++); |
| 87 |
$form['target_time']['day'] = array( |
$form['target_time']['day'] = array( |
| 88 |
'#type' => 'select', |
'#type' => 'select', |
| 89 |
'#title' => t('Day'), |
'#title' => t('Day'), |
| 92 |
); |
); |
| 93 |
unset($month_days); |
unset($month_days); |
| 94 |
|
|
| 95 |
for($hrs = array(), $i = 0; $i < 24; $hrs[] = $i, $i++); |
for ($hrs = array(), $i = 0; $i < 24; $hrs[] = $i, $i++); |
| 96 |
$form['target_time']['hour'] = array( |
$form['target_time']['hour'] = array( |
| 97 |
'#type' => 'select', |
'#type' => 'select', |
| 98 |
'#title' => t('Hour'), |
'#title' => t('Hour'), |
| 101 |
); |
); |
| 102 |
unset($hrs); |
unset($hrs); |
| 103 |
|
|
| 104 |
for($mins = array(), $i = 0; $i < 60; $mins[] = $i, $i++); |
for ($mins = array(), $i = 0; $i < 60; $mins[] = $i, $i++); |
| 105 |
$form['target_time']['min'] = array( |
$form['target_time']['min'] = array( |
| 106 |
'#type' => 'select', |
'#type' => 'select', |
| 107 |
'#title' => t('Minute'), |
'#title' => t('Minute'), |
| 126 |
case 'view': |
case 'view': |
| 127 |
if (user_access('access content')) { |
if (user_access('access content')) { |
| 128 |
$block['subject'] = variable_get('countdown_block_title', t('Countdown')); |
$block['subject'] = variable_get('countdown_block_title', t('Countdown')); |
| 129 |
$time = time(); |
$block['content'] = theme('countdown_block'); |
|
$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['content'] .= t('%i days', array('%i' => $days_left)); |
|
|
if($accuracy == 'h' || $accuracy == 'm' || $accuracy == 's') { |
|
|
$block['content'] .= t(', %i hours', array('%i' => $hrs_left)); |
|
|
} |
|
|
if($accuracy == 'm' || $accuracy == 's') { |
|
|
$block['content'] .= t(', %i minutes', array('%i' => $min_left)); |
|
|
} |
|
|
if($accuracy == 's') { |
|
|
$block['content'] .= t(', %i seconds', array('%i' => $secs_left)); |
|
|
} |
|
|
$block['content'] .= t(($passed) ? ' since %s.' : ' until %s.', array('%s' => variable_get('countdown_event_name', ''))); |
|
|
/* |
|
|
$yrs_left = floor($difference/31556926); // 31556926 seconds in a year |
|
|
$months_left = floor(($difference%31556926)/2629744); // remainder of years into months - 2629744 seconds in month |
|
|
$days_left = floor((($difference%31556926)%2629744)/86400); // remainder of months into days - 86400 seconds in a day |
|
|
$hrs_left = floor(((($difference%31556926)%2629744)%86400)/3600); // remainder of days into hours - 3600 seconds in an hour |
|
|
$min_left = floor((((($difference%31556926)%2629744)%86400)%3600)/60); // remainder of hours into minutes - 60 seconds in a minute |
|
|
$secs_left = floor((((($difference%31556926)%2629744)%86400)%3600)%60); // remainder of minutes, already in seconds so no need to divide |
|
|
|
|
|
$block['content'] .= t("%i years ", array('%i' => $yrs_left)); |
|
|
$block['content'] .= t("%i months ", array('%i' => $months_left)); |
|
|
$block['content'] .= t("%i days ", array('%i' => $days_left)); |
|
|
$block['content'] .= t("%i hours ", array('%i' => $hrs_left)); |
|
|
$block['content'] .= t("%i minutes ", array('%i' => $min_left)); |
|
|
$block['content'] .= t("%i seconds ", array('%i' => $secs_left)); |
|
|
*/ |
|
| 130 |
return $block; |
return $block; |
| 131 |
} |
} |
| 132 |
break; |
break; |
| 133 |
} |
} |
| 134 |
} |
} |
| 135 |
|
|
| 136 |
?> |
function theme_countdown_block() { |
| 137 |
|
$time = time(); |
| 138 |
|
$difference = variable_get('countdown_timestamp', $time) - $time; |
| 139 |
|
if ($difference < 0) { |
| 140 |
|
$passed = 1; |
| 141 |
|
$difference = abs($difference); |
| 142 |
|
} |
| 143 |
|
else { |
| 144 |
|
$passed = 0; |
| 145 |
|
} |
| 146 |
|
$accuracy = variable_get('countdown_accuracy', 'd'); |
| 147 |
|
$days_left = floor($difference/60/60/24); |
| 148 |
|
$hrs_left = floor(($difference - $days_left*60*60*24)/60/60); |
| 149 |
|
$min_left = floor(($difference - $days_left*60*60*24 - $hrs_left*60*60)/60); |
| 150 |
|
$secs_left = floor(($difference - $days_left*60*60*24 - $hrs_left*60*60 - $min_left*60)); |
| 151 |
|
|
| 152 |
|
$block = ''; |
| 153 |
|
|
| 154 |
|
$block .= t('%i days', array('%i' => $days_left)); |
| 155 |
|
if ($accuracy == 'h' || $accuracy == 'm' || $accuracy == 's') { |
| 156 |
|
$block .= t(', %i hours', array('%i' => $hrs_left)); |
| 157 |
|
} |
| 158 |
|
if ($accuracy == 'm' || $accuracy == 's') { |
| 159 |
|
$block .= t(', %i minutes', array('%i' => $min_left)); |
| 160 |
|
} |
| 161 |
|
if ($accuracy == 's') { |
| 162 |
|
$block .= t(', %i seconds', array('%i' => $secs_left)); |
| 163 |
|
} |
| 164 |
|
$block .= t(($passed) ? ' since %s.' : ' until %s.', array('%s' => variable_get('countdown_event_name', ''))); |
| 165 |
|
return $block; |
| 166 |
|
} |