### Eclipse Workspace Patch 1.0
#P buddylist
Index: buddylist.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/buddylist/buddylist.module,v
retrieving revision 1.65
diff -u -r1.65 buddylist.module
--- buddylist.module	5 Jul 2006 09:36:37 -0000	1.65
+++ buddylist.module	6 Jul 2006 05:21:26 -0000
@@ -60,24 +60,34 @@
 
   $links = array();
   $id = is_numeric(arg(1)) ? arg(1) : $user->uid;
+
   if ($may_cache) {
-    $links[] = array('path' => 'buddylist', 'title' => t('my %buddylist', buddylist_translation()), 'access' => (user_access('view buddy lists') && $user->uid), 'callback' => 'buddylist_buddylisting_page');
+    // my buddylist menu item
+    $links[] = array('path' => 'buddylist', 'title' => t('my %buddylist', buddylist_translation()), 'access' => (user_access('maintain buddy list') && $id), 'callback' => 'buddylist_buddylisting_page', 'callback arguments' => array($user->uid,'buddies'));
   }
-  elseif ($id == $user->uid || user_access('administer users')) {
-    //tabs
-      $links[] = array('path' => 'buddylist/'. $id .'/buddies', 'title' => t('%buddies', buddylist_translation()), 'access' => user_access('view buddy lists'), 'callback' => 'buddylist_buddylisting_page', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -1, 'callback arguments' => array($id));
-      $links[] = array('path' => 'buddylist/'. $id .'/buddyof', 'title' => t('%buddyof', buddylist_translation()), 'access' => user_access('view buddy lists'), 'callback' => 'buddylist_buddylisting_page','type' => MENU_LOCAL_TASK, 'weight' => 1, 'callback arguments' => array($id, 'buddyof'));
+  else {
+    // 'edit access' only granted to user's own buddy list or to administrative users
+    $editAccess = (($id == $user->uid && user_access('maintain buddy list') && $user->uid) || user_access('administer users'));
+    $links[] = array('path' => 'buddylist/'. $id .'/buddies/groups/edit', 'title' => t('edit groups'), 'access' => $editAccess, 'callback' => 'buddylist_buddiesgroups_form', 'type' => MENU_LOCAL_TASK, 'weight' => 3, 'callback arguments' => array($id));
+    $links[] = array('path' => 'buddy/add', 'title' => t('add to %buddylist', buddylist_translation()), 'access' => $editAccess, 'callback' => 'buddylist_addbuddy', 'type' => MENU_CALLBACK);
+    $links[] = array('path' => 'buddy/delete', 'title' => t('delete from %buddylist', buddylist_translation()), 'access' => $editAccess, 'callback' => 'buddylist_deletebuddy', 'type' => MENU_CALLBACK);
+    
+    // 'view only' tabs
+    $viewAccess = (($id == $user->uid) || user_access('view buddy lists'));
+    $links[] = array('path' => 'buddylist/'. $id .'/buddies', 'title' => t('%buddies', buddylist_translation()), 'access' => $viewAccess, 'callback' => 'buddylist_buddylisting_page', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -1, 'callback arguments' => array($id));
+    $links[] = array('path' => 'buddylist/'. $id .'/buddyof', 'title' => t('%buddyof', buddylist_translation()), 'access' => $viewAccess, 'callback' => 'buddylist_buddylisting_page','type' => MENU_LOCAL_TASK, 'weight' => 1, 'callback arguments' => array($id, 'buddyof'));
     // subtabs
-      $links[] = array('path' => 'buddylist/'. $id .'/buddies/list', 'title' => t('list'), 'access' => user_access('view buddy lists'), 'callback' => 'buddylist_buddylisting_page', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -1, 'callback arguments' => array($id));
-      $links[] = array('path' => 'buddylist/'. $id .'/buddies/recent', 'title' => t('recent posts'), 'access' => (user_access('view buddy lists') && module_exist('tracker')), 'callback' => 'buddylist_buddiesrecent_page', 'type' => MENU_LOCAL_TASK, 'weight' => 1, 'callback arguments' => array($id));
-      $links[] = array('path' => 'buddylist/'. $id .'/buddies/groups/view', 'title' => t('view groups'), 'access' => user_access('view buddy lists'), 'callback' => 'buddylist_buddiesgroups_page', 'type' => MENU_LOCAL_TASK, 'weight' => 2, 'callback arguments' => array($id));
-      $links[] = array('path' => 'buddylist/'. $id .'/buddies/groups/edit', 'title' => t('edit groups'), 'access' => user_access('maintain buddy list'), 'callback' => 'buddylist_buddiesgroups_form', 'type' => MENU_LOCAL_TASK, 'weight' => 3, 'callback arguments' => array($id));
-    // RSS feeds
-      $links[] = array('path' => 'buddylist/'. $id .'/buddies/recent/feed', 'title' => t('xml feed'), 'access' => user_access('view buddy lists'), 'callback' => 'buddylist_buddyfeed', 'type' => MENU_CALLBACK, 'callback arguments' => array($id));
+    $links[] = array('path' => 'buddylist/'. $id .'/buddies/list', 'title' => t('list'), 'access' => $viewAccess, 'callback' => 'buddylist_buddylisting_page', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -1, 'callback arguments' => array($id));
+    $links[] = array('path' => 'buddylist/'. $id .'/buddies/recent', 'title' => t('recent posts'), 'access' => ($viewAccess && module_exist('tracker')), 'callback' => 'buddylist_buddiesrecent_page', 'type' => MENU_LOCAL_TASK, 'weight' => 1, 'callback arguments' => array($id));
+    $links[] = array('path' => 'buddylist/'. $id .'/buddies/groups/view', 'title' => t('view groups'), 'access' => $viewAccess, 'callback' => 'buddylist_buddiesgroups_page', 'type' => MENU_LOCAL_TASK, 'weight' => 2, 'callback arguments' => array($id));
     // other callbacks
-      $links[] = array('path' => 'buddy/add', 'title' => t('add to %buddylist', buddylist_translation()), 'access' => user_access('maintain buddy list'), 'callback' => 'buddylist_addbuddy', 'type' => MENU_CALLBACK);
-      $links[] = array('path' => 'buddy/delete', 'title' => t('delete from %buddylist', buddylist_translation()), 'access' => user_access('maintain buddy list'), 'callback' => 'buddylist_deletebuddy', 'type' => MENU_CALLBACK);
-  }
+    if ($id != $user->uid) {
+      // This callback can interfere with the 'my buddylist' menu item, so we only load it if the user is viewing another user's list.
+      $links[] = array('path' => 'buddylist/'. $id, 'title' => t('%buddylist', buddylist_translation()), 'access' => (($viewAccess || $editAccess) && $id), 'callback' => 'buddylist_buddylisting_page', 'type' => MENU_CALLBACK, 'callback arguments' => array($id));
+    }
+    $links[] = array('path' => 'buddylist/'. $id .'/buddies/recent/feed', 'title' => t('xml feed'), 'access' => $viewAccess, 'callback' => 'buddylist_buddyfeed', 'type' => MENU_CALLBACK, 'callback arguments' => array($id));
+  } 
+  
   return $links;
 }
 
@@ -85,6 +95,7 @@
  * Implementation of hook_settings
  */
 function buddylist_settings() {
+  
   // TODO: move these to block settings
   $form['block_settings'] = array(
     '#type' => 'fieldset',
@@ -146,7 +157,7 @@
 
   $output = array();
   // show any buddylist notifications upon login and upon viewing own profile
-  if (user_access('view buddy lists') && (($type == 'login') || ($type == 'view') && ($thisuser->uid == $user->uid))) {
+  if (user_access('maintain buddy list') && (($type == 'login') || ($type == 'view') && ($thisuser->uid == $user->uid))) {
     buddylist_setmsg_received($thisuser);
   }
 
@@ -177,7 +188,9 @@
     if ($listbuddyof) {
       $output[] = array('title' => t('%Buddy of', buddylist_translation()), 'value' => theme('user_list', $listbuddyof));
     }
-
+  }
+  
+  if ($type == 'view' && user_access('maintain buddy list')) {
     // Check to see whether or not $thisuser is in global $user's buddy list
     // If $thisuser is already in $user's buddy list, a link offering to delete $thisuser from $user's buddy list is generated
     // If $thisuser is not on $user's buddy list, and $thisuser != $user, then a link offering to add $thisuser to $user's buddy list
@@ -376,20 +389,19 @@
  */
 function buddylist_buddylisting_page($uid = NULL, $mode = 'buddies') {
   global $user;
-
+  
   if (!module_exist('profile')) {
     drupal_set_message(t('The %buddylist module requires the profile module to be enabled in order to use this functionality', buddylist_translation()), 'error');
   }
   if (empty($uid)) {
     $uid = $user->uid;
   }
-  elseif ($uid != $user->uid && !user_access('administer users')) {
-    // a normal user can only view own buddylist
-    drupal_access_denied();
+  // Check that the uid is valid, not the anonymous user, and the user exists
+  if (!(is_numeric($uid) && ($uid > 0) && $thisuser = user_load(array('uid' => $uid)))) {
+    drupal_not_found();
     exit();
   }
-
-  $thisuser = user_load(array('uid' => $uid));
+  
   drupal_set_title(t('%username\'s %buddylist', array('%username' => $thisuser->name) + buddylist_translation()));
 
   $output = '<div class="members">';
@@ -420,7 +432,7 @@
     }
   }
   else {
-    $output .= t('none');
+    $output .= theme('placeholder',t('No %buddies found.',buddylist_translation()));
   }
   $output .= '</div>';
   $output .= theme('pager', NULL, $buddies_per_page);
@@ -452,6 +464,7 @@
 }
 
 function buddylist_buddiesgroups_page($uid) {
+  global $user;
   $thisuser = user_load(array('uid' => $uid));
   drupal_set_title(t('%username\'s %buddy groups', array('%username' => $thisuser->name) + buddylist_translation()));
 
@@ -464,7 +477,10 @@
   }
 
   if (count($groups) == 0) {
-    drupal_set_message(t("You don't have any groups defined. To organize your %buddies into groups, visit the %edit_groups page", array('%edit_groups' => l(t('edit_groups'), "buddylist/$uid/buddies/groups/edit")) + buddylist_translation()));
+    if ($thisuser->uid == $user->uid) {
+      drupal_set_message(t("To organize your %buddies into groups, visit the %edit_groups page", array('%edit_groups' => l(t('edit groups'), "buddylist/$uid/buddies/groups/edit")) + buddylist_translation()));
+    }
+    return theme('placeholder',t("No groups found."));
   }
 
   $buddies = buddylist_get_buddies($thisuser->uid);
@@ -585,7 +601,8 @@
     return theme('buddylist_edit_groups_form', $output);
   }
   else {
-    return theme('placeholder',t('Unable to edit %buddy groups. No %buddies found.', buddylist_translation()));
+    drupal_set_message(t('Unable to edit %buddy groups. Add %buddies to your %buddylist before making groups.', buddylist_translation()));
+    return theme('placeholder',t('No %buddies found.', buddylist_translation()));
   }
 }
 
@@ -694,11 +711,16 @@
  * Feed for buddies recent posts
  */
 function buddylist_buddyfeed($uid) {
+  if (!(is_numeric($uid) && $uid > 0)) {
+  	return drupal_not_found();
+  	exit();
+  }
+  
   $buddy_ids = array_keys(buddylist_get_buddies($uid));
 
   // false query to be used if no posts from buddies are available (as in this user has no buddies).
   $result = db_query('SELECT nid FROM {node} WHERE 0');
-  if (count($buddy_ids > 0)) {
+  if (count($buddy_ids)) {
     $buddy_ids_str = '('. implode(',', $buddy_ids). ')';
     $result = db_query(db_rewrite_sql('SELECT nid FROM {node} WHERE status = 1 AND uid IN %s ORDER BY nid DESC'), $buddy_ids_str);
   }
