aboutsummaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
Diffstat (limited to 'actions')
-rw-r--r--actions/friends/add.php24
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);