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('!!i', '"', $body); - $body = preg_replace('!!i', '/', $body); - $body = preg_replace('!!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("@\n?@i", "\n", $body); - $body = preg_replace("@@i", "\n\n# ", $body); - $body = preg_replace("@@i", "\n\n## ", $body); - $body = preg_replace("@@i", "\n\n### ", $body); - $body = preg_replace("@@i", "\n\n#### ", $body); - $body = preg_replace("@@i", "* ", $body); - $body = strip_tags($body); - $body = decode_entities($body); - $body = wordwrap($body, 72); - } - else { - $body = decode_entities($body); - } - return $body; -} - /** - * Define all OG emails + * Define all OG message strings. * Modelled after Drupal's user.module */ function _og_user_mail_text($messageid, $variables = array()) { @@ -2190,27 +1955,6 @@ $form['og_register']['og_register'] = array('#type' => 'checkboxes', '#options' => $options, '#default_value' => $default_value); } return $form; - case 'form': - if ($category == 'account' && !empty($account->og_groups)) { - $form['og_settings'] = array( - '#type' => 'fieldset', - '#title' => t('Organic groups settings'), - '#collapsible' => TRUE, - '#weight' => 4); - $options = array(OG_NOTIFICATION_NEVER => t('Never send email notifications. Useful when tracking activity via RSS feed instead.'), - OG_NOTIFICATION_ALWAYS => t('Always send email notifications'), - OG_NOTIFICATION_SELECTIVE => t("Selectively send email notification based on the checkbox for each of my group's My Membership page."), - ); - - $form['og_settings']['og_email'] = array('#type' => 'radios', - '#title' => t('Email notifications'), - '#options' => $options, - '#default_value' => isset($account->og_email) ? $account->og_email : variable_get('og_notification', 2), - '#description' => t('When posts are submitted into your groups, you may be notified via email.'), - ); - return $form; - } - break; case 'insert': if (is_array($edit['og_register'])) { foreach (array_keys(array_filter($edit['og_register'])) as $gid) { @@ -2221,32 +1965,13 @@ } } - $sql = 'INSERT INTO {og_uid_global} (uid, og_email) VALUES (%d, %d)'; - db_query($sql, $account->uid, variable_get('og_notification', OG_NOTIFICATION_ALWAYS)); - $account->og_email = NULL; - break; - case 'update': - if (isset($edit['og_email'])) { - $sql = 'UPDATE {og_uid_global} SET og_email=%d WHERE uid=%d'; - db_query($sql, $edit['og_email'], $account->uid); - $account->og_email = NULL; - } break; case 'delete': - // user delete doesn't exist, but it should and will one day. - $sql = 'DELETE FROM {og_uid_global} WHERE uid=%d'; - db_query($sql, $account->uid); - $sql = 'DELETE FROM {og_uid} WHERE uid=%d'; db_query($sql, $account->uid); break; case 'load': $account->og_groups = og_get_subscriptions($account->uid); - - $result = db_query("SELECT og_email FROM {og_uid_global} WHERE uid = %d", $account->uid); - if (db_num_rows($result)) { - $account->og_email = db_result($result); - } break; case 'view': // only show list of groups to self and admins @@ -2295,13 +2020,13 @@ $usages = array( 'group' => t('Group node'), 'omitted' => t('May not be posted into a group.'), - 'group_post_standard_mail' => t('Standard group post (typically only author may edit). Sends email notifications.'), - 'group_post_standard_nomail' => t('Standard group post (typically only author may edit). No email notification.'), + 'group_post_standard_mail' => t('Standard group post (typically only author may edit). Sends notifications.'), + 'group_post_standard_nomail' => t('Standard group post (typically only author may edit). No notification.'), ); if (module_exists('og_access')) { - $usages['group_post_wiki_mail'] = t('Wiki group post (any group member may edit). Sends email notifications.'); - $usages['group_post_wiki_nomail'] = t('Wiki group post (any group member may edit). No email notification.'); + $usages['group_post_wiki_mail'] = t('Wiki group post (any group member may edit). Sends notifications.'); + $usages['group_post_wiki_nomail'] = t('Wiki group post (any group member may edit). No notification.'); } return $usages; @@ -2324,12 +2049,6 @@ return isset($return[$usage]) ? $return[$usage] : array(); } -// returns TRUE if node type should generate email notifications when posted to a group. -function og_is_mail_type($type) { - $usage = variable_get('og_content_type_usage_'. $type, 'omitted'); - return strpos($usage, 'mail') && !strpos($usage, 'nomail') ? TRUE : FALSE; -} - // returns TRUE if node type lets all subscribers edit the node. function og_is_wiki_type($type) { $usage = variable_get('og_content_type_usage_'. $type, 'omitted'); @@ -2450,7 +2169,7 @@ if ($groupnode = og_get_group_context()) { // only members can see this block if (in_array($groupnode->nid, array_keys($user->og_groups))) { - $content = t('This group offers a !groupfeed and an !email.', array('!groupfeed' => l(t('RSS feed'), "node/$groupnode->nid/feed"), '!email' => l(t('email subscription'), 'og/manage/'. $groupnode->nid))); + $content = t('This group offers a !groupfeed and a !subscription.', array('!groupfeed' => l(t('RSS feed'), "node/$groupnode->nid/feed"), '!subscription' => l(t('subscription option'), 'og/manage/'. $groupnode->nid))); if (module_exists('views') && module_exists('views_rss')) { // NOTE: See og.css for styling specific to these lists $content .= ' '. t('Or subscribe to these personalized, sitewide feeds:'); @@ -2724,6 +2443,7 @@ $form['#action'] = url("og/search/$group->nid"); return $form; } + function og_admin_settings() { drupal_set_title(t('Organic groups configuration')); @@ -2765,12 +2485,6 @@ ); $form['og_settings']['group_details']['og_visibility_registration'] = array('#type' => 'radios', '#title' => t('Registration form control'), '#default_value' => variable_get('og_visibility_registration', OG_REGISTRATION_CHOOSE_FALSE), '#description' =>t('OG admins always see the checkbox for adding a group to the %dir. Note that changing this setting has no effect on existing posts. Re-save those posts to acquire this new setting.', array('%dir' => t('registration form'))), '#options' => $options); - // email notifications default - $options = array(OG_NOTIFICATION_SELECTIVE => t('New members are not subscribed to group email notifications by default. A member may choose to enable this from her profile page or her My membership page.'), - OG_NOTIFICATION_ALWAYS => t('New members are subscribed to group email notifications by default. A member may choose to disable this from her profile page.'), - ); - $form['og_settings']['group_details']['og_notification'] = array('#type' => 'radios', '#title' => t('Group email notifications'), '#default_value' => variable_get('og_notification', OG_NOTIFICATION_ALWAYS), '#description' =>t('Should new members automatically be notified via email when new content is posted to their group? Note that changing this setting has no effect on existing members.'), '#options' => $options); - // audience checkboxes $form['og_settings']['group_details']['og_audience_checkboxes'] = array('#type' => 'checkbox', '#title' => t('Audience checkboxes'), '#default_value' => variable_get('og_audience_checkboxes', TRUE), '#description' => t('Show each group that the user is a member of as a checkbox in the Audience section. This enables the member to place her post into multiple groups. If unchecked, simplify the user interface by omitting the checkboxes and assuming user wants to post into the current group. This simplification only applies to new nodes, and not to edits of existing nodes. Group administrators always see checkboxes.')); @@ -2786,27 +2500,104 @@ // member pictures $form['og_settings']['group_details']['og_member_pics'] = array('#type' => 'checkbox', '#title' => t('Member pictures'), '#default_value' => variable_get('og_member_pics', TRUE), '#description' => t('Should member pictures be shown on the members page, the group members block, and group details block? You must also enable pictures in !user.', array('!user' => l(t('User configuration'), 'admin/user/settings')))); - $form['og_settings']['email'] = array('#type' => 'fieldset', '#title' => t('Email settings'), '#collapsible' => TRUE, '#collapsed' => TRUE); - - $form['og_settings']['email']['og_email_notification_pattern'] = array( + // Messages fieldset. + $form['og_settings']['notifications'] = array( + '#type' => 'fieldset', + '#title' => t('Messaging & Notifications'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + $form['og_settings']['notifications']['og_email_notification_pattern'] = array( '#type' => 'textfield', '#title' => t('Format of From: field'), '#default_value' => variable_get("og_email_notification_pattern", '@user_name <@site_mail>'), '#description' => t('Specify the format of the "From:" field on outgoing notifications. Available variables: @user_mail, @user_name, @site_mail, @site_name. Note that the @user_mail token reveals the author\'s email address. If the admin email examples above appear blank, you need to set your site email in the Site Configuration panel.'), ); - $form['og_settings']['email']['og_new_node_subject'] = array('#type' => 'textfield', '#title' => t('New content subject'), '#description' => t('Subject of email for new content. Available variables: @group, !group_url, @type, @site, !content_url, !reply_url, @title, @subject, @node_full, @node_teaser, @username. %subject contains the comment title in the case of a comment but the node title in the case of a new post. @title is always the node title.'), '#default_value' => _og_user_mail_text('og_new_node_subject')); - $form['og_settings']['email']['og_new_node_body'] = array('#type' => 'textarea', '#title' => t('New content body'), '#rows' => 10, '#description' => t('Body of email for new content. Available variables: @group, !group_url, @type, @site, !content_url, !reply_url, @title, @subject, @node_full, @node_teaser, @username. @subject contains the comment title in the case of a comment but the node title in the case of a new post. %title is always the node title.'), '#default_value' => _og_user_mail_text('og_new_node_body')); - $form['og_settings']['email']['og_admin_email_body'] = array('#type' => 'textarea', '#title' => t('Group admin email body'), '#rows' => 10, '#description' => t('The body of the email sent to users from the group admin. Available variables: @group, @body, @site, !url_group, !url_unsubscribe'), '#default_value' => _og_user_mail_text('og_admin_email_body')); - $form['og_settings']['email']['og_approve_user_subject'] = array('#type' => 'textfield', '#title' => t('User approved email subject'), '#description' => t('The subject of the email sent to new approved members. Available variables: !group_url, @title'), '#default_value' => _og_user_mail_text('og_approve_user_subject')); - $form['og_settings']['email']['og_approve_user_body'] = array('#type' => 'textarea', '#title' => t('User approved email body'), '#rows' => 10, '#description' => t('The body of the email sent to new approved members. Available variables: !group_url, @title'), '#default_value' => _og_user_mail_text('og_approve_user_body')); - $form['og_settings']['email']['og_deny_user_subject'] = array('#type' => 'textfield', '#title' => t('User denied email subject'), '#description' => t('The subject of the email sent to denied users. Available variables: !group_url, @title'), '#default_value' => _og_user_mail_text('og_deny_user_subject')); - $form['og_settings']['email']['og_deny_user_body'] = array('#type' => 'textarea', '#title' => t('User denied email body'), '#rows' => 10, '#description' => t('The body of the email sent to denied users. Available variables: !group_url, @title'), '#default_value' => _og_user_mail_text('og_deny_user_body')); - $form['og_settings']['email']['og_invite_user_subject'] = array('#type' => 'textfield', '#title' => t('Invite user email subject'), '#description' => t('The subject of the email sent to users invited to join a group. Available variables: @group, @site, @description, !group_url, @body'), '#default_value' => _og_user_mail_text('og_invite_user_subject')); - $form['og_settings']['email']['og_invite_user_body'] = array('#type' => 'textarea', '#title' => t('Invite user email body'), '#rows' => 10, '#description' => t('The body of the email sent to users invited to join a group. Available variables: @group, @site, @description, !group_url, @body'), '#default_value' => _og_user_mail_text('og_invite_user_body')); - $form['og_settings']['email']['og_request_user_subject'] = array('#type' => 'textfield', '#title' => t('Request user email subject'), '#description' => t("The subject of the email sent to a user's request to join a group. Available variables: @group, @username, !approve_url, !group_url"), '#default_value' => _og_user_mail_text('og_request_user_subject')); - $form['og_settings']['email']['og_request_user_body'] = array('#type' => 'textarea', '#title' => t('Request user email body'), '#rows' => 10, '#description' => t("The body of the email sent to a user's request to join a group. Available variables: @group, @username, !approve_url, !group_url"), '#default_value' => _og_user_mail_text('og_request_user_body')); - $form['og_settings']['email']['og_new_admin_subject'] = array('#type' => 'textfield', '#title' => t('New admin user email subject'), '#description' => t('The subject of the email sent to a new admin for a group. Available variables: @group, @username, !group_url'), '#default_value' => _og_user_mail_text('og_new_admin_subject')); - $form['og_settings']['email']['og_new_admin_body'] = array('#type' => 'textarea', '#title' => t('New admin user email body'), '#rows' => 10, '#description' => t('The body of the email sent to a new admin for a group. Available variables: @group, @username, !group_url, !invite_url'), '#default_value' => _og_user_mail_text('og_new_admin_body')); + $form['og_settings']['notifications']['og_new_node_subject'] = array( + '#type' => 'textfield', + '#title' => t('New content subject'), + '#description' => t('Subject of notification message for new content. Available variables: @group, !group_url, @type, @site, !content_url, !reply_url, @title, @subject, @node_full, @node_teaser, @username. %subject contains the comment title in the case of a comment but the node title in the case of a new post. @title is always the node title.'), + '#default_value' => _og_user_mail_text('og_new_node_subject') + ); + $form['og_settings']['notifications']['og_new_node_body'] = array( + '#type' => 'textarea', + '#title' => t('New content body'), + '#rows' => 10, + '#description' => t('Body of the notification for new content. Available variables: @group, !group_url, @type, @site, !content_url, !reply_url, @title, @subject, @node_full, @node_teaser, @username. @subject contains the comment title in the case of a comment but the node title in the case of a new post. %title is always the node title.'), + '#default_value' => _og_user_mail_text('og_new_node_body') + ); + $form['og_settings']['notifications']['og_admin_email_body'] = array( + '#type' => 'textarea', + '#title' => t('Group admin notification body'), + '#rows' => 10, + '#description' => t('The body of the message sent to users from the group admin. Available variables: @group, @body, @site, !url_group, !url_unsubscribe'), + '#default_value' => _og_user_mail_text('og_admin_email_body') + ); + $form['og_settings']['notifications']['og_approve_user_subject'] = array( + '#type' => 'textfield', + '#title' => t('User approved notification subject'), + '#description' => t('The subject of the message sent to new approved members. Available variables: !group_url, @title'), + '#default_value' => _og_user_mail_text('og_approve_user_subject') + ); + $form['og_settings']['notifications']['og_approve_user_body'] = array( + '#type' => 'textarea', + '#title' => t('User approved notification body'), + '#rows' => 10, + '#description' => t('The body of the message sent to new approved members. Available variables: !group_url, @title'), + '#default_value' => _og_user_mail_text('og_approve_user_body') + ); + $form['og_settings']['notifications']['og_deny_user_subject'] = array( + '#type' => 'textfield', + '#title' => t('User denied notification subject'), + '#description' => t('The subject of the message sent to denied users. Available variables: !group_url, @title'), + '#default_value' => _og_user_mail_text('og_deny_user_subject') + ); + $form['og_settings']['notifications']['og_deny_user_body'] = array( + '#type' => 'textarea', + '#title' => t('User denied notification body'), + '#rows' => 10, + '#description' => t('The body of the message sent to denied users. Available variables: !group_url, @title'), + '#default_value' => _og_user_mail_text('og_deny_user_body') + ); + $form['og_settings']['notifications']['og_invite_user_subject'] = array( + '#type' => 'textfield', + '#title' => t('Invite user notification subject'), + '#description' => t('The subject of the message sent to users invited to join a group. Available variables: @group, @site, @description, !group_url, @body'), + '#default_value' => _og_user_mail_text('og_invite_user_subject') + ); + $form['og_settings']['notifications']['og_invite_user_body'] = array( + '#type' => 'textarea', + '#title' => t('Invite user notification body'), + '#rows' => 10, + '#description' => t('The body of the message sent to users invited to join a group. Available variables: @group, @site, @description, !group_url, @body'), + '#default_value' => _og_user_mail_text('og_invite_user_body') + ); + $form['og_settings']['notifications']['og_request_user_subject'] = array( + '#type' => 'textfield', + '#title' => t('Request user notification subject'), + '#description' => t("The subject of the message sent to a user's request to join a group. Available variables: @group, @username, !approve_url, !group_url"), + '#default_value' => _og_user_mail_text('og_request_user_subject') + ); + $form['og_settings']['notifications']['og_request_user_body'] = array( + '#type' => 'textarea', + '#title' => t('Request user notification body'), + '#rows' => 10, + '#description' => t("The body of the message sent to a user's request to join a group. Available variables: @group, @username, !approve_url, !group_url"), + '#default_value' => _og_user_mail_text('og_request_user_body') + ); + $form['og_settings']['notifications']['og_new_admin_subject'] = array( + '#type' => 'textfield', + '#title' => t('New admin user notification subject'), + '#description' => t('The subject of the message sent to a new admin for a group. Available variables: @group, @username, !group_url'), + '#default_value' => _og_user_mail_text('og_new_admin_subject') + ); + $form['og_settings']['notifications']['og_new_admin_body'] = array( + '#type' => 'textarea', + '#title' => t('New admin user notification body'), + '#rows' => 10, + '#description' => t('The body of the message sent to a new admin for a group. Available variables: @group, @username, !group_url, !invite_url'), + '#default_value' => _og_user_mail_text('og_new_admin_body') + ); return system_settings_form($form); } @@ -2950,21 +2741,6 @@ } } -// A hook from replies.module. Return TRUE if og is handling the notification to a given recipient on a given reply -function og_replies_mine($comment, $recipient) { - $node = node_load($comment->nid); - // check each group that this node is in - foreach ((array)$node->og_groups as $gid) { - // check if recipient is an active member - if (isset($recipient->og_groups[$gid]) && $recipient->og_groups[$gid]['is_active']) { - // check if user is already getting this group notification - if ($recipient->og_email || $recipient->og_groups[$gid]['mail_type']) { - return TRUE; - } - } - } -} - function og_requirements($phase) { $requirements = array(); // Ensure translations don't break at install time @@ -2980,14 +2756,6 @@ ); } - if (!module_exists('job_queue')) { - $requirements['og_modules'] = array( - 'title' => $t('Organic groups modules'), - 'value' => $t('Organic groups works best when !job_queue.module is enabled. See the Integration section of the !readme.', array('!job_queue' => l('job_queue.module', 'http://drupal.org/project/job_queue'), '!readme' => og_readme())), - 'severity' => REQUIREMENT_INFO - ); - } - if (!module_exists('og_access')) { $requirements['og_access'] = array( 'title' => $t('Organic groups access control'), Index: og_notifications/og_notifications.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/og/og_notifications/Attic/og_notifications.module,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 og_notifications.module --- og_notifications/og_notifications.module 6 Jun 2008 08:27:47 -0000 1.1.2.2 +++ og_notifications/og_notifications.module 11 Jul 2008 20:13:05 -0000 @@ -3,17 +3,13 @@ /** * @file * Subscriptions to content in groups. - * - * Group subscriptions are allowed for users who have view access to the group - * node. Whether a user can get a notification about a specific post will be - * decided later. */ /** * Implementation of hook_menu_() */ function og_notifications_menu($may_cache) { - global $user; // we need the user to to build some urls + global $user; $items = array(); if (!$may_cache) { @@ -43,7 +39,7 @@ } /** - * Implementation of hook_perm() + * Implementation of hook_perm(). */ function og_notifications_perm() { return array('subscribe to content in groups'); @@ -82,36 +78,47 @@ // TODO: Is perm checking necessary here? // Insert autosubscribe option into the messaging section of the user edit // form. - $account = $form['_account']['#value']; - // TODO: Strings need to conform with OG and notifications terminology. - $form['messaging']['og_notifications_autosubscribe'] = array( - '#type' => 'checkbox', - '#title' => t('Automatically enable notifications for any organic groups that I join.'), - '#description' => t('Group notifications can be customised in greater detail if necessary.', array('!manage-url' => url('user/'. $account->uid .'/notifications/group'))), - '#default_value' => isset($account->og_notifications_autosubscribe) ? $account->og_notifications_autosubscribe : variable_get('og_notifications_autosubscribe', 1) - ); + + // user_edit is, oddly enough, also the form_id for forms in other + // sub-tabs such as those added by the profile module. + if (!arg(3)) { + $account = $form['_account']['#value']; + // TODO: Strings need to conform with OG and notifications terminology. + $form['messaging']['og_notifications_autosubscribe'] = array( + '#type' => 'checkbox', + '#title' => t('Automatically enable notifications for any groups that I join.'), + '#description' => t('Group notifications can be customised in greater detail if required.', array('!manage-url' => url('user/'. $account->uid .'/notifications/group'))), + '#default_value' => isset($account->og_notifications_autosubscribe) ? $account->og_notifications_autosubscribe : variable_get('og_notifications_autosubscribe', 1) + ); + } break; case 'og_admin_settings': - // Insert the global autosubsribe checkbox into the OG administration - // page. The fieldset should probably be renamed? - $form['og_settings']['email']['og_notifications_autosubscribe'] = array( + $form['og_settings']['notifications']['og_notifications_autosubscribe'] = array( '#type' => 'checkbox', '#title' => t('Autosubscribe users to any groups that they join.'), '#description' => t('Automatically enable notifications by default. Users can override this via their account page.'), '#default_value' => variable_get('og_notifications_autosubscribe', 1), - '#weight' => -1 + '#weight' => -5 + ); + $form['og_settings']['notifications']['og_notifications_delivery'] = array( + '#type' => 'radios', + '#title' => t('Delivery method'), + '#description' => t('Select the delivery method for administrative messages.'), + '#options' => messaging_method_list(), + '#default_value' => variable_get('og_notifications_delivery', 'mail'), + '#weight' => -4 ); break; } } /** - * Implementation of hook_nodeapi() + * Implementation of hook_nodeapi(). */ function og_notifications_nodeapi(&$node, $op, $arg = 0) { switch ($op) { case 'delete': - // Remove all group subscriptions for this node + // Remove all group subscriptions for this node. notifications_delete_subscriptions(array('type' => 'group'), array('group' => $node->nid)); notifications_delete_subscriptions(array('type' => 'grouptype'), array('group' => $node->nid)); } @@ -130,15 +137,109 @@ $account = user_load(array('uid' => $uid)); og_notifications_user_unsubscribe($account, $gid); break; + case 'user request': + // This and other notifications related ops drop down to the same case. + // These different ops have been provided for consistency and flexibility + // during use by other modules. + case 'user approve': + case 'admin create': + case 'admin new': + case 'user broadcast': + // @TODO: Consider providing options for the full gamut of message body + // options (header, footer etc.). + // @TODO: Reuse the messaging API's inbuilt token support. + + $method = variable_get('og_notifications_delivery', 'mail'); + // Avoid exposing the messaging API's internal data structure to OG to + // promote reuse. + $args['body'] = array('event' => $args['body']); + $args['type'] = 'og-notifications'; + + // Allow queue and from address overrides. + $queue = isset($args['queue']) ? $args['queue'] : FALSE; + if (isset($args['from'])) { + $args['sender_account'] = $args['from']; + // This should probably be using the og_email_notification_pattern + // variable. + } + + // Clean up $message ($args). + unset($args['queue'], $args['from']); + + // Is this a bulk message? + $bulk = is_array($uid) ? TRUE : FALSE; + if ($bulk) { + // Are the recipients UIDs or e-mail addresses? + if (isset($args['email']) && $args['email'] == TRUE) { + $destinations = $uid; + } + else { + $destinations = array(); + foreach ($uid as $recipient) { + $destinations[] = messaging_load_user($recipient); + } + } + unset($args['email']); + // Disabled until bulk messaging is fixed in messaging_message_send_out(). + // messaging_message_send($destinations, $args, $method, $queue); + + // Workaround: (doesn't work for e-mail input) + foreach ($destinations as $account) { + messaging_message_send_user($account, $args, $method, $queue); + } + } + else { + // It is assumed that a non-bulk e-mail is always targetted at a UID + // and not an e-mail address. + $account = messaging_load_user($uid); + messaging_message_send_user($account, $args, $method, $queue); + } + break; } } /** - * Temporary implementation of hook_og_notify() to override og's inbuilt - * notification system. + * Implementation of hook_messaging(). */ -function og_notifications_og_notify() { - return TRUE; +function og_notifications_messaging($op, $arg1 = NULL, $arg2 = NULL, $arg3 = NULL, $arg4 = NULL) { + switch ($op) { + case 'message groups': + // Generic notifications event + $info['og-notifications'] = array( + 'module' => 'og_notifications', + 'name' => t('OG notifications'), + 'help' => t('Most fields will be provided during the event.') + ); + return $info; + case 'message keys': + $type = $arg1; + switch ($type) { + case 'og-notifications': + return array( + 'subject' => t('Subject for event notifications'), + 'header' => t('Body header for event notifications'), + 'main' => t('Body for event notifications'), + 'footer' => t('Body footer for event notifications'), + ); + break; + } + break; + case 'messages': + $type = $arg1; + switch ($type) { + case 'og-notifications': + return array( + 'subject' => t('[site-name] subscription update for [user]'), + 'header' => t("Greetings, [user].\n\nThese are your messages"), + 'main' => t("A [type] has been updated: [title]\n\n[event_list]"), + 'footer' => array( + t('This is an automatic message from [site-name])'), + t('To manage your subscriptions, browse to [subscriptions-manage]'), + ) + ); + } + break; + } } /** @@ -176,8 +277,8 @@ $query = array(); if ($node->og_groups) { $query[] = array( - 'join' => "LEFT JOIN {og_ancestry} og ON f.field = 'group' AND f.value = CAST(og.group_nid AS CHAR(255))", - 'where' => 'og.nid = %d', + 'join' => "LEFT JOIN {og_ancestry} oga ON f.field = 'group' AND f.value = CAST(oga.group_nid AS CHAR(255))", + 'where' => 'oga.nid = %d', 'args' => array($node->nid), ); } @@ -517,5 +618,6 @@ ); } } + return $options; } Index: og_notifications/og_notifications.install =================================================================== RCS file: og_notifications/og_notifications.install diff -N og_notifications/og_notifications.install --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ og_notifications/og_notifications.install 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,55 @@ + $subscription->uid)); + og_notifications_user_subscribe($account, $subscription->nid); + } + // @todo Save auto-subscription in the user table based on og_uid_global. + + + // Drop field notification. + $ret[] = update_sql("ALTER TABLE {og} DROP notification"); + // Drop field mail_type. + $ret[] = update_sql("ALTER TABLE {og_uid} DROP mail_type"); + // Drop table og_uid_global. + $ret[] = update_sql("DROP TABLE {og_uid_global}"); + + variable_del('og_notifications_update_required'); + + return $ret; +} + +/** + * Implementation of hook_uninstall(). + */ +function og_notifications_uninstall() { + drupal_set_message(t('Organic groups notifications module uninstallation script complete.')); +} Index: og_notifications/README.txt =================================================================== RCS file: og_notifications/README.txt diff -N og_notifications/README.txt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ og_notifications/README.txt 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,9 @@ +$Id$ + +og_notifications integrates OG with the notifications and messaging modules +family thereby enabling such features as group subscriptions, administrative +notifications etc. + +The notifications and messaging modules extend beyond simple e-mail based +delivery systems and provide other avenues to contact recipients such as +private messages, simple alerts and even SMS.