Basic Countdown

This forum is now closed as part of retiring phpBB2
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
Computerwolf
Registered User
Posts: 55
Joined: Thu Jul 10, 2003 3:40 pm

Basic Countdown

Post by Computerwolf »

I know this has been requested before, but none of the results were what I was looking for, or they do not work with the newest version of phpBB.
Anyways, I am just looking for a simple countdown that you can modify through the Administration Panel that puts one or multiple countdowns to a date on the main index page, preferably at the bottom, and it looks just like a normal category, such as the "who is online" area or any of the forum titles.

Thanks,
ComputerWolf
Einstein
Registered User
Posts: 247
Joined: Sat Oct 18, 2003 9:48 pm
Location: Finland
Contact:

Post by Einstein »

Countdown for what ... nobody knows when next phpBB version comes out.
Computerwolf
Registered User
Posts: 55
Joined: Thu Jul 10, 2003 3:40 pm

Post by Computerwolf »

Like a countdown for anything the admin decides, like an important date for an event, a graduation, birthday, etc.
Computerwolf
Registered User
Posts: 55
Joined: Thu Jul 10, 2003 3:40 pm

Post by Computerwolf »

bump? please?
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

Can you make an example of the output you would like on your index page?

Is it something like

"Please vote now here (link) - only 3 days left!"

??

In that case I would go for a javascript addition to the index_body.tpl file.
Computerwolf
Registered User
Posts: 55
Joined: Thu Jul 10, 2003 3:40 pm

Post by Computerwolf »

Ok something like this, please note, this picture is just photoshopped:

Image

And I would like to have these different things changeable through the administration panel, but even a code right now would be sufficient. Thanks.
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

OK that is a good example. I would go for a Javascript function similar to

Code: Select all

<script language="Javascript" type="text/javascript">
  <!--
      document.write (countdown('text $ more text', deadline_date));
  //-->
</script>
that will write the text line, with the countdown time to go inserted at "$", at that point in the document.

Do you have any experience with javascript? Have you searched the net for functions or parts of functions that would be able to do this?

This might be a good place to start stealing code ... :D
http://www.tdscripts.com/jscountdown.html
Computerwolf
Registered User
Posts: 55
Joined: Thu Jul 10, 2003 3:40 pm

Post by Computerwolf »

I know a little Javascript, but I am unfamiliar with where to put them in the phpBB files because I'm not sure what each file does what and how to get it formatted right like my picture. I'm sure i could find the javascripts, but I need the phpBB code to use for formatting and what file to add it to.
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

OK, I had a fiddle because it is something that I may use in the future as well. Here is what I've made:

Code: Select all

MOD Countdown
Author: Merlin Sythove


Countdown function example:
countdown('Poll in ', 'Jan 24 2005 8:02', '. Go vote!', 'Poll closed!')

  1st argument: text to the left of deadline - include trailing space if necessary
  2nd argument: deadline in the date-time format as the example
  3rd argument: text to the right of the deadline - include leading space if necessary
  4th argument: text to show if deadline is passed.

Display: 
  shows days if days more than 0
  Shows hours if days < 7 and hours > 0 
  Shows minutes too if days < 1
  Words like "days" are hard-coded


### Open overall_header.tpl

### FIND

  </head>
  
 ### BEFORE ADD
 
<script LANGUAGE="JavaScript">
<!--

function countdown(s_start, deadline, s_end, s_finished) {
var now = new Date();
var cd_event = new Date(deadline);
var cd_sec = (cd_event - now) / 1000;
if (cd_sec < 0) {return s_finished};
var cd_min = Math.round( cd_sec / 60);
var cd_hrs = Math.floor(cd_min / 60);
var cd_days = Math.floor(cd_hrs / 24);
cd_min=cd_min -(cd_hrs * 60);
cd_hrs = cd_hrs-(cd_days*24);
temp = s_start;
if (cd_days > 1) temp += cd_days + ' days'; 
if (cd_days == 1) temp += cd_days + ' day'; 
if ((cd_days < 7) & (cd_hrs>0)) temp += ' ' + cd_hrs + ' hours';
if (cd_days < 1) temp += ' ' + cd_min + ' minutes';
return temp += s_end;
}
// -->
</script>

### OPEN index_body.tpl

### FIND (look for TOTAL_USERS_ONLINE)

	<td class="row1" align="left"><span class="gensmall">{TOTAL_USERS_ONLINE} &nbsp; [ {L_WHOSONLINE_ADMIN} ] &nbsp; [ {L_WHOSONLINE_MOD} ]<br />{RECORD_USERS}<br />{LOGGED_IN_USER_LIST}</span></td>
	</tr>


### ADD AFTER 
  <tr>
	<td class="row1" align="left"><span class="gensmall">

    <script LANGUAGE="JavaScript">
    <!--
    document.write (countdown('Poll in ', 'Jan 24 2005 8:02', '. Go vote!', 'Poll closed!'))
    // -->
    </script>

  </span></td>
  </tr>
So the display changes the closer you get to the deadline, it starts with days only, within a week it does days and hours, within one day it does hours and minutes, and within one hour it does minutes only. Once the deadline is passed it will show the 'deadline passed' message, until you have time to remove the block of code from index_body.tpl.

Formatting: use class = "gen", class = "genmed" and class = "gensmall" for the various font sizes. You will find the various css styles in overall_header.tpl. You can add <b> and <i> etc. as needed in the message text itself.

If you want more than one deadline displayed, you can either duplicate the complete block from <tr> to </tr>, or duplicate the 'document.write....' line and add <br /> between them. You can also optionally insert html code in the strings you pass to the countdown function, like <b> </b> for bold etc. You could even put the complete table row code in the strings and leave the final message empty so there is no message and not even a table row when the poll is passed and so on. Plenty of opportunity to customise.

Have fun!
Computerwolf
Registered User
Posts: 55
Joined: Thu Jul 10, 2003 3:40 pm

Post by Computerwolf »

thanks, this is great! I'll be trying this for sure! Now if only i had admin panel access instead of changing code everytime, but this will work just fine for now, thanks again!
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

Admin panel access will be handy if you have a fixed amount of these messages going most of the time. It takes a lot of extra effort to add database fields, change admin php and tpl files, add explanations to the language files, as well as change the template tpl files (which you have to do anyway), and then you are stuck with a single message in a fixed location. The net gain is that you type in the message parts in the admin page, instead of typing the same message parts into your index_body.tpl.
But maybe someone fancies designing all that or maybe in a few months you yourself understand enough of the code to do it!
Eric_H
Registered User
Posts: 149
Joined: Fri Jan 21, 2005 8:03 pm
Contact:

Post by Eric_H »

EricHoes.com - My personal home page
StockCarBar.com - NASCAR Talk
Y2kGoofball
Registered User
Posts: 64
Joined: Wed Jul 23, 2003 10:03 pm

Post by Y2kGoofball »

definately!

computerwolf I have been searching since Christmas for this sort of countdown, and even come across this thread god knows how many times in the process of searching, but Eric seems to have one that works!

Ive been running it since yesterday (thanks to a server failure) and ive had no issues
Post Reply

Return to “[2.0.x] MOD Requests”