aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2011-12-08 19:15:33 +0100
committerSem <sembrestels@riseup.net>2011-12-08 19:15:33 +0100
commit5c4dc1474ae89437f52101039f1452c267c252a7 (patch)
treed79e54a330b9682f635b21bafbce58157fe45650
parentf14c7d977d57e7a2cca8bff8931a56fe405cf50c (diff)
downloadelgg-5c4dc1474ae89437f52101039f1452c267c252a7.tar.gz
elgg-5c4dc1474ae89437f52101039f1452c267c252a7.tar.bz2
Added friend/remove and friendrequest/decline actions.
-rwxr-xr-xactions/friendrequest/decline.php12
-rw-r--r--actions/friends/add.php3
-rw-r--r--actions/friends/remove.php24
-rw-r--r--start.php7
4 files changed, 41 insertions, 5 deletions
diff --git a/actions/friendrequest/decline.php b/actions/friendrequest/decline.php
new file mode 100755
index 000000000..5b48acfb4
--- /dev/null
+++ b/actions/friendrequest/decline.php
@@ -0,0 +1,12 @@
+<?php
+
+$user = elgg_get_logged_in_user_entity();
+$friend = get_entity(sanitize_int(get_input("guid")));
+
+if(remove_entity_relationship($friend->guid, 'friendrequest', $user->guid)) {
+ system_message(elgg_echo("friendrequest:remove:success"));
+} else {
+ system_message(elgg_echo("friendrequest:remove:fail"));
+}
+
+forward(REFERER);
diff --git a/actions/friends/add.php b/actions/friends/add.php
index 702a384d3..5d4ecc078 100644
--- a/actions/friends/add.php
+++ b/actions/friends/add.php
@@ -9,7 +9,8 @@ if(!elgg_instanceof($friend, 'user')){
}
if(check_entity_relationship($friend->guid, "friendrequest", $user->guid)
- || check_entity_relationship($friend->guid, "friend", $user->guid)) {
+ || check_entity_relationship($friend->guid, "friend", $user->guid)) {
+
$user->addFriend($friend->guid);
remove_entity_relationship($friend->guid, "friendrequest", $user->guid);
diff --git a/actions/friends/remove.php b/actions/friends/remove.php
new file mode 100644
index 000000000..4ba7bc572
--- /dev/null
+++ b/actions/friends/remove.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: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('friendrequest:remove:failure', array($friend->name)));
+ forward(REFERER);
+ }
+}
+
+system_message(elgg_echo('friendrequest:remove:successful', array($friend->name)));
+forward(REFERER);
diff --git a/start.php b/start.php
index 0b38a341d..e044cc9b5 100644
--- a/start.php
+++ b/start.php
@@ -22,15 +22,14 @@ function friendrequest_init() {
elgg_register_menu_item('page', $params);
}
- $actions_dir = elgg_get_plugins_path().'friendrequest/actions/friendrequest';
- elgg_register_action('friendrequest/approve', "$actions_dir/approve.php");
- elgg_register_action('friendrequest/decline', "$actions_dir/decline.php");
-
//We need to override the friend remove action to remove the relationship we created
$actions_dir = elgg_get_plugins_path().'friendrequest/actions/friends';
elgg_register_action('friends/add', "$actions_dir/add.php");
elgg_register_action('friends/remove', "$actions_dir/remove.php");
+ $actions_dir = elgg_get_plugins_path().'friendrequest/actions/friendrequest';
+ elgg_register_action('friendrequest/decline', "$actions_dir/decline.php");
+
//Regular Elgg engine sends out an email via an event. The 400 priority will let us run first.
//Then we return false to stop the event chain. The normal event handler will never get to run.
//elgg_register_event_handler('create', 'friend', 'friendrequest_event_create_friend', 400);