Create Add/Delete Buddy Button

ygg - February 1, 2008 - 05:21
Project:Buddylist2
Version:5.x-1.x-dev
Component:Buddylist UI
Category:feature request
Priority:normal
Assigned:Unassigned
Status:postponed (maintainer needs more info)
Description

I may just not get this, but I have been trying to figure out how to add an 'Add/Delete Buddy' button on a user profile. That way when users are looking for other users and look at a profile they can that person as a buddy.

I have not yet figured it out. Now I am not a programmer which is probably mostly the reason. Nonetheless, it would awesome to see maybe a block that could be added that is simply the 'Add/Delete Buddy' button.

Can someone help me for now to build that?

#1

criz - February 1, 2008 - 16:17

Hi, displaying a "buddy-add link" on other pages than the user-page is very easy: Just create a link with an relative url like "/buddy/add/UID", where UID is the User ID of the user that should be added to your buddylist.

#2

nodestroy - February 20, 2008 - 08:00
Component:Miscellaneous» Buddylist UI
Status:active» fixed

Hi,

i have added this links to the book page:
http://drupal.org/node/217087

regards

#3

sterwa - March 3, 2008 - 02:00
Version:» 5.x-1.x-dev

You guys,

your solution is not flexible enough. If I create a link like "/buddy/add/UID", it will be displayed everywhere regardless of whether this UID is already a friend of current user or not.

I am trying to add buddy action buttons to author's info block. I am retrieving a author's ID using

$viewed_user_id=$node->uid;

(the $node I received by loading a node for nid fetched from the URL)

Then I am getting the author-of-node user object with

$viewed_user=user_load($array=array('uid'=>$viewed_user_id));

Now, I want to take advantage of the function theme_buddylist_ui_user_actions. I write the following:

print theme('buddylist_ui_user_actions', $viewed_user);

And what it prints says "Array". I think i am not getting something basic related to displaying arrays... Any help would be appreciated.

#4

criz - March 3, 2008 - 17:26

Hi, do you have seen this snippet? It should accomplish what you are asking for...

#5

sterwa - March 3, 2008 - 17:36

Thanks criz for the tip, that snippet does work!!!
I guess my question is more general regarding printing out arrays in Drupal.

See,
what that snippet does in 6 lines of code, my line does in one, by taking advantage of the appropriate API (that does all the reading my buddies computations for me). But it fails to output the result properly. I would like to understand how to print arrays. Right now, if I use print_r to display the content of the array, I get correct list of actions. But wrapped in ugly form-looking wrapping. Ideas on how to print forms? Here is what I get displayed when running:

global $user;
$puser = user_load(array('uid' => $node->uid));

print_r(theme('buddylist_ui_user_actions', $puser));

Displayed result:

Array ( [title] => Buddy actions [value] =>

* Add CorrectPuserNickname to my buddylist

[class] => buddylist_actions )

Tis is not to undermine the utility of your snippet, criz, but for educational purposes (and the purpose of code efficiency)...

#6

BeechyBoy - March 10, 2008 - 22:41

#7

BeechyBoy - March 10, 2008 - 22:41
Status:fixed» postponed (maintainer needs more info)

Hello,
I have looked around and done the research, but haven't been able to manage to implement these buttons using BL2.
PHP snippets that I have seen just haven't got to work?
http://drupal.org/node/226423#comment-747395
The way I have been doing it is using the 'mini panels'. I have tried adding snippets to the user profiles by creating a panel in the 'basic info' mini pane and enabling it to recognise PHP.
I've experienced some of the problems flagged up during previous postings, but not come to any 'fixed' conclusion. What am I doing wrong? Is there another way this feature should now be implemented rather than using panels/min panels?

#8

nodestroy - March 11, 2008 - 10:21

hi,

maybe you can post what you have done exactly (with code). at the moment i can just guess...

#9

BeechyBoy - March 11, 2008 - 11:25

I'll be working on this today so I can post more later on. I wonder if it because the right variables for the user and the account being viewed are incorrect? Here is the code I have posted into my mini panel using 'Advanced Profile' module.

<?php
 
//load current user object
 
global $user;
 
//load profile-user object
 
$puser = user_load(array('uid' => $node->uid));
 
//load all buddies from active user
 
$buddies = buddy_api_get_buddies($user->uid);

//load all buddies from active user
$userbuddies = buddy_api_get_buddies($user->uid);
//buddylist links
if ($account->uid != $user->uid && user_access('maintain buddy list')) {
 
in_array($account->uid, array_keys($userbuddies)) ? print l(t('Remove @username from your contact list',array('@username'=>$account->name)), 'buddy/delete/'.$account->uid, array(), drupal_get_destination(), NULL, FALSE, FALSE) : print l(t('Add @username to your contact list',array('@username'=>$account->name)), 'buddy/add/'.$account->uid, array(), drupal_get_destination(), NULL, FALSE, FALSE);
}
?>

Do you think it's something to do with the $account variable not being passed?

#10

nodestroy - March 11, 2008 - 11:54

try with this one ;)

<?php
 
//load current user object
 
global $user;
 
//load profile-user object
 
$puser = user_load(array('uid' => $node->uid));

 
//load all buddies from active user
 
$userbuddies = buddy_api_get_buddies($user->uid);

//buddylist links
if ($puser->uid != $user->uid && user_access('maintain buddy list')) {
 
in_array($puser->uid, array_keys($userbuddies)) ? print l(t('Remove @username from your contact list',array('@username'=>$puser->name)), 'buddy/delete/'.$puser->uid, array(), drupal_get_destination(), NULL, FALSE, FALSE) : print l(t('Add @username to your contact list',array('@username'=>$puser->name)), 'buddy/add/'.$puser->uid, array(), drupal_get_destination(), NULL, FALSE, FALSE);
}
?>

#11

BeechyBoy - March 11, 2008 - 13:35

That looks good to me, but it hasn't worked. The link stays the same on every profile users page "Add to your contact list" and when clicked just displays the message: "This user does not exist"
The link is:
http://localhost:8888/dev_alpha/buddy/add/0?destination=user%2F1

I'm stumped?! Your snippet looks like it should do the job. Any ideas? How have you got this configured in the past?

#12

nodestroy - March 11, 2008 - 14:31

from here i can´t say whats wrong with your system. you posted a local link...i can´t access your site.

but at your URL i can see, that the profile-owner is not loaded correctly. buddy/add/uid is the syntax of the callback, and a 0 is passed to it. the third argument hast to be a user-uid.

that means $puser->uid is not correct -> $puser = user_load(array('uid' => $node->uid)); is not correct.

try to output $node->uid.

<?php
echo "Test-output: ". $node->uid;
?>

#13

BeechyBoy - March 12, 2008 - 08:02

Thanks nodestroy,
figured the puser array wasn't loading the users info. I tried some test outputs and got nothing back.

<?php
echo "Test-output: ". $node->uid;
?>

Outputed:
"Test-output:"

Could it be something to do with the panles and where the block is being viewed? Perhaps the array is out of alignment with where it needs to be accessing.. if you see what I mean?

#14

BeechyBoy - March 12, 2008 - 09:19

If you' ve ever used Panels 2 for this, do you think it could be something to do with the 'contexts' getting passed? Let me know if more explanation of this is required.

#15

nodestroy - March 13, 2008 - 11:25

i think, this is a panels issue.

you have to get the node->uid from the node you embed the panel, then your php snippet should work. please create a panels issue to get your needed informations.

your user profile -> block -> panel -> snippet
^- contains the uid you need (has to be available when executing the php code)

regards,
dominik

#16

majsan - March 27, 2008 - 20:31

I get about the same problem. I get
mypath/buddy/add/0?destination=user/3
which gives me "The user doesn't exist".

I use clean URLs but that shouldn't matter, should it?

#17

criz - March 29, 2008 - 21:37

If you want to use the snippet in a block outside a node or the userpage, you will have to care that $uid is available. $node would not be available then.

How do you do this? It depends where you want do display your block. Assuming you want to display the block in context to the userpage (/user/UID) you would have to change

 
  //load profile-user object
  $puser = user_load(array('uid' => $node->uid));

into

  //load profile-user object
  if (arg(0) == 'user' && is_numeric(arg(1))) {
    $uid = arg(1);
    $puser = user_load(array('uid' => $uid));
  }

But I have not tested this, please report back. If you use Panels or you want to display the block in context to a node (e.g. userprofile as node) you would have to load $uid in a different way (I guess with panels2 you will have to work with arguments). Maybe we could sum up this stuff in the documentation section sometimes.

#18

majsan - April 1, 2008 - 17:02

I do not use panels but have exactly the same problem.

(This is reply to #14)

 
 

Drupal is a registered trademark of Dries Buytaert.