Index: drupal-modules/buddylist/buddylist.module
===================================================================
--- drupal-modules/buddylist/buddylist.module	(révision 647)
+++ drupal-modules/buddylist/buddylist.module	(copie de travail)
@@ -463,17 +463,23 @@ function buddylist_user($type, &$edit, &
     buddylist_setmsg_received($thisuser);
   }
   if ($type == 'view') {
-    if ($list = buddylist_get_buddylist($thisuser)) {
-      $output[] = array('title' => t('@Buddies', buddylist_translation()), 'value' => $list, 'class' => 'buddylist');
-    }
-    if ($list = buddylist_get_buddylist($thisuser, TRUE)) {
-      $output[] = array('title' => t('@buddy of', buddylist_translation()), 'value' => $list, 'class' => 'buddyoflist');
-    }
-    if ($actions = buddylist_get_buddy_actions($user, $thisuser)) {
-      $output[] = array('title' => t('@Buddy actions', buddylist_translation()), 'value' => theme('item_list', $actions), 'class' => 'buddylist_actions');
+    // Check if the user we are viewing has enabled the buddylist feature
+    if ($thisuser->buddylist_enabled) {
+      if ($list = buddylist_get_buddylist($thisuser)) {
+        $output[] = array('title' => t('@Buddies', buddylist_translation()), 'value' => $list, 'class' => 'buddylist');
+      }
+      if ($list = buddylist_get_buddylist($thisuser, TRUE)) {
+        $output[] = array('title' => t('@buddy of', buddylist_translation()), 'value' => $list, 'class' => 'buddyoflist');
+      }
+      if ($actions = buddylist_get_buddy_actions($user, $thisuser)) {
+        $output[] = array('title' => t('@Buddy actions', buddylist_translation()), 'value' => theme('item_list', $actions), 'class' => 'buddylist_actions');
+      }
+      if(count($output) > 0) {
+        return array(t('@Buddy List', buddylist_translation()) => $output);
+      }
     }
-    if(count($output) > 0) {
-      return array(t('@Buddy List', buddylist_translation()) => $output);
+    else {// if not, don't add the buddylist links
+      return array();
     }
   }
   else if ($type == 'delete') {
@@ -491,6 +497,11 @@ function buddylist_user($type, &$edit, &
       '#type' => 'fieldset',
       '#title' => t('Buddylist settings'),
       '#weight' => 5);
+    $form['buddylist_settings']['buddylist_enabled'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Enable the @buddylist feature', buddylist_translation()),
+                    '#default_value' => isset($edit['buddylist_enabled']) ? $edit['buddylist_enabled'] : 1,
+      '#description' => t('Uncheck this if you don\'t want other users to add you in their @buddylist.', buddylist_translation()));
     $form['buddylist_settings']['buddylist_mail'] = array(
       '#type' => 'checkbox',
       '#title' => t('Receive @buddylist notification mails', buddylist_translation()),
@@ -1395,6 +1406,14 @@ function buddylist_addbuddy($uid) {
   global $user;
   $buddy = user_load(array('uid' => $uid));
 
+  // Has the user enabled the buddylist feature?
+  if (!isset($buddy->buddylist_enabled)) {
+    // if the user has never selected if s/he wants to use the buddylist feature, we enable it by default
+    $buddylist_enabled = true;
+  } else {
+    $buddylist_enabled = $buddy->buddylist_enabled == 1;
+  }
+
   if (empty($buddy->name)) {
     drupal_set_message(t('This user does not exist'));
   }
@@ -1404,6 +1423,10 @@ function buddylist_addbuddy($uid) {
   elseif ($user->uid == $uid) {
     drupal_set_message(t('Cannot add yourself to @buddylist', buddylist_translation()));
   }
+  elseif (!$buddylist_enabled) {
+    drupal_set_message(t('%name has disabled the @Buddylist feature, hence you cannot add him/her into your @buddylist.',
+                       array('%name' => $buddy->name) + buddylist_translation()));
+  }
   else {
     $form['uid'] = array('#type' => 'hidden', '#value' => $uid);
     $form['name'] = array('#type' => 'hidden', '#value' => $buddy->name);
@@ -1499,12 +1522,16 @@ function buddylist_add_request($id) {
   $already_buddies = in_array($id, array_keys(buddylist_get_buddies($user->uid)));
 
   if (!$already_requested && !$already_buddies) {
-    db_query('INSERT INTO {buddylist_pending_requests} (requester_uid, requestee_uid, received) VALUES (%d, %d, %d)', $user->uid, $id, 0);
+    if (variable_get('buddylist_user_mail', FALSE)
+        && isset($buddy->buddylist_enabled) && $buddy->buddylist_enabled) {
+
+      db_query('INSERT INTO {buddylist_pending_requests} (requester_uid, requestee_uid, received) VALUES (%d, %d, %d)', $user->uid, $id, 0);
 
-    if (variable_get('buddylist_send_request', FALSE)) {
-      buddylist_mail_user('request', $user_to_add);
+      if (variable_get('buddylist_send_request', FALSE)) {
+        buddylist_mail_user('request', $user_to_add);
+      }
+      drupal_set_message(t('Your request to add %username to your @buddylist has been submitted.  %username will be notified.', array('%username' => $user_to_add->name) + buddylist_translation()));
     }
-    drupal_set_message(t('Your request to add %username to your @buddylist has been submitted.  %username will be notified.', array('%username' => $user_to_add->name) + buddylist_translation()));
   }
   else {
     if ($already_requested) {
