summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Douglass2006-12-06 21:22:04 (GMT)
committerRobert Douglass2006-12-06 21:22:04 (GMT)
commite4cefdd63e1c2a4fef977e2c59fc43be593a448d (patch)
tree5fc74bec55e9eae1a77643125507cdfaf2f7da96
parent6172d5d43a9e67c7c15341b559ad8f5a9358dc43 (diff)
#80166 by ankur: optional workflow to send request emails to the user who must approve or deny the request to become buddies.
-rw-r--r--README.txt2
-rwxr-xr-xbuddylist.install39
-rw-r--r--buddylist.module460
3 files changed, 467 insertions, 34 deletions
diff --git a/README.txt b/README.txt
index 725d0e2..5aba284 100644
--- a/README.txt
+++ b/README.txt
@@ -108,6 +108,8 @@ Browsing improvements by Doug Sikora
Maintainer: Robert Douglass
Status: maintained (Feb. 2006)
+Request/Approval Feature by Ankur Rishi, courtesy of Jewcy.com
+
TODO
----
1. PGSQL schema (see buddylist.install, buddylist_install())
diff --git a/buddylist.install b/buddylist.install
index 0ff955d..8c3f3cd 100755
--- a/buddylist.install
+++ b/buddylist.install
@@ -33,8 +33,16 @@ function buddylist_install() {
visible tinyint(1) NOT NULL default '0',
PRIMARY KEY (uid, label_id)
) /*!40100 DEFAULT CHARACTER SET utf8 */;");
+
+ $query4 = db_query("
+ CREATE TABLE {buddylist_pending_requests} (
+ requester_uid int(11) NOT NULL default '0',
+ requestee_uid int(11) NOT NULL default '0',
+ received tinyint(1),
+ PRIMARY KEY (requester_uid, requestee_uid)
+ ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
- if ($query1 && $query2 && $query3) {
+ if ($query1 && $query2 && $query3 && $query4) {
$created = TRUE;
}
break;
@@ -50,3 +58,32 @@ function buddylist_install() {
function buddylist_update_1() {
return _system_update_utf8(array('buddylist'));
}
+
+function buddylist_update_2() {
+ $ret = array();
+
+ switch ($GLOBALS['db_type']) {
+ case 'mysql':
+ case 'mysqli':
+ $result = update_sql("
+ CREATE TABLE {buddylist_pending_requests} (
+ requester_uid int(11) NOT NULL default '0',
+ requestee_uid int(11) NOT NULL default '0',
+ received tinyint(1),
+ PRIMARY KEY (requester_uid, requestee_uid)
+ ) /*!40100 DEFAULT CHARACTER SET utf8 */;
+ ");
+
+ $ret[] = $result;
+ break;
+ }
+
+ if ($result['success']) {
+ drupal_set_message(t('The database schema update for the Buddylist module was successful.'));
+ }
+ else {
+ drupal_set_message(t('Table database schema update for the Buddylist module was unsuccessful. The schema may need to be updated by hand. See the README.txt file for a list of the installation queries.'), 'error');
+ }
+
+ return $ret;
+}
diff --git a/buddylist.module b/buddylist.module
index 6b6f481..d925227 100644
--- a/buddylist.module
+++ b/buddylist.module
@@ -8,6 +8,8 @@ if (module_exists('views')) {
define('BUDDYLIST_ADD_SUBJECT', variable_get('buddylist_add_subject', "[@site] You are @adder_name's newest @buddy"));
define('BUDDYLIST_REMOVE_SUBJECT', variable_get('buddylist_remove_subject', "[@site] You have been removed from @adder_name's @buddy list"));
+define('BUDDYLIST_REQUEST_SUBJECT', variable_get('buddylist_request_subject', "[@site] @adder_name has requested to add you to his/her @buddy list"));
+define('BUDDYLIST_APPROVAL_SUBJECT', variable_get('buddylist_approval_subject', "[@site] @addee_name has approved your @buddy list add request"));
/**
* returns an array of common translation placeholders
@@ -105,6 +107,8 @@ function buddylist_menu($may_cache) {
$editAccess = (
($id == $user->uid && user_access('maintain buddy list') && $user->uid)
|| user_access('administer users'));
+
+ $approval_required = variable_get('buddylist_require_approval', 0);
$items[] = array(
'path' => 'buddylist/'. $id .'/buddies/groups/edit',
@@ -143,15 +147,20 @@ function buddylist_menu($may_cache) {
'weight' => -1,
'callback arguments' => array($id)
);
- $items[] = 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')
- );
+
+ // If buddylist approval is required, then upon approval, both parties become buddies of each other.
+ // So, in effect, idea 'buddyof' becomes redundant.
+ if (!$approval_required) {
+ $items[] = 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
$items[] = array(
@@ -181,6 +190,29 @@ function buddylist_menu($may_cache) {
'weight' => 2,
'callback arguments' => array($id),
);
+
+ // sub-subtabs
+ if ($approval_required && $editAccess) {
+ $items[] = array(
+ 'path' => 'buddylist/'. $id .'/buddies/requests',
+ 'title' => t('Requests'),
+ 'access' => $editAccess,
+ 'callback' => 'buddylist_pending_requests_list',
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 0,
+ 'callback arguments' => array($id)
+ );
+
+ $items[] = array(
+ 'path' => 'buddylist/'. $id .'/buddies/requested',
+ 'title' => t('Requested'),
+ 'access' => $editAccess,
+ 'callback' => 'buddylist_pending_requested_list',
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 1,
+ 'callback arguments' => array($id)
+ );
+ }
// other callbacks
if ($id != $user->uid) {
@@ -261,6 +293,20 @@ function buddylist_admin_settings() {
'#options' => drupal_map_assoc(range(0, 10)),
'#description' => t('The default maximum number of @buddies and users who\'ve added me as a @buddy to display on a user\'s profile page.', buddylist_translation()),
);
+
+ $form['other'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Approval'),
+ '#prefix' => '<a name="approval"/>',
+ );
+
+ $form['other']['buddylist_require_approval'] = array(
+ '#type' => 'radios',
+ '#title' => t('Require approval'),
+ '#default_value' => variable_get('buddylist_require_approval', 0),
+ '#description' => t("Select 'Yes' if a user's request to be someone's buddy should be approved by the other user first. Upon approval, both parties will be buddies of each other."),
+ '#options' => array(0 => t('No'), 1 => t('Yes'))
+ );
$form['mail'] = array(
'#type' => 'fieldset',
@@ -268,6 +314,7 @@ function buddylist_admin_settings() {
);
$macros = implode(', ', array_keys(buddylist_mail_replacements() + buddylist_translation()));
+ $approval_macros = implode(', ', array_keys(buddylist_approval_mail_replacements() + buddylist_translation()));
$form['mail']['buddylist_send_add'] = array(
'#type' => 'checkbox',
@@ -306,10 +353,54 @@ function buddylist_admin_settings() {
$form['mail']['buddylist_remove_text'] = array(
'#type' => 'textarea',
- '#title' => t('Removed @buddy email message'),
+ '#title' => t('Removed @buddy email message', buddylist_translation()),
'#default_value' => variable_get('buddylist_remove_text', $remove_default),
'#description' => t('Replacement strings are: %macros', array('%macros' => $macros)),
);
+
+ $form['mail']['buddylist_send_request'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Send request messages.'),
+ '#description' => t('Check this box if you want users to receive an email when someone requests to be their buddy. This setting only has effect if approval is required to be on someone\'s buddylist. (See <a href="#approval">Approval</a>)'),
+ '#default_value' => variable_get('buddylist_send_request', FALSE)
+ );
+
+ $form['mail']['buddylist_request_subject'] = array(
+ '#type' => 'textfield',
+ '#title' => t('@buddy request email subject', buddylist_translation()),
+ '#default_value' => BUDDYLIST_REQUEST_SUBJECT,
+ );
+
+ $request_default = buddylist_mail_request_default();
+
+ $form['mail']['buddylist_request_text'] = array(
+ '#type' => 'textarea',
+ '#title' => t('@buddy request email message', buddylist_translation()),
+ '#default_value' => variable_get('buddylist_request_text', $request_default),
+ '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)),
+ );
+
+ $form['mail']['buddylist_send_approval'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Send approval messages'),
+ '#default_value' => variable_get('buddylist_send_approval', FALSE),
+ '#description' => t('Check this box if you want users to receive an email to the requester when someone approves an add request. This setting only has effect if approval is required to be on someone\'s @buddylist. (See <a href="#approval">Approval</a>)', buddylist_translation())
+ );
+
+ $form['mail']['buddylist_approval_subject'] = array(
+ '#type' => 'textfield',
+ '#title' => t('@buddy request email subject', buddylist_translation()),
+ '#default_value' => BUDDYLIST_APPROVAL_SUBJECT,
+ );
+
+ $approval_default = buddylist_mail_approval_default();
+
+ $form['mail']['buddylist_approval_text'] = array(
+ '#type' => 'textarea',
+ '#title' => t('@buddy approval email message', buddylist_translation()),
+ '#default_value' => variable_get('buddylist_approval_text', $request_default),
+ '#description' => t('Replacement strings are: %macros', array('%macros' => $approval_macros)),
+ );
return system_settings_form($form);
}
@@ -345,13 +436,16 @@ function buddylist_user($type, &$edit, &$thisuser, $category = NULL) {
// This portion of code is used to see if this $thisuser is a buddy of others and, if s/he is, returns a list
// of people s/he is a buddy of.
// Note the distinction between having a buddy and being someone else's buddy (i.e., 'buddyof')
- $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)) {
- $listbuddyof[$row->uid] = $row;
- }
- if ($listbuddyof) {
- $output[] = array('title' => t('@buddy of', buddylist_translation()), 'value' => theme('user_list', $listbuddyof));
+ // Of course, this distinction doesn't exist if approval is required to add a buddy (in which case, buddy relationships are symmetric)
+ if (!variable_get('buddylist_require_approval', 0)) {
+ $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)) {
+ $listbuddyof[$row->uid] = $row;
+ }
+ if ($listbuddyof) {
+ $output[] = array('title' => t('@buddy of', buddylist_translation()), 'value' => theme('user_list', $listbuddyof));
+ }
}
}
@@ -478,16 +572,42 @@ function buddylist_get_buddies($uid = NULL, $key = 'uid') {
return $buddies[$key][$uid];
}
+function buddylist_get_requestees($uid) {
+ $buddies = array();
+
+ $result = db_query('SELECT bpr.requestee_uid, u.name FROM {buddylist_pending_requests} bpr INNER JOIN {users} u ON bpr.requestee_uid = u.uid WHERE requester_uid = %d', $uid);
+
+ while ($row = db_fetch_object($result)) {
+ $buddies[$row->requestee_uid] = $row->name;
+ }
+
+ return $buddies;
+}
+
function buddylist_setmsg_received($thisuser) {
global $user;
- $check_received = db_query('SELECT received, b.uid as uid, u.name FROM {buddylist} b LEFT JOIN {users} u ON u.uid = b.uid WHERE buddy = %d AND received = 1', $thisuser->uid);
- while ($rec = db_fetch_object($check_received)) {
- if (($rec->received) and ($thisuser->uid == $user->uid)) {
- // TODO: This is where integration with Privatemsg could happen. If enabled, send a private message instead.
- $link = (user_access('access user profiles')) ? l($rec->name, 'user/'. $rec->uid) : $rec->name;
- drupal_set_message(t('!linktouser has added you to his/her @buddylist.', array('!linktouser' => $link) + buddylist_translation()));
- db_query('UPDATE {buddylist} SET received = 0 WHERE buddy = %d', $user->uid);
+ if (variable_get('buddylist_require_approval', 0)) {
+ // Go through and find new buddylist add-requests, (i.e., the ones in {buddylist_pending_requests} w/ received column == 0
+ $result = db_query('SELECT bpr.requester_uid, u.name FROM {buddylist_pending_requests} bpr INNER JOIN {users} u ON bpr.requester_uid = u.uid WHERE bpr.requestee_uid = %d AND bpr.received = 0', $user->uid);
+ $acknowledged_uids = array();
+ while ($row = db_fetch_object($result)) {
+ drupal_set_message(t('!linktouser has requested to add you to his/her @buddylist. Please view your !pending_buddy_requests to approve/deny.', array('!linktouser' => l($row->name, 'user/'. $user->uid), '!pending_buddy_requests' => l(t('pending buddy requests'), 'buddylist/'. $user->uid .'/buddies/requests')) + buddylist_translation()));
+ $acknowledged_uids[] = $row->requester_uid;
+ }
+ if (count($acknowledged_uids)) {
+ db_query('UPDATE {buddylist_pending_requests} SET received = 1 WHERE requestee_uid = %d AND requester_uid IN (%s)', $user->uid, implode(',', $acknowledged_uids));
+ }
+ }
+ else {
+ $check_received = db_query('SELECT received, b.uid as uid, u.name FROM {buddylist} b LEFT JOIN {users} u ON u.uid = b.uid WHERE buddy = %d AND received = 1', $thisuser->uid);
+ while ($rec = db_fetch_object($check_received)) {
+ if (($rec->received) and ($thisuser->uid == $user->uid)) {
+ // TODO: This is where integration with Privatemsg could happen. If enabled, send a private message instead.
+ $link = (user_access('access user profiles')) ? l($rec->name, 'user/'. $rec->uid) : $rec->name;
+ drupal_set_message(t('!linktouser has added you to his/her @buddylist.', array('!linktouser' => $link) + buddylist_translation()));
+ db_query('UPDATE {buddylist} SET received = 0 WHERE buddy = %d', $user->uid);
+ }
}
}
}
@@ -551,6 +671,171 @@ function buddylist_buddylisting_page($uid = NULL, $mode = 'buddies') {
return $output;
}
+
+/**
+ * Displays a list of people who've requested to be added to the given user's buddylist
+ */
+function buddylist_pending_requests_list($id) {
+ global $user;
+
+ $account = user_load(array('uid' => $id));
+
+ $viewing_own_account = ($user->uid == $id);
+
+ $result = db_query('SELECT bpr.requester_uid, u.name FROM {buddylist_pending_requests} bpr INNER JOIN {users} u ON bpr.requester_uid = u.uid WHERE requestee_uid = %d', $id);
+
+ if (!db_num_rows($result)) {
+ $output = '<p>'. t("!someone currently !does_or_do not have any pending @buddy requests from other users.", array('!someone' => ($viewing_own_account ? t('You') : $account->name), '!does_or_do' => $viewing_own_account ? t('do') : t('does')) + buddylist_translation()) .'</p>';
+ }
+ else {
+ $output = '<p>'. t("The following people have requested to be !someones @buddy.", array('!someones' => ($viewing_own_account ? t('your') : $account->name ."'s ")) + buddylist_translation()) .'</p>';
+
+ $item_list = array();
+
+ $html_rows = array();
+ while ($row = db_fetch_object($result)) {
+ $html_row = array();
+ $html_row[] = l($row->name, 'user/'. $row->requester_uid);
+ $html_row[] = drupal_get_form('buddylist_approval_form', $id, $row->requester_uid, $row->name);
+ $html_rows[] = $html_row;
+ }
+
+ $output .= theme('table', NULL, $html_rows);
+ }
+
+ return $output;
+}
+
+function buddylist_approval_form($requestee_uid, $requester_uid) {
+ $form = array();
+
+ $form['requestee_uid'] = array(
+ '#type' => 'hidden',
+ '#value' => $requestee_uid,
+ );
+
+ $form['requester_uid'] = array(
+ '#type' => 'hidden',
+ '#value' => $requester_uid
+ );
+
+ $form['approve'] = array(
+ '#type' => 'submit',
+ '#value' => t('Approve')
+ );
+
+ $form['deny'] = array(
+ '#type' => 'submit',
+ '#value' => t('Deny'),
+ );
+
+ return $form;
+}
+
+function buddylist_approval_form_submit($form_id, $form_values) {
+ $requestee_account = user_load(array('uid' => $form_values['requestee_uid'])); // most likely global user, unless admin looking
+
+ // Delete pending request from {buddylist_penging_requests}
+ db_query('DELETE FROM {buddylist_pending_requests} WHERE requestee_uid = %d AND requester_uid = %d', $form_values['requestee_uid'], $form_values['requester_uid']);
+
+ $requester_account = user_load(array('uid' => $form_values['requester_uid']));
+
+ if ($form_values['op'] == t('Approve')) {
+ // Make sure, for some weird reason, we don't already have these guys marked as buddies of each other in the database
+ $result = db_query('SELECT * FROM {buddylist} WHERE uid = %d AND buddy = %d', $form_values['requestee_uid'], $form_values['reqeuster_uid']);
+
+ $time = time();
+
+ if (!db_num_rows($result)) {
+ db_query('INSERT INTO {buddylist} (uid, buddy, timestamp, received) VALUES (%d, %d, %d, %d)', $form_values['requestee_uid'], $form_values['requester_uid'], $time, 1);
+ }
+
+ $result = db_query('SELECT * FROM {buddylist} WHERE uid = %d AND buddy = %d', $form_values['requester_uid'], $form_values['requestee_uid']);
+ if (!db_num_rows($result)) {
+ db_query('INSERT INTO {buddylist} (uid, buddy, timestamp, received) VALUES (%d, %d, %d, %d)', $form_values['requester_uid'], $form_values['requestee_uid'], $time, 1);
+ }
+
+ if (variable_get('buddylist_send_approval', FALSE)) {
+ buddylist_mail_user('approval', $requester_account, $requestee_account);
+ }
+
+ drupal_set_message(t('Congratulations! !linktouser is now your @buddy.', array('!linktouser' => l($requester_account->name, 'user/'. $requester_account->uid)) + buddylist_translation()));
+ }
+ else {
+ drupal_set_message(t("!user's request to be your @buddy has been denied.", array('!user' => l($requester->name, 'user/'. $requester->uid)) + buddylist_translation()));
+ }
+
+
+
+ return 'buddylist/'. $form_values['requestee_uid'] .'/buddies/requests';
+}
+
+/**
+ * Displays a list of user's who this given user has requested to be buddies with.
+ */
+function buddylist_pending_requested_list($id) {
+ global $user;
+
+ $account = user_load(array('uid' => $id));
+
+ $viewing_own_account = ($user->uid == $id);
+
+ $result = db_query('SELECT bpr.requestee_uid, u.name FROM {buddylist_pending_requests} bpr INNER JOIN {users} u ON bpr.requestee_uid = u.uid WHERE requester_uid = %d', $account->uid);
+
+ if (!db_num_rows($result)) {
+ $output = t('!Person !do_or_does not have any pending @buddy requests that !person !have_or_has made.',
+ array(
+ '!Person' => ($viewing_own_account ? t('You') : $account->name),
+ '!do_or_does' => ($viewing_own_account ? t('do') : t('does')),
+ '!have_or_has' => ($viewing_own_account ? t('have') : t('has')),
+ '!person' => ($viewing_own_account ? t('you') : $account->name) ) + buddylist_translation());
+ }
+ else {
+ $output = t('!person !have_or_has requested to be added to the @buddylist of the following users.', array('!person' => ($viewing_own_account ? t('You') : $account->name), '!have_or_has' => ($viewing_own_account ? t('have') : t('has'))) + buddylist_translation());
+
+ $html_rows = array();
+ while ($row = db_fetch_object($result)) {
+ $html_row = array();
+ $html_row[] = l($row->name, 'user/'. $row->requestee_uid);
+ $html_row[] = drupal_get_form('buddylist_request_cancel_form', $row->requestee_uid, $id);
+ $html_rows[] = $html_row;
+ }
+
+ $output .= theme('table', NULL, $html_rows);
+
+ }
+
+ return $output;
+}
+
+function buddylist_request_cancel_form($requestee_uid, $requester_uid) {
+ $form['requestee_uid'] = array(
+ '#type' => 'hidden',
+ '#value' => $requestee_uid,
+ );
+
+ $form['requester_uid'] = array(
+ '#type' => 'hidden',
+ '#value' => $requester_uid
+ );
+
+ $form['cancel'] = array(
+ '#type' => 'submit',
+ '#value' => t('Cancel')
+ );
+
+ return $form;
+}
+
+function buddylist_request_cancel_form_submit($form_id, $form_values) {
+ db_query('DELETE FROM {buddylist_pending_requests} WHERE requester_uid = %d AND requestee_uid = %d', $form_values['requester_uid'], $form_values['requestee_uid']);
+
+ $former_potential_buddy = user_load(array('uid' => $form_values['requestee_uid']));
+ drupal_set_message(t('The request to add !user_name has been cancelled.', array('!user_name' => l($former_potential_buddy->name, 'user/'. $former_potential_buddy->uid))));
+
+ return 'buddylist/'. $form_values['requester_uid'] .'/buddies/requested';
+}
+
function buddylist_form_buddiesrecent_page($buddies) {
foreach ($buddies as $user_id => $buddy) {
$form[] = array('#type' => 'fieldset',
@@ -903,8 +1188,13 @@ function buddylist_addbuddy($uid) {
* Confirm and add a buddy.
*/
function buddylist_addbuddy_submit($form_id, $form_values) {
- buddylist_add($form_values['uid']);
- drupal_set_message(t('%name will be be notified the next time s/he logs in.', array('%name' => $form_values['name'])));
+ if (variable_get('buddylist_require_approval', 0)) {
+ buddylist_add_request($form_values['uid']);
+ }
+ else {
+ buddylist_add($form_values['uid']);
+ drupal_set_message(t('%name will be be notified the next time s/he logs in.', array('%name' => $form_values['name'])));
+ }
return 'user';
};
@@ -965,6 +1255,32 @@ function buddylist_add($id) {
}
}
+function buddylist_add_request($id) {
+ global $user;
+ $user_to_add = user_load(array('uid' => $id));
+
+ $already_requested = in_array($id, array_keys(buddylist_get_requestees($user->uid)));
+ $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_send_request', FALSE)) {
+ buddylist_mail_user('request', $user_to_add);
+ }
+ drupal_set_message(t('Your request to add %username to your @buddy list has been submitted. %username will be notified.', array('%username' => $user_to_add->name) + buddylist_translation()));
+ }
+ else {
+ if ($already_requested) {
+ drupal_set_message(t('You have already requested to add %username to your @buddylist', array('%username' => $user_to_add->name) + buddylist_translation()));
+ }
+
+ if ($already_buddies) {
+ drupal_set_message(t('%username is already on your @buddylist', array('%username' => $user_to_add->name) + buddylist_translation()));
+ }
+ }
+}
+
function buddylist_remove($id) {
global $user;
db_query('DELETE FROM {buddylist} WHERE uid = %d AND buddy = %d' , $user->uid , $id);
@@ -973,6 +1289,10 @@ function buddylist_remove($id) {
buddylist_mail_user('remove', $thisuser);
}
drupal_set_message(t('%username has been removed from your @buddylist', array('%username' => $thisuser->name) + buddylist_translation()));
+
+ if (variable_get('buddylist_require_approval', 0)) {
+ db_query('DELETE FROM {buddylist} WHERE uid = %d AND buddy = %d', $id, $user->uid);
+ }
}
function buddylist_cancel_add($id) {
@@ -1001,12 +1321,21 @@ function buddylist_mail_user($op, $account, $user = NULL) {
case 'remove':
$subject = BUDDYLIST_REMOVE_SUBJECT;
$message = variable_get('buddylist_remove_message', buddylist_mail_remove_default());
- break;
+ break;
+ case 'request':
+ $subject = BUDDYLIST_REQUEST_SUBJECT;
+ $message = variable_get('buddylist_request_message', buddylist_mail_request_default());
+ break;
+ case 'approval':
+ $subject = BUDDYLIST_APPROVAL_SUBJECT;
+ $message = variable_get('buddylist_approval_message', buddylist_mail_approval_default());
+ break;
}
// eval the replacements
$replacements = array();
- foreach(buddylist_mail_replacements() as $key => $code) {
+ $replacement_evals = ($op == 'approval') ? buddylist_approval_mail_replacements() : buddylist_mail_replacements();
+ foreach($replacement_evals as $key => $code) {
eval('$replacements["$key"] = '. $code .';');
}
$replacements += buddylist_translation();
@@ -1024,13 +1353,25 @@ function buddylist_mail_user($op, $account, $user = NULL) {
}
// send the email
- if (! drupal_mail("buddylist_mail_user_$op", $account->mail, $subject, $message, $site_mail)) {
- $message = t('%type message was sent to %username', array('%type' => $op, '%username' => $account->name));
- watchdog('buddylist', $message);
+ if ($op != 'approval') {
+ if (! drupal_mail("buddylist_mail_user_$op", $account->mail, $subject, $message, $site_mail)) {
+ $message = t('%type message was sent to %username', array('%type' => $op, '%username' => $account->name));
+ watchdog('buddylist', $message);
+ }
+ else {
+ $message = t('There was a problem sending the %type message to %username', array('%type' => $op, '%username' => $account->name));
+ watchdog('buddylist', $message, WATCHDOG_WARNING);
+ }
}
else {
- $message = t('There was a problem sending the %type message to %username', array('%type' => $op, '%username' => $account->name));
- watchdog('buddylist', $message, WATCHDOG_WARNING);
+ if (! drupal_mail("buddylist_mail_user_$op", $account->mail, $subject, $message, $site_mail)) {
+ $message = t('%type message was sent to %username', array('%type' => $op, '%username' => $user->name));
+ watchdog('buddylist', $message);
+ }
+ else {
+ $message = t('There was a problem sending the %type message to %username', array('%type' => $op, '%username' => $user->name));
+ watchdog('buddylist', $message, WATCHDOG_WARNING);
+ }
}
}
@@ -1066,6 +1407,43 @@ The @site team
MESSAGE;
}
+function buddylist_mail_request_default() {
+ return <<<MESSAGE
+Hi @addee_name,
+
+@adder_name has requested to add you to his/her @buddy list.
+
+Here's a link to @adder_name's profile:
+
+ @adder_link
+
+To approve/deny this request, log in to @siteurl and see your pending @buddy requests.
+
+Enjoy your new freedom!
+
+Regards,
+The @site team
+MESSAGE;
+}
+
+function buddylist_mail_approval_default() {
+ return <<<MESSAGE
+Hi @adder_name,
+
+@addee_name has approved your request to join his/her @buddy list.
+
+Here's a link to your buddylist:
+
+ @adder_list_link
+
+Enjoy your new freedom!
+
+Regards,
+The @site team
+
+MESSAGE;
+}
+
function buddylist_mail_replacements(){
return array(
'@adder_name' => '$user->name',
@@ -1075,5 +1453,21 @@ function buddylist_mail_replacements(){
'@addee_link' => 'url("user/". $account->uid, NULL, NULL, TRUE)',
'@addee_uid' => '$account->uid',
'@site' => 'variable_get("site_name", "Drupal")',
+ '@siteurl' => '$GLOBALS["base_url"]',
+ '@adder_list_link' => 'url("buddylist/". $user->uid ."/buddies/list", NULL, NULL, TRUE)'
);
}
+
+function buddylist_approval_mail_replacements() {
+ return array(
+ '@adder_name' => '$account->name',
+ '@adder_link' => 'url("user/". $account->uid, NULL, NULL, TRUE)',
+ '@adder_uid' => '$account->uid',
+ '@addee_name' => '$user->name',
+ '@addee_link' => 'url("user/". $user->uid, NULL, NULL, TRUE)',
+ '@addee_uid' => '$user->uid',
+ '@site' => 'variable_get("site_name", "Drupal")',
+ '@siteurl' => '$GLOBALS["base_url"]',
+ '@adder_list_link' => 'url("buddylist/". $account->uid ."/buddies/list", NULL, NULL, TRUE)'
+ );
+} \ No newline at end of file