function og_mail in Organic groups 5.2
Same name and namespace in other branches
- 5 og.module \og_mail()
- 5.7 og.module \og_mail()
- 6.2 og.module \og_mail()
- 6 og.module \og_mail()
Send this node/comment via email to all email subscribers. Called from og_nodeapi() and og_comment() TODO: this mail feature is a bit messy. rethink.
Parameters
$type: the object type: node or comment
$obj: the node or comment which was just added. if comment, the $og_groups element should be copied from parent node
Return value
none
2 calls to og_mail()
- og_comment in ./
og.module - og_nodeapi in ./
og.module - Implementation of hook_nodeapi().
1 string reference to 'og_mail'
File
- ./
og.module, line 1659
Code
function og_mail($type, $obj) {
if ($obj->og_groups) {
// prepare the body
if ($type == 'comment') {
// registered user
if ($obj->uid) {
$account = user_load(array(
'uid' => $obj->uid,
));
$obj->name = $account->name;
}
else {
$obj->name = variable_get('anonymous', 'Anonymous');
}
$obj->body = check_markup($obj->comment, $comment->format, FALSE);
$originalurl = url("node/{$obj->nid}", NULL, "comment-{$obj->cid}", TRUE);
$replyurl = url("comment/reply/{$obj->nid}/{$obj->cid}", NULL, NULL, TRUE);
}
else {
$account = user_load(array(
'uid' => $obj->uid,
));
$obj->name = $account->name;
$obj->subject = $obj->title;
$obj = node_prepare($obj, FALSE);
// fills body with CCK fields, event fields, etc. instead of "n/a"
$obj->body = og_node_view($obj);
$originalurl = url("node/{$obj->nid}", NULL, NULL, TRUE);
$replyurl = url("comment/reply/{$obj->nid}", NULL, 'comment-form', TRUE);
}
$sitemail = variable_get("site_mail", ini_get("sendmail_from"));
$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 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),
'@body' => trim(og_mail_output($obj->body)),
'@username' => $obj->name,
);
// send email to selective subscribers and global subscribers
$groups = implode(', ', $obj->og_groups);
// tricky query here. mysql returns NULL in the case of NULL != 0 so i rework this for 3 positive statements about og_email field
// og_email can be NULL when you enable og on an existing site.
$sql = "SELECT DISTINCT(u.mail) as mail, ou.nid AS gid, n.title AS group_name, n.uid AS group_uid, u.name AS group_owner, oug.og_email \n FROM {og_uid} ou INNER JOIN {users} u ON ou.uid=u.uid LEFT JOIN {og_uid_global} oug ON ou.uid=oug.uid INNER JOIN {node} n ON ou.nid=n.nid \n WHERE u.mail != '' AND\n ou.nid IN ({$groups}) AND (\n (oug.og_email IS NULL AND ou.mail_type=1) OR\n (oug.og_email = %d AND ou.mail_type=1) OR\n (oug.og_email = %d)\n ) AND u.status = 1";
$result = db_query($sql, OG_NOTIFICATION_SELECTIVE, OG_NOTIFICATION_ALWAYS);
while ($row = db_fetch_object($result)) {
// append these group specific variables
$variables['@group'] = $row->group_name;
$variables['!group_url'] = url("og/manage/{$row->gid}", NULL, NULL, TRUE);
$variables['@type'] = $type;
// see http://www.ietf.org/rfc/rfc2369.txt. UTF8 OK? $headers .= "\nX-List_ID: ";
$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' => "{$row->group_name} <{$group_home}>",
'List-Unsubscribe' => "<{$unsubscribe}>",
'List-Owner' => "{$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), $obj->name . " <{$sitemail}>", $groupheaders);
}
}
}