Index: og.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og/Attic/og.install,v
retrieving revision 1.71.4.5
diff -u -r1.71.4.5 og.install
--- og.install 15 May 2009 17:28:02 -0000 1.71.4.5
+++ og.install 22 Jun 2009 17:02:33 -0000
@@ -143,6 +143,24 @@
),
'primary key' => array('nid', 'group_nid'),
);
+ $schema['og_invite'] = array(
+ 'description' => 'Pending OG Invitations',
+ 'fields' => array(
+ 'mail' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'description' => "Invited email address.",
+ ),
+ 'group_nid' => array(
+ 'description' => "The group's {node}.nid.",
+ 'type' => 'int',
+ 'size' => 'normal',
+ 'not null' => TRUE,
+ ),
+ ),
+ 'primary key' => array('mail', 'group_nid'),
+ );
return $schema;
}
@@ -432,6 +450,31 @@
return $ret;
}
+// Add og_invite table to store emails for inviting non-users to groups.
+function og_update_6204() {
+ $ret = array();
+ $schema['og_invite'] = array(
+ 'description' => 'Pending OG Invitations',
+ 'fields' => array(
+ 'mail' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'description' => "Invited email address.",
+ ),
+ 'group_nid' => array(
+ 'description' => "The group's {node}.nid.",
+ 'type' => 'int',
+ 'size' => 'normal',
+ 'not null' => TRUE,
+ ),
+ ),
+ 'primary key' => array('mail', 'group_nid'),
+ );
+ db_create_table($ret, 'og_invite', $schema['og_invite']);
+ return $ret;
+}
+
// end updates //
function og_uninstall() {
Index: og.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og/Attic/og.module,v
retrieving revision 1.628.4.12
diff -u -r1.628.4.12 og.module
--- og.module 18 Jun 2009 02:06:44 -0000 1.628.4.12
+++ og.module 22 Jun 2009 17:02:33 -0000
@@ -718,36 +718,44 @@
$node = node_load($gid);
switch ($node->og_selective) {
case OG_MODERATED:
- $admins = array();
- og_save_subscription($gid, $account->uid, array('is_active' => 0));
- $sql = og_list_users_sql(1, 1, NULL);
- $res = db_query($sql, $node->nid);
- $admins = array();
- while ($row = db_fetch_object($res)) {
- $admins[] = $row->uid;
- }
- if (!empty($admins)) {
- $variables = array(
- '@group' => $node->title,
- '@username' => $account->name,
- '!approve_url' => url("og/approve/$node->nid/$account->uid", array('absolute' => TRUE)),
- '!group_url' => url("og/users/$node->nid", array('absolute' => TRUE)),
- '@request' => $request,
- );
+ $sql = "SELECT COUNT(*) FROM {og_invite} WHERE mail = '%d' AND group_nid = %d";
+ $cnt = db_result(db_query($sql, $account->uid, $node->nid));
+ if (!$cnt) {
+ $admins = array();
+ og_save_subscription($gid, $account->uid, array('is_active' => 0));
+ $sql = og_list_users_sql(1, 1, NULL);
+ $res = db_query($sql, $node->nid);
+ $admins = array();
+ while ($row = db_fetch_object($res)) {
+ $admins[] = $row->uid;
+ }
+ if (!empty($admins)) {
+ $variables = array(
+ '@group' => $node->title,
+ '@username' => $account->name,
+ '!approve_url' => url("og/approve/$node->nid/$account->uid", array('absolute' => TRUE)),
+ '!group_url' => url("og/users/$node->nid", array('absolute' => TRUE)),
+ '@request' => $request,
+ );
- $message = array(
- 'subject' => _og_mail_text('og_request_user_subject', $variables),
- 'body' => _og_mail_text('og_request_user_body', $variables),
- );
+ $message = array(
+ 'subject' => _og_mail_text('og_request_user_subject', $variables),
+ 'body' => _og_mail_text('og_request_user_body', $variables),
+ );
- // Send notifications to each admin; Sending an array of recipients
- // implies that this is a bulk message.
- module_invoke_all('og', 'user request', $gid, $admins, $message);
- }
- $return_value = array('type' => 'approval',
- 'message' => t('Membership request to the %group group awaits approval by an administrator.', array('%group' => $node->title)));
+ // Send notifications to each admin; Sending an array of recipients
+ // implies that this is a bulk message.
+ module_invoke_all('og', 'user request', $gid, $admins, $message);
+ }
+ $return_value = array('type' => 'approval',
+ 'message' => t('Membership request to the %group group awaits approval by an administrator.', array('%group' => $node->title)));
- break;
+ break;
+ } else {
+ $sql = "DELETE FROM {og_invite} WHERE mail = '%d'";
+ $result = db_query($sql, $account->uid);
+ }
+ // fall through if we are already invited
case OG_OPEN:
og_save_subscription($gid, $account->uid, array('is_active' => 1));
$return_value = array('type' => 'subscribed',
@@ -1830,6 +1838,7 @@
);
return $form;
}
+ break;
case 'insert':
if (isset($edit['og_register'])) {
foreach (array_keys(array_filter($edit['og_register'])) as $gid) {
@@ -1839,6 +1848,16 @@
}
}
}
+ $sql = "SELECT group_nid FROM {og_invite} WHERE mail = '%s'";
+ $result = db_query($sql, $account->mail);
+ while ($group = db_fetch_array($result)) {
+ $gid = $group['group_nid'];
+ $groupnode = node_load($gid);
+ og_save_subscription($gid, $account->uid, array('is_active' => 1));
+ drupal_set_message(t('You are now a member of the %group.', array('%group' => $groupnode->title)));
+ }
+ $sql = "DELETE FROM {og_invite} WHERE mail = '%s'";
+ $result = db_query($sql, $account->mail);
break;
case 'delete':
$sql = 'DELETE FROM {og_uid} WHERE uid=%d';
@@ -2084,7 +2103,7 @@
if ($subscription == 'active' || user_access('administer nodes')) {
$links = module_invoke_all('og_create_links', $node);
// We want to open this up for OG_INVITE_ONLY but we need to handle invitation workflow much better. See http://drupal.org/node/170332
- if ($node->og_selective < OG_INVITE_ONLY) {
+ if ($node->og_selective < OG_INVITE_ONLY || og_is_group_admin($node)) {
$links['invite'] = l(t('Invite friend'), "og/invite/$node->nid");
}
$links['subscribers'] = $txt;
@@ -2160,11 +2179,14 @@
}
function og_subscribe_link($node) {
- if ($node->og_selective == OG_MODERATED) {
- $txt = t('Request membership');
- }
- elseif ($node->og_selective == OG_OPEN) {
+ global $user;
+ $sql = "SELECT COUNT(*) FROM {og_invite} WHERE mail = '%d' AND group_nid = %d";
+ $cnt = db_result(db_query($sql, $user->uid, $node->nid));
+ if ($cnt || $node->og_selective == OG_OPEN) {
+ // already invited or open group
$txt = t('Join');
+ } elseif ($node->og_selective == OG_MODERATED) {
+ $txt = t('Request membership');
}
if(isset($txt))
return l($txt, "og/subscribe/$node->nid", array('attributes' => array('rel' => 'nofollow'), 'query' => drupal_get_destination()));
Index: og.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og/Attic/og.pages.inc,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 og.pages.inc
--- og.pages.inc 10 Jun 2009 01:07:27 -0000 1.1.2.2
+++ og.pages.inc 22 Jun 2009 17:02:33 -0000
@@ -214,6 +214,9 @@
elseif (in_array($user->mail, $emails)) {
form_set_error('mails', t('You may not invite yourself - @self.', array('@self' => $user->mail)));
}
+ elseif (in_array($user->name, $emails)) {
+ form_set_error('mails', t('You may not invite yourself - @self.', array('@self' => $user->name)));
+ }
else {
$valid_emails = array();
$bad = array();
@@ -253,13 +256,38 @@
'@group' => $node->title,
'@description' => $node->og_description,
'@site' => variable_get('site_name', 'drupal'),
- '!group_url' => url("og/subscribe/$node->nid", array('absolute' => TRUE)),
'@body' => $form_state['values']['pmessage'],
);
global $user;
$from = $user->mail;
foreach ($emails as $mail) {
+ $variables['!group_url'] = url("og/subscribe/$node->nid", array('absolute' => TRUE));
+ if (og_is_group_admin($node)) {
+ $account = user_load(array('mail' => $mail));
+ if ($account) {
+ $sql = "SELECT COUNT(*) FROM {og_invite} WHERE mail = '%d' AND group_nid = %d";
+ $cnt = db_result(db_query($sql, $account->uid, $node->nid));
+ if ($cnt) {
+ drupal_set_message(t('@username was already on the invitation list for this group, but will be re-invited.', array('@username' => $account->name)));
+ }
+ else {
+ $record = array('mail' => $account->uid, 'group_nid' => $node->nid);
+ $result = drupal_write_record('og_invite', $record);
+ }
+ } else {
+ $sql = "SELECT COUNT(*) FROM {og_invite} WHERE mail = '%s' AND group_nid = %d";
+ $cnt = db_result(db_query($sql, $mail, $node->nid));
+ if ($cnt) {
+ drupal_set_message(t('@email was already on the invitation list for this group, but will be re-invited.', array('@email' => $mail)));
+ }
+ else {
+ $record = array('mail' => $mail, 'group_nid' => $node->nid);
+ $result = drupal_write_record('og_invite', $record);
+ }
+ $variables['!group_url'] = url('user/register', array('absolute' => TRUE));
+ }
+ }
drupal_mail('og', 'invite_user', $mail, $GLOBALS['language'], $variables, $from);
}
drupal_set_message(format_plural(count($emails), '1 invitation sent.', '@count invitations sent.'));
@@ -312,7 +340,9 @@
function og_confirm_subscribe($form_state, $gid, $node, $account) {
$form['gid'] = array('#type' => 'value', '#value' => $gid);
$form['account'] = array('#type' => 'value', '#value' => $account);
- if ($node->og_selective == OG_MODERATED) {
+ $sql = "SELECT COUNT(*) FROM {og_invite} WHERE mail = '%d' AND group_nid = %d";
+ $cnt = db_result(db_query($sql, $account->uid, $node->nid));
+ if ($node->og_selective == OG_MODERATED && !$cnt) {
$form['request'] = array(
'#type' => 'textarea',
'#title' => t('Additional details'),
@@ -384,6 +414,7 @@
'#description' => t('Add one or more usernames in order to associate users with this group. Multiple usernames should be separated by a comma.'),
'#element_validate' => array('og_add_users_og_names_validate'),
);
+ $form['og_names']['#description'] .= '
' . t('If you wish to use emails in addition to usernames, invite will accept a mix of both.', array( '@url' => url('og/invite/'. $group_node->nid)));
$form['op'] = array('#type' => 'submit', '#value' => t('Add users'));
$form['gid'] = array('#type' => 'value', '#value' => $group_node->nid);
return $form;