Custom Implementation Idea

WISEOZ - February 24, 2008 - 01:21
Project:Javascript Countdown Timer
Version:5.x-1.17
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Hello! I've got my countdown timers working very well with the code shown below.

I'd like to ask you about a particular custom implementation of them. I'm hoping you can either guide me or offer a paid customization.

For my countdown timer, I'd like it to always assume the Event Start Date (from the Event module) as the "datetime" for the node it belongs to. Is this possible?

<p align="center">
<b>Countdown to the start of this event...</b>
<span class="countdowntimer">Count Down
<span style="display:none" name="datetime">2008-02-26T17:00:00</span>
<span style="display:none" name="tz_hours">-5</span>
<span style="display:none" name="dir">down</span>
</span>
<br>
</p>
-->

For the count-up timer, I'd like it to always assume the Current Date/Time as the "datetime", however, not to reset if the node is later edited and resaved. Is this possible?

<p align="center">
<b>This event has been running for...</b>
<span class="countdowntimer">Count Up, this shows until timer initializes or for non-js folks
<span style="display:none" name="datetime">2008-02-23T016:42:00</span>
<span style="display:none" name="tz_hours">-5</span>
<span style="display:none" name="dir">up</span>
</span>
<br>
</p>

#1

jrglasgow - March 1, 2008 - 23:36

Have you tried Content Templates?
Setting the body template to (for whatever node you are using)

<?php
$body
= str_replace('-countdown timer created time-',date('Y-m-d\TH:i:s', $node->created), $body);
?>

This will search for "-countdown timer created time-" and replace it with the time the node was created. Just put "-countdown timer created time-" instead of a time when creating your span in your node.

For that you would have to insert this in the content

<span class="countdowntimer">
   etc...
</span>

yourself.
Otherwise you would use this in the body template:
  <p align="center">
    <b>This event has been running for...</b>
    <span class="countdowntimer">Count Up, this shows until timer initializes or for non-js folks
      <span style="display:none" name="datetime"><?php echo date('Y-m-d\TH:i:s', $node->created) ?></span>
      <span style="display:none" name="tz_hours">-5</span>
      <span style="display:none" name="dir">up</span>
    </span>
    <br>
  </p>

For the Event Start date in the Event Module.

  <p align="center">
    <b>Countdown to the start of this event...</b>
    <span class="countdowntimer">Count Down
      <span style="display:none" name="datetime"><?php echo date('Y-m-d\TH:i:s', $node->event_start) ?></span>
      <span style="display:none" name="tz_hours">-5</span>
      <span style="display:none" name="dir">down</span>
    </span>
    <br>
  </p>

If you have any questions let me know.

#2

WISEOZ - March 2, 2008 - 14:25

Wow! I wasn't expecting all that at all! Thank you!

I was trying to avoid using Contemplate. I have it but I'm not entirely comfortable with it yet.

Instead, I placed this in the Default field for the CCK Text field I'm using with with my Content Type for counting up and applied the Full HTML filter:

  <p align="center">
    <b>This event has been running for...</b>
    <span class="countdowntimer">Count Up, this shows until timer initializes or for non-js folks
      <span style="display:none" name="datetime"><?php echo date('Y-m-d\TH:i:s', $node->created) ?></span>
      <span style="display:none" name="tz_hours">-5</span>
      <span style="display:none" name="dir">up</span>
    </span>
    <br>
  </p>

The result was:

"This event has been running for... NaN days + 0NaN:0NaN:0NaN"

And, I placed this in the Default field for the CCK Text field I'm using with with my Content Type for counting down and applied the Full HTML:

<p align="center">
    <b>Countdown to the start of this event...</b>
    <span class="countdowntimer">Count Down
      <span style="display:none" name="datetime"><?php echo date('Y-m-d\TH:i:s', $node->event_start) ?></span>
      <span style="display:none" name="tz_hours">-5</span>
      <span style="display:none" name="dir">down</span>
    </span>
    <br>
  </p>

The result was:

"Countdown to the start of this event... NaN days + 0NaN:0NaN:0NaN"

Do I still need to place something in the Content Template as well to make it work?

#3

jrglasgow - March 2, 2008 - 15:14

You will need the PHP Filter instead of the Full HTML Filter. The PHP Filter is required to interpret the code between the <?php ?> tags. This allows the PHP interpreter to take $noe->event_start or $node->created which is the time in Unix time format and convert it to the required (human readable) date time format. Otherwise the Countdown timer sees this <?php echo date('Y-m-d\TH:i:s', $node->event_start) ?> as the time. With the PHP Filter enabled the Countdown Timer sees this as the time: 2008-02-26T17:00:00

#4

WISEOZ - March 2, 2008 - 20:36

I simply switched by input filter to PHP, as you suggested, but I still get this ...

"Countdown to the start of this event..."

"This event has been running for... Count Up, this shows until timer initializes or for non-js folks 1969-12-31T19:00:00 -5 up"

#5

jrglasgow - March 3, 2008 - 05:25

The problem is I gave you the variables $node->event_start, $node->created that Contemplate uses. These variables are defined in the scope of contemplate. A node body, though, has no variables defined in its scope. The Solution I gave you works in contemplate, I have tested it. I don't know of an easy way to do this in the node body.

#6

WISEOZ - March 4, 2008 - 01:41
Status:active» fixed

I got it! Thanks so much for working me through this.

#7

Anonymous (not verified) - March 18, 2008 - 01:41
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.