summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.txt4
-rw-r--r--buddylist.module265
-rw-r--r--buddylist.mysql9
3 files changed, 163 insertions, 115 deletions
diff --git a/README.txt b/README.txt
index 23b1695..f0c3ffa 100644
--- a/README.txt
+++ b/README.txt
@@ -3,5 +3,7 @@ Readme
This module allows users to put each other on a personal 'Buddy List' ,
also enabling them to keep up with their friend's postings via the 'My Friend's Blogs' block.
-Send comments to adrian@daemon.co.za.
+Users may put their buddies into groups, like many instant messaging applications. These groups may be used for controlling access to nodes using the buddylist_access.module
+
+Send comments to walkah@walkah.net.
diff --git a/buddylist.module b/buddylist.module
index 0d5d299..06ed4a4 100644
--- a/buddylist.module
+++ b/buddylist.module
@@ -4,11 +4,13 @@
/**
* Implementation of hook_help
*/
-function buddylist_help($field) {
- switch ($field) {
+function buddylist_help($section) {
+ switch ($section) {
case 'admin/modules#description':
return t('Enable buddy list functionality.');
- case 'admin/help#buddylist':
+ case (strpos($section, 'buddies/groups/edit') !== FALSE):
+ return t('Enter a comma-separated list of groups for each buddy (Example: work, immediate family, friends).');
+ case 'admin/help#buddylist':
$output = t("
<p>Buddy list enables users to keep a list of buddies from their social network in their user account. Users can also track what their buddies are posting to the site. Furthermore, they can track their <i>buddies'</i> buddies and thereby explore their social network.</p>
<p>If the administrator has enabled the profile module, users can add buddies via their buddies' user profiles. On the \"View\" tab of each user's profile, there is a \"Buddy list\" section. Select the 'add buddy' action to add the user to your buddy list. If a user is already in your buddy list, the 'delete' action will remove the buddy. Administrators can also enable the buddylist block. This block allows you to see a list of your buddies. If the Friends Of A Friend (FOAF) module is enabled, it will be possible to share buddy lists with other FOAF-aware social networking applications.</p>
@@ -33,23 +35,25 @@ array('%Userprofiles' => url('/profile'),
/**
* Public API for retrieving buddies. Feel free to use this from other
* modules.
+ * $key can be 'uid' or 'label'.
*/
-function buddylist_get_buddies($uid = NULL) {
+function buddylist_get_buddies($uid = NULL, $key = 'uid') {
static $buddies;
if (!$uid) {
global $user;
$uid = $user->uid;
}
- if (!isset($buddies[$uid])) {
- $buddies[$uid] = array();
- $sql = "SELECT b.buddy as uid, u.name, u.mail FROM {buddylist} b INNER JOIN {users} u ON b.buddy = u.uid WHERE b.uid = %d ORDER BY b.timestamp DESC";
+ if (!isset($buddies[$uid][$key])) {
+ $buddies[$uid][$key] = array();
+ $sql = "SELECT b.buddy as uid, b.label, u.name, u.mail FROM {buddylist} b INNER JOIN {users} u ON b.buddy = u.uid WHERE b.uid = %d ORDER BY b.timestamp, b.label DESC";
$result = db_query($sql, $uid);
while ($row = db_fetch_object($result)) {
- $buddies[$uid][$row->uid] = (object) array('uid' => $row->uid, 'name' => $row->name, 'mail' => $row->mail);
+ $nonkey = $key == 'uid' ? 'label' : 'uid';
+ $buddies[$uid][$key][$row->$key][$row->$nonkey] = (object) array('uid' => $row->uid, 'name' => $row->name, 'mail' => $row->mail, 'label' => $row->label);
}
}
- return $buddies[$uid];
+ return $buddies[$uid][$key];
}
/**
@@ -60,8 +64,9 @@ function buddylist_select() {
global $user;
if ($buddies = buddylist_get_buddies()) {
- foreach ($buddies as $buddy) {
- $options[$buddy->uid] = $buddy->name;
+ foreach (array_keys($buddies) as $uid) {
+ $account = user_load(array('uid' => $uid));
+ $options[$account->uid] = $account->name;
}
$output = form_select('', 'buddy', $edit['buddy'] ? $edit['buddy'] : '', $options);
return $output;
@@ -69,9 +74,26 @@ function buddylist_select() {
}
/**
+ * Implements a simple single select box suitable for use in a block
+ * or in theme, or in another module, for example.
+ */
+function buddylist_groups_select($uid, $desc, $edit = array()) {
+ if ($buddies = buddylist_get_buddies($uid, 'label')) {
+ $labels = array_keys($buddies);
+ $options = drupal_map_assoc($labels);
+ unset($options['all']);
+ if ($options) {
+ $output = form_select(t('Buddy groups'), 'buddylist_groups', $edit['buddylist_groups'], $options, $desc, 0, TRUE);
+ return $output;
+ }
+ }
+}
+
+/**
* Implementation of hook_settings
*/
function buddylist_settings() {
+ // TODO: move these to block settings
$group .= form_select(t('Number of buddies to list in the user\'s buddy block'), 'buddylist_blocklisting_size', variable_get('buddylist_blocklisting_size', 5), drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), t('This setting controls the maximum number of buddies displayed in a user\'s "buddylist block" given that the "buddylist block" is enabled in the %link.', array('%link' => l(t('block settings'), 'admin/block')) ));
$group .= form_select(t('Number of posts to list in the buddies\' recent posts block'), 'buddylist_posts_block', variable_get('buddylist_posts_block', 7), drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), t('This setting controls the maximum number of posts to display in a user\'s "buddy recent posts" block given that the "buddies\' recent posts" block is enabled in the %link.', array('%link' => l(t('block settings'), 'admin/block')) ));
$group .= form_textfield(t('Block title'), 'buddylist_block_title', variable_get('buddylist_block_title', t('My buddies\' recent posts')), 70, 128, t('This will be the title for the recent buddies post block. If none is specified, the default will be used.'));
@@ -85,8 +107,6 @@ function buddylist_settings() {
}
-
-// TODO. it looks like $type and $edit are unused
function buddylist_setmsg_received($thisuser) {
global $user;
@@ -94,7 +114,7 @@ function buddylist_setmsg_received($thisuser) {
while ($rec = db_fetch_object($check_received)) {
if (($rec->received) and ($thisuser->uid == $user->uid)) {
drupal_set_message(l($rec->name, 'user/'. $rec->uid) .' has added you to his/her buddylist.');
- db_query('UPDATE {buddylist} SET received = 0 WHERE buddy = '. $user->uid);
+ db_query('UPDATE {buddylist} SET received = 0 WHERE buddy = %d', $user->uid);
}
}
}
@@ -114,8 +134,9 @@ function buddylist_user($type, &$edit, &$thisuser, $category = NULL) {
// if thisuser has friends, show friends
$cnt = variable_get('buddylist_prof_buddies', 5);
if ($buddies = buddylist_get_buddies($thisuser->uid)) {
- foreach($buddies as $buddy) {
- $listbuddies[] = $buddy;
+ foreach(array_keys($buddies) as $buddy) {
+ $account = user_load(array('uid' => $buddy));
+ $listbuddies[] = $account;
$i++;
if ($i > $cnt) {
break;
@@ -130,7 +151,7 @@ function buddylist_user($type, &$edit, &$thisuser, $category = NULL) {
$sql = 'SELECT b.uid, u.name FROM {buddylist} b INNER JOIN {users} u ON b.uid = u.uid WHERE b.buddy = %d ORDER BY u.access DESC';
$result = db_query_range($sql, $thisuser->uid, 0, $cnt);
while ($row = db_fetch_object($result)) {
- $listbuddiesof[] = format_name($row);
+ $listbuddiesof[$row->uid] = theme('username', $row);
}
if ($listbuddiesof) {
$output .= form_item(t('Buddy of'), theme('item_list', $listbuddiesof));
@@ -140,19 +161,18 @@ function buddylist_user($type, &$edit, &$thisuser, $category = NULL) {
// 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
// is generated.
- $_SESSION['buddylist_op_destination'] = $_SERVER['HTTP_REFERER'];
if (@in_array($thisuser->uid, array_keys(buddylist_get_buddies($user->uid))) && user_access('maintain buddy list')) {
- $actions[] = l(t('Remove %name from my buddy list', array('%name' => theme('placeholder', $thisuser->name))), 'buddy/delete/' . $thisuser->uid, NULL, NULL, NULL, FALSE, TRUE);
+ $actions[] = l(t('Remove %name from my buddy list', array('%name' => theme('placeholder', $thisuser->name))), 'buddy/delete/' . $thisuser->uid, NULL, drupal_get_destination(), NULL, FALSE, TRUE);
}
else {
if ($user->uid != $thisuser->uid && user_access('maintain buddy list')) {
- $actions[] = l(t('Add %name to my buddy list', array('%name' => theme('placeholder', $thisuser->name))), 'buddy/add/' . $thisuser->uid, NULL, NULL, NULL, FALSE, TRUE);
+ $actions[] = l(t('Add %name to my buddy list', array('%name' => theme('placeholder', $thisuser->name))), 'buddy/add/' . $thisuser->uid, NULL, drupal_get_destination(), NULL, FALSE, TRUE);
}
}
if ($actions) {
$output .= form_item(t('Buddy actions'), theme('item_list', $actions));
}
- return array ('Buddy List' => $output);
+ return array (t('Buddy List') => array($output));
}
}
@@ -171,8 +191,8 @@ function buddylist_block($op = 'list', $delta = 0) {
switch ($delta) {
case 0 : // Shows buddylist block
if ($buddies = buddylist_get_buddies()) {
- foreach ($buddies as $buddy) {
- $users[] = $buddy;
+ foreach (array_keys($buddies) as $buddy) {
+ $users[] = user_load(array('uid' => $buddy));
$i++;
if ($i == variable_get('buddylist_blocklisting_size', 5)) {
break;
@@ -192,8 +212,9 @@ function buddylist_block($op = 'list', $delta = 0) {
break;
case 1: // Shows my buddies recent posts block
-
- $result = db_query_range(db_rewrite_sql('SELECT n.nid, n.format, n.status, n.type, u.uid, u.name, n.created, n.title FROM {buddylist} b LEFT JOIN {node} n ON n.uid=b.buddy LEFT JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND b.uid=%d ORDER BY n.nid DESC'), $user->uid, 0, variable_get('buddylist_posts_block', 7));
+ $buddies = buddylist_get_buddies();
+ $str_buddies = implode(',', array_keys($buddies));
+ $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.status, n.type, u.uid, u.name, n.created, n.title FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND n.uid IN ($str_buddies) ORDER BY n.nid DESC"), 0, variable_get('buddylist_posts_block', 7));
if (db_num_rows($result)) {
$block['subject'] = variable_get('buddylist_block_title', t('My buddies\' recent posts'));
@@ -230,38 +251,44 @@ function buddylist_menu($may_cache) {
$id = arg(1) ? arg(1) : $user->uid;
if ($may_cache) {
$links[] = array('path' => 'buddylist', 'title' => t('my buddylist'), 'access' => user_access('view buddy lists'), 'callback' => 'buddylist_buddylisting_page');
- $links[] = array('path' => 'buddylist/help', 'title' => t(''), 'access' => user_access('maintain buddy list'), 'callback' => 'buddylist_help', 'type' => MENU_CALLBACK);
- }
- elseif ($id) {
- //tabs
- $links[] = array('path' => 'buddylist/'. $id .'/buddies', 'title' => t('buddies'), '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 .'/buddiesof', 'title' => t('buddies of'), 'access' => user_access('view buddy lists'), 'callback' => 'buddylist_buddylisting_page','type' => MENU_LOCAL_TASK, 'weight' => 1, 'callback arguments' => array($id, 'buddiesof'));
- // 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);
- $links[] = array('path' => 'buddylist/'. $id .'/buddies/recent', 'title' => t('recent posts'), 'access' => user_access('view buddy lists'), 'callback' => 'buddylist_buddiesrecent_page', 'type' => MENU_LOCAL_TASK, 'weight' => 1);
- // 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);
- // other callbacks
- $links[] = array('path' => 'buddy/add', 'title' => t('add to buddylist'), 'access' => user_access('maintain buddy list'), 'callback' => 'buddylist_addbuddy', 'type' => MENU_CALLBACK);
- $links[] = array('path' => 'buddy/delete', 'title' => t('delete from buddylist'), 'access' => user_access('maintain buddy list'), 'callback' => 'buddylist_deletebuddy', 'type' => MENU_CALLBACK);
}
+ elseif ($id == $user->uid || user_access('administer users')) {
+ //tabs
+ $links[] = array('path' => 'buddylist/'. $id .'/buddies', 'title' => t('buddies'), '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 .'/buddiesof', 'title' => t('buddies of'), 'access' => user_access('view buddy lists'), 'callback' => 'buddylist_buddylisting_page','type' => MENU_LOCAL_TASK, 'weight' => 1, 'callback arguments' => array($id, 'buddiesof'));
+ // 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'), '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('edit buddy lists'), '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));
+ // other callbacks
+ $links[] = array('path' => 'buddy/add', 'title' => t('add to buddylist'), 'access' => user_access('maintain buddy list'), 'callback' => 'buddylist_addbuddy', 'type' => MENU_CALLBACK);
+ $links[] = array('path' => 'buddy/delete', 'title' => t('delete from buddylist'), 'access' => user_access('maintain buddy list'), 'callback' => 'buddylist_deletebuddy', 'type' => MENU_CALLBACK);
+ }
return $links;
}
/**
* Displays a list of a given user's buddies.
*/
-function buddylist_buddylisting_page($userid = NULL, $mode = 'buddies') {
+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'), 'error');
}
- if (empty($userid)) {
- $userid = $user->uid;
+ if (empty($uid)) {
+ $uid = $user->uid;
+ }
+ elseif ($uid != $user->uid && !user_access('administer users')) {
+ // a normal user caan only view own buddylist
+ drupal_access_denied();
+ exit();
}
- $thisuser = user_load(array('uid' => $userid));
+ $thisuser = user_load(array('uid' => $uid));
drupal_set_title(t('%username\'s buddylist', array('%username' => $thisuser->name)));
$output = '<div class="members">';
@@ -277,12 +304,12 @@ function buddylist_buddylisting_page($userid = NULL, $mode = 'buddies') {
//TODO: use the get_buddies function instead
if ($mode == 'buddies') {
- $sql = "SELECT buddy FROM {buddylist} b INNER JOIN {users} u ON b.buddy = u.uid WHERE b.uid = ". db_escape_string($userid) ." ORDER BY u.access DESC";
+ $sql = "SELECT DISTINCT(buddy) FROM {buddylist} b INNER JOIN {users} u ON b.buddy = u.uid WHERE b.uid = %d ORDER BY u.access DESC";
}
else {
- $sql = "SELECT u.uid as buddy FROM {buddylist} b INNER JOIN {users} u ON b.uid = u.uid WHERE b.buddy = ". db_escape_string($userid) ." ORDER BY u.access DESC";
+ $sql = "SELECT DISTINCT(u.uid) as buddy FROM {buddylist} b INNER JOIN {users} u ON b.uid = u.uid WHERE b.buddy = %d ORDER BY u.access DESC";
}
- $result = pager_query($sql, $buddies_per_page, 0 , NULL);
+ $result = pager_query($sql, $buddies_per_page, 0 , NULL, $uid);
$output .= '<div id="profile">';
@@ -301,19 +328,17 @@ function buddylist_buddylisting_page($userid = NULL, $mode = 'buddies') {
return $output;
}
-function buddylist_buddiesrecent_page() {
+function buddylist_buddiesrecent_page($uid) {
global $user;
- $userid = arg(1);
-
- $thisuser = user_load(array('uid' => $userid));
+ $thisuser = user_load(array('uid' => $uid));
drupal_set_title(t('%username\'s buddylist', array('%username' => $thisuser->name)));
$output = '';
- $result = pager_query(db_rewrite_sql('SELECT n.nid, n.type, n.format, n.status FROM {node} n LEFT JOIN {buddylist} b ON n.uid = b.buddy WHERE n.status = 1 AND b.uid = '. $userid . ' ORDER BY n.nid DESC'), variable_get('default_nodes_main', 10));
+ $result = pager_query(db_rewrite_sql('SELECT n.nid, n.type, n.status FROM {node} n LEFT JOIN {buddylist} b ON n.uid = b.buddy WHERE n.status = 1 AND b.uid = %d ORDER BY n.nid DESC'), variable_get('default_nodes_main', 10), 0, NULL, $uid);
while ($node = db_fetch_object($result)) {
- $output .= node_view(node_load(array('nid' => $node->nid)), 1);
+ $output .= node_view(node_load($node->nid), TRUE);
}
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
$output .= theme('xml_icon', url('buddylist/'. $userid .'/buddies/recent/feed'));
@@ -322,17 +347,74 @@ function buddylist_buddiesrecent_page() {
return $output;
}
+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)));
+
+ $buddies = buddylist_get_buddies($uid, 'label');
+
+ if (count($buddies)) {
+ foreach ($buddies as $label => $users) {
+ $output .= theme('user_list', $users, $label);
+ }
+ }
+ else {
+ $output .= t('No groups');
+ }
+ return $output;
+}
+
+function buddylist_buddiesgroups_form($uid) {
+ $thisuser = user_load(array('uid' => $uid));
+ drupal_set_title(t('%username\'s buddy groups', array('%username' => $thisuser->name)));
+
+ if ($edit = $_POST['edit']) {
+ $sql = "DELETE FROM {buddylist} WHERE uid=%d AND label != 'all'";
+ $result = db_query($sql, $uid);
+ foreach ($edit['buddylist_labels'] as $buddy => $str_labels) {
+ $labels = explode(',', $str_labels);
+ foreach ($labels as $label) {
+ $sql = "INSERT INTO buddylist (uid, buddy, label, timestamp, received) VALUES (%d, %d, '%s', %d, 0)";
+ db_query($sql, $uid, $buddy, trim($label), time());
+ }
+ }
+ drupal_set_message(t('buddy groups saved.'));
+ }
+
+ if ($buddies = buddylist_get_buddies($userid)) {
+ foreach ($buddies as $uid => $accounts) {
+ $items = array();
+ foreach ($accounts as $account) {
+ if ($account->label != 'all') {
+ $items[] = $account->label;
+ }
+ }
+ if (!$val = $edit['buddylist_labels'][$account->uid]) {
+ $val = implode(',', $items);
+ }
+ $rows[] = array(theme('username', $account), form_textfield('', "buddylist_labels]". $account->uid, $val, 70, 255));
+ }
+ $headers = array(t('buddy'), t('buddy groups'));
+ $output .= theme('table', $headers, $rows);
+ $output .= form_button(t('Submit'));
+ return form($output);
+ }
+ else {
+ drupal_set_message(t('No buddy groups'));
+ }
+}
/**
* Feed for buddies recent posts
*/
-function buddylist_buddyfeed() {
+function buddylist_buddyfeed($uid) {
global $user;
- $userid = arg(1);
- $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {buddylist} b ON b.buddy = u.uid WHERE n.status = 1 AND b.uid = '. $userid .' ORDER BY n.nid DESC'));
+ $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {buddylist} b ON b.buddy = u.uid WHERE n.status = 1 AND b.uid = %d ORDER BY n.nid DESC'), $uid);
$channel['title'] = t('Buddies recent posts on %site', array('%site' => variable_get('site_name', 'drupal')));
- $channel['link'] = url('buddylist/'. $userid .'/buddies/recent');
+ $channel['link'] = url('buddylist/'. $uid .'/buddies/recent', NULL, NULL, TRUE);
$channel['description'] = $term->description;
node_feed($result, $channel);
}
@@ -345,21 +427,19 @@ function buddylist_addbuddy($uid) {
if (empty($buddy->name)) {
return t('This user does not exist');
}
- else if (in_array($uid, array_keys(buddylist_get_buddies($user->uid)))) {
+ elseif (in_array($uid, array_keys(buddylist_get_buddies($user->uid)))) {
return t('This user is already on your buddy list');
}
- else if ($user->uid == $uid) {
+ elseif ($user->uid == $uid) {
return t('Cannot add yourself to buddy list');
}
- else {
- if (($_POST['op'] == t('add user')) && $_POST['edit']['confirm']) {
- buddylist_add($uid);
- buddylist_goto_referrer();
- }
+ elseif (($_POST['op'] == t('add user')) && $_POST['edit']['confirm']) {
+ buddylist_add($uid);
+ drupal_goto('buddylist');
+ }
- return theme('confirm', t('Add user %name to your buddy list?', array('%name' => $buddy->name)), 'user',
+ return theme('confirm', t('Add user %name to your buddy list?', array('%name' => $buddy->name)), 'user',
t('%name will be be notified the next time s/he logs in.', array('%name' => $buddy->name)), t('add user'));
- }
}
function buddylist_deletebuddy($uid) {
@@ -372,14 +452,13 @@ function buddylist_deletebuddy($uid) {
else if (!in_array($uid, array_keys(buddylist_get_buddies($user->uid)))) {
return t('This user is not on your buddy list');
}
- else {
- if (($_POST['op'] == t('remove user')) && $_POST['edit']['confirm']) {
- buddylist_remove($uid);
- buddylist_goto_referrer();
- }
- return theme('confirm', t('Remove user %name from your buddy list?', array('%name' => $buddy->name)), 'user',
- t('%name will be not be notified the next time s/he logs in.', array('%name' => $buddy->name)), t('remove user'));
+ elseif (($_POST['op'] == t('remove user')) && $_POST['edit']['confirm']) {
+ buddylist_remove($uid);
+ drupal_goto('buddylist');
}
+
+ return theme('confirm', t('Remove user %name from your buddy list?', array('%name' => $buddy->name)), 'user',
+ t('%name will be not be notified the next time s/he logs in.', array('%name' => $buddy->name)), t('remove user'));
}
function buddylist_add($id) {
@@ -393,7 +472,8 @@ function buddylist_add($id) {
// buddylist.received set back to 0 when user logs in along with being informed of new buddy
drupal_set_message(t('%username has been added to your buddy list', array('%username' => theme('placeholder', $user_to_add->name))));
- } else {
+ }
+ else {
drupal_set_message(t('%username is already on your buddylist', array('%username' => theme('placeholder', $user_to_add->name))));
}
}
@@ -412,42 +492,5 @@ function buddylist_cancel_add($id) {
function buddylist_cancel_remove($id) {
$thisuser = user_load(array('uid' => $id));
- drupal_set_message(t('User %name was NOT removed to your buddylist.', array('%name' => theme('placehodler', $thisuser->name))));
+ drupal_set_message(t('User %name was NOT removed to your buddylist.', array('%name' => theme('placeholder', $thisuser->name))));
}
-
-/**
- * This code is used to redirect a browser back to the url that referred the browser
- * to the buddylist_add() or buddylist_remove() actions.
- *
- * Until a patch comes out that allows us to directly pass a complete
- * URL to drupal_goto(), we take the code from drupal_goto, and change
- * the last parameter to str_replace() from a call to url() to the
- * actual url we want to forward to (and have stored in a session variable)
- */
-function buddylist_goto_referrer() {
- // Translate &amp; to simply & in the absolute URL
- $url = str_replace('&amp;', '&', $_SESSION['buddylist_op_destination']);
-
- if (ini_get('session.use_trans_sid') && session_id() && !strstr($url, session_id())) {
- $sid = session_name() . '=' . session_id();
-
- if (strstr($url, '?') && !strstr($url, $sid)) {
- $url = $url .'&'. $sid;
- }
- else {
- $url = $url .'?'. $sid;
- }
- }
-
- // Before the redirect, allow modules to react to the end of the page request.
- module_invoke_all('exit', $url);
- unset($_SESSION['buddylist_op_destination']);
- header('Location: '. $url);
-
- // The "Location" header sends a REDIRECT status code to the http
- // daemon. In some cases this can go wrong, so we make sure none
- // of the code below the drupal_goto() call gets executed when we redirect.
- exit();
-}
-
-?>
diff --git a/buddylist.mysql b/buddylist.mysql
index 159fd31..08eeca2 100644
--- a/buddylist.mysql
+++ b/buddylist.mysql
@@ -2,6 +2,9 @@ CREATE TABLE buddylist (
uid int(10) UNSIGNED NOT NULL,
buddy int(10) UNSIGNED NOT NULL,
timestamp int(11) NOT NULL,
- PRIMARY KEY (uid, buddy)
-);
-ALTER TABLE buddylist ADD received tinyint(1) NOT NULL;
+ `received` tinyint(1) NOT NULL default '0',
+ `label` varchar(255) NOT NULL default 'all',
+ UNIQUE KEY `uid-buddy-label` (`uid`,`buddy`,`label`),
+ KEY `uid` (`uid`),
+ KEY `label` (`label`)
+); \ No newline at end of file