aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2011-12-08 18:48:23 +0100
committerSem <sembrestels@riseup.net>2011-12-08 18:48:23 +0100
commitf14c7d977d57e7a2cca8bff8931a56fe405cf50c (patch)
tree5bbeae34cbbaf240dcc9f29a95da9a4b508e004b
parent306844a74237a26ea332468e78c9b5732e3e5fa7 (diff)
downloadelgg-f14c7d977d57e7a2cca8bff8931a56fe405cf50c.tar.gz
elgg-f14c7d977d57e7a2cca8bff8931a56fe405cf50c.tar.bz2
Add friend refactored.
-rw-r--r--actions/friends/add.php24
-rw-r--r--languages/en.php6
-rw-r--r--start.php17
3 files changed, 43 insertions, 4 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);
diff --git a/languages/en.php b/languages/en.php
index 346ea0633..1f9e88a46 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -6,6 +6,12 @@
$english = array(
'friendrequest' => 'Friend Requests',
+
+ 'friendrequest:add:successful' => 'You sent a friend request to %s. She has to accept it. Give she time.',
+ 'friendrequest:add:failure' => 'Oops! There was a problem while trying to send the request. Try it again.',
+ 'friendrequest:add:exists' => 'You already sent a friend request to %s, don\'t be so intense.',
+
+
);
add_translation('en', $english);
diff --git a/start.php b/start.php
index 744a3ef84..0b38a341d 100644
--- a/start.php
+++ b/start.php
@@ -27,7 +27,9 @@ function friendrequest_init() {
elgg_register_action('friendrequest/decline', "$actions_dir/decline.php");
//We need to override the friend remove action to remove the relationship we created
- elgg_register_action('friends/remove', "$actions_dir/removefriend.php");
+ $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");
//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.
@@ -58,10 +60,17 @@ function friendrequest_page_handler($page){
return true;
}
-function friendrequest_event_create_friend(){
-
+function friendrequest_event_create_friend($event, $object_type, $object){
+ if (($object instanceof ElggRelationship) && ($event == 'create') && ($object_type == 'friend')) {
+ //We don't want anything happening here... (no email/etc)
+
+ //Returning false will interrupt the rest of the chain.
+ //The normal handler for the create friend event has a priority of 500 so it will never be called.
+ return false;
+ }
+ return true; //Shouldn't get here...
}
-function friendrequest_event_create_friendrequest(){
+function friendrequest_event_create_friendrequest($event, $object_type, $object){
}