If you are usign the user relationship module in Drupal and want to print an "Add as a friend" link somewhere in the theme, views, etc and you want to preserve the AJAX goodness this is how you do it.
[syntaxhighlighter] <?php print l(t('Add as a friend'),'relationship/'.$friend->uid.'/request/1',array('html'=> true, 'query'=> drupal_get_destination(), 'attributes'=> array('class'=>'user_relationships_popup_link'))); ?>[/syntaxhighlighter]
The AJAX magic is done by the class "user_relationships_popup_link'.
You should make some checks to see if the user is already a friend or if the user is logged in to see the "add friend" link. And check to see if you're not looking at your own profile, so you don't add the link for you to become your own friend.
To check if you already have a relantionship with an user use this:
if ($relationships = user_relationships_load(array('between' => array($user->uid, $friend->uid),'approved' => 0))) {
print '<div class="user-flags">'.t('You have a pending friend request with this user').'</div>';
}
if ($relationships = user_relationships_load(array('between' => array($user->uid, $friend->uid),'approved' => 1))) {
print '<div class="user-flags">'.t('This is a friend').'</div>';
}
$friend->uid is the UID of the user you are trying to add as a friend.