vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Random hex color (https://vborg.vbsupport.ru/showthread.php?t=116334)

Trommsdorff 05-21-2006 11:13 PM

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)?

Adrian Schneider 05-21-2006 11:15 PM

Stick the PHP code in a new plugin using the "global_start" hook. $randomnumber should then be available to use in most templates.

Dan 05-21-2006 11:15 PM

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.

Trommsdorff 05-21-2006 11:18 PM

wow, fast replies, many thanks.

Is it simply called with $randomnumber ? Or does it need some {} or [] ?

Adrian Schneider 05-21-2006 11:19 PM

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.

Trommsdorff 05-21-2006 11:22 PM

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);
?>


Adrian Schneider 05-21-2006 11:25 PM

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.

Trommsdorff 05-21-2006 11:32 PM

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?

Adrian Schneider 05-21-2006 11:37 PM

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).

Trommsdorff 05-21-2006 11:41 PM

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!


All times are GMT. The time now is 09: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.00989 seconds
  • Memory Usage 1,736KB
  • 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
  • (1)bbcode_code_printable
  • (2)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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