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

Reply
 
Thread Tools Display Modes
  #1  
Old 05-21-2006, 11:13 PM
Trommsdorff Trommsdorff is offline
 
Join Date: May 2002
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Random hex color

Hello,

I have some PHP code that generates a random hex color code. I would like to incorporate it for use in vbulletin (it has to be server side). In a normal PHP file, the output is something like $randomcolor.

Does anyone know how to get that to be displayed properly within VB using the plugin system (if that's the proper way to do it)?
Reply With Quote
  #2  
Old 05-21-2006, 11:15 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Stick the PHP code in a new plugin using the "global_start" hook. $randomnumber should then be available to use in most templates.
Reply With Quote
  #3  
Old 05-21-2006, 11:15 PM
Dan's Avatar
Dan Dan is offline
 
Join Date: Dec 2002
Location: Titusville, Florida
Posts: 1,787
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Best way is to put the code in a plugin for global_start and then call the variable you are using for it wherever you want to use it.
Reply With Quote
  #4  
Old 05-21-2006, 11:18 PM
Trommsdorff Trommsdorff is offline
 
Join Date: May 2002
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

wow, fast replies, many thanks.

Is it simply called with $randomnumber ? Or does it need some {} or [] ?
Reply With Quote
  #5  
Old 05-21-2006, 11:19 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Trommsdorff
wow, fast replies, many thanks.

Is it simply called with $randomnumber ? Or does it need some {} or [] ?
We can't tell you without seeing your code.
Reply With Quote
  #6  
Old 05-21-2006, 11:22 PM
Trommsdorff Trommsdorff is offline
 
Join Date: May 2002
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, the code I plan on using is from here:

http://www.zend.com/tips/tips.php?id=243&single=1

My rendition is below:
Code:
<? 

// randomize the color 
$r = rand(128,255); 
$g = rand(128,255); 
$b = rand(128,255); 

$randomcolor = dechex($r) . dechex($g) . dechex($b); 
?>
Reply With Quote
  #7  
Old 05-21-2006, 11:25 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay, in your plugin, do NOT include the PHP tags (<? and ?>). Everything else looks okay - be sure to add the # in front of $randomcolor when you use it. And no, you won't need any []s or {}s.
Reply With Quote
  #8  
Old 05-21-2006, 11:32 PM
Trommsdorff Trommsdorff is offline
 
Join Date: May 2002
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, thanks again for the quick reply. I'm trying to use it in the postbit_legacy to display in posts, but nothing is showing.

Should I call it differently for there?
Reply With Quote
  #9  
Old 05-21-2006, 11:37 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Trommsdorff
OK, thanks again for the quick reply. I'm trying to use it in the postbit_legacy to display in posts, but nothing is showing.

Should I call it differently for there?
Posts are processed in a function, so it's not available there. If you want every post to have a different color, do this: hook: postbit_display_complete
PHP Code:
$r rand(128,255); 
$g rand(128,255); 
$b rand(128,255); 

$randomcolor dechex($r) . dechex($g) . dechex($b); 
and then $randomcolor will be available (and unique) in all of your posts (you can remove the other plugin you created in global_start).

If you want them all the same:
postbit_display_complete
PHP Code:
global $randomcolor
(while leaving the original global_start hook intact).
Reply With Quote
  #10  
Old 05-21-2006, 11:41 PM
Trommsdorff Trommsdorff is offline
 
Join Date: May 2002
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Fantastic! My deepest thanks. I'm actually using as part of an included JS script that needs an image border color and it works well now! 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 01:27 PM.


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.04245 seconds
  • Memory Usage 2,251KB
  • 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
  • (2)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete