Creating a buddy list system in Drupal

Creating a buddy list system in Drupal

Anyone who has used a social networking site won’t have failed to notice the importance of having a buddy or friend list system to allow site users to connect with each other.
So in this simple tutorial I’m going to show you how to create a buddy list system in Drupal using the buddylist 1 module.

Which module(s) to use
As some of you may have noticed there are two versions of the buddylist module; version 1 and version 2 (buddy API) as well as the relatively new friend module for Drupal 6 and the User Relationships module, so it’s important you choose the module that suites you needs and site the best.
I choose version 1 of the buddy list module because I only wanted to deploy a simple buddy system on DrupalSN. Version 1 is very lightweight and integrates with the views and the activity modules as well as providing a built in notifications (email) system.
If you wanted to create a more complex buddy system with buddy shortest route (a la Facebook) and buddy privacy settings it’s worth looking at the buddylist2 and the user relationships module as they provide API’s that you can interact with. Both these modules provide all the functionality of the buddy list module and more but if you only want a simple system they can be overkill.

One last thing on the modules, I’m not saying any of these modules are better than each other as I haven’t fully tested them all, they all offer something slightly different so it’s down to you which one suites your site the best. For this tutorial I’ll be using version 1 of the buddy list module.

Buddylist Module Setup
You can download the latest version of the buddy list module I’m using at http://drupal.org/project/buddylist and the first thing you will need to download and install this module. Please refer to http://drupal.org/node/70151 for help with installing modules and themes.

Once you’ve installed the module the configuration settings can all be found at http://yoursite.com/admin/settings/buddylist and it only takes a few simple steps to get up and running.

1) General settings
For a traditional social network setup you should select “Yes” under “Require Approval”. This will mean users have to confirm buddy requests before they made official. ie. User A makes a request to user B and user B then has to decide if they want to accept user A’s buddy request.
Selecting “No” under “Require Approval” is more like a site user just keeping a list of contacts rather than buddies as no approval is required.

2) Profile page options and Buddylist block options
The settings in these fieldsets are to do with the display of buddies in user profiles and blocks. My personal preference is to ignore these and set up these displays using the views module as it gives you a bit more freedom, I’m planning to cover this in a future tutorial so keep checking the site for more on this.

3) email
Screen shotThis is one of the most important parts of the buddy list configuration. This is where you select when a user should be notified (emailed) about buddy requests and confirmations and also where you can input custom email content if you like. That said the default email content provided by the module is sufficient for most sites.

A classic buddy system like on Facebook will notify users when they have a new buddy request and when a request they made has been accepted, so that’s the setup I recommend. For this setup you should enable the bottom two options as per the screen grab on the right.

That’s the basic setup you need for your buddy system done.

Custom theming
The buddy list module offers a number of theme functions that you can override to fit your needs. For example all of the buddy add, remove, accept/reject links could be overridden using your theme to use icons instead of links as I’ve done on DrupalSN, or you could simple change the link text (see below).

I’ll briefly run over an example below but if you’d like to know more about how to overridden theme function you should check out one of my previous tutorials @ http://drupalsn.com/drupal-tutorials/drupal-theme-function-overriding.

So for this example I’ll quickly change the default “Add to buddy list” link on line 757 of the buddylist module to read “Add USERNAME to my buddy list” where USERNAME is the name of the user to be added.

Old code:

uid, array(‘title’ => t(‘Add User’)), drupal_get_destination(), NULL, FALSE, TRUE);
}
?>
New code to add to your themes template.php file:

$buddyuser->name));
return l($title, ‘buddy/add/’ . $buddyuser->uid, array(‘title’ => $title), drupal_get_destination(), NULL, FALSE, TRUE);
}
?>
You could use this same principle with all the theme functions offered by the buddy list module, check out from line 740 in the buddy list module or do a code search (for theme_) to view the available theme functions.

Taking it further
By now you should have your basic buddy list system up and running, so I’m briefly going to take a look some other contrib. modules you could look at in order to take your buddy system to the next step.

1) Invite module
This module does exactly as the name suggests; it invites users to a site and it integrates with the buddy list module (see the contrib. folder within the buddy list module folder) so that invited users automatically become buddies of the person who invited them to the site.
It’s a great way of promoting your site as well as creating buddy connections.

2) Userpoints
This collection is collection of modules that run off the userpoints API that allows you to give users points or credits when they complete tasks on your site. So you could offer users points for adding buddies and then reward the users with a high amount of points.

3) Activity
The Activity module keeps track of the things people do on your site and provides mini-feeds of these activities and it integrates with the buddy list module so you could provide users with their buddies “activity” on your site.

4) CCK Field Privacy
This module allows users to restrict access to certain fields on nodes they have created, so users could use it restrict access to certain node information to just their buddies.
There is also some development happening and patches available for the profile privacy module so users can restrict access certain profile fields to just their buddies. View the thread @ http://drupal.org/node/156082.

Well, I hope that this tutorial has helped you get your buddy list system up and running and hopefully it’s given you an insight into the options that are available to you. I know this wasn’t the most practical tutorial but I hope you’ve found it interesting, as always please leave your comments and suggestions below.

Thanks for reading!

Leave a Reply

Your email address will not be published. Required fields are marked *