vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   vBulletin Hook Help (https://vborg.vbsupport.ru/showthread.php?t=221222)

James Birkett 08-18-2009 09:43 PM

vBulletin Hook Help
 
I have a custom profile field, and I have multiple options that can fill this field.
I have this profile field displayed on the postbit and I want it to display a result at random.

Scenario:
My profile field is: Username
I have 2 usernames: Username 1 and username 2.

I want the postbit to show username 1 and 2, but not at the same time. Maybe it shows Username 1 first, then username 2 on a refresh etc.

I am not sure which hook to use, would it be a showthread or would it be member_customfields.. or another one?

Lynne 08-18-2009 09:51 PM

You want the *postbit* template to show it? If so, you probably want a hook location like postbit_display_complete (or postbit_display_start).

James Birkett 08-18-2009 09:54 PM

Thanks Lynne,
How would I begin this?
PHP Code:

if(($user['userid'] == 1) && ($post[field5] == true)) { 

?

Lynne 08-18-2009 10:11 PM

Well, it depends on what you are trying to say with the condition. If you simply care if field5 exists, then you just say && $post['field5'] - you don't need to say equals true. And you are only doing this only for userid 1?

James Birkett 08-18-2009 11:28 PM

Yeah.
I was thinking (based off your current code):
PHP Code:

if((user['userid'] == 1) && ($post[field5])) {
$post[field5] == '(some random generic testing text)';



Lynne 08-19-2009 12:07 AM

Yeah. You may be able to just use rand() to pick a random number and then based on that spit out a different field5. It's hard to guess exactly what to do given the posted information. Something like (not real php below!!!):
PHP Code:

$random rand(1,2);
if (
$random == 1field5 username 1;
else 
field5 username 2


James Birkett 08-19-2009 12:59 AM

Thanks Lynne, I guessed as much.
My forum is based around an online gaming community, and I have multiple usernames so I want it to randomly display each one. (Can rand() be used with strings?).
Just need it to display either or, really.
PHP Code:

$username = array('Username 1','Username 2');
$rand rand(0,1);
$post[field5] == $username['rand']; 

What about that?

Lynne 08-19-2009 02:56 AM

I don't know if that would work. I'm a trial and error coder. (I'm terrible at remembering syntax!) Just try it and see.

James Birkett 08-19-2009 02:45 PM

PHP Code:

if(($user['userid'] == 1) && ($post[field5])) {
$array = array("Test 1","Test 2");
shuffle($array);
$post[field5] = $array[0];


I've tried that code on postbit_display_start and postbit_display_complete with no luck.

Lynne 08-19-2009 03:59 PM

I added this to postbit_display_complete and it worked just fine (and added $testing to my postbit):
PHP Code:

$array = array("Test 1","Test 2");
shuffle($array);
$testing $array[0]; 

So, I'd say your condition is wrong. First off, $user is most likely not valid. If this is the person who is posting, then that would be $this->post['userid'] . And, you should probably be using $post['field5'], not $post[field5].

James Birkett 08-19-2009 11:09 PM

Thanks Lynne, that seems to have worked.


All times are GMT. The time now is 06:54 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.02490 seconds
  • Memory Usage 1,742KB
  • 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
  • (6)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (11)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