| 1 |
<?php |
<?php |
| 2 |
|
|
| 3 |
// $Id: mail.module,v 1.23 2006/10/17 18:08:50 nedjo Exp $ |
// $Id: mail.module,v 1.19.2.4 2006/10/17 18:09:27 nedjo Exp $ |
| 4 |
|
|
| 5 |
/** |
/** |
| 6 |
* Provide online user help |
* Provide online user help |
| 7 |
*/ |
*/ |
| 8 |
function mail_help($section = 'admin/help#story') { |
function mail_help($section = 'admin/help#story') { |
| 9 |
switch ($section) { |
switch ($section) { |
| 10 |
case 'admin/modules#description': |
case 'admin/modules#description': |
| 11 |
return t('Enables site administrator or users to send emails to registered users.'); |
return t('Enables site administrator or users to send emails to registered users.'); |
| 12 |
case 'admin/settings/mail': |
case 'admin/settings/mail': |
| 13 |
return t('Mail postings are sent to registered users with specified roles and also saved to the site database for future reference. Email messages may be customized through the use of variables as listed under the "Message" field.'); |
return t('Mail postings are sent to registered users with specified roles and also saved to the site database for future reference. Email messages may be customized through the use of variables as listed under the "Message" field.'); |
| 14 |
case 'admin/help#mail': |
case 'admin/help#mail': |
| 15 |
return t(" |
return t(" |
| 16 |
<p>The mail module lets your users with appropriate permissions send mail to registered site users. Emails are also saved to the site database for future reference. The module provides a mail content type, and also lets other content types be emailed.</p> |
<p>The mail module lets your users with appropriate permissions send mail to registered site users. Emails are also saved to the site database for future reference. The module provides a mail content type, and also lets other content types be emailed.</p> |
| 17 |
<p>Mails sent from the admin account are tagged with the site name and come from the site admin email address. Mail sent from other accounts have that account's email as a return address and are tagged with a name in the form \"username at site\" where username is the user name of the user doing the posting and site is the name of the site.</p> |
<p>Mails sent from the admin account are tagged with the site name and come from the site admin email address. Mail sent from other accounts have that account's email as a return address and are tagged with a name in the form \"username at site\" where username is the user name of the user doing the posting and site is the name of the site.</p> |
| 18 |
<h3>Setting up content types for mailing</h3> |
<h3>Setting up content types for mailing</h3> |
| 19 |
<p>Use a content type's <a href=\"%node-configuration\">configuration page</a> to enable emailing for that content type. Set Email to \"enabled\". This will add an email section to the editing form for that content type, allowing users with appropriate permissions to send updates by email.</p> |
<p>Use a content type's <a href=\"%node-configuration\">configuration page</a> to enable emailing for that content type. Set Email to \"enabled\". This will add an email section to the editing form for that content type, allowing users with appropriate permissions to send updates by email.</p> |
| 20 |
<h3>Accepting emails</h3> |
<h3>Accepting emails</h3> |
| 21 |
<p>The mail module adds a new field to the user registration and editing forms through which users can opt in to receiving site emails. Emails send from non-admin accounts will go out only to users who have opted to receive emails. However, mails sent from user accounts with the \"administer users\" permission can go out to all users, whether or not they have opted in.</p> |
<p>The mail module adds a new field to the user registration and editing forms through which users can opt in to receiving site emails. Emails send from non-admin accounts will go out only to users who have opted to receive emails. However, mails sent from user accounts with the \"administer users\" permission can go out to all users, whether or not they have opted in.</p> |
| 22 |
<h3>User access permissions for mail</h3> |
<h3>User access permissions for mail</h3> |
| 23 |
<p><strong>send emails to users:</strong> Allows a role to post email to users. You must enable this permission to in order for a role to create a mail message.</p> |
<p><strong>send emails to users:</strong> Allows a role to post email to users. You must enable this permission to in order for a role to create a mail message.</p> |
| 24 |
<h3>Settings</h3> |
<h3>Settings</h3> |
| 25 |
<p>Use the mail <a href=\"%mail-settings\">mail settings page</a> to set default sending options. These include format (plain text or HTML), priority, character set, and receipt request. These options can be overridden for a particular mail post on the node editing page.</p> |
<p>Use the mail <a href=\"%mail-settings\">mail settings page</a> to set default sending options. These include format (plain text or HTML), priority, character set, and receipt request. These options can be overridden for a particular mail post on the node editing page.</p> |
| 26 |
<h3>Attachments</h3> |
<h3>Attachments</h3> |
| 27 |
<p>To allow users to send attachments with email messages, enable the upload module and ensure that uploads are enabled for mail posts. Any files uploaded with a mail post will then be sent as attachments.</p> |
<p>To allow users to send attachments with email messages, enable the upload module and ensure that uploads are enabled for mail posts. Any files uploaded with a mail post will then be sent as attachments.</p> |
| 28 |
", array("%node-configuration" => url("admin/settings/content-types"), "%mail-settings" => url("admin/settings/mail"))); |
", array("%node-configuration" => url("admin/settings/content-types"), "%mail-settings" => url("admin/settings/mail"))); |
| 29 |
case 'node/add/mail': |
case 'node/add/mail': |
| 30 |
if (!variable_get('mail_mail', 0)) { |
if (!variable_get('mail_mail', 0)) { |
| 31 |
return t('Emailing is not yet enabled for mail posts. An administrator must enable it in the <a href="%configure">mail content configuration page</a>.', array("%configure" => url("admin/settings/content-types/mail"))); |
return t('Emailing is not yet enabled for mail posts. An administrator must enable it in the <a href="%configure">mail content configuration page</a>.', array("%configure" => url("admin/settings/content-types/mail"))); |
| 32 |
} |
} |
| 33 |
case 'node/add#mail': |
case 'node/add#mail': |
| 34 |
return t('A mail post can be sent to users of selected roles.'); |
return t('A mail post can be sent to users of selected roles.'); |
| 35 |
} |
} |
| 36 |
} |
} |
| 37 |
|
|
| 38 |
/** |
/** |
| 39 |
* Declare administrative settings for a module. |
* Declare administrative settings for a module. |
| 40 |
*/ |
*/ |
| 41 |
function mail_settings() { |
function mail_settings() { |
| 42 |
$form = array(); |
$form = array(); |
| 43 |
$form['options'] = array( |
$form['options'] = array( |
| 44 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 45 |
'#title' => t('Default mail sending options'), |
'#title' => t('Default mail sending options'), |
| 46 |
'#description' => t('These options will be the defaults for new mail messages, but can be overridden in the mail editing form.'), |
'#description' => t('These options will be the defaults for new mail messages, but can be overridden in the mail editing form.'), |
| 47 |
); |
); |
| 48 |
$form['options']['mail_format'] = array( |
$form['options']['mail_format'] = array( |
| 49 |
'#type' => 'select', |
'#type' => 'select', |
| 50 |
'#title' => t('Format'), |
'#title' => t('Format'), |
| 51 |
'#description' => t('Select the default email sending format.'), |
'#description' => t('Select the default email sending format.'), |
| 52 |
'#options' => array('plain' => t('plain'), 'html' => t('html')), |
'#options' => array('plain' => t('plain'), 'html' => t('html')), |
| 53 |
'#default_value' => variable_get('mail_format', 'plain'), |
'#default_value' => variable_get('mail_format', 'plain'), |
| 54 |
); |
); |
| 55 |
$form['options']['mail_priority'] = array( |
$form['options']['mail_priority'] = array( |
| 56 |
'#type' => 'select', |
'#type' => 'select', |
| 57 |
'#title' => t('Priority'), |
'#title' => t('Priority'), |
| 58 |
'#description' => t('Note that email priority is ignored by a lot of email programs.'), |
'#description' => t('Note that email priority is ignored by a lot of email programs.'), |
| 59 |
'#options' => array(0 => t('none'), 1 => t('highest'), 2 => t('high'), 3 => t('normal'), 4 => t('low'), 5 => t('lowest')), |
'#options' => array(0 => t('none'), 1 => t('highest'), 2 => t('high'), 3 => t('normal'), 4 => t('low'), 5 => t('lowest')), |
| 60 |
'#default_value' => variable_get('mail_priority', 0), |
'#default_value' => variable_get('mail_priority', 0), |
| 61 |
); |
); |
| 62 |
$form['options']['mail_character_set'] = array( |
$form['options']['mail_character_set'] = array( |
| 63 |
'#type' => 'select', |
'#type' => 'select', |
| 64 |
'#title' => t('Character set'), |
'#title' => t('Character set'), |
| 65 |
'#description' => t('Different languages may need a different character set to have email messages displayed correctly. The default for English is (en) iso-8859-1. For more details visit the <a href=\"http://www.w3.org/International/O-charset-lang.html\">w3.org character set guide</a>.'), |
'#description' => t('Different languages may need a different character set to have email messages displayed correctly. The default for English is (en) iso-8859-1. For more details visit the <a href=\"http://www.w3.org/International/O-charset-lang.html\">w3.org character set guide</a>.'), |
| 66 |
'#options' => drupal_map_assoc(array('iso-8859-1','iso-8859-7','iso-8859-5', 'UTF-8')), |
'#options' => drupal_map_assoc(array('iso-8859-1','iso-8859-7','iso-8859-5', 'UTF-8')), |
| 67 |
'#default_value' => variable_get('mail_character_set', 'iso-8859-1'), |
'#default_value' => variable_get('mail_character_set', 'iso-8859-1'), |
| 68 |
); |
); |
| 69 |
$form['options']['mail_receipt'] = array( |
$form['options']['mail_receipt'] = array( |
| 70 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 71 |
'#title' => t('Request receipt'), |
'#title' => t('Request receipt'), |
| 72 |
'#description' => t('Request a Read Receipt from your mails. A lot of email programmes ignore these so it is not a definitive indication of how many people have read your mailout.'), |
'#description' => t('Request a Read Receipt from your mails. A lot of email programmes ignore these so it is not a definitive indication of how many people have read your mailout.'), |
| 73 |
'#default_value' => variable_get('mail_receipt', 0), |
'#default_value' => variable_get('mail_receipt', 0), |
| 74 |
); |
); |
| 75 |
|
|
| 76 |
return $form; |
return $form; |
| 77 |
} |
} |
| 78 |
|
|
| 79 |
/** |
/** |
| 80 |
* Implementation of hook_node_info(). |
* Implementation of hook_node_info(). |
| 81 |
*/ |
*/ |
| 82 |
function mail_node_info() { |
function mail_node_info() { |
| 83 |
return array('mail' => array('name' => t('mail'), 'base' => 'mail')); |
return array('mail' => array('name' => t('mail'), 'base' => 'mail')); |
| 84 |
} |
} |
| 85 |
|
|
| 86 |
/** |
/** |
| 87 |
* Define user permissions. |
* Define user permissions. |
| 88 |
*/ |
*/ |
| 89 |
function mail_perm() { |
function mail_perm() { |
| 90 |
return array('send mail to users'); |
return array('send mail to users'); |
| 91 |
} |
} |
| 92 |
|
|
| 93 |
/** |
/** |
| 94 |
* Define access restrictions |
* Define access restrictions |
| 95 |
*/ |
*/ |
| 96 |
function mail_access($op, $node) { |
function mail_access($op, $node) { |
| 97 |
global $user; |
global $user; |
| 98 |
|
|
| 99 |
if ($op == 'view') { |
if ($op == 'view') { |
| 100 |
return $node->status; |
return $node->status; |
| 101 |
} |
} |
| 102 |
|
|
| 103 |
if ($op == 'create') { |
if ($op == 'create') { |
| 104 |
return user_access('send mail to users'); |
return user_access('send mail to users'); |
| 105 |
} |
} |
| 106 |
|
|
| 107 |
} |
} |
| 108 |
|
|
| 109 |
/** |
/** |
| 110 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 111 |
*/ |
*/ |
| 112 |
function mail_menu($may_cache) { |
function mail_menu($may_cache) { |
| 113 |
$items = array(); |
$items = array(); |
| 114 |
|
|
| 115 |
if ($may_cache) { |
if ($may_cache) { |
| 116 |
$items[] = array( |
$items[] = array( |
| 117 |
'path' => 'node/add/mail', |
'path' => 'node/add/mail', |
| 118 |
'title' => t('mail'), |
'title' => t('mail'), |
| 119 |
'access' => user_access('send mail to users'), |
'access' => user_access('send mail to users'), |
| 120 |
); |
); |
| 121 |
} |
} |
| 122 |
|
|
| 123 |
return $items; |
return $items; |
| 124 |
} |
} |
| 125 |
|
|
| 126 |
/** |
/** |
| 127 |
* Display a node editing form |
* Display a node editing form |
| 128 |
*/ |
*/ |
| 129 |
function mail_form(&$node) { |
function mail_form(&$node) { |
| 130 |
$form['title'] = array( |
$form['title'] = array( |
| 131 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 132 |
'#title' => t('Title'), |
'#title' => t('Title'), |
| 133 |
'#required' => TRUE, |
'#required' => TRUE, |
| 134 |
'#default_value' => $node->title, |
'#default_value' => $node->title, |
| 135 |
'#weight' => -5 |
'#weight' => -5 |
| 136 |
); |
); |
| 137 |
$form['body_filter']['body'] = array( |
$form['body_filter']['body'] = array( |
| 138 |
'#type' => 'textarea', |
'#type' => 'textarea', |
| 139 |
'#title' => t('Message'), |
'#title' => t('Message'), |
| 140 |
'#description' => t('This will be the body of your email message.') .' '. t('Available variables are:') .' %username, %site, %uri, %uri_brief, %mailto, %login_uri, %edit_uri.', |
'#description' => t('This will be the body of your email message.') .' '. t('Available variables are:') .' %username, %site, %uri, %uri_brief, %mailto, %login_uri, %edit_uri.', |
| 141 |
'#default_value' => $node->body, |
'#default_value' => $node->body, |
| 142 |
'#rows' => 20, |
'#rows' => 20, |
| 143 |
'#required' => TRUE |
'#required' => TRUE |
| 144 |
); |
); |
| 145 |
$form['body_filter']['format'] = filter_form($node->format); |
$form['body_filter']['format'] = filter_form($node->format); |
| 146 |
return $form; |
return $form; |
| 147 |
} |
} |
| 148 |
|
|
| 149 |
/** |
/** |
| 150 |
* Implementation of hook_form_alter(). |
* Implementation of hook_form_alter(). |
| 151 |
*/ |
*/ |
| 152 |
function mail_form_alter($form_id, &$form) { |
function mail_form_alter($form_id, &$form) { |
| 153 |
if (isset($form['type'])) { |
if (isset($form['type'])) { |
| 154 |
if ($form['type']['#value'] .'_node_settings' == $form_id) { |
if ($form['type']['#value'] .'_node_settings' == $form_id) { |
| 155 |
$form['workflow']['mail_'. $form['type']['#value']] = array( |
$form['workflow']['mail_'. $form['type']['#value']] = array( |
| 156 |
'#type' => 'radios', |
'#type' => 'radios', |
| 157 |
'#title' => t('Allow pages of this content type to be mailed'), |
'#title' => t('Allow pages of this content type to be mailed'), |
| 158 |
'#default_value' => variable_get('mail_'. $form['type']['#value'], 0), |
'#default_value' => variable_get('mail_'. $form['type']['#value'], 0), |
| 159 |
'#options' => array(t('Disabled'), t('Enabled')), |
'#options' => array(t('Disabled'), t('Enabled')), |
| 160 |
); |
); |
| 161 |
} |
} |
| 162 |
|
|
| 163 |
$node = $form['#node']; |
$node = $form['#node']; |
| 164 |
if ($form['type']['#value'] .'_node_form' == $form_id && variable_get("mail_$node->type", FALSE) && user_access('send mail to users')) { |
if ($form['type']['#value'] .'_node_form' == $form_id && variable_get("mail_$node->type", FALSE) && user_access('send mail to users')) { |
| 165 |
|
|
| 166 |
$form['mail_options'] = array( |
$form['mail_options'] = array( |
| 167 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 168 |
'#title' => t('Mail sending options'), |
'#title' => t('Mail sending options'), |
| 169 |
'#collapsible' => TRUE, |
'#collapsible' => TRUE, |
| 170 |
); |
); |
| 171 |
$form['mail_options']['mail_out'] = array( |
$form['mail_options']['mail_out'] = array( |
| 172 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 173 |
'#title' => t('Email out a copy of this post'), |
'#title' => t('Email out a copy of this post'), |
| 174 |
'#default_value' => $node->mail_out, |
'#default_value' => $node->mail_out, |
| 175 |
); |
); |
| 176 |
$roles = user_roles(TRUE); |
$roles = user_roles(TRUE); |
| 177 |
$form['mail_options']['mail_roles_selected'] = array( |
$form['mail_options']['mail_roles_selected'] = array( |
| 178 |
'#type' => 'checkboxes', |
'#type' => 'checkboxes', |
| 179 |
'#title' => t('Roles'), |
'#title' => t('Roles'), |
| 180 |
'#default_value' => $node->mail_roles_selected ? $node->mail_roles_selected : array(), |
'#default_value' => $node->mail_roles_selected ? $node->mail_roles_selected : array(), |
| 181 |
'#options' => $roles, |
'#options' => $roles, |
| 182 |
'#description' => t('Select roles to send the email to. At least one role is required for email to be sent.'), |
'#description' => t('Select roles to send the email to. At least one role is required for email to be sent.'), |
| 183 |
); |
); |
| 184 |
if (user_access('administer users')) { |
if (user_access('administer users')) { |
| 185 |
$form['mail_options']['mail_override_opt'] = array( |
$form['mail_options']['mail_override_opt'] = array( |
| 186 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 187 |
'#title' => t('Send to users who haven\'t opted in'), |
'#title' => t('Send to users who haven\'t opted in'), |
| 188 |
'#default_value' => $node->mail_override_opt, |
'#default_value' => $node->mail_override_opt, |
| 189 |
'#description' => t('Checking this option will send mail to users in the selected roles even if they have not opted in to receiving mail.'), |
'#description' => t('Checking this option will send mail to users in the selected roles even if they have not opted in to receiving mail.'), |
| 190 |
); |
); |
| 191 |
} |
} |
| 192 |
$form['mail_options']['mail_format'] = array( |
$form['mail_options']['mail_format'] = array( |
| 193 |
'#type' => 'select', |
'#type' => 'select', |
| 194 |
'#title' => t('Format'), |
'#title' => t('Format'), |
| 195 |
'#description' => t('Select the default email sending format.'), |
'#description' => t('Select the default email sending format.'), |
| 196 |
'#options' => array('plain' => t('plain'), 'html' => t('html')), |
'#options' => array('plain' => t('plain'), 'html' => t('html')), |
| 197 |
'#default_value' => $node->mail_format ? $node->mail_format : variable_get('mail_format', 'plain'), |
'#default_value' => $node->mail_format ? $node->mail_format : variable_get('mail_format', 'plain'), |
| 198 |
); |
); |
| 199 |
$form['mail_options']['mail_priority'] = array( |
$form['mail_options']['mail_priority'] = array( |
| 200 |
'#type' => 'select', |
'#type' => 'select', |
| 201 |
'#title' => t('Priority'), |
'#title' => t('Priority'), |
| 202 |
'#description' => t('Note that email priority is ignored by a lot of email programs.'), |
'#description' => t('Note that email priority is ignored by a lot of email programs.'), |
| 203 |
'#options' => array(0 => t('none'), 1 => t('highest'), 2 => t('high'), 3 => t('normal'), 4 => t('low'), 5 => t('lowest')), |
'#options' => array(0 => t('none'), 1 => t('highest'), 2 => t('high'), 3 => t('normal'), 4 => t('low'), 5 => t('lowest')), |
| 204 |
'#default_value' => $node->mail_priority ? $node->mail_priority : variable_get('mail_priority', 0), |
'#default_value' => $node->mail_priority ? $node->mail_priority : variable_get('mail_priority', 0), |
| 205 |
); |
); |
| 206 |
$form['mail_options']['mail_character_set'] = array( |
$form['mail_options']['mail_character_set'] = array( |
| 207 |
'#type' => 'select', |
'#type' => 'select', |
| 208 |
'#title' => t('Character set'), |
'#title' => t('Character set'), |
| 209 |
'#description' => t('Different languages may need a different character set to have email messages displayed correctly. The default for English is (en) iso-8859-1. For more details visit the <a href=\"http://www.w3.org/International/O-charset-lang.html\">w3.org character set guide</a>.'), |
'#description' => t('Different languages may need a different character set to have email messages displayed correctly. The default for English is (en) iso-8859-1. For more details visit the <a href=\"http://www.w3.org/International/O-charset-lang.html\">w3.org character set guide</a>.'), |
| 210 |
'#options' => drupal_map_assoc(array('iso-8859-1','iso-8859-7','iso-8859-5', 'UTF-8')), |
'#options' => drupal_map_assoc(array('iso-8859-1','iso-8859-7','iso-8859-5', 'UTF-8')), |
| 211 |
'#default_value' => $node->mail_character_set ? $node->mail_character_set : variable_get('mail_character_set', 'iso-8859-1'), |
'#default_value' => $node->mail_character_set ? $node->mail_character_set : variable_get('mail_character_set', 'iso-8859-1'), |
| 212 |
); |
); |
| 213 |
$form['mail_options']['mail_receipt'] = array( |
$form['mail_options']['mail_receipt'] = array( |
| 214 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 215 |
'#title' => t('Request receipt'), |
'#title' => t('Request receipt'), |
| 216 |
'#description' => t('Request a Read Receipt from your mails. A lot of email programmes ignore these so it is not a definitive indication of how many people have read your mailout.'), |
'#description' => t('Request a Read Receipt from your mails. A lot of email programmes ignore these so it is not a definitive indication of how many people have read your mailout.'), |
| 217 |
'#default_value' => $node->mail_receipt ? $node->mail_receipt : variable_get('mail_receipt', 0), |
'#default_value' => $node->mail_receipt ? $node->mail_receipt : variable_get('mail_receipt', 0), |
| 218 |
); |
); |
| 219 |
} |
} |
| 220 |
} |
} |
| 221 |
} |
} |
| 222 |
|
|
| 223 |
/** |
/** |
| 224 |
* Implementation of _nodeapi hook. |
* Implementation of _nodeapi hook. |
| 225 |
* Provides the ability to add mailing functionality to any node type. |
* Provides the ability to add mailing functionality to any node type. |
| 226 |
*/ |
*/ |
| 227 |
function mail_nodeapi(&$node, $op, $arg) { |
function mail_nodeapi(&$node, $op, $arg) { |
| 228 |
global $db_url; |
global $db_url; |
| 229 |
if (variable_get('mail_'. $node->type, FALSE) && user_access('send mail to users')) { |
if (variable_get('mail_'. $node->type, FALSE) && user_access('send mail to users')) { |
| 230 |
switch ($op) { |
switch ($op) { |
| 231 |
case 'validate': |
case 'validate': |
| 232 |
if ($node->mail_out && !count(array_filter($node->mail_roles_selected))) { |
if ($node->mail_out && !count(array_filter($node->mail_roles_selected))) { |
| 233 |
form_set_error('mail_roles_selected', t('You need to select at least one role to send the mail to.')); |
form_set_error('mail_roles_selected', t('You need to select at least one role to send the mail to.')); |
| 234 |
} |
} |
| 235 |
break; |
break; |
| 236 |
case 'insert': |
case 'insert': |
| 237 |
case 'update': |
case 'update': |
| 238 |
if($node->mail_out && $node->status && !$node->moderate) { |
if($node->mail_out && $node->status && !$node->moderate) { |
| 239 |
$node->mail_roles_selected = array_filter($node->mail_roles_selected); |
$node->mail_roles_selected = array_filter($node->mail_roles_selected); |
| 240 |
_mail_dispatch($node); |
_mail_dispatch($node); |
| 241 |
$db_type = substr($db_url, 0, strpos($db_url, '://')); |
$db_type = substr($db_url, 0, strpos($db_url, '://')); |
| 242 |
if ($db_type != 'pgsql') { |
if ($db_type != 'pgsql') { |
| 243 |
$body = '<p>' . t('This email was sent to users with the following roles: ') . implode(', ', _mail_get_roles_names($node->mail_roles_selected)) . "</p>\n"; |
$body = '<p>' . t('This email was sent to users with the following roles: ') . implode(', ', _mail_get_roles_names($node->mail_roles_selected)) . "</p>\n"; |
| 244 |
$node->body = $body . $node->body; |
$node->body = $body . $node->body; |
| 245 |
$node->mail_out = FALSE; |
$node->mail_out = FALSE; |
| 246 |
node_save($node); |
node_save($node); |
| 247 |
} |
} |
| 248 |
} |
} |
| 249 |
break; |
break; |
| 250 |
} |
} |
| 251 |
} |
} |
| 252 |
} |
} |
| 253 |
|
|
| 254 |
/** |
/** |
| 255 |
* Prepare a node's body content for viewing |
* Prepare a node's body content for viewing |
| 256 |
*/ |
*/ |
| 257 |
function mail_content($node, $main = 0) { |
function mail_content($node, $main = 0) { |
| 258 |
return node_prepare($node, $main); |
return node_prepare($node, $main); |
| 259 |
} |
} |
| 260 |
|
|
| 261 |
/** |
/** |
| 262 |
* Implementation of hook_user(). |
* Implementation of hook_user(). |
| 263 |
* |
* |
| 264 |
* Provide form element to opt in to content mailouts. |
* Provide form element to opt in to content mailouts. |
| 265 |
*/ |
*/ |
| 266 |
function mail_user($type, $edit, &$user, $category = NULL) { |
function mail_user($type, $edit, &$user, $category = NULL) { |
| 267 |
if ($type == 'register' || ($type == 'form' && $category == 'account')) { |
if ($type == 'register' || ($type == 'form' && $category == 'account')) { |
| 268 |
$form['mail'] = array( |
$form['mail'] = array( |
| 269 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 270 |
'#title' => t('Email settings'), |
'#title' => t('Email settings'), |
| 271 |
'#weight' => 5, |
'#weight' => 5, |
| 272 |
'#collapsible' => TRUE, |
'#collapsible' => TRUE, |
| 273 |
); |
); |
| 274 |
$form['mail']['mail_accept'] = array('#type' => 'checkbox', |
$form['mail']['mail_accept'] = array('#type' => 'checkbox', |
| 275 |
'#title' => t('Accept email'), |
'#title' => t('Accept email'), |
| 276 |
'#default_value' => $edit['mail_accept'], |
'#default_value' => $edit['mail_accept'], |
| 277 |
'#description' => t('Allow users posting content to sent it to you by email. Note that your e-mail address is not made public and that privileged users such as site administrators are able to email you even if you choose not to enable this feature.'), |
'#description' => t('Allow users posting content to send it to you by email. Note that your e-mail address is not made public and that privileged users such as site administrators are able to email you even if you choose not to enable this feature.'), |
| 278 |
); |
); |
| 279 |
return $form; |
return $form; |
| 280 |
} |
} |
| 281 |
elseif ($type == 'validate') { |
elseif ($type == 'validate') { |
| 282 |
return array('mail_accept' => $edit['mail_accept']); |
return array('mail_accept' => $edit['mail_accept']); |
| 283 |
} |
} |
| 284 |
} |
} |
| 285 |
|
|
| 286 |
/** |
/** |
| 287 |
* Return an HTML page to be sent out as an email message body. |
* Return an HTML page to be sent out as an email message body. |
| 288 |
* |
* |
| 289 |
* @param $node |
* @param $node |
| 290 |
* The node object. |
* The node object. |
| 291 |
* @return |
* @return |
| 292 |
* A string containing the entire HTML page. |
* A string containing the entire HTML page. |
| 293 |
*/ |
*/ |
| 294 |
function theme_mail_message($node) { |
function theme_mail_message($node) { |
| 295 |
global $user, $base_url; |
global $user, $base_url; |
| 296 |
$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
| 297 |
$output .= '<html xmlns="http://www.w3.org/1999/xhtml">'; |
$output .= '<html xmlns="http://www.w3.org/1999/xhtml">'; |
| 298 |
$output .= '<head>'; |
$output .= '<head>'; |
| 299 |
$output .= ' <title>'. check_plain($node->title) .'</title>'; |
$output .= ' <title>'. check_plain($node->title) .'</title>'; |
| 300 |
$output .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"; |
$output .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"; |
| 301 |
$base = $base_url; |
$base = $base_url; |
| 302 |
if (strlen(base_path()) > 1) { |
if (strlen(base_path()) > 1) { |
| 303 |
$base = substr($base, 0, strpos($base, substr(base_path(), 0, strlen(base_path()) - 1))); |
$base = substr($base, 0, strpos($base, substr(base_path(), 0, strlen(base_path()) - 1))); |
| 304 |
} |
} |
| 305 |
$output .= '<base href="'. $base .'" />'; |
$output .= '<base href="'. $base .'" />'; |
| 306 |
/* |
/* |
| 307 |
$output .= '<style type="text/css" src="'. base_path() .'/misc/drupal.css" />'; |
$output .= '<style type="text/css" src="'. base_path() .'/misc/drupal.css" />'; |
| 308 |
foreach (theme_add_style() as $style) { |
foreach (theme_add_style() as $style) { |
| 309 |
$style->path = $base_url .'/'. substr($style->path, strlen(base_path()), strlen($style->path)); |
$style->path = $base_url .'/'. substr($style->path, strlen(base_path()), strlen($style->path)); |
| 310 |
$output .= '<style type="text/css" src="'. $style->path .'" />'; |
$output .= '<style type="text/css" src="'. $style->path .'" />'; |
| 311 |
} |
} |
| 312 |
*/ |
*/ |
| 313 |
$output .= '</head>'; |
$output .= '</head>'; |
| 314 |
$output .= '<body style="background-color: #fff; color: #000;">'; |
$output .= '<body style="background-color: #fff; color: #000;">'; |
| 315 |
$output .= '<table border="0" cellspacing="4" cellpadding="4"><tr><td style="vertical-align: top;">'; |
$output .= '<table border="0" cellspacing="4" cellpadding="4"><tr><td style="vertical-align: top;">'; |
| 316 |
|
|
| 317 |
$output .= "\n<!-- begin content -->\n"; |
$output .= "\n<!-- begin content -->\n"; |
| 318 |
$output .= '<p>' . t('Sent by <a href="%name-url">%name</a> from %site.', array('%name' => $user->name, '%name-url' => url("user/$user->uid", NULL, NULL, TRUE), '%site' => variable_get('site_name', 'drupal'))) . '</p>'; |
$output .= '<p>' . t('Sent by <a href="%name-url">%name</a> from %site.', array('%name' => $user->name, '%name-url' => url("user/$user->uid", NULL, NULL, TRUE), '%site' => variable_get('site_name', 'drupal'))) . '</p>'; |
| 319 |
$output .= '<p>' . t('If you don\'t wish to receive such e-mails, you can <a href="%url">change your account settings</a>.', array('%url' => url('user/' . $node->uid, NULL, NULL, TRUE))) . '</p>'; |
$output .= '<p>' . t('If you don\'t wish to receive such e-mails, you can <a href="%url">change your account settings</a>.', array('%url' => url('user/' . $node->uid, NULL, NULL, TRUE))) . '</p>'; |
| 320 |
$output .= node_view($node, FALSE, FALSE, FALSE); |
$output .= node_view($node, FALSE, FALSE, FALSE); |
| 321 |
$output .= "\n<!-- end content -->\n"; |
$output .= "\n<!-- end content -->\n"; |
| 322 |
|
|
| 323 |
$output .= '</td></tr></table>'; |
$output .= '</td></tr></table>'; |
| 324 |
$output .= '</body></html>'; |
$output .= '</body></html>'; |
| 325 |
|
|
| 326 |
return $output; |
return $output; |
| 327 |
} |
} |
| 328 |
|
|
| 329 |
/** |
/** |
| 330 |
* Send mail to specified users |
* Send mail to specified users |
| 331 |
*/ |
*/ |
| 332 |
function _mail_dispatch($node) { |
function _mail_dispatch($node) { |
| 333 |
global $user, $base_url; |
global $user, $base_url; |
| 334 |
$node->from_address = ($user->uid == 1 ? variable_get('site_mail', ini_get('sendmail_from')) : $user->mail); |
$node->from_address = ($user->uid == 1 ? variable_get('site_mail', ini_get('sendmail_from')) : $user->mail); |
| 335 |
$node->from_name = ($user->uid == 1 ? variable_get('site_name', 'drupal') : t('%user at %site', array('%user' => $user->name, '%site' => variable_get('site_name', 'drupal')))); |
$node->from_name = ($user->uid == 1 ? variable_get('site_name', 'drupal') : t('%user at %site', array('%user' => $user->name, '%site' => variable_get('site_name', 'drupal')))); |
| 336 |
$node->encode = 'quoted-printable'; |
$node->encode = 'quoted-printable'; |
| 337 |
$roles = $node->mail_roles_selected; |
$roles = $node->mail_roles_selected; |
| 338 |
if (empty($roles)) { |
if (empty($roles)) { |
| 339 |
$roles = array(); |
$roles = array(); |
| 340 |
} |
} |
| 341 |
$roles_where = array(); |
$roles_where = array(); |
| 342 |
// If 'authenticated user' role is selected, we don't filter by role as we're sending to all roles. |
// If 'authenticated user' role is selected, we don't filter by role as we're sending to all roles. |
| 343 |
if (!in_array(DRUPAL_AUTHENTICATED_RID, $roles)) { |
if (!in_array(DRUPAL_AUTHENTICATED_RID, $roles)) { |
| 344 |
foreach ($roles as $rid) { |
foreach ($roles as $rid) { |
| 345 |
$roles_where[] = 's.rid = ' . $rid; |
$roles_where[] = 's.rid = ' . $rid; |
| 346 |
} |
} |
| 347 |
(count($roles_where)) ? $where = ' AND (' . implode(' OR ', $roles_where) . ') ' : $where = ''; |
(count($roles_where)) ? $where = ' AND (' . implode(' OR ', $roles_where) . ') ' : $where = ''; |
| 348 |
$result = db_query('SELECT DISTINCT(u.uid) FROM {users} u, {role} r, {users_roles} s WHERE u.uid = s.uid AND r.rid = s.rid AND u.status != 0' . $where); |
$result = db_query('SELECT DISTINCT(u.uid) FROM {users} u, {role} r, {users_roles} s WHERE u.uid = s.uid AND r.rid = s.rid AND u.status != 0' . $where); |
| 349 |
} |
} |
| 350 |
else { |
else { |
| 351 |
$result = db_query('SELECT uid FROM {users} WHERE status != 0'); |
$result = db_query('SELECT uid FROM {users} WHERE status != 0'); |
| 352 |
} |
} |
| 353 |
$success = TRUE; |
$success = TRUE; |
| 354 |
while ($uid = db_fetch_object($result)) { |
while ($uid = db_fetch_object($result)) { |
| 355 |
$account = user_load(array('uid' => $uid->uid, 'status' => 1)); |
$account = user_load(array('uid' => $uid->uid, 'status' => 1)); |
| 356 |
if (!$account->mail_accept && !($node->mail_override_opt && user_access('administer users'))) { |
if (!$account->mail_accept && !($node->mail_override_opt && user_access('administer users'))) { |
| 357 |
//continue; |
//continue; |
| 358 |
} |
} |
| 359 |
if ($account->mail) { |
if ($account->mail) { |
| 360 |
$node->to = $account->mail; |
$node->to = $account->mail; |
| 361 |
$variables = array('%username' => $account->name, '%site' => variable_get('site_name', 'drupal'), '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mailto' => $account->mail, '%date' => format_date(time()), '%login_uri' => url('user/login', NULL, NULL, TRUE), '%edit_uri' => url('user/edit', NULL, NULL, TRUE)); |
$variables = array('%username' => $account->name, '%site' => variable_get('site_name', 'drupal'), '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mailto' => $account->mail, '%date' => format_date(time()), '%login_uri' => url('user/login', NULL, NULL, TRUE), '%edit_uri' => url('user/edit', NULL, NULL, TRUE)); |
| 362 |
$message = strtr(node_view($node, FALSE, FALSE, FALSE), $variables); |
$message = strtr(node_view($node, FALSE, FALSE, FALSE), $variables); |
| 363 |
if ($node->mail_format == 'plain') { |
if ($node->mail_format == 'plain') { |
| 364 |
$node->message = strip_tags($message); |
$node->message = strip_tags($message); |
| 365 |
} |
} |
| 366 |
else { |
else { |
| 367 |
$node->message = theme('mail_message', $node); |
$node->message = theme('mail_message', $node); |
| 368 |
} |
} |
| 369 |
if (!mail_send($node)) { |
if (!mail_send($node)) { |
| 370 |
$success = FALSE; |
$success = FALSE; |
| 371 |
} |
} |
| 372 |
} |
} |
| 373 |
} |
} |
| 374 |
if ($success) { |
if ($success) { |
| 375 |
drupal_set_message(t('Message %title sent to users with the following roles: %roles.', array('%title' => $node->title, '%roles' => implode(', ', _mail_get_roles_names($roles))))); |
drupal_set_message(t('Message %title sent to users with the following roles: %roles.', array('%title' => $node->title, '%roles' => implode(', ', _mail_get_roles_names($roles))))); |
| 376 |
} |
} |
| 377 |
else { |
else { |
| 378 |
drupal_set_message(t('Error sending message %title to users with the following roles: %roles.', array('%title' => $node->title, '%roles' => implode(', ', _mail_get_roles_names($roles))))); |
drupal_set_message(t('Error sending message %title to users with the following roles: %roles.', array('%title' => $node->title, '%roles' => implode(', ', _mail_get_roles_names($roles))))); |
| 379 |
} |
} |
| 380 |
} |
} |
| 381 |
|
|
| 382 |
/** |
/** |
| 383 |
* Send mail |
* Send mail |
| 384 |
*/ |
*/ |
| 385 |
function mail_send($mail) { |
function mail_send($mail) { |
| 386 |
require_once('activeMailLib.php'); |
require_once('activeMailLib.php'); |
| 387 |
$email = new activeMailLib($mail->mail_format); |
$email = new activeMailLib($mail->mail_format); |
| 388 |
$email->From($mail->from_name . ' <' . $mail->from_address . '>'); |
$email->From($mail->from_name . ' <' . $mail->from_address . '>'); |
| 389 |
$email->To($mail->to); |
$email->To($mail->to); |
| 390 |
$email->Subject($mail->title); |
$email->Subject($mail->title); |
| 391 |
$email->Message($mail->message, $mail->mail_character_set, $mail->mail_encode); |
$email->Message($mail->message, $mail->mail_character_set, $mail->mail_encode); |
| 392 |
$email->priority($mail->mail_priority); |
$email->priority($mail->mail_priority); |
| 393 |
if ($mail->mail_receipt) { |
if ($mail->mail_receipt) { |
| 394 |
$email->Receipt($mail->from_address); |
$email->Receipt($mail->from_address); |
| 395 |
} |
} |
| 396 |
if ($mail->files) { |
if ($mail->files) { |
| 397 |
foreach ($mail->files as $file) { |
foreach ($mail->files as $file) { |
| 398 |
$email->Attachment($file->filepath, $file->filename); |
$email->Attachment($file->filepath, $file->filename); |
| 399 |
} |
} |
| 400 |
} |
} |
| 401 |
$email->Send(); |
$email->Send(); |
| 402 |
return $email->isSent($mail->to); |
return $email->isSent($mail->to); |
| 403 |
} |
} |
| 404 |
|
|
| 405 |
/** |
/** |
| 406 |
* Generate an array of role names |
* Generate an array of role names |
| 407 |
*/ |
*/ |
| 408 |
function _mail_get_roles_names($roles = array()) { |
function _mail_get_roles_names($roles = array()) { |
| 409 |
$roles_names = array(); |
$roles_names = array(); |
| 410 |
if (count($roles)) { |
if (count($roles)) { |
| 411 |
$result = db_query('SELECT name FROM {role} WHERE rid in (' . implode(',', $roles) . ') ORDER BY name'); |
$result = db_query('SELECT name FROM {role} WHERE rid in (' . implode(',', $roles) . ') ORDER BY name'); |
| 412 |
while ($role = db_fetch_object($result)) { |
while ($role = db_fetch_object($result)) { |
| 413 |
$roles_names[] = $role->name; |
$roles_names[] = $role->name; |
| 414 |
} |
} |
| 415 |
} |
} |
| 416 |
return $roles_names; |
return $roles_names; |
| 417 |
} |
} |