Friend Request v1.5

Release Notes

I have helped many users here who came up with problems but never done any pluggin. This is the first and I believe it is good.

This is a very good pluggin originally created by Zac Hopkinson for Elgg version 1.0 which I have modified a bit to be compatible with Elgg version 1.5 . I have seen the Friendship moderation pluggin by webcubes which was suppossed to do the same job as this one will do (Which actually didn't cause I have seen all the frustated users and their comments  here . Well, All the features are listed below:

  • When you request someone to be your friend he/she will get internal visible notification on the topbar and an email will be sent to the use as well to notify about the request.
  • Trying to add the same person again while the add request is pending will throw a message saying "You've already requested to be friends with -username-"
  • Clicking on the link on the topbar will take users to a friendship accept/deny page where he/she can approve or deny to be the other persons friend.
  • If he/she approves then a two way friendship is created between both users.
  • If he/she denys the request is simply dropped and remove the hold on "add freind feature" so that the user can send a friend request again.
  • River notification for new relationship(friendship).

Hope that describes the pluggin and I will be very happy if this is of any help to the community. Any feedback is most welcome.

Professional and affordable website design

My Profile

  • Hi again, i have another problem. I am not sure when was the precise moment where the problem starts, but I think that all begin when I install the plugin “friend request”. I start to have problems with the plugin “members” (that have the basic funciontality of allow fast search of users to add).

     

    I already disable and reconnect the “friend request” plugin and the members plugin, but the problem is still there.

    Despite I disable the plugin “friend request” and disable the plugin “members”, and then re-enable them, continued throwing me the following error message:

     

    "InvalidParameterException

    Todos los Archivos deben tener un propietario (all files must have an owner) "

    Could someone help me with this?

     

    Thanks you!

  • Hi

    Fantastic plugin.
    Ive detected a bug with the translation files

    In the file

    elgg1.6\mod\friend_request\views\default\friendrequest\listing.php

    there are two lines where the terms "APPROVE" and "DENY" are not retrived through elgg_echo funtion, so it is not possible  to translate this terms.

    The corrections are:

    1- Replace line in listing.php

    $info .= '<p><a href="'. $vars['url'] . 'action/friendrequest/approve?guid=' . $guid . '&__elgg_token=' . $token . '&__elgg_ts=' . $ts . '">Approve</a> | ';

    with:
            $info .= '<p><a href="'. $vars['url'] . 'action/friendrequest/approve?guid=' . $guid . '&__elgg_token=' . $token . '&__elgg_ts=' . $ts . '">' . elgg_echo('friendrequest:approve') . '</a> | ';

    2. Replace line in listing.php

    $info .= '<a href="'. $vars['url'] . 'action/friendrequest/decline?guid=' . $guid . '&__elgg_token=' . $token . '&__elgg_ts=' . $ts . '">Deny</a></p>';

    with  
    $info .= '<a href="'. $vars['url'] . 'action/friendrequest/decline?guid=' . $guid . '&__elgg_token=' . $token . '&__elgg_ts=' . $ts . '">' . elgg_echo('friendrequest:deny') . '</a> | ';

    3. Add the corresponding terms in the languages files (en.php, es.php, etc)       

    'friendrequest:approve'=> "Approve",

    'friendrequest:deny'=> "Deny",

  • Thanks for the coding help Jose Br.

  • @antifmradio..........

    Can you send me your site address plz........

  • Hiya,

    Great plugin!

    Just wondered if there is a way to make profile viewing restricted until you add someone as a friend? (Like on Facebook). Or if not, if there is anything similar to this?

     

    Cheers

  • Eveyything works fine for me except,when i click the add friend link.the green box notification isn't displayed.

    When i click it again,it shows the red notification that the friendship has already been requested...

    I am using elgg 1.6.1

  • For whatever reason, it isn't working for me. When I click to add a friend, it gives me a ts_token error. Any ideas?

    Using Elgg 1.5

    Thanks!

     

  • This works FINE on my elgg v1.6.1

  • I am switching "friends" naming to "contacts" how sould I do this with this plugin?

  • I use 1.5 but I assume that the plug in and 1.6 still use the language file.  look for

    /languages/en.php you can change all the wording there

    p.s. en.php is for english  en-being english    -  I only point this out cuz there may be other language files in there.  ; )

  • Hi,

    First off, great plugin - it really fills my needs nicely.

    I also experienced the problem of an invited user who registers not becoming friends automatically.  I looked into it more closely, and it's really not a problem with the invitefriends plugin.  The code for inserting the mutual relationship is initiated in action/register.php.  Ultimately it ends up calling add_entity_relationship() in engine/lib/relationships.php to create the relationship, but that method contains the following after the relationship has been made:

                if (trigger_elgg_event('create', $relationship, $obj)) {
                    return true;
                } else {
                    delete_relationship($result);
                }

    In friend_request's friend_request_event_create_friend() method (in start.php) the event flow is interrupted by returning false.  Now, looking at the code above, when that false bubbles up, it tells the Elgg core to delete the relationship it had just created.

    I thought of a way to work around this.  I wrapped your return of false with a conditional function that checks if the current process is handling a registration action, and if so, it allows the event flow to proceed.  Otherwise it returns it's normal 'false'.

    Here's what I have in friend_request_event_create_friend():
                if (! isRegistering())
                {
                    return false;
                }
    ...
         return true; 

    Here's my code for isRegistering() - much of it was borrowed from the siteaccess plugin!

        /**
         * Examines the request url and returns true if in the process of registering
         * @return boolean Is is code running in response to a register action?
         */
        function isRegistering()
        {
            global $CONFIG;
            $p = parse_url($CONFIG->wwwroot);
            $base_url = $p['scheme'] . "://" . $p['host'];
            if ((isset($p['port'])) && ($p['port']))
            {
                $base_url .= ":" . $p['port'];
            }
            $uri = preg_replace('#\?.*|\#.*#', '', $_SERVER['REQUEST_URI']);
            $url = $base_url . $uri;
           
            return stripos($url, $CONFIG->wwwroot . 'action/register') === 0;
        }

    So now, if an invited person is registering, the Elgg core creates a mutual friend relationship - which is what I want.

    Again, thanks for all your work!

    Mike

  • Hi Mike:

    I make what you recomend in your post, but it didnt work for me.

    What I did is to copy and paste this code exactly as you write it in your post (i copy it into engine/lib/relationships.php):

    function isRegistering()
        {
            global $CONFIG;
            $p = parse_url($CONFIG->wwwroot);
            $base_url = $p['scheme'] . "://" . $p['host'];
            if ((isset($p['port'])) && ($p['port']))
            {
                $base_url .= ":" . $p['port'];
            }
            $uri = preg_replace('#\?.*|\#.*#', '', $_SERVER['REQUEST_URI']);
            $url = $base_url . $uri;
           
            return stripos($url, $CONFIG->wwwroot . 'action/register') === 0;
        }

     

    I also add in engine/lib/relationships.php this

           if (! isRegistering())
                {
                    return false;
                }


    I just copy and past that part of your post, but i didnt change any of the code. I should make any change in any part to adapt it to my implementation? My knowledge of php is not very good, as you can see. Your help would be very important for me.

    Thanks a lot!


    JP

  • Juan Pablo,

    I think the problem is in where you put the:  if (! isRegistering()) part.  You mention that you put this in engine/lib/relationships, but I put mine in /mod/friend_request/start.php.  I modified (my change indicated by the IP override comment) the contents of the following function:

        function friend_request_event_create_friend($event, $object_type, $object) {
            global $CONFIG;
               
            if (($object instanceof ElggRelationship) && ($event == 'create') && ($object_type == 'friend') ) {
                //We don't want anything happening here... (no email/etc)

    //IP - override
    // Reason: We want the default handling TO occur if the user is registering           
                //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.   
                if (! isRegistering())
                {
                    return false;
                }
    //IP - end modification
            }
            return true; //Shouldn't get here...
        }

    I hope that helps.

    Mike

  • I'd like to add a personal message to de friend request email.

    So i added a form:

    // Get the Elgg engine
        require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");

        // If we're not logged on, forward the user elsewhere
        if (!isloggedin()) {
            forward();
        }
       
        $friend_guid = (int) get_input('friend');

        $user = get_entity($friend_guid);

        $naam = $user->name;

       
        $form_body = "<p>Voeg een persoonlijke boodschap toe</p>";
        $form_body .= elgg_view('input/longtext', array('internalname' => 'emailmessage', 'value' =>  'Beste '.$naam.',<br /> '.elgg_echo('friendrequest:message:default')));
        $form_body .=elgg_view('input/hidden', array('internalname' => 'friend', 'value' => $friend_guid));
        $form_body .=elgg_view('input/hidden', array('internalname' => 'post', 'value' => $vars['entity']->id));
        $form_body .= elgg_view('input/submit', array('internalname' => 'submit', 'value' => elgg_echo('send')));
         
       
       
       
        // get the required canvas area
        $body = elgg_view_layout("two_column_left_sidebar", $area1, $area2);
        // Make call on page of the called person
        $area2 = elgg_view_title(elgg_echo('friendrequest'));
       
       
        $area2 .= '$friend_guid:'.$friend_guid.'<br>';
        $area2 .= '$elgg_token:'.$elgg_token.'<br>';
        $area2 .='<p>'.$naam.'</p>';
        $area2 .= elgg_view('input/form', array('body' => $form_body, 'action' => "{$CONFIG->url}action/friends/add", 'method' => 'get'));
        $body = elgg_view_layout("two_column_left_sidebar", $area1, $area2);
        // Draw the page
        page_draw(elgg_echo("profile:call"),$body);

     

    The question is: What is the right way to add the extra personal message to the friend request email (notify_user)

     

  • Oke, here's my own solution to it:

    @ start.php

    function iagree_event_create_friendrequest($event, $object_type, $object, $uitnodiging) {
       
       
        global $CONFIG;
        /*   
        if (($object instanceof ElggRelationship) && ($event == 'create') && ($object_type == 'friendrequest')) {
            $user_one = get_entity($object->guid_one);
            $user_two = get_entity($object->guid_two);
           
            $view_friends_url = $CONFIG->url . "pg/friendrequests";
           
            // Notify target user
            return notify_user(    $object->guid_two,
                                $object->guid_one,
                                sprintf(elgg_echo('friendrequest:newfriend:subject'), $user_one->name),
                                sprintf(elgg_echo("friendrequest:newfriend:body"), $user_one->name, $view_friends_url),
                                elgg_echo($uitnodiging)
                               
                                );
        }
        */
    }

     

     

    @add.php:

     

    <?php
    // Friend request relationship plugin. This action code is based on the regular friend/add action but with a different relationship type.

    //Ensure we're logged in
    gatekeeper();

    //If the user has a referer string then let's send them back to their previous page, otherwise we'll send them to their friend list.
    $forward_url = "mod/mijnpal4members/index.php?h=members:";

    //Get our data
    $friend_guid = (int) get_input('friend');
    $friend = get_entity($friend_guid);
    $user_guid = (int) $_SESSION['guid'];
    $user = get_entity($user_guid);
    $uitnodiging = get_input('emailmessage');
    $errors = false;

    //Now we need to attempt to create the relationship
    if(get_class($user) != "ElggUser" || get_class($friend) != "ElggUser") {
        $errors = true;
        register_error(elgg_echo("friendrequest:add:failure"));
    } else {
        //New for v1.1 - If the other user is already a friend (fan) of this user we should auto-approve the friend request...
        if(check_entity_relationship($friend_guid, "friend", $user_guid)) {
            try {
                if(isset($CONFIG->events['create']['friend'])) {
                    $oldEventHander = $CONFIG->events['create']['friend'];
                    $CONFIG->events['create']['friend'] = array();            //Removes any event handlers
                }

                $user->addFriend($friend_guid);
                system_message(sprintf(elgg_echo("friends:add:successful"),$friend->name));
               
                if(isset($CONFIG->events['create']['friend'])) {
                    $CONFIG->events['create']['friend'] = $oldEventHander;
                }
               
                forward($forward_url);
            } catch (Exception $e) {
                register_error(sprintf(elgg_echo("friends:add:failure"),$friend->name));
                $errors = true;
            }
        } else {
            try {
                $result = add_entity_relationship($user_guid, "friendrequest", $friend_guid);
                if($result == false) {
                    $errors = true;
                    register_error(sprintf(elgg_echo("friendrequest:add:exists"),$friend->name));
                }
            } catch(Exception $e) {    //register_error calls insert_data which CAN raise Exceptions.
                $errors = true;
                register_error(sprintf(elgg_echo("friendrequest:add:exists"),$friend->name));
            }
        }
    }



    if(!$errors) {
        system_message(sprintf(elgg_echo("friendrequest:add:successful"),$friend->name));
    }

    $view_friends_url = $CONFIG->url . "pg/friendrequests";
                $message = sprintf(elgg_echo("friendrequest:newfriend:body"), $user->name, $view_friends_url) ."<br />".elgg_echo($uitnodiging);
                // Notify target user
                return notify_user(    $friend_guid,
                                    $user_guid,
                                    sprintf(elgg_echo('friendrequest:newfriend:subject'), $user->name),
                                    $message
                                   
                                    );

    forward($forward_url);

    ?>

     

     

     

  • Where do I unzip/install this plugin? 

  • really?  elgg 1.5?  are you using 1.5 or a newer version.  i am not positive, but pretty sure this will not work on 1.7 or 1.8.  but in any case you install it into the mod directory

  • @Asmarino: better use this one http://community.elgg.org/plugins/384965/3.2/friend-request as it's for Elgg 1.8 (and I'm pretty sure you are not using any older version...).

bosssumon

I am just a coder. Have got an MSc in Computer Science. Working with Elgg for about 2 years now. I love open source and I love elgg. I have worked in many webdevelopment projects that used open souce applications. A brief portfolio of current websites I am working on can be found at http://dhakawebdesign.com/portfolio.html

Stats

  • Category: Uncategorized
  • License: GNU General Public License (GPL) version 2
  • Updated: 2014-11-17
  • Downloads: 6488
  • Recommendations: 6