aboutsummaryrefslogtreecommitdiff
path: root/actions/friends/add.php
blob: 1ead0dc9e15947c04fc3f33155f2d528a575d744 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php

$friend = get_entity(sanitize_int(get_input('friend')));
$user = elgg_get_logged_in_user_entity();

if(!elgg_instanceof($friend, 'user')){
	register_error(elgg_echo('friendrequest:add:failure'));
	forward(REFERER);
}

if(check_entity_relationship($friend->guid, "friendrequest", $user->guid)
	|| check_entity_relationship($friend->guid, "friend", $user->guid)) {
	
	$user->addFriend($friend->guid);
	remove_entity_relationship($friend->guid, "friendrequest", $user->guid);
	
	add_to_river('river/relationship/friend/create', 'friend', $user->guid, $friend->guid);
	system_message(elgg_echo("friends:add:successful", array($friend->name)));
	
} elseif(add_entity_relationship($user->guid, "friendrequest", $friend->guid)) {
	system_message(elgg_echo("friendrequest:add:successful", array($friend->name)));
} else {
	register_error(elgg_echo("friendrequest:add:exists", array($friend->name)));
}

forward(REFERER);