aboutsummaryrefslogtreecommitdiff
path: root/actions/friends/remove.php
blob: 76716ebe651870dd653a8ce17129730d672a9d7b (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
27
<?php
/**
 * @override actions/friends/remove.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('friends:remove:failure', array($friend->name)));
	forward(REFERER);
}

if(check_entity_relationship($user->guid, "friend", $friend->guid)) {
	try {
		$user->removeFriend($friend->guid);
		if(check_entity_relationship($friend->guid, "friend", $user->guid)){
			$friend->removeFriend($user->guid);
		}
	} catch (Exception $e) {
		register_error(elgg_echo('friends:remove:failure', array($friend->name)));
		forward(REFERER);
	}
}

system_message(elgg_echo('friends:remove:successful', array($friend->name)));
forward(REFERER);