Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-03-2012, 09:20 PM
stryka stryka is offline
 
Join Date: Aug 2002
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Random background image with PHP

I currently have a PHP function that does a directory scan and randomly pulls an image to appear in the background CSS tag...

It essentially creates the following entry before the BODY tag

PHP Code:
<style type="text/css">
body {
background-imageurl(http://www.sitename.com/img/bg/IMG_1461_edit.jpg);
}
</
style
Any idea how i can do this in VB3.8?

Thanx
Reply With Quote
  #2  
Old 07-03-2012, 10:12 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try creating a new plugin using hook parse_templates and code like this (insert your function at the comment):

Code:
ob_start();
// call your function here
$str = ob_get_contents();
ob_end_clean();

$vbulletin->templatecache['headinclude'] .= addcslashes($str, '\\"');
Reply With Quote
  #3  
Old 07-04-2012, 09:55 PM
stryka stryka is offline
 
Join Date: Aug 2002
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmm... I think I lost you... what value does $str need to be for it to work?

is this the value i am sending

PHP Code:
background-imageurl(http://www.sitename.com/img/bg/IMG_1461_edit.jpg); 
Reply With Quote
  #4  
Old 07-04-2012, 10:03 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$str would have to be the entire thing you posted in the first post. If your function is only returning the part you posted above, then try this:

PHP Code:
ob_start();
// call your function here
$str ob_get_contents();
ob_end_clean();

$str '<style type="text/css">
body {
$str '
}
</style>
'
;
$vbulletin->templatecache['headinclude'] .= addcslashes($str'\\"'); 

Also, I was assuming that your function output a string. If it returns a string, then you don't need the ob_start()/ob_end_clean() calls.
Reply With Quote
  #5  
Old 07-04-2012, 10:24 PM
stryka stryka is offline
 
Join Date: Aug 2002
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ahh... so my plugin would look like this...

PHP Code:


function get_random_image() {

    
$files scandir($_SERVER['DOCUMENT_ROOT'].'/app/webroot/img/bg');
    
$count  count($files);
    
srand(time());
    
$img $files[rand(0,$count)];
    if((
$count-2) <= 0) return FALSE;
    return 
$img;

}

function 
get_random_image_ex() {
do {
    
$img get_random_image();
    if(
$img === FALSE) return FALSE;
    if(
$img != '.' && $img != '..' && !empty($img))  break;
    }while(
true);
    
    return 
FULL_BASE_URL.'/img/bg/'.$img;
}


$str get_random_image_ex();

if(
$str!== FALSE) {


$str '<style type="text/css">
body {background-image: 
$str '
}
</style>
'
;
$vbulletin->templatecache['headinclude'] .= addcslashes($str'\\"'); 
Reply With Quote
  #6  
Old 07-04-2012, 10:27 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Looks good, except the post is missing the last } .
Reply With Quote
  #7  
Old 07-04-2012, 10:45 PM
stryka stryka is offline
 
Join Date: Aug 2002
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Darn... the entry is getting inserted into the HTML when i view source... but the page isn't taking the value and showing the image... i even tried deleting the "background" value in style template of admincp... hmmmm.... so close
Reply With Quote
  #8  
Old 07-04-2012, 10:56 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What does it look like when you view the html? Looking more closely at the function you posted, I don't see where the "background-image: url(" and the closing ")" come from - maybe those need to be added to the plugin code?
Reply With Quote
  #9  
Old 07-05-2012, 09:54 AM
stryka stryka is offline
 
Join Date: Aug 2002
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yup.. that was it.. i usually dont get much help in this forum....

THanks for the help!

Quote:
Originally Posted by kh99 View Post
What does it look like when you view the html? Looking more closely at the function you posted, I don't see where the "background-image: url(" and the closing ")" come from - maybe those need to be added to the plugin code?
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:05 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.04452 seconds
  • Memory Usage 2,258KB
  • 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
  • (1)bbcode_code
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)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