How do I add 2 buttons

Add to friends, become a fan

on node.tpl and comment.tpl as next to user name.

Comments

alex.k’s picture

I will look at it tomorrow, I hope, as I don't know this off-hand. Something involving drupal_get_form, i suspect...

alex.k’s picture

Also, have you looked at #319104: how to implement 'one click friend request' for ideas.

Flying Drupalist’s picture

Thanks, I've seen it, but I'm not a coder, so I don't actually know how to adapt his solution.

alex.k’s picture

StatusFileSize
new1.06 KB
new759 bytes

Attached are the snippets since I can't paste html inline.

You need to replace "3" with the id of your relationship type.
Let me know how it works.

Flying Drupalist’s picture

Thank you so much, this works atm, but may I make 2 requests?

Can the buttons be standard links instead, for easier theming, and a variation for 1 - way fan adds. Simply changing it to my second type of relationship type didn't work.

Roulion’s picture

Hi the snppet is working good on comments. However, the request is sent to annonymous instead of comment's author, which is actually quite buggy :p

It would be good to add a "remove relationship" form as well, if there is already a relation between the user and the comment's author.

PS : I tested it on drupal 6.5

Roulion’s picture

StatusFileSize
new4.13 KB
new4.3 KB
new2.37 KB

I just make a little modification to the comment snippet :
you can add or remove relations depending if it's already created or not.
I also make the form appaear as an image

alex.k’s picture

Thank you, @Roulion

unxposed’s picture

What would I need to change to the snippet above to get the add / remove buttons working on the user profile pages?

Thanks!

alex.k’s picture

StatusFileSize
new34.05 KB

@unxposed user_relationships_ui already places all action links onto the user profile, do you have them? See attached for the standard UI. This issue is for comments/nodes, where normally the links are not displayed.

unxposed’s picture

Hi Alex,

Yes I've got those coming up (another issue, but I need to remove them form the main page).

My situation is that I basically want two contextual buttons in the user profile sidebar, I guess in a block, one which says 'add as a friend' when you don't have a relationship with the profile you're looking at, or if you do, a button should appear saying 'delete from friends'... ideally they would be single clicks, no confirmation. What would be the best way of doing this? I thought this post was kind of along the right lines?

alex.k’s picture

That's a little clearer. I think one of the blocks in user_relationship_blocks.module is an 'actions' block. So I want to fix the bugs in #257198: Return the user id of the user to compare with the current user which will probably take care of your request.

As to doing it in one click, a number of users have asked for it, but currently UR's workflow is to always confirm, if the standard links are used. The only way to subvert it is to use submit buttons and a form, like the snippet above.

unxposed’s picture

Okay cool, I'll see if I can style this as desired.

Where is the copy such as 'You have sent a new Friend request to this user' and the html for this being generated out of interest?

Thanks

alex.k’s picture

This is function _user_relationships_ui_actions_between(&$viewer, &$viewed) { in user_relationships_ui.module

unxposed’s picture

Brilliant, thanks again.

Flying Drupalist’s picture

Hi, how do you edit this so that anon users don't show a add to friend link. Thanks.

alex.k’s picture

At the top of the snippet, you just need to add && $comment->uid, so it will look like this:

    // set up variables
    global $user;
    if ($user->uid && $comment->uid) {  //<---- this line has changed
      // when clicked do this
..... snippet continues

This will work for both my and Roulion's versions. Sorry about not adding it right away.

Flying Drupalist’s picture

Status: Active » Fixed

Thanks, works great.

unxposed’s picture

Okay, still trying to work out how to change the class so it's different on the status of the relationship, 1. none, 2. pending 3.friends - doesn't matter what it's called so long as they're different so I can add unique icons... I keep trying different variables but without any luck

$output[] = theme('item_list', $actions, t('Relationship actions'), 'ul', array('class' => 'user_relationships_actions_' . $relationships));

Any ideas on what might work?

Thanks

alex.k’s picture

@unxposed there isn't a way to tag individual links based on their status. Could you patch the functions in user_relationships_ui the way you want it, and submit a patch? The two functions are the one you used, plus _user_relationships_ui_between($viewer, $account). This would help a lot.

ascetic’s picture

thanks for the great snippets,

what should we do to return the submit button to an AJAX confirmation dialog which is integrated on the latest beta9 release?

unxposed’s picture

Hi, sorry. I don't fully understand... there is no variable that gives one value if you are in a relationship with the user you are viewing, and another if not?... isn't one needed to determine whether or not to add the relevent action link on the user page?

I have no idea how to create a patch (plus I'm not sure you're prepared for the damage I've done to your nice code)... but once I'm done I can email you the files if it will help you at all?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

Flying Drupalist’s picture

Status: Closed (fixed) » Active

Has this stopped working?

I did this in node.tpl.php:

        // set up variables
        global $user;
        if ($user->uid) {
          // when clicked do this
          if (isset($_POST['add_submit_1'])) {
            $relationship = user_relationships_request_relationship ($user->uid,$uid,1,false);
            if ($relationship) {
              drupal_set_message(t('your friend request has been submitted'));
            } else {
              drupal_set_message(t('the relationship could not be created'), 'warning');
            }
            drupal_goto();
          }
          if ($user->uid != $uid && !user_relationships_load(array('between' => array($user->uid, $uid), 'rtid' => 1))) {
          
print url(NULL, array('query' => drupal_get_destination())); ">

          }
        }
        

It takes me to ?destination=node%2F163

Rather than the node I was viewing, and no friend request either.

alex.k’s picture

Could you confirm you are using the same snippet as in comment #4, plus correction in #17. In what you pasted there is no < form>...

Have you changed anything else, or updated user_relationships code?

Flying Drupalist’s picture

Version: 6.x-1.x-dev » 6.x-1.0-beta9

Ahh I should update what I'm using now.

Oh the form, I am using what's in #4, I think the d.o input filters probably stripped out the form I tried to paste. But yes it's #4.

[form method="post" action=" print url(NULL, array('query' => drupal_get_destination())); ">
[input type="submit" name="add_submit_1" value="add as friend" id="add_submit">
[/form>

The form looks like this.

alex.k’s picture

I've just tried the code from #4, it worked, no changes. This is using the latest -dev code, but i don't remember that it's different from -beta9. I've tried both a two-way, no approval relationship, and a one-way, approval required relationship. So, something else must have changed in your setup :(

Rosamunda’s picture

subscribing

alex.k’s picture

Status: Active » Postponed (maintainer needs more info)
alex.k’s picture

Assigned: Unassigned » alex.k
Status: Postponed (maintainer needs more info) » Fixed

Please reopen if problem reoccurs.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

Automatically closed -- issue fixed for 2 weeks with no activity.

cincy_kid’s picture

I know this is a slightly different issue, but since it was mentioned earlier in this thread by unxposed, i thought I would ask here..

I have been looking through the user_relationships_ui.module (and various others) at the different functions trying to figure out what code i need to extract to be able do a conditional statement on the user profile page.

the part that basically says:

if user is not already your friend{
print "add to friends"
else
print "remove from friends"
}

I have a user-profile.tpl.php file where I need to put this code into. Currently it just shows the "add to friends" link because thats the only part I have in. It looks like:

<?php if($user->uid != $account->uid): ?>
	 <a href="<?php print base_path()?>relationship/<?php print $account->uid ?>/request/4?destination=user/<?php print $account->uid ?>">Add to Friends</a> 
	<?php endif; ?>

So I need to put in a conditional to show "Remove From Friends" if they are already a Friend...

andrenoronha’s picture

subscribing

andrenoronha’s picture

I have this code outputting the link to add or remove a friend:

$output[] = theme('item_list', $actions, t(' '), 'ul', array('class' => 'user_relationships_actions'));

I tried changing the ul to a div tag because I already have an ul outside it. it works fine in FF but not on IE. It gives me a bug in the css.... the right column goes downward.

i dont know what's happening...

How can I changed it to just a li item?

andrenoronha’s picture

ok nevermind

i got it by using this function

http://www.justin-cook.com/wp/2006/03/31/php-parse-a-string-between-two-...

now it just prints what's in between

  • tags inside my own li tag.