Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og/README.txt,v
retrieving revision 1.36.2.17
diff -u -r1.36.2.17 README.txt
--- README.txt 5 May 2008 21:27:57 -0000 1.36.2.17
+++ README.txt 11 Jul 2008 20:13:02 -0000
@@ -41,8 +41,9 @@
INTEGRATION
---------------------
-- I recommend enabling the job_queue.module. When you do, group email notifications are sent during cron runs, instead of immediately after a post is submitted. This speeds up posting a lot, for big groups. The delay also helps authors fix typos in their posts before the mail is sent.
- This module exposes an API for retrieving and managing membership via direct PHP functions [og_save_subscription()] and via XMLRPC.
+- Enabling og_notifications provides subscription support for groups and group
+posts. The README in the og_notifications directory provides more information.
UNIT TESTING
----------------------
Index: og.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og/og.install,v
retrieving revision 1.21.2.32
diff -u -r1.21.2.32 og.install
--- og.install 2 Jul 2008 14:51:26 -0000 1.21.2.32
+++ og.install 11 Jul 2008 20:13:03 -0000
@@ -12,7 +12,6 @@
theme varchar(255) NULL,
register int(1) NOT NULL default 0,
directory int(1) NOT NULL default 0,
- notification int(1) NOT NULL default 0,
language varchar(12) NOT NULL default '',
private int(1) NOT NULL default 0,
PRIMARY KEY (nid)
@@ -24,17 +23,11 @@
is_active int(1) NOT NULL DEFAULT 0,
is_admin int(1) NOT NULL DEFAULT 0,
uid int(11) NOT NULL,
- mail_type int(11) NULL,
- created int(11) NULL DEFAULT 0,
- changed int(11) NULL DEFAULT 0,
+ created int(11) NULL DEFAULT 0,
+ changed int(11) NULL DEFAULT 0,
PRIMARY KEY (nid, uid)
) /*!40100 DEFAULT CHARACTER SET utf8 */;");
- db_query("CREATE TABLE {og_uid_global} (
- uid int(11) NOT NULL,
- og_email int(11) NOT NULL DEFAULT 2,
- PRIMARY KEY (uid)
- ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {og_ancestry} (
nid int(11) NOT NULL,
group_nid int(11) NOT NULL,
@@ -52,7 +45,6 @@
website varchar(255) NULL,
register smallint NOT NULL default 0,
directory smallint NOT NULL default 0,
- notification smallint NOT NULL default 0,
language varchar(12) NOT NULL default '',
private smallint NOT NULL default 0,
PRIMARY KEY (nid)
@@ -64,20 +56,12 @@
is_active smallint NOT NULL DEFAULT 0,
is_admin smallint NOT NULL DEFAULT 0,
uid int NOT NULL,
- mail_type int NULL,
- created int NULL DEFAULT 0,
- changed int NULL DEFAULT 0,
+ created int NULL DEFAULT 0,
+ changed int NULL DEFAULT 0,
PRIMARY KEY (nid, uid)
);");
- db_query("CREATE TABLE {og_uid_global} (
- uid int NOT NULL,
- og_email int NOT NULL DEFAULT 2,
- PRIMARY KEY (uid)
- );");
-
- db_query("
- CREATE TABLE {og_ancestry} (
+ db_query("CREATE TABLE {og_ancestry} (
nid int NOT NULL,
group_nid int NOT NULL,
is_public smallint NOT NULL
@@ -424,8 +408,7 @@
}
function og_update_19() {
- og_populate_uid_global_table();
- return array('Populated og_uid_global table');
+ return array();
}
function og_update_20() {
@@ -506,30 +489,22 @@
return $ret;
}
+ /**
+ * Notifications upgrade: Set flag to indicate that this is an upgraded
+ * installation.
+ */
+ function og_update_5703() {
+ variable_set('og_notifications_update_required', 1);
-// end updates //
-
-function og_enable() {
- og_populate_uid_global_table();
-}
-
-// need to populate og_uid_global for existing users on enable
-// this is called from update 13 & 19 & og_enable.
-// TODO: conditionally use subquery
-function og_populate_uid_global_table() {
- $sql = 'SELECT u.uid FROM {users} u LEFT JOIN {og_uid_global} oug ON u.uid=oug.uid WHERE u.uid > 0 AND oug.og_email IS NULL';
- $result = db_query($sql);
- while ($row = db_fetch_object($result)) {
- $sql = "INSERT INTO {og_uid_global} (uid, og_email) VALUES (%d, %d)";
- db_query($sql, $row->uid, OG_NOTIFICATION_SELECTIVE);
- }
-}
+ return array();
+ }
+
+ // end updates //
function og_uninstall() {
// Drop database table
db_query('DROP TABLE {og}');
db_query('DROP TABLE {og_uid}');
- db_query('DROP TABLE {og_uid_global}');
db_query('DROP TABLE {og_ancestry}');
// Delete variables
@@ -545,7 +520,8 @@
'og_invite_user_body', 'og_invite_user_subject',
'og_new_admin_body', 'og_new_admin_subject',
'og_new_node_body', 'og_new_node_subject',
- 'og_notification', 'og_request_user_body', 'og_request_user_subject',
+ 'og_request_user_body', 'og_request_user_subject',
+ 'og_notifications_update_required'
);
foreach ($variables as $variable) {
variable_del($variable);
Index: og_views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og/Attic/og_views.inc,v
retrieving revision 1.12.2.55
diff -u -r1.12.2.55 og_views.inc
--- og_views.inc 26 May 2008 14:03:35 -0000 1.12.2.55
+++ og_views.inc 11 Jul 2008 20:13:05 -0000
@@ -79,11 +79,6 @@
'notafield' => TRUE,
'help' => t('Displays a links for joining a group when a user is not already a member.'),
),
- 'notification' => array(
- 'name' => t('OG: Group: Notification'),
- 'handler' => 'og_handler_field_yesempty',
- 'help' => t('Displays yes if group automatically sends email notifications to members'),
- ),
'language' => array(
'name' => t('OG: Group: Language'),
'handler' => 'og_handler_field_language',
@@ -225,12 +220,6 @@
),
),
'fields' => array(
- 'mail_type' => array(
- 'name' => t('OG: Subscription email'),
- 'handler' => 'og_handler_field_yesempty',
- 'sortable' => false,
- 'help' => t('Does member receive email notifications for a group.'),
- ),
'managelink' => array(
'name' => t('OG: Manage membership link'),
'handler' => 'og_handler_field_managelink',
Index: og.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og/og.module,v
retrieving revision 1.298.2.195
diff -u -r1.298.2.195 og.module
--- og.module 2 Jul 2008 19:57:44 -0000 1.298.2.195
+++ og.module 11 Jul 2008 20:13:04 -0000
@@ -19,11 +19,6 @@
define('OG_DIRECTORY_CHOOSE_TRUE', 2);
define('OG_DIRECTORY_CHOOSE_FALSE', 3);
-// site admin chooses in og_admin_settings() whether new registrants receive group email notifications by default
-define('OG_NOTIFICATION_NEVER', 0);
-define('OG_NOTIFICATION_ALWAYS', 1);
-define('OG_NOTIFICATION_SELECTIVE', 2);
-
function og_help($section) {
switch ($section) {
case !empty($section) && strstr($section, 'admin/build/block/configure/og'):
@@ -91,12 +86,20 @@
$node = node_load($gid);
$items[] = array('path' => "og/users/$gid/add_user", 'callback' => 'drupal_get_form', 'title' => t('Add members'), 'callback arguments' => array('og_add_users', $gid), 'type' => MENU_LOCAL_TASK, 'weight' => 5, 'access' => og_is_node_admin($node));
}
-
- // email tab on group node
+
+ // Broadcast tab on group node.
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
if (og_is_group_type($node->type)) {
- $items[] = array('path' => 'node/'. arg(1). '/email', 'title' => t('E-mail'), 'callback' => 'drupal_get_form', 'callback arguments' => array('og_email_form', arg(1)), 'access' => og_is_node_admin($node), 'type' => MENU_LOCAL_TASK, 'weight' => 7);
+ $items[] = array(
+ 'path' => 'node/'. arg(1) .'/broadcast',
+ 'title' => t('Broadcast'),
+ 'callback' => 'drupal_get_form',
+ 'callback arguments' => array('og_broadcast_form', arg(1)),
+ 'access' => og_is_node_admin($node),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 7
+ );
}
}
}
@@ -297,31 +300,39 @@
}
/**
- * Admins may broadcast email to all their members
+ * Admins may broadcast messages to all their members.
*
* @param $gid
* the nid of a group.
*/
- function og_email_form($gid) {
+ function og_broadcast_form($gid) {
$node = node_load($gid);
- drupal_set_title(t('Send email to %group', array('%group' => $node->title)));
+ drupal_set_title(t('Send message to %group', array('%group' => $node->title)));
$result = db_query(og_list_users_sql(1), $gid);
$txt = format_plural(db_num_rows($result), 'the sole member', 'all @count members');
if (!$_POST) {
- drupal_set_message(t('Your email will be sent to !count in this group. Please use this feature sparingly.', array('!count' => l($txt, "og/users/$gid"))));
+ drupal_set_message(t('Your message will be sent to !count in this group.', array('!count' => l($txt, "og/users/$gid"))));
}
- $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#size' => 70, '#maxlength' => 250, '#description' => t("Enter a subject for your email."), '#required' => true);
- $form['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#rows' => 5, '#cols' => 90, '#description' => t('Enter a body for your email.'), '#required' => true);
- $form['send'] = array('#type' => 'submit', '#value' => t('Send email'));
+ $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#size' => 70, '#maxlength' => 250, '#description' => t("Enter a subject for your message."), '#required' => true);
+ $form['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#rows' => 5, '#cols' => 90, '#description' => t('Enter the body of your message.'), '#required' => true);
+ $form['send'] = array('#type' => 'submit', '#value' => t('Send message'));
$form['gid'] = array('#type' => 'value', '#value' => $gid);
return $form;
}
-function og_email_form_submit($form_id, $form_values) {
- $node = node_load($form_values[gid]);
+function og_broadcast_form_submit($form_id, $form_values) {
+ global $user;
+
+ $sql = og_list_users_sql(1);
+ $result = db_query($sql, $form_values['gid']);
+ $recipients = array();
+ while ($row = db_fetch_object($result)) {
+ $recipients[] = $row->uid;
+ }
+ $node = node_load($form_values[gid]);
$variables = array(
'@group' => $node->title,
'@body' => $form_values['body'],
@@ -329,30 +340,24 @@
'!url_group' => url("node/$node->nid", NULL, NULL, TRUE),
'!url_unsubscribe' => url("og/unsubscribe/$node->nid", NULL, NULL, TRUE)
);
-
- global $user;
- $from = $user->mail;
- $sql = og_list_users_sql(1);
- $result = db_query($sql, $form_values['gid']);
- while ($row = db_fetch_object($result)) {
- $emails[] = $row->mail;
- }
- foreach ($emails as $mail) {
- drupal_mail('og_mail', trim($mail), $form_values['subject'], _og_user_mail_text('og_admin_email_body', $variables), $from);
- }
- drupal_set_message(format_plural(count($emails), '1 email sent.', '@count emails sent.'));
+ $message = array(
+ 'from' => $user,
+ 'subject' => $form_values['subject'],
+ 'body' => _og_user_mail_text('og_admin_email_body', $variables),
+ 'queue' => TRUE
+ );
+
+ // Send notifications to each member; Sending an array of recipients implies
+ // that this is a bulk message.
+ module_invoke_all('og', 'user broadcast', $gid, $recipients, $message);
+ drupal_set_message(format_plural(count($recipients), '1 message queued for delivery.', '@count messages queued for delivery.'));
+
drupal_goto("node/{$form_values[gid]}");
}
function og_manage($gid) {
global $user;
- // warn users who can't receive mail anyway
- if ($txt = user_validate_mail($user->mail)) {
- drupal_set_message($txt, 'error');
- return '';
- }
-
$group = node_load($gid);
$bc[] = array('path' => "og", 'title' => t('Groups'));
$bc[] = array('path' => "node/$gid", 'title' => $group->title);
@@ -379,20 +384,6 @@
}
}
- switch ($user->og_email) {
- // og_email can be NULL when you enable og on an existing site.
- case NULL:
- case OG_NOTIFICATION_SELECTIVE:
- $form['mail_type'] = array('#type' => 'radios', '#title' => t('Email notification'), '#default_value' => $user->og_groups[$group->nid]['mail_type'], '#options' => array(1 => t('enabled'), 0 => t('disabled')), '#description' => t('Do you want to receive an email each time a message is posted to this group?'));
- $submit = TRUE;
- break;
- case OG_NOTIFICATION_ALWAYS:
- $form['mail_type'] = array('#type' => 'item', '#title' => t('Email notification'), '#value' => t('Your personal profile is configured to: Always receive email notifications.', array('!prof' => url("user/$user->uid/edit"))));
- break;
- case OG_NOTIFICATION_NEVER:
- $form['mail_type'] = array('#type' => 'item', '#title' => t('Email notification'), '#value' => t('Your personal profile is configured to: Never receive email notifications.', array('!prof' => url("user/$user->uid/edit"))));
- break;
- }
if ($submit) {
$form['op'] = array('#type' => 'submit', '#value' => t('Submit'));
}
@@ -414,7 +405,7 @@
* @param $gid node ID of a group
* @param $uid user ID of user
* @param $args an array with details of this membership. Possible array keys are:
- is_active, is_admin, mail_type, created
+ is_active, is_admin, created
*/
function og_save_subscription($gid, $uid, $args = array()) {
$sql = "SELECT COUNT(*) FROM {og_uid} WHERE nid = %d AND uid = %d";
@@ -422,7 +413,7 @@
$time = time();
// Allow other modules to pass their data inside the $args.
- $og_allowed_args = array('is_active', 'is_admin', 'mail_type', 'created');
+ $og_allowed_args = array('is_active', 'is_admin', 'created');
$return_args = $args;
foreach ($args as $key => $value) {
if (!in_array($key, $og_allowed_args)) {
@@ -477,13 +468,15 @@
drupal_set_message(t('Membership request approved.'));
$variables = array(
- '@title' => $node->title,
- '!group_url'=> url("node/$node->nid", NULL, NULL, TRUE)
- );
-
- $from = variable_get('site_mail', ini_get('sendmail_from'));
- $account = user_load(array('uid' => $uid));
- drupal_mail('og_approve', $account->mail, _og_user_mail_text('og_approve_user_subject', $variables), _og_user_mail_text('og_approve_user_body', $variables), $from);
+ '@title' => $node->title,
+ '!group_url'=> url("node/$node->nid", NULL, NULL, TRUE)
+ );
+ $message = array(
+ 'subject' => _og_user_mail_text('og_approve_user_subject', $variables),
+ 'body' => _og_user_mail_text('og_approve_user_body', $variables)
+ );
+
+ module_invoke_all('og', 'user approve', $gid, $uid, $message);
drupal_goto("node/$gid");
}
}
@@ -500,12 +493,14 @@
$variables = array(
'@title' => $node->title,
- '!group_url' => url("node/$node->nid", NULL, NULL, TRUE)
+ '!group_url'=> url("node/$node->nid", NULL, NULL, TRUE)
);
-
- $from = variable_get('site_mail', ini_get('sendmail_from'));
- $account = user_load(array('uid' => $uid));
- drupal_mail('og_deny', $account->mail, _og_user_mail_text('og_deny_user_subject', $variables), _og_user_mail_text('og_deny_user_body', $variables), $from);
+ $message = array(
+ 'subject' => _og_user_mail_text('og_deny_user_subject', $variables),
+ 'body' => _og_user_mail_text('og_deny_user_body', $variables)
+ );
+
+ module_invoke_all('og', 'user deny', $gid, $uid, $message);
drupal_goto("node/$gid");
}
else {
@@ -553,9 +548,12 @@
'!group_url' => url("node/$node->nid", NULL, NULL, TRUE),
'@username' => $account->name
);
-
- $from = variable_get('site_mail', ini_get('sendmail_from'));
- drupal_mail('og_new_admin', $account->mail, _og_user_mail_text('og_new_admin_subject', $variables), _og_user_mail_text('og_new_admin_body', $variables), $from);
+ $message = array(
+ 'subject' => _og_user_mail_text('og_new_admin_subject', $variables),
+ 'body' => _og_user_mail_text('og_new_admin_body', $variables)
+ );
+
+ module_invoke_all('og', 'admin create', $node->nid, $account->uid, $message);
return "og/users/$node->nid";
}
@@ -745,7 +743,7 @@
/**
- * Create a new membership for a given user to given group and send proper email. Edits to membership should
+ * Create a new membership for a given user to given group. Edits to membership should
* go through og_save_subscription(). No access control since this is an API function.
*
* @return string 'approval', 'subscribed' or 'rejected' depending on the group's configuration.
@@ -756,28 +754,36 @@
switch ($node->og_selective) {
case OG_MODERATED:
og_save_subscription($gid, $account->uid, array('is_active' => 0));
+
$sql = og_list_users_sql(1, 1);
$res = db_query($sql, $node->nid);
+ $admins = array();
while ($row = db_fetch_object($res)) {
- if ($row->mail) {
- $admins[] = $row->mail;
- }
+ $admins[] = $row->uid;
}
- if ($admins) {
+
+ if (!empty($admins)) {
+ // Prepend user's request text with standard cruft. Should be a
+ // variable but that's a bit annoying.
+ if ($request) {
+ $request = t("\n\nPersonal message from @name:\n------------------\n\n@request", array('@name' => $account->name, '@request' => $request));
+ }
$variables = array(
'@group' => $node->title,
'@username' => $account->name,
'!approve_url' => url("og/approve/$node->nid/$account->uid", NULL, NULL, TRUE),
'!group_url' => url("og/users/$node->nid", NULL, NULL, TRUE)
);
-
- $from = variable_get('site_mail', ini_get('sendmail_from'));
- // prepend user's request text with standard cruft. should be a mail variable but thats a bit annoying
- if ($request) {
- $request = t("\n\nPersonal message from @name:\n------------------\n\n@request", array('@name' => $account->name, '@request' => $request));
- }
- drupal_mail('og_subscription_request', implode(', ', $admins), _og_user_mail_text('og_request_user_subject', $variables), _og_user_mail_text('og_request_user_body', $variables). $request, $from);
+ $message = array(
+ 'subject' => _og_user_mail_text('og_request_user_subject', $variables),
+ 'body' => _og_user_mail_text('og_request_user_body', $variables) . $request
+ );
+
+ // 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)));
@@ -1299,20 +1305,20 @@
}
function og_load_group(&$node) {
- $sql = 'SELECT selective AS og_selective, description AS og_description, theme AS og_theme, register AS og_register, directory AS og_directory, notification AS og_notification, language AS og_language, private AS og_private FROM {og} WHERE nid = %d';
+ $sql = 'SELECT selective AS og_selective, description AS og_description, theme AS og_theme, register AS og_register, directory AS og_directory, language AS og_language, private AS og_private FROM {og} WHERE nid = %d';
$result = db_query($sql, $node->nid);
$node = (object) array_merge((array)$node, (array)db_fetch_array($result));
$node->comment = COMMENT_NODE_DISABLED; // we don't use comments on og nodes. technically not needed since we set this on node submit
}
function og_insert_group($node) {
- $sql = "INSERT INTO {og} (nid, theme, selective, description, register, directory, notification, language, private) VALUES (%d, '%s', %d, '%s', %d, %d, %d, '%s', %d)";
- db_query($sql, $node->nid, $node->og_theme, $node->og_selective, $node->og_description, $node->og_register, $node->og_directory, $node->og_notification, $node->og_language, $node->og_private);
+ $sql = "INSERT INTO {og} (nid, theme, selective, description, register, directory, language, private) VALUES (%d, '%s', %d, '%s', %d, %d, '%s', %d)";
+ db_query($sql, $node->nid, $node->og_theme, $node->og_selective, $node->og_description, $node->og_register, $node->og_directory, $node->og_language, $node->og_private);
}
function og_update_group($node) {
- $sql = "UPDATE {og} SET theme = '%s', selective = %d, register = %d, description = '%s', directory = %d, notification = %d, language = '%s', private = %d WHERE nid = %d";
- db_query($sql, $node->og_theme, $node->og_selective, $node->og_register, $node->og_description, $node->og_directory, $node->og_notification, $node->og_language, $node->og_private, $node->nid);
+ $sql = "UPDATE {og} SET theme = '%s', selective = %d, register = %d, description = '%s', directory = %d, language = '%s', private = %d WHERE nid = %d";
+ db_query($sql, $node->og_theme, $node->og_selective, $node->og_register, $node->og_description, $node->og_directory, $node->og_language, $node->og_private, $node->nid);
if (!db_affected_rows()) {
og_insert_group($node);
}
@@ -1356,12 +1362,6 @@
break;
case 'validate':
if (og_is_group_type($node->type)) {
- // Email address is required for contacting the Manager
- $account = user_load(array('uid' => $node->uid));
- if ($account->uid > 0 && empty($account->mail)) {
- form_set_error('name', t('The group manager, %name, must have an email address in his profile.', array('%name' => $account->name, '!profile' => url("user/$node->uid/edit"))));
- }
-
// Must be authored in the default input format or else admins might not get their admin perms
// If Body field is omitted, there may not yet be a $node->format
if (isset($node->format) && $node->format != filter_resolve_format(FILTER_FORMAT_DEFAULT)) {
@@ -1412,33 +1412,17 @@
'@username' => $account->name,
'!invite_url' => url("og/invite/$node->nid", NULL, NULL, TRUE)
);
+ $message = array(
+ 'subject' => _og_user_mail_text('og_new_admin_subject', $variables),
+ 'body' => _og_user_mail_text('og_new_admin_body', $variables)
+ );
- // alert the user that they are now the admin of the group
- $from = variable_get('site_mail', ini_get('sendmail_from'));
- drupal_mail('og_new_admin', $account->mail, _og_user_mail_text('og_new_admin_subject', $variables), _og_user_mail_text('og_new_admin_body', $variables), $from);
+ module_invoke_all('og', 'admin new', $gid, $account->uid, $message);
}
else {
og_save_ancestry($node);
}
-
- $skip_notification = FALSE;
- // Any module that returns TRUE from its hook_og_notify($node) will prevent sending notifications.
- // og2list and og_subscriptions use this to send own notifications.
- foreach(module_implements('og_notify') as $module) {
- if (module_invoke($module,'og_notify',$node)) {
- $skip_notification = TRUE;
- break;
- }
- }
- if (!$skip_notification && $node->status && og_is_mail_type($node->type) && $node->og_groups) {
- if (module_exists('job_queue')) {
- $description = t('OG: notify group members about node %nid - !link.', array('%nid' => $node->nid, '!link' => l($node->title, "node/$node->nid")));
- job_queue_add('og_mail', $description, array('node', $node->nid));
- }
- else {
- og_mail('node', $node);
- }
- }
+
break;
case 'update':
if (og_is_group_type($node->type)) {
@@ -1838,179 +1822,11 @@
}
}
-function og_comment($comment, $op) {
- switch ($op) {
- case 'publish':
- $comment = (array) $comment;
- // fall through
- case 'insert':
- $skip_notification = FALSE;
- // Any module that returns true from its hook_og_notify($node) will prevent sending notifications.
- // og2list uses this to send its own notifications instead for mailing list content.
- $node = node_load($comment['nid']);
-
- foreach(module_implements('og_notify') as $module) {
- if (module_invoke($module, 'og_notify', $node)) {
- $skip_notification = TRUE;
- break;
- }
- }
- // remove the perm check after 5.3 is released.
- if ($comment['status'] == COMMENT_PUBLISHED && !$skip_notification && og_is_mail_type($node->type) && isset($node->og_groups) && !empty($node->og_groups)) {
- if (module_exists('job_queue')) {
- $description = t('OG: Notify group members about comment %id on !link.', array('%id' => $comment['cid'], '!link' => l($node->title, "node/$node->nid", NULL, NULL, 'comment-'. $comment['cid'])));
- job_queue_add('og_mail', $description, array('comment', $comment['cid']));
- }
- else {
- og_mail('comment', (object)$comment);
- }
- }
- break;
- }
-}
-
-
-/**
- * Send this node/comment via email to all email members. Called from og_nodeapi() and og_comment().
- * Sometimes called from during cron if job_queue.module is enabled (recommended).
- * TODO: this function is a bit messy. rethink.
- *
- * @param $type
- * the object type: node or comment
- * @param $id
- * a node or comment object. if a non object is supplied, a load() operation is performed.
- * @return
- * none
- */
-function og_mail($type, $obj) {
- if ($type == 'comment') {
- if (!is_object($obj)) {
- $obj = _comment_load($obj);
- }
- // registered user
- if ($obj->uid) {
- $account = user_load(array('uid' => $obj->uid));
- $obj->name = $account->name;
- }
- else {
- $obj->name = variable_get('anonymous', 'Anonymous');
- }
- $rendered = check_markup($obj->comment, $obj->format, FALSE);
-
- $obj->body = $rendered;
- $obj->teaser = $rendered;
- $originalurl = url("node/$obj->nid", NULL, "comment-$obj->cid", TRUE);
- $replyurl = url("comment/reply/$obj->nid/$obj->cid", NULL, NULL, TRUE);
- $node = node_load($obj->nid);
- $obj->og_groups = $node->og_groups;
- $obj->title = $node->title;
- $obj->msgid = $obj->nid. '-'. $obj->cid. og_msgid_server();
- $reply = $obj->nid. '-';
- if ($obj->pid) {
- $reply .= $obj->pid;
- }
- else {
- $reply .= '0';
- }
- $obj->in_reply_to .= $reply. og_msgid_server();
- $type_friendly = 'comment';
- }
- else {
- if (!is_object($obj)) {
- $obj = node_load($obj);
- }
- $account = user_load(array('uid' => $obj->uid));
- $obj->name = $account->name;
- $obj->subject = $obj->title;
- // These calls to og_node_view() setup the node body and teaser, apply the
- // appropriate input filters, and handle CCK fields, event fields, etc.
- $obj->body = og_node_view($obj, FALSE);
- $obj->teaser = og_node_view($obj, TRUE);
- $obj->msgid = $obj->nid. '-0'. og_msgid_server();
- $originalurl = url("node/$obj->nid", NULL, NULL, TRUE);
- $replyurl = url("comment/reply/$obj->nid", NULL, 'comment-form', TRUE);
- $type_friendly = node_get_types('name', $obj);
- }
-
- // set email from variables
- $variables = array(
- '@user_mail' => $account->mail ? $account->mail : variable_get("site_mail", ini_get("sendmail_from")),
- '@user_name' => mime_header_encode($obj->name),
- '@site_mail' => variable_get("site_mail", ini_get("sendmail_from")),
- '@site_name' => mime_header_encode(variable_get("site_name", 'Drupal')),
- );
- $from_mail = strtr(variable_get("og_email_notification_pattern", '@user_name <@site_mail>'), $variables);
-
- $headers = array('X-Mailer' => 'Drupal - og_mail', 'Precedence' => 'list', 'Message-Id' => "<$obj->msgid>");
- if ($obj->in_reply_to) {
- $headers['In-Reply-To'] = "<$obj->in_reply_to>";
- }
-
- // set email body variables
- $variables = array(
- '@site' => variable_get('site_name', 'drupal'),
- '!read_more' => $obj->readmore ? t('Read more') : t('View original'),
- '!content_url' => $originalurl,
- '!reply_url' => $replyurl,
- '@title' => trim($obj->title),
- '@subject' => trim($obj->subject),
- '@node_full' => trim(og_mail_output($obj->body)),
- '@node_teaser' => trim(og_mail_output($obj->teaser)),
- '@username' => $obj->name
- );
-
- // Send email to selective subscribers and global subscribers.
- // We use if() here in case node/comment no longer has any groups (i.e. this function can be called from cron).
- if (is_array($obj->og_groups) && !empty($obj->og_groups)) {
- $groups = implode(', ', $obj->og_groups);
- // tricky query here. mysql returns NULL in the case of NULL != 0 so i rework this for 2 positive statements about og_email field
- // ORDER BY favors newer groups to help them get ramped up. Thus, they are perceived as active.
- $sql = "SELECT u.mail, ou.nid AS gid, n.title AS group_name, n.uid AS group_uid, u.name AS group_owner, oug.og_email
- FROM {og_uid} ou INNER JOIN {users} u ON ou.uid=u.uid
- INNER JOIN {og_uid_global} oug ON ou.uid=oug.uid
- INNER JOIN {node} n ON ou.nid=n.nid
- WHERE ou.nid IN ($groups) AND (
- (oug.og_email = %d AND ou.mail_type=1) OR
- (oug.og_email = %d)
- ) AND u.status = 1 AND u.mail != '' AND ou.is_active = 1
- ORDER by u.mail DESC, n.created DESC
- ";
- $result = db_query($sql, OG_NOTIFICATION_SELECTIVE, OG_NOTIFICATION_ALWAYS);
- $last_mail = '';
- while ($row = db_fetch_object($result)) {
- // only notify each user once. we used to do this with GROUP BY but got very hard to assure that all the selected fields came from same record.
- if ($row->mail == $last_mail) {
- continue;
- }
- $last_mail = $row->mail;
-
- // TODO: add node_access('view') call here in case node is moderated or other.
- // Hopefully D6 will avert need to impersonate.
- // Append these group specific variables.
- $variables['@group'] = $row->group_name;
- $variables['!group_url'] = url("og/manage/$row->gid", NULL, NULL, TRUE);
- $variables['@type'] = $type_friendly;
-
- $unsubscribe = url("og/manage/$row->gid", NULL, NULL, TRUE);
- $ownerurl = url("user/$row->group_uid", NULL, NULL, TRUE);
- $group_home = url("node/$row->gid", NULL, NULL, TRUE);
- $groupheaders = $headers + array(
- 'List-Id' => mime_header_encode($row->group_name). " <$group_home>",
- 'List-Unsubscribe' => "<$unsubscribe>",
- 'List-Owner' => mime_header_encode($row->group_owner). " <$ownerurl>",
- "List-Archive" => "<$group_home>"
- );
- drupal_mail('og_mail', $row->mail, _og_user_mail_text('og_new_node_subject', $variables), _og_user_mail_text('og_new_node_body', $variables), $from_mail, $groupheaders);
- }
- }
-}
-
/**
* Similar to node_view() but without calling theme('node').
*
* This is needed to get the proper body or teaser for nodes (e.g. Event,
- * Location, CCK node types) and to clean up the body for use in email
- * notifications.
+ * Location, CCK node types) and to clean up the body for use in notifications.
*
* @param $node
* The node object you want to view.
@@ -2042,59 +1858,8 @@
return $teaser ? $node->teaser : $node->body;
}
-// 2 functions ripped from mail.inc in project.module package
-function og_mail_urls($url = 0) {
- static $urls = array();
- if ($url) {
- $urls[] = strpos($url, '://') ? $url : url($url, NULL, NULL, 1);
- return count($urls);
- }
- return $urls;
-}
-
-// takes filtered HTML as input and transforms for email
-// modified from project.module
-function og_mail_output($body, $html = TRUE) {
- static $i = 0;
-
- if ($html) {
- $pattern = '@]+ )*?href *= *"([^>"]+?)"[^>]*>([^<]+?)@ei';
- $body = preg_replace($pattern, "'\\3 ['. og_mail_urls('\\2') .']'", $body);
- $urls = og_mail_urls();
- if (count($urls)) {
- $body .= "\n";
- for ($max = count($urls); $i < $max; $i++) {
- $body .= '['. ($i + 1) .'] '. $urls[$i] ."\n";
- }
- }
-
- $body = preg_replace('!?blockquote>!i', '"', $body);
- $body = preg_replace('!?(em|i)>!i', '/', $body);
- $body = preg_replace('!?(b|strong)>!i', '*', $body);
- $body = preg_replace("@
(?!\n)@i", "\n", $body);
- $body = preg_replace("@(?!\n\n)@i", "\n\n", $body);
- $body = preg_replace("@(?!\n\n)@i", " #\n", $body);
- $body = preg_replace("@(?!\n\n)@i", " ##\n", $body);
- $body = preg_replace("@(?!\n\n)@i", " ###\n", $body);
- $body = preg_replace("@(?!\n\n)@i", " ####\n", $body);
- $body = preg_replace("@(li|dd)>\n?@i", "\n", $body);
- $body = preg_replace("@