View Full Version : post pop-up menu conditional
zetetic
06-04-2005, 01:26 AM
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
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)...
$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:
<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:
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:
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
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:
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:
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
<if condition="in_array($post['userid'], $buddylist)">
Remove $post[username] from your buddylist<br />
<else />
Add $post[username] to 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:
$mybuddylist = array();
$mybuddylist = explode(' ', $bbuserinfo['buddylist']);
And this to the postbit:
<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:
echo "<pre>";
print_r($mybuddylist);
echo "</pre>";
And this is what I get at the top of the page (with one buddy, userid = 2):
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...
$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...Nope, didn't work unfortunately. Exactly the same results.
zetetic
06-05-2005, 01:51 AM
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:
$show['messageicon'] = iif($post['iconpath'], true, false);
Add above:
// 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:
<if condition="$post['userid']">
<tr><td class="vbmenu_option"><a href="profile.php?$session[sessionurl]do=addlist&userlist=buddy&u=$post[userid]"><phrase 1="$post[username]">$vbphrase[add_x_to_buddy_list]</phrase></a></td></tr>
</if>
Replace with:
<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&userlist=buddy&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&userlist=buddy&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
Bad Bunny
06-06-2005, 12:20 AM
wow
That's some great thinking there! Thanks, man!
Andreas
06-06-2005, 12:40 AM
A (maybe) easier approach:
In template phpinclude_start add
$buddyarray = explode(' ', $bbuserinfo['buddylist']);
In Template postbit
FIND
<if condition="$post['userid']">
<tr><td class="vbmenu_option"><a href="profile.php?$session[sessionurl]do=addlist&userlist=buddy&u=$post[userid]"><phrase 1="$post[username]">$vbphrase[add_x_to_buddy_list]</phrase></a></td></tr>
</if>
REPLACE that with
<if condition="$post['userid'] AND $post['userid'] != $bbuserinfo['userid']">
<if condition="!in_array($post['userid'], $GLOBALS['buddyarray'])">
<tr><td class="vbmenu_option"><a href="profile.php?$session[sessionurl]do=addlist&userlist=buddy&u=$post[userid]"><phrase 1="$post[username]">$vbphrase[add_x_to_buddy_list]</phrase></a></td></tr>
<else />
<tr><td class="vbmenu_option"><a href="profile.php?$session[sessionurl]do=removelist&userlist=buddy&u=$post[userid]"><phrase 1="$post[username]">$vbphrase[remove_x_from_buddy_list]</phrase></a></td></tr>
</if>
</if>
And add the phrase as tmhall suggested.
The advantage over tmhalls suggestion is that this does require less processing (explode() is only executed once), and you don't have to modify the php files.
zetetic
06-06-2005, 02:03 AM
wow
That's some great thinking there! Thanks, man!
Thanks. I did the same for the ignorelist, btw. It looks like Kirby's idea might be better though. But...
Kirby, you can do explode in the phpinclude_start template? I tried it in the postbit but it said explode wasn't allowed to be used in templates. I didn't know phpinclude_start existed. :nervous:
Andreas
06-06-2005, 02:18 AM
Yes you can.
In normal Templates you can use only a few functions.
But phpinclude_start is a special template where you can place PHP - only PHP.
The code there will be executed by global.php
zetetic
06-06-2005, 02:22 AM
Well I'll be damned. That's good to know, thanks. :)
Yep, that works like a charm. Thanks again, Kirby.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.