You could add the snippet below as a new module scheduler_unpublish_countdown
. It defines a block which you can shown on the node page of any content type you choose and allow it to countdown to the scheduled unpublish time for that node. As the block that comes with the jquery_countdown
module counts down to a global event; this might be better for your use case.
<?php
/**
* Implements hook_block_info().
*/
function scheduler_unpublish_countdown_block_info() {
return array(
'unpublish_countdown' => array(
'info' => t('Scheduler Unpublish Countdown'),
'cache' => DRUPAL_NO_CACHE
)
);
}
/**
* Implements hook_block_view().
*/
function scheduler_unpublish_countdown_block_view($delta) {
if ($delta == 'unpublish_countdown') {
$node = menu_get_object();
// Ignore non-node pages, already unpublished nodes, nodes that don't have a
// date/time set for unpublishing and nodes whose unpublishing date-time is in the past.
if (!$node ||
empty($node->status) ||
empty($node->scheduler['unpublish_on']) ||
($node->scheduler['unpublish_on'] <= REQUEST_TIME)) {
return;
}
$variables = array(
'id' => drupal_html_id('jquery_countdown-' . $delta),
'options' => array(
'until' => date("F d, Y g:i a", $node->scheduler['unpublish_on']),
'description' => ' ', // So that the CSS doesn't get screwed
// Reload the page when the countdown is done
'onExpiry' => '(function() { location.reload(); })',
)
);
return array(
'subject' => t('Scheduled unpublish in..'),
'content' => theme('jquery_countdown', $variables)
);
}
}
Once the countdown is complete, the page will simply reload (see onExpiry
option above). As unpublishing happens only either during the normal Drupal cron run or through the Scheduler's own light-weight variant, it may not happen exactly at the time of unpublishing meaning the page would reload and nothing would happen (except for the timer not showing up anymore) which might be slightly awkward.
I'd recommend, therefore, to redirect to a custom page once the countdown expires where you explicitly call _scheduler_unpublish()
and then redirect back to the node page. You might want to send a one-time-only token along for security.
Remember to add scheduler
and jquery_countdown
as dependencies for your new module.
jquery_countdown_add
of jQuery Countdown module you named in your question should be enough. What's wrong with it?jquery_countdown_add
use a date from a field. For unpublished, allow everyone to see, but in tpl hide anything but timer for those who shouldn't see it yet.