? .DS_Store
? modules/.DS_Store
? modules/og_actions/.DS_Store
? modules/og_notifications/.DS_Store
? modules/og_views/.DS_Store
? modules/og_views/includes/.DS_Store
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 23 Jun 2009 18:45:51 -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 23 Jun 2009 18:45:51 -0000
@@ -716,53 +716,68 @@
function og_subscribe_user($gid, $account, $request = NULL) {
// moderated groups must approve all members (selective=1)
$node = node_load($gid);
+ // this switch statement may take some careful reading
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);
+ // 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;
}
- $return_value = array('type' => 'approval',
- 'message' => t('Membership request to the %group group awaits approval by an administrator.', array('%group' => $node->title)));
-
- break;
+ case OG_INVITE_ONLY:
+ if (!$cnt) {
+ $sql = "SELECT COUNT(*) FROM {og_invite} WHERE mail = '%d' AND group_nid = %d";
+ $cnt = db_result(db_query($sql, $account->uid, $node->nid));
+ }
+ case OG_CLOSED:
+ if (!$cnt) {
+ // no invitations
+ // admins can add members to these groups, but others can't.
+ if (og_is_group_admin($node)) {
+ og_save_subscription($gid, $account->uid, array('is_active' => 1));
+ }
+ else {
+ $return_value = array('type' => 'rejected',
+ 'message' => t('Membership request to the %group group was rejected, only group administrators can add users to this group.', array('%group' => $node->title)));
+ }
+ break;
+ }
+ $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',
'message' => t('You are now a member of the %group.', array('%group' => $node->title)));
break;
- case OG_CLOSED:
- case OG_INVITE_ONLY:
- // admins can add members to these groups, but others can't.
- if (og_is_group_admin($node)) {
- og_save_subscription($gid, $account->uid, array('is_active' => 1));
- }
- else {
- $return_value = array('type' => 'rejected',
- 'message' => t('Membership request to the %group group was rejected, only group administrators can add users to this group.', array('%group' => $node->title)));
- }
}
return $return_value;
}
@@ -1830,6 +1845,7 @@
);
return $form;
}
+ break;
case 'insert':
if (isset($edit['og_register'])) {
foreach (array_keys(array_filter($edit['og_register'])) as $gid) {
@@ -1839,6 +1855,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 +2110,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 +2186,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 23 Jun 2009 18:45:51 -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,16 +256,69 @@
'@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;
+ $sent = 0;
foreach ($emails as $mail) {
+ $variables['!group_url'] = url("og/subscribe/$node->nid", array('absolute' => TRUE));
+ $account = user_load(array('mail' => $mail));
+ $wasinactive = FALSE;
+ if ($account) {
+ $sql = "SELECT is_active,uid FROM {og_uid} WHERE uid = %d AND nid = %d";
+ $oguid = db_fetch_array(db_query($sql, $account->uid, $node->nid));
+ if ($oguid['uid']) {
+ // user already active/pending
+ if($oguid['is_active']) {
+ drupal_set_message("@username is already a member of the group", array('@username' => $account->name));
+ continue;
+ } else {
+ $wasinactive = TRUE;
+ drupal_set_message('@username already requested group membership', array('@username' => $account->name));
+ }
+ }
+ }
+
+ if (og_is_group_admin($node)) {
+ if ($account) {
+ if ($wasinactive) {
+ // user wanted to be a member, we want them to be a member--oh happy day
+ db_query("UPDATE {og_uid} SET is_active = 1 WHERE uid = %d and nid = %d", $account->uid, $node->nid);
+ drupal_set_message('@username has now been approved as a member', array('@username' => $account->name));
+ } else {
+ $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));
+ }
+ }
+ // could still be here if user in there but is_active = 0: don't send another invitation if they don't need one
+ if ($wasinactive) {
+ continue;
+ }
+ $sent ++;
drupal_mail('og', 'invite_user', $mail, $GLOBALS['language'], $variables, $from);
}
- drupal_set_message(format_plural(count($emails), '1 invitation sent.', '@count invitations sent.'));
+ drupal_set_message(format_plural($sent, '1 invitation sent.', '@count invitations sent.'));
}
function og_subscribe($node, $uid = NULL) {
@@ -285,8 +341,10 @@
else {
$account = user_load(array('uid' => $uid));
}
-
- if ($node->og_selective >= OG_INVITE_ONLY || $node->status == 0 || !og_is_group_type($node->type)) {
+
+ $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_INVITE_ONLY && !$cnt) || $node->og_selective >= OG_CLOSED || $node->status == 0 || !og_is_group_type($node->type)) {
drupal_access_denied();
exit();
}
@@ -312,7 +370,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 +444,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;
Index: modules/og_actions/og_actions.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og/modules/og_actions/Attic/og_actions.module,v
retrieving revision 1.9.4.2
diff -u -r1.9.4.2 og_actions.module
--- modules/og_actions/og_actions.module 9 Jun 2009 01:04:44 -0000 1.9.4.2
+++ modules/og_actions/og_actions.module 23 Jun 2009 18:45:51 -0000
@@ -33,6 +33,12 @@
'nodeapi' => array('insert', 'update'),
),
),
+ 'og_invite_user_action' => array(
+ 'type' => 'user',
+ 'description' => t('Invite user to the specified groups'),
+ 'configurable' => TRUE,
+ 'hooks' => array(),
+ ),
'og_subscribe_user_action' => array(
'type' => 'user',
'description' => t('Subscribe user to the specified groups'),
@@ -274,6 +280,63 @@
}
/**
+ * A configurable action to subscribe a user to specific groups.
+ */
+function og_invite_user_action($account, $context) {
+ if (isset($context['groups'])) {
+ require_once drupal_get_path('module', 'og') ."/og.pages.inc";
+ foreach ($context['groups'] as $gid) {
+ $form_state = array('values' => array('mails' => $account->name, 'gid' => $gid, 'pmessage' => $context['pmessage']));
+ drupal_execute('og_invite_form', $form_state, node_load($gid));
+ }
+ watchdog('action', 'Invited user %name to groups %groups.', array('%name' => $account->name, '%groups' => implode(',', $context['groups'])));
+ }
+}
+
+/**
+ * Configuration form for Invite User action.
+ */
+function og_invite_user_action_form($context) {
+ $form = array();
+
+ if (!isset($context['groups'])) {
+ $context['groups'] = array();
+ }
+
+ $groups = og_all_groups_options();
+ if (count($groups)) {
+ $form['groups'] = array(
+ '#type' => 'select',
+ '#title' => t('Groups'),
+ '#options' => $groups,
+ '#description' => t('Select the groups to which this user should be invited.'),
+ '#default_value' => $context['groups'],
+ '#required' => TRUE,
+ '#multiple' => TRUE,
+ );
+ $form['pmessage'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Personal message'),
+ '#description' => t('Optional. Enter a message which will become part of the invitation email.')
+ );
+ }
+ else {
+ drupal_set_message(t('Please create a group first.', array('!url' => url('admin/content'))));
+ }
+ return $form;
+}
+
+/**
+ * Submission handler for Invite User action configuration form.
+ */
+function og_invite_user_action_submit($form, &$form_state) {
+ return array(
+ 'groups' => $form_state['values']['groups'],
+ 'pmessage' => $form_state['values']['pmessage'],
+ );
+}
+
+/**
* A configurable action to unsubscribe a user from specific groups.
*/
function og_unsubscribe_user_action($account, $context) {