vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   post pop-up menu conditional (https://vborg.vbsupport.ru/showthread.php?t=82471)

zetetic 06-04-2005 01:26 AM

post pop-up menu conditional
 
I'm trying to add something to the post popup menu that's conditional based on whether the user is on your buddylist. This is as close as I can guess, but it doesn't seem to work:

<if condition="in_array($post[userid], $bbuserinfo[buddylist])">

Any idea how to make that work?

Okay after many hours of poking around and trying different things, at this point I'm guessing my question above doesn't even make sense. I would think what I'm trying to do is very simple, but so far it doesn't seem to be. I want to put a conditional in the postbit template so that "Add {user} to your buddylist" becomes "Remove {user} from your buddylist" if they're already your buddy. At this point I think I have a better chance of building a car that gets 1000 miles to a gallon of water. :(

Adrian Schneider 06-04-2005 05:28 AM

The buddy list isn't an array, it's a list of userIDs seperated with spaces. You'll have to use another function.

Cloudrunner 06-04-2005 12:23 PM

Quote:

Originally Posted by tmhall
I'm trying to add something to the post popup menu that's conditional based on whether the user is on your buddylist. This is as close as I can guess, but it doesn't seem to work:

<if condition="in_array($post[userid], $bbuserinfo[buddylist])">

Any idea how to make that work?

Okay after many hours of poking around and trying different things, at this point I'm guessing my question above doesn't even make sense. I would think what I'm trying to do is very simple, but so far it doesn't seem to be. I want to put a conditional in the postbit template so that "Add {user} to your buddylist" becomes "Remove {user} from your buddylist" if they're already your buddy. At this point I think I have a better chance of building a car that gets 1000 miles to a gallon of water. :(

Offa the top of me noggin (I'm not near a computer with testing capabilities right now)...

PHP Code:

$buddylist = array(); //initializes the variable $buddylist to be an array
$buddylist explode(' '$bbuserinfo['buddylist']); //This will put the buddylist id's into the array called $buddylist with $buddylist[0] being the first id in the array. 

and then you can call the conditional:

Code:

<if condition="in_array($post[userid], $buddylist)">
  Remove $post[username] from your buddylist<br />
<else />
  Add $post[username] to your buddylist<br />
</if>

My thoughts right now (again, no test availability) would be to put the $buddylist php code in your ./global.php file.

zetetic 06-04-2005 01:27 PM

Thanks for your replies, guys.

I came pretty close to that same solution myself last night, except I didn't initialize the array first* and I was putting the code in showthread.php instead of global.php. Unfortunately I get the same results either way:

Code:

Warning: in_array(): Wrong datatype for second argument in /includes/functions_showthread.php(640) : eval()'d code on line 213
For testing purposes I put print_r($buddylist); in showthread.php and it comes up:

Code:

Array
(
    [0] => 2
)

(I'm on a test server and have one person on my buddylist, userid = 2)


*Is that really necessary? For some reason I thought it wasn't.

Cloudrunner 06-04-2005 02:52 PM

Quote:

Originally Posted by tmhall
Thanks for your replies, guys.

I came pretty close to that same solution myself last night, except I didn't initialize the array first* and I was putting the code in showthread.php instead of global.php. Unfortunately I get the same results either way:

Code:

Warning: in_array(): Wrong datatype for second argument in /includes/functions_showthread.php(640) : eval()'d code on line 213
For testing purposes I put print_r($buddylist); in showthread.php and it comes up:

Code:

Array
(
    [0] => 2
)

(I'm on a test server and have one person on my buddylist, userid = 2)


*Is that really necessary? For some reason I thought it wasn't.

found my goof...sorry

PHP Code:

<if condition="in_array($post['userid'], $buddylist)">
  
Remove $post[usernamefrom your buddylist<br />
<else />
  
Add $post[usernameto your buddylist<br />
</if> 

note the singlequote in the conditional array $post.

see if that helps any,

zetetic 06-04-2005 04:33 PM

Unfortunately it's still not working. :(

Just to be clear, I added this to the bottom of global.php:

PHP Code:

$mybuddylist = array();
$mybuddylist explode(' '$bbuserinfo['buddylist']); 

And this to the postbit:

HTML Code:

<tr><td><if condition="in_array($post['userid'], $mybuddylist)">
  Remove $post[username] from your buddylist<br />
<else />
  Add $post[username] to your buddylist<br />
</if></td></tr>

And this to showthread.php:

PHP Code:

echo "<pre>";
print_r($mybuddylist);
echo 
"</pre>"

And this is what I get at the top of the page (with one buddy, userid = 2):

Code:

Warning: in_array(): Wrong datatype for second argument in /includes/functions_showthread.php(640) : eval()'d code on line 213

Warning: in_array(): Wrong datatype for second argument in /includes/functions_showthread.php(640) : eval()'d code on line 213

Warning: in_array(): Wrong datatype for second argument in /includes/functions_showthread.php(640) : eval()'d code on line 213

Array
(
    [0] => 2
)


Cloudrunner 06-04-2005 07:46 PM

try this one then, since it's looking for an integer in the array I think...still away from testing computer...

PHP Code:

$mybuddylist = array();
$mybuddylist trim($bbuserinfo['buddylist']);
 
$mybuddylist explode(' '$mybuddylist);
foreach (
$mybuddylist AS $key => $value){
    
$mybuddylist[$key] = intval($value);


That's about the extent of my abilities until I can get back to my testing server...

zetetic 06-04-2005 08:08 PM

Nope, didn't work unfortunately. Exactly the same results.

Cloudrunner 06-04-2005 08:38 PM

Well crap dude, I'm stuck then....

Not quite sure where to go from there...
Quote:

Originally Posted by tmhall
Nope, didn't work unfortunately. Exactly the same results.


zetetic 06-05-2005 01:51 AM

Quote:

Originally Posted by Cloudrunner
Well crap dude, I'm stuck then....

Not quite sure where to go from there...

Hey no problem, man. I'm not really sure what to do either. This seems like it would be such a simple thing... thanks for giving it a shot anyway.

Okay I stumbled on a solution, so here it is for posterity. :)

I'm not gonna bother posting it in mini-mods since there's probably an easier way:

Find in includes/functions_showthread.php:
PHP Code:

$show['messageicon'] = iif($post['iconpath'], truefalse); 

Add above:

PHP Code:

    // set-up for buddylist conditional - postbit
    
$isbuddy explode(' '$bbuserinfo['buddylist']);
    
    if (
in_array($post['userid'], $isbuddy))
    {
        
$isbuddy true;
    }
    else
    {
        
$isbuddy false;
    } 

Find in postbit template:

HTML Code:

<if condition="$post['userid']">
        <tr><td class="vbmenu_option"><a href="profile.php?$session[sessionurl]do=addlist&amp;userlist=buddy&amp;u=$post[userid]"><phrase 1="$post[username]">$vbphrase[add_x_to_buddy_list]</phrase></a></td></tr>
        </if>

Replace with:

HTML Code:

<if condition="($bbuserinfo['userid'] AND ($post[userid] != $bbuserinfo['userid']))">
<if condition="($isbuddy == false)">
                <tr><td class="vbmenu_option"><a href="$vboptions[bburl]/profile.php?$session[sessionurl]do=addlist&amp;userlist=buddy&amp;u=$userinfo[userid]"><phrase 1="$post[username]">$vbphrase[add_x_to_buddy_list]</phrase></a></td></tr>
                <else />
                <tr><td class="vbmenu_option"><a href="$vboptions[bburl]/profile.php?$session[sessionurl]do=removelist&amp;userlist=buddy&amp;u=$userinfo[userid]"><phrase 1="$post[username]">$vbphrase[remove_x_from_buddy_list]</phrase></a></td></tr>
                </if>
</if>

Add this postbit phrase:

remove_x_from_buddy_list
Remove {1} from your Buddy List


All times are GMT. The time now is 05:00 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.01238 seconds
  • Memory Usage 1,776KB
  • 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_code_printable
  • (3)bbcode_html_printable
  • (7)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete