| 1 |
<?php
|
| 2 |
// $Id: commentmail.module,v 1.18 2008/11/26 22:52:31 maartenvg Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @todo
|
| 6 |
* - integrate with token module
|
| 7 |
* - user comment_load from the menu system
|
| 8 |
* - $comment in commentmail_comment() is already good
|
| 9 |
* - use FAPI #redirect
|
| 10 |
*/
|
| 11 |
|
| 12 |
define('COMMENTMAIL_DEFAULT_APPROVE', "An unapproved comment has been posted on @site for the post '@node'. You need to publish this comment before it will appear on your site.
|
| 13 |
|
| 14 |
approve/edit/delete/ban: @quick_approve
|
| 15 |
|
| 16 |
Name: @user | Email: @mail | URL: @homepage | IP: @host
|
| 17 |
Comment:
|
| 18 |
|
| 19 |
@subject
|
| 20 |
|
| 21 |
@comment
|
| 22 |
|
| 23 |
approve/edit/delete/ban: @quick_approve
|
| 24 |
|
| 25 |
Comment administration: @admin_url");
|
| 26 |
|
| 27 |
define('COMMENTMAIL_DEFAULT_NOTIFY', "A new comment has been posted on @site for the post '@node'.
|
| 28 |
|
| 29 |
THIS COMMENT DOES NOT REQUIRE APPROVAL
|
| 30 |
|
| 31 |
Name: @user | Email: @mail | URL: @homepage | IP: @host
|
| 32 |
Comment:
|
| 33 |
|
| 34 |
@subject
|
| 35 |
|
| 36 |
@comment
|
| 37 |
|
| 38 |
edit/delete/ban: @quick_approve
|
| 39 |
|
| 40 |
Comment administration: @admin_url");
|
| 41 |
|
| 42 |
|
| 43 |
/**
|
| 44 |
* Implementation of hook_menu().
|
| 45 |
*/
|
| 46 |
function commentmail_menu() {
|
| 47 |
$items = array();
|
| 48 |
|
| 49 |
$items['comment/qa/%'] = array(
|
| 50 |
'title' => 'Quick edit',
|
| 51 |
'page callback' => 'commentmail_quick_approve',
|
| 52 |
'page arguments' => array(2),
|
| 53 |
'type' => MENU_CALLBACK,
|
| 54 |
'access callback' => TRUE,
|
| 55 |
'file' => 'commentmail.actions.inc',
|
| 56 |
);
|
| 57 |
|
| 58 |
$items['comment/qa/%/%'] = array(
|
| 59 |
'title' => 'Quick edit',
|
| 60 |
'page callback' => 'commentmail_quick_approve',
|
| 61 |
'page arguments' => array(2, 3),
|
| 62 |
'type' => MENU_CALLBACK,
|
| 63 |
'access callback' => TRUE,
|
| 64 |
'file' => 'commentmail.actions.inc',
|
| 65 |
);
|
| 66 |
|
| 67 |
$items['admin/settings/commentmail'] = array(
|
| 68 |
'title' => 'Comment mail',
|
| 69 |
'description' => 'Settings for the comment mail module.',
|
| 70 |
'access arguments' => array('administer comments'),
|
| 71 |
'page callback' => 'drupal_get_form',
|
| 72 |
'page arguments' => array('commentmail_admin_settings'),
|
| 73 |
'file' => 'commentmail.admin.inc',
|
| 74 |
);
|
| 75 |
|
| 76 |
$items['comment/approve/%'] = array(
|
| 77 |
'title' => 'Approve comment',
|
| 78 |
'access arguments' => array('administer comments'),
|
| 79 |
'page callback' => 'drupal_get_form',
|
| 80 |
'page arguments' => array('commentmail_approve', 2),
|
| 81 |
'type' => MENU_CALLBACK,
|
| 82 |
'file' => 'commentmail.actions.inc',
|
| 83 |
);
|
| 84 |
|
| 85 |
$items['comment/deleteban/%'] = array(
|
| 86 |
'title' => 'Delete comment and ban user',
|
| 87 |
'access arguments' => array('administer comments'),
|
| 88 |
'page callback' => 'drupal_get_form',
|
| 89 |
'page arguments' => array('commentmail_deleteban', 2),
|
| 90 |
'type' => MENU_CALLBACK,
|
| 91 |
'file' => 'commentmail.actions.inc',
|
| 92 |
);
|
| 93 |
|
| 94 |
$items['comment/quickdelete/%'] = array(
|
| 95 |
'title' => 'Quick delete',
|
| 96 |
'access arguments' => array('administer comments'),
|
| 97 |
'page callback' => 'commentmail_quick_delete',
|
| 98 |
'page arguments' => array(2),
|
| 99 |
'type' => MENU_CALLBACK,
|
| 100 |
'file' => 'commentmail.actions.inc',
|
| 101 |
);
|
| 102 |
|
| 103 |
$items['comment/quickdeleteban/%'] = array(
|
| 104 |
'title' => 'Quick delete and ban',
|
| 105 |
'access arguments' => array('administer comments'),
|
| 106 |
'page callback' => 'commentmail_quick_deleteban',
|
| 107 |
'page arguments' => array(2),
|
| 108 |
'type' => MENU_CALLBACK,
|
| 109 |
'file' => 'commentmail.actions.inc',
|
| 110 |
);
|
| 111 |
|
| 112 |
return $items;
|
| 113 |
}
|
| 114 |
|
| 115 |
/**
|
| 116 |
* Implementation of hook_comment().
|
| 117 |
*/
|
| 118 |
function commentmail_comment($comment, $op) {
|
| 119 |
global $language;
|
| 120 |
|
| 121 |
if ($op == 'insert') {
|
| 122 |
// Load the real comment object from the database.
|
| 123 |
$comment_obj = _comment_load($comment['cid']);
|
| 124 |
|
| 125 |
$mode = variable_get('commentmail_mode', 'approval');
|
| 126 |
|
| 127 |
// Only proceed if mail is sent always or the comment is not published yet.
|
| 128 |
if(!($mode == 'approval' && $comment_obj->status == COMMENT_PUBLISHED) && $mode != 'disable') {
|
| 129 |
$recipient = variable_get('commentmail_to', variable_get('site_mail', FALSE));
|
| 130 |
|
| 131 |
// Only send a mail if a recipient has been specified.
|
| 132 |
if ($recipient) {
|
| 133 |
$params['comment'] = $comment_obj;
|
| 134 |
drupal_mail('commentmail', $mode .'_mail', $recipient, $language, $params);
|
| 135 |
|
| 136 |
}
|
| 137 |
else {
|
| 138 |
watchdog('commentmail', 'Site mail address is not configured.', array(), WATCHDOG_ERROR);
|
| 139 |
}
|
| 140 |
}
|
| 141 |
}
|
| 142 |
}
|
| 143 |
|
| 144 |
|
| 145 |
/**
|
| 146 |
* Implementation of hook_mail().
|
| 147 |
*/
|
| 148 |
function commentmail_mail($key, &$message, $params) {
|
| 149 |
// Load the node to get the title.
|
| 150 |
$node = node_load($params['comment']->nid);
|
| 151 |
|
| 152 |
if ($key == 'approval_mail') {
|
| 153 |
$body = variable_get('commentmail_mail_approve', t(COMMENTMAIL_DEFAULT_APPROVE));
|
| 154 |
}
|
| 155 |
else {
|
| 156 |
$body = variable_get('commentmail_mail_notify', t(COMMENTMAIL_DEFAULT_NOTIFY));
|
| 157 |
}
|
| 158 |
|
| 159 |
// Check if the user is logged in.
|
| 160 |
if ($params['comment']->uid) {
|
| 161 |
$account = user_load(array('uid' => $comment_obj->uid));
|
| 162 |
$params['comment']->mail = $account->mail;
|
| 163 |
$params['comment']->homepage = $account->homepage;
|
| 164 |
}
|
| 165 |
|
| 166 |
$options = array('absolute' => TRUE);
|
| 167 |
|
| 168 |
$variables = array(
|
| 169 |
'@site' => variable_get('site_name', 'Drupal'),
|
| 170 |
'@node' => $node->title,
|
| 171 |
'@quick_approve' => url('comment/qa/'. $params['comment']->cid, $options),
|
| 172 |
'@approval_url' => url('comment/approve/'. $params['comment']->cid, $options),
|
| 173 |
'@delete_url' => url('comment/delete/'. $params['comment']->cid, $options),
|
| 174 |
'@ban_url' => url('comment/deleteban/'. $params['comment']->cid, $options),
|
| 175 |
'@edit_url' => url('comment/edit/'. $params['comment']->cid, $options),
|
| 176 |
'@queue_url' => url('admin/content/comment/approval', $options),
|
| 177 |
'@view_url' => url('node/'. $node->nid, array('fragment' => 'comment-'. $params['comment']->cid, 'absolute' => TRUE)),
|
| 178 |
'@admin_url' => url('admin/content/comment', $options),
|
| 179 |
'@host' => $params['comment']->hostname,
|
| 180 |
'@user' => $params['comment']->name,
|
| 181 |
'@mail' => $params['comment']->mail,
|
| 182 |
'@homepage' => $params['comment']->homepage,
|
| 183 |
'@subject' => $params['comment']->subject,
|
| 184 |
'@comment' => $params['comment']->comment,
|
| 185 |
);
|
| 186 |
|
| 187 |
$message['subject'] = t('[!site] New Comment posted on "!title"', array('!title' => $node->title, '!site' => variable_get('site_name', 'Drupal')));
|
| 188 |
$message['body'][] = strtr($body, $variables);
|
| 189 |
}
|