vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4.x Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=245)
-   -   vBulletin CMS Widgets - Countdown to Calendar Event (https://vborg.vbsupport.ru/showthread.php?t=252146)

JohnKF 10-14-2010 10:00 PM

Countdown to Calendar Event
 
1 Attachment(s)
This widget picks up the next 2 events from a calendar of your choice.

It displays a countdown to the first event then once the first event has arrived it begins a countdown to the second event. The only reason for picking up two events is that someone may visit the page close to the end of the first event then see the no event message. By picking up two events such a visitor will see the countdown to the second event start.

To install...

From the ZIP file, extract eventcountdown.js and copy it to your site.

Navigate to AdminCP -> Style & Templates -> Style Manager -> Edit Template
Double click the headinclude template to edit it and add the following just above the first <script tag you find...
HTML Code:

<script src="scripts/eventcountdown.js" type="text/javascript"></script>
...the above assumes you have copied eventcountdown.js file in to a folder called scripts. Adjust the src path to wherever you have placed the .js file.

Navigate to AdminCP -> CMS -> Widgets.
Create a PHP Type Widget and paste the below code.

PHP Code:

ob_start();
global 
$db,$vbulletin;
$event_calendarid="1";
$no_events_message="<div style='width: 100%; text-align: center; font-weight: bold'>There are no events.</div>";
$today_date mktime(000date(date("m")), date(date("d")),  date(date("y")));
$and=" and dateline_from > '".$today_date."'";

$getevents=$db->query_read("SELECT eventid, title, dateline_from from " TABLE_PREFIX "event WHERE calendarid='".$event_calendarid."' $and order by dateline_from ASC LIMIT 2");
$count=1;
if(!
$db->num_rows($getevents))
{
echo 
$no_events_message;

else
{
echo 
"<script type='text/javascript'>\n";
WHILE (
$events=$db->fetch_array($getevents))
{
$event_title=$events['title'];
$event_date vbdate('U',$events['dateline_from'], false,true,false,true)-vbdate('U');
if(
$count==1)
{
echo 
"var CountDownTimer=new CountDown('CountDownToChange',1,'".$event_title."<br />','".$event_date."','ywdhms',1)\n";
}
else
{
echo 
"CountDownTimer.AddNewEvent('".$event_title."<br />','".$event_date."','ywdhms',".$count.")\n";
}
$count++;
}
}
echo 
"CountDownTimer.DisplayTime(FormatResults)\n";
echo 
"</script>\n";
$db->free_result($getevents);
unset(
$events);
$output=ob_get_contents();
ob_end_clean(); 

To create a forum block...
  1. Navigate to AdminCP -> Forums & Moderators -> Forum Blocks Manager
  2. Click the Add Block button
  3. From the drop down list select Custom HTML/PHP
  4. Click the Continue button
  5. Give the block a title (e.g. Event Countdown) and a short description
  6. Set the cache time to 1 minute
  7. In Content Type select PHP
  8. In Content paste the PHP code above in to the text box
  9. Click the Save button

You can set the value for $event_calendarid to the calendar that you want countdown events to come from. Change $no_events_message to the HTML you want to have appear when there are no events left in the selected calendar.

This is the first widget I've written so if you spot any errors or improvements that can be made then please let me know.

If you have an all day event in the calendar the countdown is to the begining of that day. Add a ranged event to the calendar for an exact time. Also, allow for any changes that may occur if a change to or from DST occurs.

Added ob_start(); to beginning of script (17th Oct, 2010)

To have a picture make the Title of the event in the calendar the HTML to display the picture. For example...
HTML Code:

Your Event<br /><img src="images/picture.gif" width="140" height="130" alt="">
...which shows as the text above in the calendar title, but displays as text and a picture in the countdown.

betts02 10-15-2010 08:24 PM

REQUESTS :

Allow upto 5 events
Forum Block

Cheers

JohnKF 10-15-2010 08:30 PM

I'll do that but in the meantime just change the number 2 at the end of this line...

("SELECT eventid, title, dateline_from from " . TABLE_PREFIX . "event WHERE calendarid='".$event_calendarid."' $and order by dateline_from ASC LIMIT 2");

...to the number of events you want picking up.

The JavaScript can handle many events.

What's Forum Block? I only started using vBulletin a week or so ago and I'm not completely familiar with it yet.

betts02 10-15-2010 09:39 PM

Forum block is the side bar if you wish

Check my site in the link below to see the side blocks i have

paarmis.queen 10-15-2010 09:48 PM

tnx installed

JohnKF 10-16-2010 06:28 AM

Thank betts02. I assume then that you wanted multiple countdowns to be displayed. The script only shows a single countdown to the next event. Once that has been reached it starts the countdown to the second event. If the visitor arrives at a page with the countdown running a few seconds before zero then once zero arrives the second countdown will start. This is the reason for picking up 2 events. I'll look at allowing for multiple countdows to be show, say the first one from each calendar.

ProFifaLeagues 10-16-2010 06:50 AM

Be great in the forum block if you can do mate

betts02 10-16-2010 06:50 AM

What i wanted if possible is for this in a forum block

Shows events 1-5

Event 1 shall be on countdown
Event 2-5 shall be shown

As soon as event 1 has been and gone, It removes the event and places event 2 on countdown

Then event 6 shall become event 5 and be shown

JohnKF 10-16-2010 07:02 AM

Noted. Suggest you have a quick try of it as it stands so that you can see how an event countdown is show regarding width for an event that's a few weeks off.

Also I forgot to mention another slight change you can make...
In the widget PHP code find 'ywdhms' which appears twice. This sets which units appear in the countdown. The default is to show a countdown in Years, Weeks, Days, Hours, Minutes and Seconds.

You can pick which units are shown, so for a seconds only countdown you should just need 's' and for Days, and Minutes it would be 'dm'.

betts02 10-16-2010 07:29 AM

Tried it in a forumblock and it just messes all my forums up

sadiq6210 10-16-2010 09:57 AM

Thanks ..

betts02 10-16-2010 07:58 PM

Hey buddy,

You're missing an ob_start at the front of this script. Recommend you add it in, otherwise the block will break the script that started before it as well as itself.

ahmedipa 10-16-2010 08:50 PM

nice one thank you very much

trophyrider 10-17-2010 01:12 AM

The script works fine in the forum block area if you add:

ob_start();

at the beginning of the php script.

trophyrider 10-17-2010 01:13 AM

Quote:

Originally Posted by trophyrider (Post 2110881)
The script works fine in the forum block area if you add:

ob_start();

at the beginning of the php script.

See example at http://www.sporttouring.us

CharlieDelta 10-17-2010 02:42 AM

Quote:

Originally Posted by trophyrider (Post 2110882)

I can confirm this works as well.
Thank you.

betts02 10-17-2010 06:58 AM

Quote:

Originally Posted by betts02 (Post 2110797)
Hey buddy,

You're missing an ob_start at the front of this script. Recommend you add it in, otherwise the block will break the script that started before it as well as itself.

Quote:

Originally Posted by trophyrider (Post 2110881)
The script works fine in the forum block area if you add:

ob_start();

at the beginning of the php script.

Quote:

Originally Posted by trophyrider (Post 2110882)

As i stated then ?

Also looking more into this

If you post and event it shows up
But if you then post an event before the first event it does not display

Will get it working myself anyway mate cheers

JohnKF 10-17-2010 11:32 AM

Thanks for that advice about ob_start();
It's my first script you know :o

JohnKF 10-17-2010 11:35 AM

Quote:

Originally Posted by betts02 (Post 2110937)
As i stated then ?

Also looking more into this

If you post and event it shows up
But if you then post an event before the first event it does not display

Will get it working myself anyway mate cheers

I think it may be because it's cached the first event. I usually clear the CMS cache whenever I change anything just to be sure. If you find another cause though please let me know; thanks.

betts02 10-18-2010 05:49 PM

Something is not correct here

I have an event in 2 days time, Yet its showing the event is due NOW

Will look into this myself but if you manage to figure it out post up dude

JohnKF 10-20-2010 07:56 AM

Quote:

Originally Posted by betts02 (Post 2111382)
Something is not correct here

I have an event in 2 days time, Yet its showing the event is due NOW

Will look into this myself but if you manage to figure it out post up dude

Is the event a full day event or a ranged event? Also, what time zone are you in as a client and what time zone is the server in?

MadtownHDJunkie 10-24-2010 02:07 PM

not sure how to add the calendar id to get it to pull from forums calendar...any help appreciated.

JohnKF 10-24-2010 05:34 PM

If you look near the start of the PHP code you will see...
$event_calendarid="1";
...just change the number to the id of the calendar you want to use.

MadtownHDJunkie 10-24-2010 09:10 PM

yah...it should be 1 , the default. it just shows today's date.

MadtownHDJunkie 10-24-2010 09:12 PM

got it .....ty

red-dna 10-25-2010 02:09 PM

A way to display a picture for the event and not the title?

starman? 10-25-2010 03:47 PM

Installed and working just fine as far as I can tell. Thank you very much indeed.
Would it be possible to include the ability to add a picture or format the event title with a different colour?

DjEddie 10-25-2010 09:57 PM

Hi,

I've tried to get this to work on the forum block without any luck .. the block shows up but no countdown of the no event text shows ..

any suggestions? ..

ive created forum block .. selected custom html/php .. fillout out the fields with templete block-html ..
aswell as the script code for the js file is in headerinclude templete..

Thanks :)

starman? 10-26-2010 03:07 AM

Is the URL in the script code for the js file pointing to the right place?

cindy helmond 10-26-2010 08:59 AM

Quote:

Originally Posted by DjEddie (Post 2114165)
Hi,

I've tried to get this to work on the forum block without any luck .. the block shows up but no countdown of the no event text shows ..

any suggestions? ..

ive created forum block .. selected custom html/php .. fillout out the fields with templete block-html ..
aswell as the script code for the js file is in headerinclude templete..

Thanks :)

me to not working here

cindy helmond 10-26-2010 09:01 AM

Quote:

Originally Posted by starman? (Post 2114290)
Is the URL in the script code for the js file pointing to the right place?

Basic url: www.yoursite.com/forum

working url ? www.yoursite.com/forum/scripts/js ???? ore without www.

DjEddie 10-26-2010 11:51 AM

Quote:

Originally Posted by starman? (Post 2114290)
Is the URL in the script code for the js file pointing to the right place?

hi .. yes its pointing to the right place, it has been double checked ..

also when trying this on the widget cms side .. it only shows todays date in the countdown area .. so forum block and widget aren't working for me atm :S

thanks for the help :)

Cooleyvol 10-27-2010 12:59 AM

I need some help on creating a side block. I paste the code in when creating a block and have already added a calendar event.

When I go to the forum, all it shows is the code.

What are the selections I need to choose when creating a side block using this code?

JohnKF 10-28-2010 11:09 AM

When you create a Forum Block you need to select PHP in the Content Type section.

JohnKF 10-28-2010 11:24 AM

The code uses the title of the event in the calender to display above the countdown.

I suggest you create a calendar specific to Countdown Events and set it for Admin view only; as long as you set the correct calender ID in the code it will still be picked up.

To have a picture make the Title of the event in the calendar the HTML to display the picture. For example in the forum I look after I have the following as an event title...

HTML Code:

Halloween Evening<br /><img src="files/bv/images/halloween/pumpkin.gif" width="140" height="130" alt="">
...which shows as the text above in the calendar title but displays as text and a picture in the countdown.

You can see this at http://www.buckshawvillage.com/forum.php

You can use whatever HTML you like in the event title.

The code on that site is set up a little different to that posted here. Seconds are not shown until less than 24 hours. At zero there is a firework display over the page which lasts for 1 minute. Other than that it functions the same and the HTML title will work fine.

Cooleyvol 10-28-2010 05:10 PM

Quote:

Originally Posted by JohnKF (Post 2115197)
When you create a Forum Block you need to select PHP in the Content Type section.


I did select php and then pasted the code in. As I said, once I create an event in the calendar, the side block shows the code I input from here instead of the event countdown.

I'm sure its something simple, but I don't know how else to paste code and choose 'php' as the content type.

Cooleyvol 10-29-2010 09:06 PM

It was something simple. I'm a doofus.

JohnKF 10-30-2010 07:11 AM

Quote:

Originally Posted by Cooleyvol (Post 2115828)
It was something simple. I'm a doofus.

Share it with us please; it may help others who make a similar mistake.

Cooleyvol 10-30-2010 11:32 AM

I didn't put the line of code in the template as instructed. haha.

I did input my first event and the countdown was off by an hour, so I deleted the event and put it up again an hour different, but the countdown remained the same.

Any way to clear that? Is it cached?

JohnKF 10-30-2010 12:32 PM

You need to set the cache time to 1 minute.

For a widget this is done via the Configure link.
For a forum block this is done via the Edit link.

If the cache time is set too high, say 60 minutes, then a visitor may get a countdown that could be up to an hour out of date.

Even at 1 minute it will take up to 1 minute before a change in an edited event is replicated in the countdown.

If you're in a time zone that's currently using DST you should check your event as soon as DST ends as it may be an hour out in the countdown.


All times are GMT. The time now is 02:38 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01419 seconds
  • Memory Usage 1,848KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_html_printable
  • (1)bbcode_php_printable
  • (12)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete