| 1 |
<?php |
<?php |
| 2 |
|
|
| 3 |
// $Id: mail.module,v 1.21 2006/10/16 20:15:32 nedjo Exp $ |
// $Id: mail.module,v 1.23 2006/10/17 18:08:50 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 will 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 |
unset($roles[DRUPAL_AUTHENTICATED_RID]); |
$form['mail_options']['mail_roles_selected'] = array( |
| 178 |
$form['mail_options']['mail_roles_selected'] = array( |
'#type' => 'checkboxes', |
| 179 |
'#type' => 'checkboxes', |
'#title' => t('Roles'), |
| 180 |
'#title' => t('Roles'), |
'#default_value' => $node->mail_roles_selected ? $node->mail_roles_selected : array(), |
| 181 |
'#default_value' => $node->mail_roles_selected ? $node->mail_roles_selected : array(), |
'#options' => $roles, |
| 182 |
'#options' => $roles, |
'#description' => t('Select roles to send the email to. At least one role is required for email to be sent.'), |
| 183 |
'#description' => t('Select roles to send the email to. At least one role is required for email to be sent.'), |
); |
| 184 |
); |
if (user_access('administer users')) { |
| 185 |
$form['mail_options']['mail_format'] = array( |
$form['mail_options']['mail_override_opt'] = array( |
| 186 |
'#type' => 'select', |
'#type' => 'checkbox', |
| 187 |
'#title' => t('Format'), |
'#title' => t('Send to users who haven\'t opted in'), |
| 188 |
'#description' => t('Select the default email sending format.'), |
'#default_value' => $node->mail_override_opt, |
| 189 |
'#options' => array('plain' => t('plain'), 'html' => t('html')), |
'#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 |
'#default_value' => $node->mail_format ? $node->mail_format : variable_get('mail_format', 'plain'), |
); |
| 191 |
); |
} |
| 192 |
$form['mail_options']['mail_priority'] = array( |
$form['mail_options']['mail_format'] = array( |
| 193 |
'#type' => 'select', |
'#type' => 'select', |
| 194 |
'#title' => t('Priority'), |
'#title' => t('Format'), |
| 195 |
'#description' => t('Note that email priority is ignored by a lot of email programs.'), |
'#description' => t('Select the default email sending format.'), |
| 196 |
'#options' => array(0 => t('none'), 1 => t('highest'), 2 => t('high'), 3 => t('normal'), 4 => t('low'), 5 => t('lowest')), |
'#options' => array('plain' => t('plain'), 'html' => t('html')), |
| 197 |
'#default_value' => $node->mail_priority ? $node->mail_priority : variable_get('mail_priority', 0), |
'#default_value' => $node->mail_format ? $node->mail_format : variable_get('mail_format', 'plain'), |
| 198 |
); |
); |
| 199 |
$form['mail_options']['mail_character_set'] = array( |
$form['mail_options']['mail_priority'] = array( |
| 200 |
'#type' => 'select', |
'#type' => 'select', |
| 201 |
'#title' => t('Character set'), |
'#title' => t('Priority'), |
| 202 |
'#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('Note that email priority is ignored by a lot of email programs.'), |
| 203 |
'#options' => drupal_map_assoc(array('iso-8859-1','iso-8859-7','iso-8859-5', 'UTF-8')), |
'#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_character_set ? $node->mail_character_set : variable_get('mail_character_set', 'iso-8859-1'), |
'#default_value' => $node->mail_priority ? $node->mail_priority : variable_get('mail_priority', 0), |
| 205 |
); |
); |
| 206 |
$form['mail_options']['mail_receipt'] = array( |
$form['mail_options']['mail_character_set'] = array( |
| 207 |
'#type' => 'checkbox', |
'#type' => 'select', |
| 208 |
'#title' => t('Request receipt'), |
'#title' => t('Character set'), |
| 209 |
'#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('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 |
'#default_value' => $node->mail_receipt ? $node->mail_receipt : variable_get('mail_receipt', 0), |
'#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'), |
| 212 |
} |
); |
| 213 |
} |
$form['mail_options']['mail_receipt'] = array( |
| 214 |
} |
'#type' => 'checkbox', |
| 215 |
|
'#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.'), |
| 217 |
* Implementation of _nodeapi hook. |
'#default_value' => $node->mail_receipt ? $node->mail_receipt : variable_get('mail_receipt', 0), |
| 218 |
* Provides the ability to add mailing functionality to any node type. |
); |
| 219 |
*/ |
} |
| 220 |
function mail_nodeapi(&$node, $op, $arg) { |
} |
| 221 |
global $db_url; |
} |
| 222 |
if (variable_get('mail_'. $node->type, FALSE) && user_access('send mail to users')) { |
|
| 223 |
switch ($op) { |
/** |
| 224 |
case 'validate': |
* Implementation of _nodeapi hook. |
| 225 |
if ($node->mail_out && empty($node->mail_roles_selected)) { |
* Provides the ability to add mailing functionality to any node type. |
| 226 |
form_set_error('mail_roles_selected', t('You need to select at least one role to send the mail to.')); |
*/ |
| 227 |
} |
function mail_nodeapi(&$node, $op, $arg) { |
| 228 |
break; |
global $db_url; |
| 229 |
case 'insert': |
if (variable_get('mail_'. $node->type, FALSE) && user_access('send mail to users')) { |
| 230 |
case 'update': |
switch ($op) { |
| 231 |
if($node->mail_out && $node->status && !$node->moderate) { |
case 'validate': |
| 232 |
$node->mail_roles_selected = array_filter($node->mail_roles_selected); |
if ($node->mail_out && !count(array_filter($node->mail_roles_selected))) { |
| 233 |
_mail_dispatch($node); |
form_set_error('mail_roles_selected', t('You need to select at least one role to send the mail to.')); |
| 234 |
$db_type = substr($db_url, 0, strpos($db_url, '://')); |
} |
| 235 |
if ($db_type != 'pgsql') { |
break; |
| 236 |
$body = '<p>' . t('This email was sent to users with the following roles: ') . implode(', ', _mail_get_roles_names($node->mail_roles_selected)) . "</p>\n"; |
case 'insert': |
| 237 |
$node->body = $body . $node->body; |
case 'update': |
| 238 |
$node->mail_out = FALSE; |
if($node->mail_out && $node->status && !$node->moderate) { |
| 239 |
node_save($node); |
$node->mail_roles_selected = array_filter($node->mail_roles_selected); |
| 240 |
} |
_mail_dispatch($node); |
| 241 |
} |
$db_type = substr($db_url, 0, strpos($db_url, '://')); |
| 242 |
break; |
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"; |
| 244 |
} |
$node->body = $body . $node->body; |
| 245 |
} |
$node->mail_out = FALSE; |
| 246 |
|
node_save($node); |
| 247 |
/** |
} |
| 248 |
* Prepare a node's body content for viewing |
} |
| 249 |
*/ |
break; |
| 250 |
function mail_content($node, $main = 0) { |
} |
| 251 |
return node_prepare($node, $main); |
} |
| 252 |
} |
} |
| 253 |
|
|
| 254 |
/** |
/** |
| 255 |
* Implementation of hook_user(). |
* Prepare a node's body content for viewing |
| 256 |
* |
*/ |
| 257 |
* Provide form element to opt in to content mailouts. |
function mail_content($node, $main = 0) { |
| 258 |
*/ |
return node_prepare($node, $main); |
| 259 |
function mail_user($type, $edit, &$user, $category = NULL) { |
} |
| 260 |
if ($type == 'register' || ($type == 'form' && $category == 'account')) { |
|
| 261 |
$form['mail'] = array( |
/** |
| 262 |
'#type' => 'fieldset', |
* Implementation of hook_user(). |
| 263 |
'#title' => t('Email settings'), |
* |
| 264 |
'#weight' => 5, |
* Provide form element to opt in to content mailouts. |
| 265 |
'#collapsible' => TRUE, |
*/ |
| 266 |
); |
function mail_user($type, $edit, &$user, $category = NULL) { |
| 267 |
$form['mail']['mail_accept'] = array('#type' => 'checkbox', |
if ($type == 'register' || ($type == 'form' && $category == 'account')) { |
| 268 |
'#title' => t('Accept email'), |
$form['mail'] = array( |
| 269 |
'#default_value' => $edit['mail_accept'], |
'#type' => 'fieldset', |
| 270 |
'#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.'), |
'#title' => t('Email settings'), |
| 271 |
); |
'#weight' => 5, |
| 272 |
return $form; |
'#collapsible' => TRUE, |
| 273 |
} |
); |
| 274 |
elseif ($type == 'validate') { |
$form['mail']['mail_accept'] = array('#type' => 'checkbox', |
| 275 |
return array('mail_accept' => $edit['mail_accept']); |
'#title' => t('Accept email'), |
| 276 |
} |
'#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.'), |
| 278 |
|
); |
| 279 |
/** |
return $form; |
| 280 |
* Return an HTML page to be sent out as an email message body. |
} |
| 281 |
* |
elseif ($type == 'validate') { |
| 282 |
* @param $node |
return array('mail_accept' => $edit['mail_accept']); |
| 283 |
* The node object. |
} |
| 284 |
* @return |
} |
| 285 |
* A string containing the entire HTML page. |
|
| 286 |
*/ |
/** |
| 287 |
function theme_mail_message($node) { |
* Return an HTML page to be sent out as an email message body. |
| 288 |
global $user; |
* |
| 289 |
$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
* @param $node |
| 290 |
$output .= '<html xmlns="http://www.w3.org/1999/xhtml">'; |
* The node object. |
| 291 |
$output .= '<head>'; |
* @return |
| 292 |
$output .= ' <title>'. $node->title .'</title>'; |
* A string containing the entire HTML page. |
| 293 |
$output .= drupal_get_html_head(); |
*/ |
| 294 |
$output .= theme_get_styles(); |
function theme_mail_message($node) { |
| 295 |
|
global $user, $base_url; |
| 296 |
$output .= '</head>'; |
$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
| 297 |
$output .= '<body style="background-color: #fff; color: #000;"'. theme('onload_attribute'). '">'; |
$output .= '<html xmlns="http://www.w3.org/1999/xhtml">'; |
| 298 |
$output .= '<table border="0" cellspacing="4" cellpadding="4"><tr><td style="vertical-align: top;">'; |
$output .= '<head>'; |
| 299 |
|
$output .= ' <title>'. check_plain($node->title) .'</title>'; |
| 300 |
$output .= "\n<!-- begin content -->\n"; |
$output .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"; |
| 301 |
$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>'; |
$base = $base_url; |
| 302 |
$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>'; |
if (strlen(base_path()) > 1) { |
| 303 |
$output .= node_view($node, FALSE, FALSE, FALSE); |
$base = substr($base, 0, strpos($base, substr(base_path(), 0, strlen(base_path()) - 1))); |
| 304 |
$output .= "\n<!-- end content -->\n"; |
} |
| 305 |
|
$output .= '<base href="'. $base .'" />'; |
| 306 |
$output .= '</td></tr></table>'; |
/* |
| 307 |
$output .= theme_closure(); |
$output .= '<style type="text/css" src="'. base_path() .'/misc/drupal.css" />'; |
| 308 |
$output .= '</body></html>'; |
foreach (theme_add_style() as $style) { |
| 309 |
|
$style->path = $base_url .'/'. substr($style->path, strlen(base_path()), strlen($style->path)); |
| 310 |
return $output; |
$output .= '<style type="text/css" src="'. $style->path .'" />'; |
| 311 |
} |
} |
| 312 |
|
*/ |
| 313 |
/** |
$output .= '</head>'; |
| 314 |
* Send mail to specified users |
$output .= '<body style="background-color: #fff; color: #000;">'; |
| 315 |
*/ |
$output .= '<table border="0" cellspacing="4" cellpadding="4"><tr><td style="vertical-align: top;">'; |
| 316 |
function _mail_dispatch($node) { |
|
| 317 |
global $user, $base_url; |
$output .= "\n<!-- begin content -->\n"; |
| 318 |
$node->from_address = ($user->uid == 1 ? variable_get('site_mail', ini_get('sendmail_from')) : $user->mail); |
$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 |
$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')))); |
$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 |
$node->encode = 'quoted-printable'; |
$output .= node_view($node, FALSE, FALSE, FALSE); |
| 321 |
$roles = $node->mail_roles_selected; |
$output .= "\n<!-- end content -->\n"; |
| 322 |
if(empty($roles)) { |
|
| 323 |
$roles = array(); |
$output .= '</td></tr></table>'; |
| 324 |
} |
$output .= '</body></html>'; |
| 325 |
$roles_where = array(); |
|
| 326 |
foreach ($roles as $rid) { |
return $output; |
| 327 |
$roles_where[] = 's.rid = ' . $rid; |
} |
| 328 |
} |
|
| 329 |
(count($roles_where) > 0) ? $where = ' AND (' . implode(' OR ', $roles_where) . ') ': $where = ''; |
/** |
| 330 |
$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); |
* Send mail to specified users |
| 331 |
$success = TRUE; |
*/ |
| 332 |
while ($uid = db_fetch_object($result)) { |
function _mail_dispatch($node) { |
| 333 |
$account = user_load(array('uid' => $uid->uid, 'status' => 1)); |
global $user, $base_url; |
| 334 |
if (!$account->mail_accept && !user_access('administer users')) { |
$node->from_address = ($user->uid == 1 ? variable_get('site_mail', ini_get('sendmail_from')) : $user->mail); |
| 335 |
continue; |
$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'; |
| 337 |
if($account->mail) { |
$roles = $node->mail_roles_selected; |
| 338 |
$node->to = $account->mail; |
if (empty($roles)) { |
| 339 |
$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)); |
$roles = array(); |
| 340 |
$message = strtr(node_view($node, FALSE, FALSE, FALSE), $variables); |
} |
| 341 |
if ($node->mail_format == 'plain') { |
$roles_where = array(); |
| 342 |
$node->message = strip_tags($message); |
// 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)) { |
| 344 |
else { |
foreach ($roles as $rid) { |
| 345 |
$node->message = theme('mail_message', $node); |
$roles_where[] = 's.rid = ' . $rid; |
| 346 |
} |
} |
| 347 |
if(!mail_send($node)) { |
(count($roles_where)) ? $where = ' AND (' . implode(' OR ', $roles_where) . ') ' : $where = ''; |
| 348 |
$success = FALSE; |
$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 { |
| 351 |
} |
$result = db_query('SELECT uid FROM {users} WHERE status != 0'); |
| 352 |
if($success) { |
} |
| 353 |
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))))); |
$success = TRUE; |
| 354 |
} |
while ($uid = db_fetch_object($result)) { |
| 355 |
else { |
$account = user_load(array('uid' => $uid->uid, 'status' => 1)); |
| 356 |
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))))); |
if (!$account->mail_accept && !($node->mail_override_opt && user_access('administer users'))) { |
| 357 |
} |
//continue; |
| 358 |
} |
} |
| 359 |
|
if ($account->mail) { |
| 360 |
/** |
$node->to = $account->mail; |
| 361 |
* Send mail |
$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); |
| 363 |
function mail_send($mail) { |
if ($node->mail_format == 'plain') { |
| 364 |
require_once('activeMailLib.php'); |
$node->message = strip_tags($message); |
| 365 |
$email = new activeMailLib($mail->mail_format); |
} |
| 366 |
$email->From($mail->from_name . ' <' . $mail->from_address . '>'); |
else { |
| 367 |
$email->To($mail->to); |
$node->message = theme('mail_message', $node); |
| 368 |
$email->Subject($mail->title); |
} |
| 369 |
$email->Message($mail->message, $mail->mail_character_set, $mail->mail_encode); |
if (!mail_send($node)) { |
| 370 |
$email->priority($mail->mail_priority); |
$success = FALSE; |
| 371 |
if ($mail->mail_receipt) { |
} |
| 372 |
$email->Receipt($mail->from_address); |
} |
| 373 |
} |
} |
| 374 |
if ($mail->files) { |
if ($success) { |
| 375 |
foreach ($mail->files as $file) { |
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 |
$email->Attachment($file->filepath, $file->filename); |
} |
| 377 |
} |
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))))); |
| 379 |
$email->Send(); |
} |
| 380 |
return $email->isSent($mail->to); |
} |
| 381 |
} |
|
| 382 |
|
/** |
| 383 |
/** |
* Send mail |
| 384 |
* Generate an array of role names |
*/ |
| 385 |
*/ |
function mail_send($mail) { |
| 386 |
function _mail_get_roles_names($roles) { |
require_once('activeMailLib.php'); |
| 387 |
$roles_names = array(); |
$email = new activeMailLib($mail->mail_format); |
| 388 |
$result = db_query('SELECT name FROM {role} WHERE rid in (' . implode(',', $roles) . ') ORDER BY name'); |
$email->From($mail->from_name . ' <' . $mail->from_address . '>'); |
| 389 |
while ($role = db_fetch_object($result)) { |
$email->To($mail->to); |
| 390 |
$roles_names[] = $role->name; |
$email->Subject($mail->title); |
| 391 |
} |
$email->Message($mail->message, $mail->mail_character_set, $mail->mail_encode); |
| 392 |
return $roles_names; |
$email->priority($mail->mail_priority); |
| 393 |
} |
if ($mail->mail_receipt) { |
| 394 |
|
$email->Receipt($mail->from_address); |
| 395 |
|
} |
| 396 |
|
if ($mail->files) { |
| 397 |
|
foreach ($mail->files as $file) { |
| 398 |
|
$email->Attachment($file->filepath, $file->filename); |
| 399 |
|
} |
| 400 |
|
} |
| 401 |
|
$email->Send(); |
| 402 |
|
return $email->isSent($mail->to); |
| 403 |
|
} |
| 404 |
|
|
| 405 |
|
/** |
| 406 |
|
* Generate an array of role names |
| 407 |
|
*/ |
| 408 |
|
function _mail_get_roles_names($roles = array()) { |
| 409 |
|
$roles_names = array(); |
| 410 |
|
if (count($roles)) { |
| 411 |
|
$result = db_query('SELECT name FROM {role} WHERE rid in (' . implode(',', $roles) . ') ORDER BY name'); |
| 412 |
|
while ($role = db_fetch_object($result)) { |
| 413 |
|
$roles_names[] = $role->name; |
| 414 |
|
} |
| 415 |
|
} |
| 416 |
|
return $roles_names; |
| 417 |
|
} |