diff options
author | Sem <sembrestels@riseup.net> | 2011-12-08 18:48:23 +0100 |
---|---|---|
committer | Sem <sembrestels@riseup.net> | 2011-12-08 18:48:23 +0100 |
commit | f14c7d977d57e7a2cca8bff8931a56fe405cf50c (patch) | |
tree | 5bbeae34cbbaf240dcc9f29a95da9a4b508e004b /actions | |
parent | 306844a74237a26ea332468e78c9b5732e3e5fa7 (diff) | |
download | elgg-f14c7d977d57e7a2cca8bff8931a56fe405cf50c.tar.gz elgg-f14c7d977d57e7a2cca8bff8931a56fe405cf50c.tar.bz2 |
Add friend refactored.
Diffstat (limited to 'actions')
-rw-r--r-- | actions/friends/add.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/actions/friends/add.php b/actions/friends/add.php new file mode 100644 index 000000000..702a384d3 --- /dev/null +++ b/actions/friends/add.php @@ -0,0 +1,24 @@ +<?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); + + 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); |