Closed (fixed)
Project:
Buddylist2
Version:
5.x-1.x-dev
Component:
Buddylist UI
Priority:
Normal
Category:
Support request
Assigned:
Reporter:
Created:
25 Feb 2008 at 10:45 UTC
Updated:
30 Jun 2008 at 10:02 UTC
Here are a couple of snippets I was using on my custom userpage template with buddylist. they seem to be either giving wrong info or no info with BL2.
First is:
<?php
$uid = arg(1);
$buddies = db_fetch_object(db_query("SELECT COUNT(buddy) AS count FROM {buddylist} WHERE uid= %d AND received=0", $uid));
echo "$buddies->count";
?>
which should give a number of buddies (e.g. 6) that a user has.
The next one should list out the actions (add/delete from BL) but seems to be actually breaking pages:
<?php
if ($GLOBALS['user']->uid != $account->uid) {
if (@in_array($account->uid, array_keys(buddylist_get_buddies($viewing_user->uid))) && user_access('maintain buddy list')) {
print l(t('Remove @username from your contact list',array('@username'=>$account->name)), 'buddy/delete/'. $account->uid);
}
else {
if ($account->uid != $viewing_user->uid && user_access('maintain buddy list')) {
print l(t('Add @username to your contact list',array('@username'=>$account->name)), 'buddy/add/'. $account->uid);
}
}
}
?>
this last one should list last few buddies added but I'm getting a list of only their first letters and links going to user/T for example.
<ul>
<?php
$contacts = $account->buddies;
if($contacts){
$n=1;
foreach($contacts as $contact){
if($n<=3) {
echo "<li>";
print l($contact[name], 'user/'.$contact[uid]);
echo "</li>";
}
$n++;
}
}
else {
echo "<li>$account->name has no contacts</li>";
}
?>
</ul>
has anything fundamental changed with BL2 that would render these snippets useless?
Comments
Comment #1
nodestroy commentedto your first snipped. it should work, the database structur is the same (with some additonal fields)
anyway, try this:
Comment #2
esllou commentedOK, yes that first one is working actually. I saw a figure that looked odd but it was actually correct.
The snippet I really need for BL2, which I had working for BL is the one which shows either
Add to BL | Delete from BL
depending on whether the user whose userpage you're on is on your BL or not. Any pointers for that one?
Comment #3
crizWith some little adjustments this should work too. So the function that helps you to get user's buddies is now called "buddy_api_get_buddies()". But you could use my snippet, I have something simular in use:
Comment #4
esllou commentedI got the following error when I load up my user pages:
line 329 is:
is that exact code working on your site?
Comment #5
crizno, sorry...
change the line in
if ($user->uid != $puser->uid && user_access('maintain buddy list')) {Comment #6
esllou commentedOK, no errors this time but nothing is printed at all in the part of the page where the code sits, whether I go onto a member's page who's on my buddylist or not. Nothing is being printed at all. :-(
Comment #7
crizI tested exactly this script and it was working...
Are you sure you tested it not on your own profile and you have maintaining buddylist rights?
Comment #8
esllou commentedOK, we have progress. I am user 2 and have view/maintain buddylist permissions.
when I go to my page, I still see "Add to your Contact list", which I shouldn't be seeing.
I already have members 3, 33 and 49 on my contact list. When I go to each of their pages, I still see the "add to..." link. I don't see the "delete from..." link, whatever I do. The other odd thing is that the destination URL for these "add to" links is "http://www.mysite.com/buddy/add/0?destination=node/", which, when I click just takes me to the front page without doing anything. This happens even if I click on the "add to...." link on a userpage whose members ISN'T on my buddylist, so basically the code isn't working.
I don't know if this is relevant but I use both the $user variable (for the viewing member) and the $account variable (for the member whose page is being viewed)
Comment #9
crizOk, one more try. Your problem seems to be that you don't load the right user-objects. This former snippet only works if $node is available and the author of the node is the userpage owner.
But with some small adjustements you should get it working anyway. I have no idea how your variables are configured, but try it with the following version (assuming that you have already loaded the $user variable for the viewing member and the $account variable for the member whose page is being viewed):
Comment #10
esllou commentedthat worked perfectly. Thanks a million.
What about that last block I asked about:
I have Paul and Sharon on my buddylist and the html that block is outputting is:
so, for some reason, it's only getting the first letter from each of their names and linking to that letter too, so the problem seems to be here:
could you send me your paypal address to me via my contact form....I would like to offer something to you as you've gone beyond the normal support level. Thanks.
Comment #11
crizNo problem, I just want to help people switching to buddylist2.
Listing 3 buddies in a block can be also done using views, usernodes and the buddylist argument handler.
But your snippet should be no great deal too. Something like the following should work:
Comment #12
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #13
millions commentedHi Criz,
I'm new to drupal, and bl2. I've been installing and tweaking modules like crazy the past few days (i'm not much of a coder, certainly not php). I'm using panels2, advanced profile w/bio, and now BL2 and I can't get the add/delete links to show up. They worked with BL but not BL2. It looks like I just need to paste this code somewhere, but I don't have a user_profile.tpl.php in my themes folder. Any suggestions on where to paste your code snippet would be GREATLY appreciated! Thanks.
Nick
Comment #14
crizHi Nick,
sorry for the late answer. I'm not really into Bio/Advanced Profile, but there also should be a tpl file for your user profile. For example node-bio.tpl.php.
chris