Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-04-2009, 10:02 PM
TSHNOFX TSHNOFX is offline
 
Join Date: Sep 2008
Location: USA
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default [3.7.X]Random Logo Changer

I'm wondering if anyone could make a modification that works similarly to this script:

PHP Code:
<?php
/*
By Matt Mullenweg > http://photomatt.net
Inspired by Dan Benjamin > http://hiveware.com/imagerotator.php
Latest version always at:
http://photomatt.net/scripts/randomimage
*/// Make this the relative path to the images, like "../img" or "random/images/".
// If the images are in the same directory, leave it blank.
$folder 'img/';

// Space seperated list of extensions, you probably won't have to change this.
$exts 'jpg jpeg png gif';

$files = array(); $i = -1// Initialize some variables
if ('' == $folder$folder './';

$handle opendir($folder);
$exts explode(' '$exts);
while (
false !== ($file readdir($handle))) {
foreach(
$exts as $ext) { // for each extension check the extension
if (preg_match('/\.'.$ext.'$/i'$file$test)) { // faster than ereg, case insensitive
$files[] = $file// it’s good
++$i;
}
}
}
closedir($handle); // We’re not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand mt_rand(0$i); // $i was incremented as we went along

header('Location: '.$folder.$files[$rand]); // Voila!
?>
Basically, it'd load whatever images from a given directory and display them randomly. Thanks in advance if anyone is interested.
Reply With Quote
  #2  
Old 03-04-2009, 11:47 PM
Mr-Moo Mr-Moo is offline
 
Join Date: Sep 2007
Location: Chicago, IL.
Posts: 130
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You would have to add something like this to and have it included into your header:
PHP Code:
<?php
function getRandomFromArray($ar) {
    
mt_srand( (double)microtime() * 1000000 );
    
$num array_rand($ar);
    return 
$ar[$num];
}

function 
getImagesFromDir($path) {
    
$images = array();
    if ( 
$img_dir = @opendir($path) ) {
        while ( 
false !== ($img_file readdir($img_dir)) ) {
            
// checks for gif, jpg, png
            
if ( preg_match("/(\.gif|\.jpg|\.png)$/"$img_file) ) {
                
$images[] = $img_file;
            }
        }
        
closedir($img_dir);
    }
    return 
$images;
}

$root '';
// If images not in sub directory of current directory specify root 
//$root = $_SERVER['DOCUMENT_ROOT'];

$path 'forum/images/stylename/newlogos';

// Obtain list of images from directory 
$imgList getImagesFromDir($root $path);

$img getRandomFromArray($imgList);

?>
Then wherever your header image is place this:
PHP Code:
<img src="<?php echo $path $img ?>" alt="" />
Or at least assign the above snippet code as a Vb template code and display this in your style.

I think I explained it correctly, if anyone else can elaborate please do as my thoughts sometime scatter

Hope this helps. Let me know if it does!
Reply With Quote
  #3  
Old 03-05-2009, 12:20 AM
BSMedia BSMedia is offline
 
Join Date: Feb 2009
Posts: 454
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Mr-Moo View Post
You would have to add something like this to and have it included into your header:
PHP Code:
<?php
function getRandomFromArray($ar) {
    
mt_srand( (double)microtime() * 1000000 );
    
$num array_rand($ar);
    return 
$ar[$num];
}

function 
getImagesFromDir($path) {
    
$images = array();
    if ( 
$img_dir = @opendir($path) ) {
        while ( 
false !== ($img_file readdir($img_dir)) ) {
            
// checks for gif, jpg, png
            
if ( preg_match("/(\.gif|\.jpg|\.png)$/"$img_file) ) {
                
$images[] = $img_file;
            }
        }
        
closedir($img_dir);
    }
    return 
$images;
}

$root '';
// If images not in sub directory of current directory specify root 
//$root = $_SERVER['DOCUMENT_ROOT'];

$path 'forum/images/stylename/newlogos';

// Obtain list of images from directory 
$imgList getImagesFromDir($root $path);

$img getRandomFromArray($imgList);

?>
Then wherever your header image is place this:
PHP Code:
<img src="<?php echo $path $img ?>" alt="" />
Or at least assign the above snippet code as a Vb template code and display this in your style.

I think I explained it correctly, if anyone else can elaborate please do as my thoughts sometime scatter

Hope this helps. Let me know if it does!
Other than the fact you can't put php into the templates you nailed it right on :erm:

You'll have to make a plugin at global_start more than likely and give whatever the script outputs a value and then use it in your template
Reply With Quote
  #4  
Old 03-05-2009, 12:50 AM
private_ale's Avatar
private_ale private_ale is offline
 
Join Date: Dec 2007
Location: New Jersey
Posts: 112
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What are you guys talking about? Did you even read the script?

First: Make a separate directory for your logos. Lets call it logos/. Now lets say that the logos/ directory is located in your root directory. If that is the case then it would be logos/.

Look at the portion of code below, see where I put logos/, this is where the path to your logo directory goes. (As described above)
Code:
*/// Make this the relative path to the images, like "../img" or "random/images/".
// If the images are in the same directory, leave it blank.
$folder = 'logos/';
WOW! That's all you need to edit from that script.
Next, create a new file and name it something, lets call it rotate.php. Take the newly modified script and save it into that file. Place that file (rotate.php) into you logos/ directory.

Lets check,
So far you've added the path to your logo directory to the script CHECK
You've saved the script as a php file. In this example we called it "rotate.php" CHECK
You placed your new .php file into that SAME directory as your logos CHECK

Last Step:
Where you want your logo to display, simply put a regular image tag, but instead of putting the source as an image, put it as your .php file.
Code:
<img src="path/to/logos/rotate.php" border="0" alt="" />
That's it.
Reply With Quote
  #5  
Old 03-05-2009, 01:02 PM
Mr-Moo Mr-Moo is offline
 
Join Date: Sep 2007
Location: Chicago, IL.
Posts: 130
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

private_ale, I am completely lost, that code you made makes no sense to me. I am far from a fluent PHP coder, but if you can, please explain this a tad for me.

You are placing the first bit of code into a "rotate.php" file. Which assigns variable "$folder" to the data "logos/". Which means all this is is a variable assigned to specific data.

Then you call a PHP script in the image source which is in no way related to $folder or that variable. I don't even see an echo.

In my eyes, there is no random rotation, no variables on the intervals, no directory to be called from, no variable image type definition, etc.... It would also behoove you to be a little less abrasive with your comments, as you may have offended some people and their intelligence.

---
BSMedia, you are correct. I am somewhat familiar with Vbulletin, but I am still learning how PHP is integrated with VB.

You are indeed correct, he will have to create a plugin calling these scripts and variables. Then he would be able to assign some coding to them and call within his styles/template.

Thank you everyone, I hope this information is useful TSHNOFX.
Reply With Quote
  #6  
Old 03-09-2009, 09:44 PM
TSHNOFX TSHNOFX is offline
 
Join Date: Sep 2008
Location: USA
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I ended up removing the alt out of the logo call and just using the regular php script, and it seems to work fine, 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 05:21 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.04547 seconds
  • Memory Usage 2,250KB
  • Queries Executed 13 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (5)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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_postinfo_query
  • fetch_postinfo
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete