]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Add friend refactored.
authorSem <sembrestels@riseup.net>
Thu, 8 Dec 2011 17:48:23 +0000 (18:48 +0100)
committerSem <sembrestels@riseup.net>
Thu, 8 Dec 2011 17:48:23 +0000 (18:48 +0100)
actions/friends/add.php [new file with mode: 0644]
languages/en.php
start.php

diff --git a/actions/friends/add.php b/actions/friends/add.php
new file mode 100644 (file)
index 0000000..702a384
--- /dev/null
@@ -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);
index 346ea06337d61ff0cd34792dd68c2be1fa9da0ad..1f9e88a46a96c10d5324f72735ed830f42b774a7 100644 (file)
@@ -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);
index 744a3ef84ff8d85855df7a3cc4e03e430a55e284..0b38a341def0f1a6f2cd0b9d57ca94cf73e069d8 100644 (file)
--- 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){
        
 }