Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.7 > vBulletin 3.7 Add-ons
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Random Image with Date/Time Support Details »»
Random Image with Date/Time Support
Version: 1.00, by MrEyes MrEyes is offline
Developer Last Online: May 2017 Show Printable Version Email this Page

Category: Miscellaneous Hacks - Version: 3.7.0 Beta 6 Rating:
Released: 03-10-2008 Last Update: Never Installs: 10
Re-useable Code  
No support by the author.

Well it is about time I got around to contributing something back to the vb.org modification library. So here is a simple start and a simple mod. In fact it is not really a mod at all and could be used on any site however this was written to manage logos in my vBulletin header.

What we have here is a randomimage script....

Now hold your horses, this isn't any ordinary random image script. This one allows you to specify dates/times that an should be displayed at. The script can be configured with as many images as you like, then when called it returns back as an image type (similar to how vBulletins attachment.php) works.

Anybody who is familiar with cron will see the influence behind the image display scheduling, however you do not need to know anything about cron to use this script. What will help though is at least a basic knowledge of PHP. The chances are if you are into modding your forum, you will know enough.

To use the script all you need to do is:
  1. Download the attached file.
  2. Extract it to your local machine.
  3. Run through the configuration options.
  4. Upload to your server.
  5. Upload your images to the configured paths.
  6. Run the script in debug mode to test it all.
  7. Then goto your style manager and set the site logo to be the path to the randomimage.php file.

While that is all fairly simple configuration does need a little explanation:

Each image is configured (at the top of the script) as follows:

Code:
//path to the image from web root
$image[0]["FilePath"] = "SkunkWorks/randomimage/0.jpg";

//The content type for the image, typical this
//will be "image/[extension]" for example "image/jpg",
//"image/gif", "image/png"
$image[0]["ContentType"] = "image/jpg";

//The minute at which this image can be displayed, for example "1,5,10". You can
//also merge ranges as well, for example "1,5,10-15" is equivalent to
//"1,5,10,11,12,13,14,15".  Anything outside 0 to 59 is ignored.
$image[0]["DisplayMinute"] = "*";

//The hours at which this image can be display, the rule logic is the same as
//DisplayMinute (anything outside 0 to 23 is ignored)
$image[0]["DisplayHour"] = "*";

//The months days in which this image can be display, the rule logic is the same as
//DisplayMinute (anything outside 1 to 31 is ignored)
$image[0]["DisplayMonthDay"] = "*";

//The months in which this image can be display, the rule logic is the same as
//DisplayMinute (anything outside 1 to 31 is ignored)
$image[0]["DisplayMonth"] = "*";

//The weekdays in which this image can be display, the rule logic is the same as
//DisplayMinute (anything outside 1 to 7 is ignored (1 is monday))
$image[0]["DisplayWeekDay"] = "*";
So if for example I set my "DisplayHour" value to be "*" is will display at all hours, however if I change it to "1,2,3,10-16" it will only display at 1am, 2am, 3am and 10am to 4pm

The same applies to all other time control rules. So to give a few real examples:

Code:
$image[1]["DisplayMinute"] = "12";
$image[1]["DisplayHour"] = "*";
$image[1]["DisplayMonthDay"] = "*";
$image[1]["DisplayMonth"] = "*";
$image[1]["DisplayWeekDay"] = "*";
Will only display at 12 minutes past the hour every day

Code:
$image[1]["DisplayMinute"] = "*";
$image[1]["DisplayHour"] = "*";
$image[1]["DisplayMonthDay"] = "*";
$image[1]["DisplayMonth"] = "*";
$image[1]["DisplayWeekDay"] = "1";
Will only display on mondays

Code:
$image[1]["DisplayMinute"] = "*";
$image[1]["DisplayHour"] = "20-23";
$image[1]["DisplayMonthDay"] = "*";
$image[1]["DisplayMonth"] = "1";
$image[1]["DisplayWeekDay"] = "1,2";
Will only display from 20:00 to 23:00 in January on Mondays and Tuesday

Code:
$image[1]["DisplayMinute"] = "*";
$image[1]["DisplayHour"] = "*";
$image[1]["DisplayMonthDay"] = "25";
$image[1]["DisplayMonth"] = "12";
$image[1]["DisplayWeekDay"] = "*";
Will only display on Christmas day.

In addition to these configuration options you can also set a script based time offset (just incase your server is hosted in a different timezone to your users). However this script variable can be overidden by passing a query string parameter, "tos=-5" for example.

http://mydomain/somewhere/randomimage.php?tos=-5

You can also tell the script to only use certain images from your configuration (still dependent on date/times unless you pass the no date check query string parameter (see below)). For example

http://mydomain/somewhere/randomimage.php?iid=1
http://mydomain/somewhere/randomimage.php?iid=1,2,3
http://mydomain/somewhere/randomimage.php?iid=1,5
http://mydomain/somewhere/randomimage.php?iid=1,5&nod

The last url will display image 1 or 5 regardless of date/time configuration

There is also a "default" image option, if after checking all your configured images the script has not been able to find an image that meets date/time requirements the default image will be displayed instead. There is nothing to stop you from using the default image as one of the configured timed images as well.

You can also run the script in debug mode. This is useful to find out exactly what the script is doing. Obviously do not run in debug mode while this is emdedded in your page. To do this simple pass the debug key:

http://mydomain/somewhere/randomimage.php?debug=1234

The debug key is part of the configuration, I would recommend changing this to something else, as this will prevent people from running your script in debug mode and finding images/logos that you would rather they didn't see.

Finally and probably most importantly you need to be careful with paths. Each configured image has "FilePath" value this should be the path from your web servers root directory. You then have the "$pathToWebRoot" configuration item which is the path from the server root to the web root.

If you have any problems with it, please try running in debug mode. If the problem is obvious from that then copy the debug output into a post here.

You can see all this running on the following URL:

http://4d52.net/SkunkWorks/randomimage/randomimage.php

Image number 3 is configured with the following display rule:

Code:
$image[3]["DisplayMinute"] = "1-10,20-30,40-50";
$image[3]["DisplayHour"] = "*";
$image[3]["DisplayMonthDay"] = "*";
$image[3]["DisplayMonth"] = "*";
$image[3]["DisplayWeekDay"] = "*";
So it will only display from x:01 to x:10, from x:20 to x:30 and x:40 to x:50 where X is any hour of any day or any month. However if you use the following query string

http://4d52.net/SkunkWorks/randomima...mimage.php?nod

You will randomly see one of all the images as no date checks will be performed.

If you use the following querystring that specifies and image id that doesn't exist you will see the default image

http://4d52.net/SkunkWorks/randomima...age.php?iid=42

Or if you use the following query string to display image ID 1:

http://4d52.net/SkunkWorks/randomima...mage.php?iid=1

However unless you run this at 12 minutes past the hour you will get the default image as image 1 is configured to only display at this minute for every day.

You could of course bypass the date/time check with this querystring

http://4d52.net/SkunkWorks/randomima....php?iid=1&nod

Debug output can be seen here:

http://4d52.net/SkunkWorks/randomima...php?debug=1234

or by adding "debug=1234" to any of the other URLs above

The attached file contains the script and also a few test images for you to play with.

p.s. feel free to rip this mod to pieces and use wherever you like, however it would be nice to know where it is being used

p.p.s. This has been added to 3.7 however it is not version dependant, it will work anywhere

p.p.p.s If there is sufficient interest (which is unlikely) I might convert this into a "real" mod that can be controlled through ACP

Show Your Support

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

Comments
  #2  
Old 03-11-2008, 07:04 PM
MrEyes MrEyes is offline
 
Join Date: Nov 2004
Posts: 380
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Reserving this first post as I know that there will be a bug I havent spotted
Reply With Quote
  #3  
Old 03-12-2008, 03:09 PM
sensimilla sensimilla is offline
 
Join Date: Dec 2004
Location: Poland
Posts: 555
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Looks like a great idea, wonder how this could be used. Banner rotator ?
Reply With Quote
  #4  
Old 03-12-2008, 10:32 PM
MrEyes MrEyes is offline
 
Join Date: Nov 2004
Posts: 380
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by sensimilla View Post
Looks like a great idea, wonder how this could be used. Banner rotator ?
Theoretically yes, but not in the truest sense of banner rotators

You could feasible setup a selection of different banners, one for 12am to 11am, another for 11am to 5pm, another for 5pm to 12am. You could take this even further add have different banners for different times on different days. Or go really silly and go down to month level.
Reply With Quote
  #5  
Old 03-15-2008, 06:48 AM
Feckie (Roger)'s Avatar
Feckie (Roger) Feckie (Roger) is offline
 
Join Date: May 2005
Location: Dublin Eire
Posts: 392
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

so could this be adapted to show one image per month x 12

ie: set up as a header to show a different header every month

that would be xtremly Kewl
Reply With Quote
  #6  
Old 03-15-2008, 09:43 AM
MrEyes MrEyes is offline
 
Join Date: Nov 2004
Posts: 380
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, all you would need to do is add configuration information for each of you 12 monthly images. Something like this

PHP Code:
//january
$image[0]["DisplayMinute"] = "*";
$image[0]["DisplayHour"] = "*";
$image[0]["DisplayMonthDay"] = "*";
$image[0]["DisplayMonth"] = "1";
$image[0]["DisplayWeekDay"] = "*";

//february
$image[1]["DisplayMinute"] = "*";
$image[1]["DisplayHour"] = "*";
$image[1]["DisplayMonthDay"] = "*";
$image[1]["DisplayMonth"] = "2";
$image[1]["DisplayWeekDay"] = "*"
Notice the only value that changes is "DisplayMonth"
Reply With Quote
  #7  
Old 05-06-2008, 02:45 AM
CoffeeToki's Avatar
CoffeeToki CoffeeToki is offline
 
Join Date: Nov 2007
Location: Europe
Posts: 21
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's a good idea. I will come back for it~
Reply With Quote
  #8  
Old 07-20-2008, 06:34 PM
Aresetyr Aresetyr is offline
 
Join Date: Jun 2008
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Excellent Idea - plz keep on it
Reply With Quote
  #9  
Old 09-16-2008, 08:11 PM
PinkDaisy's Avatar
PinkDaisy PinkDaisy is offline
 
Join Date: Sep 2006
Posts: 274
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Awesome idea!

We need a sig-randomizer to. That would be awesome!!
Reply With Quote
  #10  
Old 01-16-2009, 03:09 PM
mitia22 mitia22 is offline
 
Join Date: Dec 2008
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well... How can i include the file randomimage.php in my template ?
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 02:27 PM.


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.07440 seconds
  • Memory Usage 2,315KB
  • Queries Executed 23 (?)
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
  • (6)bbcode_code
  • (1)bbcode_php
  • (1)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
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)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