Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 2.x > vBulletin 2.x Full Releases
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
New vBCode Tags: [Countdown] and [Countup] timers for users Details »»
New vBCode Tags: [Countdown] and [Countup] timers for users
Version: 1.00, by KevinG KevinG is offline
Developer Last Online: Feb 2003 Show Printable Version Email this Page

Version: 2.2.x Rating:
Released: 05-02-2002 Last Update: Never Installs: 12
 
No support by the author.

Have you or any of your members ever had the need or desire to post a countdown or countup in a post?
Something that automatically shows the remaining days, hours, minutes and seconds of that upcoming Walt Disney World trip?
Or want to show everyone how many days, hours, minutes and seconds that the user has gone without a cigarette, drink, sex? - LOL

I came up with this one here. It basically gives your users two new vB Code Tags, [countdown] and [countup].
Now there is no need to worry that the user will mess up your threads with incorrect JavaScript.
All they have to do is use these tags, just like most other tags.

For counting down, they would just have to do the following:
[countdown=May 21, 2002 12:32 PM EST;We are off to see Mickey Mouse;RED]My Walt Disney World Trip Begins in [/countdown]

Same for counting up with just different text of course.

I guess this would qualify as a hack as you do need to change one field in the database to store this.
Luckily, it's in a very small table so it should not slow anything down in theory.


Modify the database
Modify the field bbcodereplacement in the bbcode table to increase the storage size.
Change the field properties from varchar(200) to LONGTEXT. This is needed for the new vB Code replacement to follow.
I used phpMyAdmin which is very easy to use for this change.

Add new JavaScript
Add the following JavaScript code to your Style under Head Insert preferrably at the bottom.
Be sure to do this for every style that you defined in your database.

PHP Code:
<SCRIPT LANGUAGE="JavaScript">
function 
countdowndaterndNumouttext ) {
now = new Date();
y2k = new Datedate );
days = (y2k now) / 1000 60 60 24;
daysRound Math.floor(days);
hours = (y2k now) / 1000 60 60 - (24 daysRound);
hoursRound Math.floor(hours);
minutes = (y2k now) / 1000 /60 - (24 60 daysRound) - (60 hoursRound);
minutesRound Math.floor(minutes);
seconds = (y2k now) / 1000 - (24 60 60 daysRound) - (60 60 hoursRound) - (60 minutesRound);
secondsRound Math.round(seconds);
if ((
days 0) | (hours 0) | (minutes 0) | (seconds 0)) {
   
thisoutput outtext;
   if (
thisoutput == ""thisoutput "Countdown Finished";
} else {
   
sec = (secondsRound == 1) ? " second." " seconds.";
   
min = (minutesRound == 1) ? " minute, " " minutes, ";
   
hr = (hoursRound == 1) ? " hour, " " hours, ";
   
dy = (daysRound == 1)  ? " day, " " days, ";
   
thisoutput daysRound  dy hoursRound hr minutesRound min secondsRound sec;
}
eval(
"document.forms.form" rndNum ".elements.countdown.value = thisoutput;");
thisclock "countdown(\""+date+"\",\""+rndNum+"\",\""+outtext+"\");";
window.setTimeout(thisclock1000);
}

function 
countupdaterndNumouttext ) {
now = new Date();
y2k = new Datedate );
days = (now y2k) / 1000 60 60 24;
daysRound Math.floor(days);
hours = (now y2k) / 1000 60 60 - (24 daysRound);
hoursRound Math.floor(hours);
minutes = (now y2k) / 1000 /60 - (24 60 daysRound) - (60 hoursRound);
minutesRound Math.floor(minutes);
seconds = (now y2k) / 1000 - (24 60 60 daysRound) - (60 60 hoursRound) - (60 minutesRound);
secondsRound Math.round(seconds);
if ((
days 0) | (hours 0) | (minutes 0) | (seconds 0)) {
   
thisoutput outtext;
} else {
   
sec = (secondsRound == 1) ? " second." " seconds.";
   
min = (minutesRound == 1) ? " minute, " " minutes, ";
   
hr = (hoursRound == 1) ? " hour, " " hours, ";
   
dy = (daysRound == 1)  ? " day, " " days, ";
   
thisoutput daysRound  dy hoursRound hr minutesRound min secondsRound sec;
}
eval(
"document.forms.form" rndNum ".elements.countup.value = thisoutput;");
thisclock "countup(\""+date+"\",\""+rndNum+"\",\""+outtext+"\");";
window.setTimeout(thisclock1000);
}

function 
explodeArray(item,delimiter) {
  
tempArray=new Array(1);
  var 
Count=0;
  var 
tempString=new String(item);

  while (
tempString.indexOf(delimiter)>0) {
    
tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
    
tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
    
Count=Count+1
  
}

  
tempArray[Count]=tempString;
  return 
tempArray;
}

</
script
Add the new vBCodes
Using the Admin CP, add the following;

vB Code tag
-----------------------------------------------------
countdown


vB Code replacement
-----------------------------------------------------
PHP Code:
<Script language='Javascript'>
var 
rndNum Math.floor(Math.random() * 10000);
var 
tempString="{option}";
tempArray=explodeArray(tempString,";");
document.writeln("<form name='form" rndNum "' action='Javascript:void(0);'>");
document.writeln('<font size=2 color="'+tempArray[2]+'">{param}</font><BR>');
document.writeln("<input type=text value='' size=40 name='countdown'>");
document.writeln("</form>");
countdown(tempArray[0], rndNumtempArray[1]);
</
script
vB Code example
-----------------------------------------------------
[countdown="May 4, 2002;Currently At WDW Now;BLUE"]My Countdown to Disney World[/countdown]

vB Code explanation
-----------------------------------------------------
Enter any text you would like to say to your members here.

Use {option} ?
-----------------------------------------------------
Select YES


Add the [countup] tag next;
vB Code tag
-----------------------------------------------------
countup

vB Code replacement
-----------------------------------------------------
PHP Code:
<Script language='Javascript'>
var 
rndNum Math.floor(Math.random() * 10000);
var 
tempString="{option}";
tempArray=explodeArray(tempString,";");
document.writeln("<form name='form" rndNum "' action='Javascript:void(0);'>");
document.writeln('<font size=2 color="'+tempArray[2]+'">{param}</font><BR>');
document.writeln("<input type=text value='' size=40 name='countup'>");
document.writeln("</form>");
countup(tempArray[0], rndNumtempArray[1]);
</
script
vB Code example
-----------------------------------------------------
[countup="May 4, 2002;Waiting for my last cigarette;RED"]Smokefree Days[/countup]

vB Code explanation
-----------------------------------------------------
Enter any text you would like to say to your members here.

Use {option} ?
-----------------------------------------------------
Select YES



There are many variations that can be use here for how the text field looks.
We can post suggestions here for everyone to share

I can post a screenshot tomorrow if you would like.
It's really just a text field containing the days, hours, minutes and seconds of the timers with the {param} text over it.

Edit:
Reformatting some of the text as the PHP blocks are very wide.
Also fixed a case conversion that the PHP code tag is making in my post.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #22  
Old 05-04-2002, 03:45 PM
Sweet Cheeks's Avatar
Sweet Cheeks Sweet Cheeks is offline
 
Join Date: Mar 2002
Location: Carson City, Nevada
Posts: 173
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Kevin I installed the hack on my site, everyone LOVES it!! I was wondering if you had a site link or something we could give your credit for? Thank you!
Reply With Quote
  #23  
Old 05-04-2002, 04:53 PM
KevinG KevinG is offline
 
Join Date: Dec 2001
Posts: 21
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by Ruth
KevinG... very nice hack

i'm thinking to use this as a gradutation count down....

users can choose the year from a drop down menu during registration

then the count down appears in their profile

is this possible to hack it even more for that purpose ?

thanks
Thanks Ruth. We could hack it some more if you'd like but that one would get away from it's simplicy

We can discuss via PM here to get your version. Sound good?
(or do others want this as well?)

Quote:
Originally posted by ~*Julie*~

Kevin I installed the hack on my site, everyone LOVES it!! I was wondering if you had a site link or something we could give your credit for? Thank you!
You're welcome. I did this and then searched here to see if anyone else already did it. During the search, you name popped up so I just decided to post it. I don't need to have my credit linked from your site. Mine is a private site for family members and strangers might freak them out - LOL. Just tell them it's from the baby stork
If my wife is expecting again ( oh I hope not ), we'll stop by. Deal?
Reply With Quote
  #24  
Old 05-06-2002, 09:03 AM
KuraFire's Avatar
KuraFire KuraFire is offline
 
Join Date: Oct 2001
Location: inside vB3's .php
Posts: 1,245
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Kevin, nice hack, but I really suggest you turn it into a Showthread hack. As it is, being put in the head of _all_ pages on the board, it's quite a bandwidth-impact for no reason. The part for in <head> is, imo, rather huge, and loading that when it's not necessary is just diminishing your bandwidth for nothing.

showthread.php hack shouldn't be too hard...
Reply With Quote
  #25  
Old 05-06-2002, 12:44 PM
KevinG KevinG is offline
 
Join Date: Dec 2001
Posts: 21
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks KuraFire.

I'll check that out. I would also have to modify newreply.php as well then. Also, the PM display code in private.php as these can also be used in sigs.

Thanks for the suggestion.
Reply With Quote
  #26  
Old 05-13-2002, 05:44 PM
Sweet Cheeks's Avatar
Sweet Cheeks Sweet Cheeks is offline
 
Join Date: Mar 2002
Location: Carson City, Nevada
Posts: 173
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Congratulations on the baby coming Kevin! Thanks again for everythign!! Woohoo!
Reply With Quote
  #27  
Old 05-13-2002, 09:34 PM
BigJohnson BigJohnson is offline
 
Join Date: Nov 2001
Posts: 535
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How can we make the changes in our board so that the button that we make for it will give you the correct java script pop up to insert all the right stuff in the correct places because it isnt a simple [countdown] hey [/countdown] thing. You need to add like font color and all the type of stuff. Is there anyone here with this type of knowledge to tell us how we can do this. Thanks you so much.
Reply With Quote
  #28  
Old 05-14-2002, 08:36 PM
BigJohnson BigJohnson is offline
 
Join Date: Nov 2001
Posts: 535
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

bump
Reply With Quote
  #29  
Old 05-15-2002, 03:46 PM
KevinG KevinG is offline
 
Join Date: Dec 2001
Posts: 21
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Maybe you can try something like this?

Add this to the vbcode.js file in your forum directory
Code:
// ************************************

function countdownup(theform,thetype) {
   // inserts countdown or countup 
   maintext = prompt("Enter Top Message for " + thetype,"");
   coloredtext = prompt("Enter the color to use for the Top Message","BLUE");
   datetext = prompt("Enter Date for " + thetype,"");
   var prompttext;
   if (thetype == "countdown") {
      prompt_text = "Enter text to display when Countdown reaches zero";
   }
   else {
      prompt_text = "Enter text to display before Countup starts (future date)";
   }
   expiredtext = prompt(prompt_text,"");
   if ((datetext != null) && (datetext != "")) {
      cdcode = "";
      if ((maintext == null) || (maintext == "")) {
         if (thetype == "countdown") {
            maintext = "My Countdown";
        }
        else {
            maintext = "My Countup";
        }
      }
      if ((coloredtext == null) || (coloredtext == ""))
         coloredtext = "BLUE";
      if ((expiredtext == null) || (expiredtext == "")) {
         if (thetype == "countdown") {
            expiredtext = "Blast Off!";
         }
         else {
            expiredtext = "Waiting to Start";
         }
      }		
      theform.message.value += "["+thetype+"="+datetext+";"+expiredtext+";"+coloredtext+"]"+maintext+"[/"+thetype+"] ";
   }		
   theform.message.focus();
}

// *************************************
Then add the buttons to your vbcode_buttons template:
My template looks like this after adding them after the "quote" button. This was added after the <BR> tag which puts them on the third line of buttons.

Code:
<input type="button" class="bginput" value="countdown" title="Insert Countdown" onclick="countdownup(this.form,'countdown')" >		
<input type="button" class="bginput" value="countup" title="Insert Countdown" onclick="countdownup(this.form,'countup')" ><br>
Reply With Quote
  #30  
Old 05-20-2002, 02:18 PM
rcooper7 rcooper7 is offline
 
Join Date: May 2002
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Great looking hack will do good on my Disney Page! thanks!

Ryan C.
Reply With Quote
  #31  
Old 05-20-2002, 02:23 PM
rcooper7 rcooper7 is offline
 
Join Date: May 2002
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

One Question, How do you Modify the database.

Can someone walk me through this? I have phpmyadmin. . .

Thanks
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:03 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05126 seconds
  • Memory Usage 2,382KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_code
  • (3)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete