aboutsummaryrefslogtreecommitdiff
path: root/actions/friends/add.php
blob: 04168c4c3230180478cf87347c97b30fb2f885ae (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
28
29
<?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);

	$friend->addFriend($user->guid);
	remove_entity_relationship($friend->guid, "friendrequest", $user->guid);
	
	add_to_river('river/relationship/friend/create', 'friend', $user->guid, $friend->guid);
	add_to_river('river/relationship/friend/create', 'friend', $friend->guid, $user->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);