vb.org Archive

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

kronnos 04-29-2008 08:47 PM

Random Conditional Help
 
Hi,

I have this complicated conditional I want to use for adds but have no idea how to code it.
Here is what I want the conditional to say in words:

If user xx1 is viewing the page, then show "adcode 1"
If user xx2 is viewing the page, then show "adcode 2"
Else, show randomly, 75% chance "adcode 1" and 25% chance "adcode 2".

Many thanks in advance!
Edit/Delete Message

GameWizard 04-30-2008 01:21 AM

Well I can't help you with the randomization code, that's something you can look for elsewhere, since the code is out there, you just need to find it.

As for your request, here is something that should get you on your way:

Code:

<if condition="is_member_of($bbuserinfo, 2)">
This will only show to Usergroup ID 2
</else>
$randombanner
</if>

<if condition="is_member_of($bbuserinfo, 3)">
This will only show to Usergroup ID 3
</else>
$randombanner
</if>

$randombanner refers to the code where the banner is randomized to your liking.

kronnos 04-30-2008 08:28 AM

Cool, thanks!

Anyone else have some ideas?

Opserty 04-30-2008 11:38 AM

Code:

<if condition="is_member_of($bbuserinfo, 2)">
    This will only show to Usergroup ID 2
</else>
    <if condition="is_member_of($bbuserinfo, 3)">
        This will only show to Usergroup ID 3
    </else>
        <if condition="rand(0, 3)">
            $randombanner1
        <else />
            $randombanner2
        </if>
    </if>
</if>


kronnos 04-30-2008 11:49 AM

Cool, so this is the full code that will do what i need?

Few question:

1-- It says it will show to certain usergroups. Can you make it say for certain users not entire groups?
2-- "rand(0, 4)", what does 0 and 4 mean? 0 chances of banner 1 and all chances of banner 2?
3-- Should I just insert instead of "$randombanner1" the adsense code? Or do i put the $ infront of the code?

GameWizard 04-30-2008 12:16 PM

1. http://www.vbulletin.com/forum/showthread.php?t=200894 - Use the conditionals you'd like, you're looking for:
Code:

<if condition="in_array($bbuserinfo[userid], array(X,Y,Z))">
2. I'm not sure how the rand function works.

3. Yes insert the code you'd like where the $randombanner1 is located.

Opserty 04-30-2008 12:38 PM

Edit whoops I made a mistake with the rand options should be: [minicode]rand(0, 3)[/minicode] instead of 4

2). rand generates a random number (in this case between 0 and 3 inclusive) 0 is evaluated as false in a condition whilst any other number would be true so you have 0 = false, 1, 2 & 3 = true. 1:3 ratio which is same as 25%:75%.

kronnos 04-30-2008 01:01 PM

Quote:

Originally Posted by Opserty (Post 1503334)
Edit whoops I made a mistake with the rand options should be: [minicode]rand(0, 3)[/minicode] instead of 4

2). rand generates a random number (in this case between 0 and 3 inclusive) 0 is evaluated as false in a condition whilst any other number would be true so you have 0 = false, 1, 2 & 3 = true. 1:3 ratio which is same as 25%:75%.

Great, I think I understand it now.... If 0(false) is picked, it will skip $randombanner1 and go to <else /> $randombanner2. If 3(1,2, or3) is picked, it will stay at $randombanner1. Right?

Thank you very much. Great help!

Dismounted 05-01-2008 05:54 AM

Quote:

Originally Posted by kronnos (Post 1503351)
Great, I think I understand it now.... If 0(false) is picked, it will skip $randombanner1 and go to <else /> $randombanner2. If 3(1,2, or3) is picked, it will stay at $randombanner1. Right?

Thank you very much. Great help!

Yes

kronnos 05-01-2008 12:43 PM

Please help! I pasted the following code into the Vb Ad management block and it gives an error. Now i cant delete the code because it doesn't show a save button to save new changes.

PHP Code:

<if condition="in_array($bbuserinfo[userid], array(132))">
    
GOOGLE CODE1


</else>
<if 
condition="in_array($bbuserinfo[userid], array(213))">

GOOGLE CODE2

    
</else>
        <if 
condition="rand(0, 3)">
            
GOOGLE CODE1

        
<else />

GOOGLE CODE2


        
</if>
    </if>
</if> 


Opserty 05-01-2008 12:49 PM

Oh dear I must have been half asleep when I wrote this the first time, try this:

Code:

<if condition="in_array($bbuserinfo[userid], array(132))">
    CODE 1
<else />
    <if condition="in_array($bbuserinfo[userid], array(213))">
        CODE 2
    <else />
        <if condition="rand(0, 3)">
            CODE 1
        <else />
            CODE 2
        </if>
    </if>
</if>


kronnos 05-01-2008 01:10 PM

Still get the following Vbulletin error message:



:

<if condition="rand(0, 3)">


rand rand(0, 3)


in_array() is_array() is_numeric() isset() empty() defined() array() can_moderate() can_moderate_calendar() exec_switch_bg() is_browser() is_member_of()

--------------- Added [DATE]1209653757[/DATE] at [TIME]1209653757[/TIME] ---------------

I now pasted this code directly into the template and got this error message:

vBulletin Message


The following template conditional expression contains function calls:

<if condition="rand(0, 3)">

Function Name Usage in Expression
rand rand(0, 3)

With a few exceptions, function calls are not permitted in template conditional expressions. Please go back and re-write this expression.

The following functions are allowed in template conditional expressions:
in_array() is_array() is_numeric() isset() empty() defined() array() can_moderate() can_moderate_calendar() exec_switch_bg() is_browser() is_member_of()

Opserty 05-01-2008 02:40 PM

AdminCP > Plugins & Products > Add New Plugin. Set the following:

Product: vBulletin
Hook Location: template_safe_functions
Plugin PHP Code:
PHP Code:

$safe_functions[] = 'rand'

Plugin Is Active: Yes

kronnos 05-01-2008 04:07 PM

Works great! Thank You!


All times are GMT. The time now is 05:02 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.01147 seconds
  • Memory Usage 1,758KB
  • 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
  • (4)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
  • (14)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