/**
  * Adds a user to this user's friends list
  *
  * @param int $friend_guid The GUID of the user to add
  * @return true|false Depending on success
  */
 function addFriend($friend_guid)
 {
     return user_add_friend($this->getGUID(), $friend_guid);
 }
<?php

// Load Elgg engine
include_once dirname(dirname(dirname(__FILE__))) . "/engine/start.php";
// make sure only logged in users can see this page
gatekeeper();
$goto_url = "select_content_items.php";
if ($_POST['add'] == 1) {
    user_add_friend($_POST['cont_it_id'], $_POST['cont_it_added_id']);
} else {
    user_remove_friend($_POST['cont_it_id'], $_POST['cont_it_added_id']);
}
$a = $_POST['cont_it_id'];
echo '<meta HTTP-EQUIV="refresh"  CONTENT="0;URL=' . $goto_url . '?cont_it_id=' . $a . '">';
Esempio n. 3
0
function pleio_api_contact_request_respond($contact_id, $accept)
{
    $user = elgg_get_logged_in_user_entity();
    $contact_id = intval($contact_id);
    $contact = get_user($contact_id);
    $removed = false;
    if ($accept == 2) {
        $removed = remove_entity_relationship($user->guid, 'friendrequest', $contact_id);
    } else {
        $removed = remove_entity_relationship($contact_id, 'friendrequest', $user->guid);
    }
    if ($user && $contact && $removed) {
        if ($accept == 1) {
            if (user_add_friend($user->guid, $contact_id) && user_add_friend($contact_id, $user->guid)) {
                return new SuccessResult(elgg_echo("friend_request:approve:successful", array($contact->name)));
            } else {
                return new SuccessResult(elgg_echo("friend_request:approve:fail", array($contact->name)));
            }
        } elseif ($accept == 2) {
            return new SuccessResult(elgg_echo("friend_request:revoke:success"));
        } else {
            $subject = elgg_echo("friend_request:decline:subject", array($user->name));
            $message = elgg_echo("friend_request:decline:message", array($contact->name, $user->name));
            notify_user($contact_id, $user->guid, $subject, $message);
            return new SuccessResult(elgg_echo("friend_request:decline:success"));
        }
    }
    switch ($accept) {
        case 0:
            return new ErrorResult(elgg_echo("friend_request:decline:fail", array($contact->name)));
        case 1:
            return new ErrorResult(elgg_echo("friend_request:approve:fail", array($contact->name)));
        case 2:
            return new ErrorResult(elgg_echo("friend_request:revoke:fail", array($contact->name)));
    }
}