vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   Rotate your logos (https://vborg.vbsupport.ru/showthread.php?t=38320)

Sparkz 05-06-2002 03:36 PM

Rotate your logos
 
This template mod randomly picks an image from a specified folder to be used as the forum logo.

In your phpinclude-template, add this code:
PHP Code:

$logos = array();
$logodir "images/";

function 
make_seed() {
    list(
$usec$sec) = explode(' 'microtime());
    return (float) 
$sec + ((float) $usec 100000);
}
srand(make_seed());

if (
$handle opendir($logodir)) {
    while (
false !== ($file readdir($handle))) { 
        if (
$file != "." && $file != "..") { 
            
array_push ($logos$logodir $file); 
        } 
    }
    
closedir($handle);
    
// $logo = rand(0, count ($logos));
    
$logo rand(0count ($logos) - 1); // Corrected a small bug
    
$titleimage $logos[$logo];


Change the value of $logodir to the directory where you have your logos.

and in your header-template, change { titleimage} to $titleimage

That should be it, really.

tkieffer 05-06-2002 07:43 PM

Thanks again Sparkz. It's installed and working great.

tkieffer 05-06-2002 07:55 PM

Hmm. I've noticed that it occasionally pushes a null to the client (img src=""). I'm thinking this could either be because the random function goes beyond the bounds of the array or the directory read is actually picking up a blank. I'm afraid to just go fooling around with coding languages I haven't learned yet so I'm going to stay away from modifying your code.

Please help.

Crazy Mofo 05-07-2002 01:26 AM

Nice but maybe need some work on it as when u refresh a few times a blank image wit the red cross appears ;)

Sparkz 05-07-2002 07:40 AM

Hmm, sorry about that.
Change
PHP Code:

$logo rand(0count ($logos)); 

to

PHP Code:

$logo rand(0count ($logos) - 1); 

Didn't check it properly before I posted, I guess :)

geniuscrew 05-07-2002 11:52 AM

You can also use DHTML by putting the code in the head bit :-/

Sparkz 05-07-2002 12:08 PM

There are probably tons of way to do this.
I just happen to know and like PHP, so that's why I chose to do it like this.

Sparkz 05-07-2002 12:09 PM

Besides, this saves bandwidth, as it is server side.

Using DHTML, you'd have to pass the whole list if images to the client, plus the code to actually do the pick which image to show.

Crazy Mofo 05-07-2002 03:39 PM

nice work sparkz very impressive :D

Crazy Mofo 05-07-2002 03:42 PM

well works like a charm i gave this 10 outta 10 m8 well done :) nice simple and very effective :D

tkieffer 05-07-2002 04:15 PM

Nifty! It's all fixed.

You get a big shiny golden star in my book!

geniuscrew 05-08-2002 11:26 AM

Quote:

Originally posted by Sparkz
Besides, this saves bandwidth, as it is server side.

Using DHTML, you'd have to pass the whole list if images to the client, plus the code to actually do the pick which image to show.

That's why i don't use it lol

Nice 'hack' though :bunny:

Sparkz 05-08-2002 12:30 PM

If you only have a few images to rotate, you could just set the content of $logos manually. Would result in a bit less processing time.

Something like:
PHP Code:

$logodir "images/";
$logos = array
(
   
$logodir "filename.png",
   
$logodir "filename2.png"
);

function 
make_seed() {
    list(
$usec$sec) = explode(' 'microtime());
    return (float) 
$sec + ((float) $usec 100000);
}
srand(make_seed());

$logo rand(0count ($logos) - 1);
$titleimage $logos[$logo]; 

Would save the server from having to list the directory every time a page was loaded.

tkieffer 05-10-2002 12:13 PM

Excellent! I upgraded to the predefined array and it is noticably faster.

afterlab 06-23-2002 08:35 PM

Is there anyway that I can get it show the random image plus a link for each one. Basically, all I need is another variable that just displays the filename, without the directory, and extensions.

afterlab 06-28-2002 11:13 AM

Anyone? [BUMP]

Sparkz 06-28-2002 02:21 PM

Try this:
PHP Code:

$logodir "images/";
$logos = array
(
   array (
$logodir "filename.png","http://mylink/"),
   array (
$logodir "filename2.png","http://anotherlink/")
);

function 
make_seed() {
    list(
$usec$sec) = explode(' 'microtime());
    return (float) 
$sec + ((float) $usec 100000);
}
srand(make_seed());

$logo rand(0count ($logos) - 1);
list (
$titleimage$titleurl) = $logos[$logo]; 

Now you can use $titleimage and $titleurl in your templates.

afterlab 06-28-2002 08:52 PM

Worked perfect, thanks.

Sparkz 06-28-2002 10:53 PM

My pleasure :D

Sparkz 06-28-2002 10:56 PM

Just looked at your site... Like what you did with this mod :)

Dyntheos 07-07-2002 01:08 PM

I have gotten this working succesfully on another skin and works beautifully.

I have tho another skin that it does not work on.

The code from the skin that doesn't work DOES work in any of the pre existing things so I know its not the array that is killing it here.

Is there anything that would interfere with this mod from working?

Sparkz 07-09-2002 10:08 AM

Hmm - as long as you have the code in the header it _should_ work. I don't really use it myself, so I haven't tested it to much.

maestrosdelweb 12-04-2002 01:52 AM

Great hack..

I'm using it under my website for christmas logos

http://www.forosdelweb.com/


All times are GMT. The time now is 07:55 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.01957 seconds
  • Memory Usage 1,773KB
  • 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
  • (5)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (23)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete