Revision 76bdcd04
Added by Assos Assos almost 6 years ago
drupal7/sites/all/modules/print/print_mail/print_mail.inc | ||
---|---|---|
10 | 10 |
* @ingroup print |
11 | 11 |
*/ |
12 | 12 |
|
13 |
require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'print') . '/print.pages.inc'); |
|
14 |
|
|
15 |
// Include MIME library |
|
16 |
@include_once('Mail/mime.php'); |
|
13 |
// Include MIME library, if available. |
|
14 |
@include_once 'Mail/mime.php'; |
|
17 | 15 |
|
18 | 16 |
/** |
19 |
* Menu callback for the send by email form.
|
|
17 |
* Form constructor for the send by email form.
|
|
20 | 18 |
* |
21 | 19 |
* @ingroup forms |
22 | 20 |
*/ |
23 | 21 |
function print_mail_form($form, &$form_state) { |
24 |
global $user; |
|
25 |
|
|
26 |
// Remove the printmail/ prefix |
|
22 |
// Remove the printmail/ prefix. |
|
27 | 23 |
$path_arr = explode('/', $_GET['q']); |
28 | 24 |
unset($path_arr[0]); |
29 | 25 |
$path = filter_xss(implode('/', $path_arr)); |
30 | 26 |
if (empty($path)) { |
31 |
// If no path was provided, let's try to generate a page for the referer |
|
27 |
// If no path was provided, let's try to generate a page for the referer.
|
|
32 | 28 |
global $base_url; |
29 |
$link = print_mail_print_link(); |
|
33 | 30 |
|
34 | 31 |
$ref = $_SERVER['HTTP_REFERER']; |
35 | 32 |
$path = preg_replace("!^$base_url/!", '', $ref); |
36 | 33 |
if (($path === $ref) || empty($path)) { |
37 | 34 |
$path = variable_get('site_frontpage', 'node'); |
38 | 35 |
} |
39 |
drupal_goto(PRINTMAIL_PATH . '/' . $path);
|
|
36 |
drupal_goto($link['path'] . '/' . $path);
|
|
40 | 37 |
} |
41 | 38 |
elseif (ctype_digit($path_arr[1])) { |
42 | 39 |
if (drupal_lookup_path('source', $path)) { |
43 |
// This is a numeric alias |
|
40 |
// This is a numeric alias.
|
|
44 | 41 |
$path = drupal_get_normal_path($path); |
45 | 42 |
} |
46 | 43 |
else { |
47 |
// normal nid
|
|
44 |
// Normal nid.
|
|
48 | 45 |
$path = 'node/' . $path; |
49 | 46 |
} |
50 | 47 |
} |
... | ... | |
52 | 49 |
$path = drupal_get_normal_path($path); |
53 | 50 |
} |
54 | 51 |
|
55 |
// Handle the query |
|
52 |
// Handle the query.
|
|
56 | 53 |
$query = $_GET; |
57 | 54 |
unset($query['q']); |
58 | 55 |
|
56 |
return print_mail_form_for_path($form, $form_state, $path, $query); |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Build email form for the page provided in the path argument. |
|
61 |
* |
|
62 |
* @param array $form |
|
63 |
* Form. |
|
64 |
* @param array $form_state |
|
65 |
* Form state. |
|
66 |
* @param string $path |
|
67 |
* Path. |
|
68 |
* @param array $query |
|
69 |
* Query. |
|
70 |
* @param Object $user |
|
71 |
* Current user. |
|
72 |
* |
|
73 |
* @return array |
|
74 |
* Modified form. |
|
75 |
* |
|
76 |
* @ingroup forms |
|
77 |
*/ |
|
78 |
function print_mail_form_for_path($form, &$form_state, $path, $query = NULL, $user = NULL) { |
|
79 |
if ($user === NULL) { |
|
80 |
global $user; |
|
81 |
} |
|
82 |
|
|
59 | 83 |
$print_mail_hourly_threshold = variable_get('print_mail_hourly_threshold', PRINT_MAIL_HOURLY_THRESHOLD); |
60 | 84 |
|
61 | 85 |
if ((!user_access('send unlimited emails')) && (!flood_is_allowed('print_mail', $print_mail_hourly_threshold))) { |
... | ... | |
68 | 92 |
|
69 | 93 |
$print_mail_teaser_default = variable_get('print_mail_teaser_default', PRINT_MAIL_TEASER_DEFAULT_DEFAULT); |
70 | 94 |
$print_mail_teaser_choice = variable_get('print_mail_teaser_choice', PRINT_MAIL_TEASER_CHOICE_DEFAULT); |
95 |
$print_mail_user_recipients_default = variable_get('print_mail_user_recipients', PRINT_MAIL_USER_RECIPIENTS_DEFAULT); |
|
71 | 96 |
$form = array(); |
72 | 97 |
|
73 |
$cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL; |
|
98 |
$cid = isset($_GET['comment']) ? (int) $_GET['comment'] : NULL;
|
|
74 | 99 |
$title = _print_get_title($path); |
75 | 100 |
|
101 |
$options = array(); |
|
102 |
if ($print_mail_user_recipients_default) { |
|
103 |
if (module_exists('realname')) { |
|
104 |
$sql = "SELECT u.mail, r.realname AS name from {users} u LEFT JOIN {realname} r ON u.uid = r.uid WHERE u.uid <> :uid AND status = 1 ORDER BY name ASC"; |
|
105 |
} |
|
106 |
else { |
|
107 |
$sql = "SELECT mail, name from {users} WHERE uid <> :uid AND status = 1 ORDER BY name ASC"; |
|
108 |
} |
|
109 |
$recipients = db_query($sql, array(':uid' => drupal_anonymous_user()->uid)); |
|
110 |
foreach ($recipients as $recipient) { |
|
111 |
$options[$recipient->mail] = $recipient->name; |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
76 | 115 |
if (count($form_state['input']) == 0) { |
77 | 116 |
$nodepath = drupal_get_normal_path($path); |
78 | 117 |
db_merge('print_mail_page_counter') |
79 | 118 |
->key(array('path' => $nodepath)) |
80 | 119 |
->fields(array( |
81 |
'totalcount' => 1,
|
|
82 |
'timestamp' => REQUEST_TIME,
|
|
120 |
'totalcount' => 1, |
|
121 |
'timestamp' => REQUEST_TIME, |
|
83 | 122 |
)) |
84 | 123 |
->expression('totalcount', 'totalcount + 1') |
85 | 124 |
->execute(); |
... | ... | |
87 | 126 |
|
88 | 127 |
$form['path'] = array('#type' => 'value', '#value' => $path); |
89 | 128 |
$form['query'] = array('#type' => 'value', '#value' => $query); |
90 |
$form['cid'] = array('#type' => 'value', '#value' => $cid);
|
|
129 |
$form['cid'] = array('#type' => 'value', '#value' => $cid); |
|
91 | 130 |
$form['title'] = array('#type' => 'value', '#value' => $title); |
92 | 131 |
|
93 | 132 |
$form['fld_from_addr'] = array( |
... | ... | |
101 | 140 |
'#title' => t('Your name'), |
102 | 141 |
'#size' => 62, |
103 | 142 |
); |
104 |
$form['txt_to_addrs'] = array( |
|
143 |
$form['txt_to'] = array( |
|
144 |
'#tree' => TRUE, |
|
145 |
); |
|
146 |
$form['txt_to']['addrs'] = array( |
|
105 | 147 |
'#type' => 'textarea', |
106 | 148 |
'#title' => t('Send to'), |
107 | 149 |
'#rows' => 3, |
108 | 150 |
'#resizable' => FALSE, |
109 | 151 |
'#description' => t('Enter multiple addresses separated by commas and/or different lines.'), |
110 |
'#required' => TRUE,
|
|
152 |
'#required' => !$print_mail_user_recipients_default,
|
|
111 | 153 |
); |
154 |
if ($print_mail_user_recipients_default) { |
|
155 |
$form['txt_to']['users'] = array( |
|
156 |
'#type' => 'select', |
|
157 |
'#title' => t('Send to users'), |
|
158 |
'#multiple' => TRUE, |
|
159 |
'#size' => 10, |
|
160 |
'#options' => $options, |
|
161 |
); |
|
162 |
} |
|
112 | 163 |
$form['fld_subject'] = array( |
113 | 164 |
'#type' => 'textfield', |
114 | 165 |
'#title' => t('Subject'), |
... | ... | |
116 | 167 |
'#required' => TRUE, |
117 | 168 |
); |
118 | 169 |
if (!empty($title)) { |
119 |
// To prevent useless translation strings, try to translate only non-node titles
|
|
170 |
// To prevent useless translation strings, translate only non-node titles.
|
|
120 | 171 |
if (drupal_substr($path, 0, 5) != 'node/') { |
121 | 172 |
$title = t($title); |
122 | 173 |
} |
... | ... | |
145 | 196 |
$form['chk_teaser'] = array('#type' => 'value', '#value' => $print_mail_teaser_default); |
146 | 197 |
} |
147 | 198 |
|
148 |
$form['btn_submit'] = array( |
|
199 |
$form['actions'] = array( |
|
200 |
'#type' => 'actions', |
|
201 |
); |
|
202 |
|
|
203 |
$form['actions']['submit'] = array( |
|
149 | 204 |
'#name' => 'submit', |
150 | 205 |
'#type' => 'submit', |
151 | 206 |
'#value' => t('Send email'), |
152 | 207 |
); |
153 |
$form['btn_cancel'] = array(
|
|
208 |
$form['actions']['cancel'] = array(
|
|
154 | 209 |
'#name' => 'cancel', |
155 | 210 |
'#type' => 'submit', |
156 | 211 |
'#value' => t('Cancel'), |
... | ... | |
167 | 222 |
$user_name = t('Someone'); |
168 | 223 |
} |
169 | 224 |
$site_name = variable_get('site_name', t('an interesting site')); |
170 |
$print_mail_text_subject = filter_xss(variable_get('print_mail_text_subject', t('!user has sent you a message from !site'))); |
|
171 |
$form['fld_subject']['#default_value'] = t($print_mail_text_subject, array('!user' => $user_name, '!site' => $site_name, '!title' => $title)); |
|
172 |
$print_mail_text_content = filter_xss(variable_get('print_mail_text_content', '')); |
|
173 |
$form['txt_message']['#default_value'] = t($print_mail_text_content); |
|
225 |
$form['fld_subject']['#default_value'] = t('!user has sent you a message from !site', array( |
|
226 |
'!user' => $user_name, |
|
227 |
'!site' => $site_name, |
|
228 |
'!title' => $title, |
|
229 |
)); |
|
230 |
$form['txt_message']['#default_value'] = ''; |
|
174 | 231 |
|
175 | 232 |
return $form; |
176 | 233 |
} |
177 | 234 |
|
178 | 235 |
/** |
179 |
* Theme function for the send by-email form submission.
|
|
236 |
* Returns HTML for the send by-email form.
|
|
180 | 237 |
* |
181 | 238 |
* Adds a class to the form labels. This class is used to place the label on |
182 | 239 |
* the left of the input fields. |
183 | 240 |
* |
241 |
* @param array $variables |
|
242 |
* Theme variables including the form. |
|
243 |
* |
|
244 |
* @return string |
|
245 |
* Send by-email form HTML. |
|
246 |
* |
|
247 |
* @see print_mail_form() |
|
184 | 248 |
* @ingroup forms |
249 |
* @ingroup themeable |
|
250 |
* @ingroup print_themeable |
|
185 | 251 |
*/ |
186 | 252 |
function theme_print_mail_form($variables) { |
187 | 253 |
$form = $variables['form']; |
188 | 254 |
|
189 |
drupal_add_css(drupal_get_path('module', 'print') . '/css/printlinks.css');
|
|
255 |
drupal_add_css(drupal_get_path('module', 'print_mail') . '/css/print_mail.theme.css');
|
|
190 | 256 |
$content = ''; |
191 | 257 |
foreach (element_children($form) as $key) { |
192 | 258 |
$tmp = drupal_render($form[$key]); |
193 | 259 |
switch ($key) { |
194 | 260 |
case 'fld_from_addr': |
195 | 261 |
case 'fld_from_name': |
196 |
case 'txt_to_addrs':
|
|
262 |
case 'txt_to': |
|
197 | 263 |
case 'fld_subject': |
198 | 264 |
case 'fld_title': |
199 | 265 |
$tmp = str_replace('<label', '<label class ="printmail-label"', $tmp); |
... | ... | |
205 | 271 |
} |
206 | 272 |
|
207 | 273 |
/** |
208 |
* Validate the send by-email form submission. |
|
274 |
* Theme function for the email sending just the link. |
|
275 |
* |
|
276 |
* Allows themes and modules to override the default sendlink plain text format. |
|
209 | 277 |
* |
278 |
* @param array $params |
|
279 |
* Value of $params as passed to print_mail_mail(). |
|
280 |
* |
|
281 |
* @return string |
|
282 |
* Plain text containing the message and a simple link to the content. |
|
283 |
* |
|
284 |
* @ingroup themeable |
|
285 |
* @ingroup print_themeable |
|
286 |
*/ |
|
287 |
function theme_print_mail_sendlink_plain($params) { |
|
288 |
return $params['message'] . '\n\n' . $params['link']; |
|
289 |
} |
|
290 |
|
|
291 |
/** |
|
292 |
* Theme function for the email sending just the link. |
|
293 |
* |
|
294 |
* Allows themes and modules to override the default sendlink HTML format. |
|
295 |
* |
|
296 |
* @param array $params |
|
297 |
* Value of $params as passed to print_mail_mail(). |
|
298 |
* |
|
299 |
* @return string |
|
300 |
* HTML text containing the message and a simple link to the content. |
|
301 |
* |
|
302 |
* @ingroup themeable |
|
303 |
* @ingroup print_themeable |
|
304 |
*/ |
|
305 |
function theme_print_mail_sendlink_html($params) { |
|
306 |
return $params['message'] . '<br/><br/>' . l($params['title'], $params['link']); |
|
307 |
} |
|
308 |
|
|
309 |
/** |
|
310 |
* Form validation handler for print_mail_form(). |
|
311 |
* |
|
312 |
* @see print_mail_form() |
|
210 | 313 |
* @ingroup forms |
211 | 314 |
*/ |
212 | 315 |
function print_mail_form_validate($form, &$form_state) { |
316 |
$print_mail_user_recipients_default = variable_get('print_mail_user_recipients', PRINT_MAIL_USER_RECIPIENTS_DEFAULT); |
|
317 |
|
|
213 | 318 |
if (array_key_exists('cancel', $form_state['input'])) { |
214 | 319 |
form_set_error(NULL, '', TRUE); |
215 | 320 |
drupal_get_messages('error'); |
... | ... | |
223 | 328 |
form_set_error('fld_from_addr', $test); |
224 | 329 |
} |
225 | 330 |
|
226 |
// All new-lines are replaced by commas |
|
227 |
$to_addrs = preg_replace('![\r|\n|,]+!', ',', trim($form_state['values']['txt_to_addrs'])); |
|
228 |
// Create an array from the string |
|
229 |
$to_array = explode(',', $to_addrs); |
|
230 |
// Verify each element of the array |
|
331 |
$to_array = array(); |
|
332 |
if (!empty($form_state['values']['txt_to']['users'])) { |
|
333 |
$to_array = array_values($form_state['values']['txt_to']['users']); |
|
334 |
} |
|
335 |
|
|
336 |
if (!empty($form_state['values']['txt_to']['addrs'])) { |
|
337 |
// All new-lines are replaced by commas. |
|
338 |
$to_addrs = preg_replace('![\r|\n|,]+!', ',', trim($form_state['values']['txt_to']['addrs'])); |
|
339 |
// Create an array from the string. |
|
340 |
$to_array = array_merge($to_array, explode(',', $to_addrs)); |
|
341 |
} |
|
342 |
|
|
343 |
if (empty($to_array) && $print_mail_user_recipients_default) { |
|
344 |
form_set_error('txt_to', t('You must specify at least one email address or user as a recipient.')); |
|
345 |
} |
|
346 |
|
|
347 |
// Verify each element of the array. |
|
231 | 348 |
foreach ($to_array as $key => $address) { |
232 | 349 |
$address = trim($address); |
233 | 350 |
if (preg_match('/(.*?) <(.*)>/s', $address, $matches)) { |
234 |
// Address is of the type User Name <user@domain.tld> |
|
351 |
// Address is of the type User Name <user@domain.tld>.
|
|
235 | 352 |
$test = user_validate_mail($matches[2]); |
236 | 353 |
$to_array[$key] = trim($matches[1]) . ' <' . $matches[2] . '>'; |
237 | 354 |
} |
238 | 355 |
else { |
239 |
// Address must be user@domain.tld |
|
356 |
// Address must be user@domain.tld.
|
|
240 | 357 |
$test = user_validate_mail($address); |
241 | 358 |
} |
242 | 359 |
if ($test) { |
243 |
form_set_error('txt_to_addrs', $test);
|
|
360 |
form_set_error('txt_to', $test); |
|
244 | 361 |
} |
245 | 362 |
} |
246 | 363 |
|
247 | 364 |
$print_mail_hourly_threshold = variable_get('print_mail_hourly_threshold', PRINT_MAIL_HOURLY_THRESHOLD); |
248 | 365 |
|
249 | 366 |
if ((!user_access('send unlimited emails')) && (!flood_is_allowed('print_mail', $print_mail_hourly_threshold - count($to_array) + 1))) { |
250 |
form_set_error('txt_to_addrs', t('You cannot send more than %number messages per hour. Please reduce the number of recipients.', array('%number' => $print_mail_hourly_threshold)));
|
|
367 |
form_set_error('txt_to', t('You cannot send more than %number messages per hour. Please reduce the number of recipients.', array('%number' => $print_mail_hourly_threshold)));
|
|
251 | 368 |
} |
252 | 369 |
|
253 |
// In all fields, prevent insertion of custom headers |
|
370 |
// In all fields, prevent insertion of custom headers.
|
|
254 | 371 |
foreach ($form_state['values'] as $key => $string) { |
255 |
if ( (drupal_substr($key, 0, 4) == 'fld_') && ((strpos($string, "\n") !== FALSE) || (strpos($string, "\r") !== FALSE)) ) {
|
|
372 |
if ((drupal_substr($key, 0, 4) == 'fld_') && ((strpos($string, "\n") !== FALSE) || (strpos($string, "\r") !== FALSE))) {
|
|
256 | 373 |
form_set_error($key, 'Found invalid character'); |
257 | 374 |
} |
258 | 375 |
} |
259 | 376 |
|
260 | 377 |
$form_state['values']['fld_from_addr'] = $from_addr; |
261 | 378 |
$form_state['values']['fld_from_name'] = trim($form_state['values']['fld_from_name']); |
262 |
// Re-create the string from the re-organized array |
|
263 |
$form_state['values']['txt_to_addrs'] = implode(', ', $to_array);
|
|
379 |
// Re-create the string from the re-organized array.
|
|
380 |
$form_state['values']['txt_to']['addrs'] = implode(', ', $to_array);
|
|
264 | 381 |
} |
265 | 382 |
|
266 | 383 |
/** |
267 |
* Process the send by-email form submission.
|
|
384 |
* Form submission handler for print_mail_form().
|
|
268 | 385 |
* |
386 |
* @see print_mail_form() |
|
387 |
* @see print_controller() |
|
269 | 388 |
* @ingroup forms |
270 | 389 |
*/ |
271 | 390 |
function print_mail_form_submit($form, &$form_state) { |
272 | 391 |
if (!array_key_exists('cancel', $form_state['values'])) { |
273 |
$cid = isset($form_state['values']['cid']) ? $form_state['values']['cid'] : NULL; |
|
274 |
$print_mail_text_message = filter_xss_admin(variable_get('print_mail_text_message', t('Message from sender'))); |
|
275 |
$sender_message = $print_mail_text_message . ':<br /><br /><em>' . nl2br(check_plain($form_state['values']['txt_message'])) . '</em>'; |
|
392 |
module_load_include('inc', 'print', 'print.pages'); |
|
393 |
module_load_include('inc', 'print', 'includes/print'); |
|
276 | 394 |
|
277 |
$print = print_controller($form_state['values']['path'], $form_state['values']['query'], $cid, PRINT_MAIL_FORMAT, $form_state['values']['chk_teaser'], $sender_message); |
|
395 |
$link = print_mail_print_link(); |
|
396 |
$cid = isset($form_state['values']['cid']) ? $form_state['values']['cid'] : NULL; |
|
397 |
$view_mode = $form_state['values']['chk_teaser'] ? 'teaser' : PRINT_VIEW_MODE; |
|
398 |
$node = print_controller($form_state['values']['path'], $link['format'], $cid, $view_mode); |
|
278 | 399 |
|
279 |
if ($print !== FALSE) {
|
|
400 |
if ($node) {
|
|
280 | 401 |
$print_mail_send_option_default = variable_get('print_mail_send_option_default', PRINT_MAIL_SEND_OPTION_DEFAULT); |
281 | 402 |
|
282 | 403 |
$params = array(); |
283 | 404 |
$params['subject'] = $form_state['values']['fld_subject']; |
284 |
$params['message'] = $sender_message;
|
|
285 |
$params['link'] = $print['url'];
|
|
405 |
$params['message'] = t('Message from sender') . ':<br /><br /><em>' . nl2br(check_plain($form_state['values']['txt_message'])) . '</em>';
|
|
406 |
$params['link'] = url($form_state['values']['path'], array('absolute' => TRUE, 'query' => $form_state['values']['query']));
|
|
286 | 407 |
$params['title'] = $form_state['values']['title']; |
287 | 408 |
|
288 |
// If a name is provided, make From: in the format Common Name <address> |
|
409 |
// If a name is provided, make From: in the format Common Name <address>.
|
|
289 | 410 |
if (!empty($form_state['values']['fld_from_name'])) { |
290 | 411 |
$from = '"' . mime_header_encode($form_state['values']['fld_from_name']) . '" <' . $form_state['values']['fld_from_addr'] . '>'; |
291 | 412 |
} |
... | ... | |
293 | 414 |
$from = $form_state['values']['fld_from_addr']; |
294 | 415 |
} |
295 | 416 |
|
296 |
// If using reply-to, move the From: info to the params array, so that it is passed to hook_mail later |
|
417 |
// If using reply-to, move the From: info to the params array, so that it |
|
418 |
// is passed to hook_mail later. |
|
297 | 419 |
if (variable_get('print_mail_use_reply_to', PRINT_MAIL_USE_REPLY_TO)) { |
298 | 420 |
$params['from'] = $from; |
299 | 421 |
$from = NULL; |
300 | 422 |
} |
301 | 423 |
|
302 |
// Spaces in img URLs must be replaced with %20 |
|
424 |
// Spaces in img URLs must be replaced with %20.
|
|
303 | 425 |
$pattern = '!<(img\s[^>]*?)>!is'; |
304 |
$print['content'] = preg_replace_callback($pattern, '_print_replace_spaces', $print['content']);
|
|
426 |
$node->content = preg_replace_callback($pattern, '_print_replace_spaces', $node->content);
|
|
305 | 427 |
|
306 |
$node = $print['node']; |
|
307 |
$params['body'] = theme('print', array('print' => $print, 'type' => PRINT_MAIL_FORMAT, 'node' => $node)); |
|
428 |
$params['body'] = theme('print', array( |
|
429 |
'node' => $node, |
|
430 |
'query' => $form_state['values']['query'], |
|
431 |
'format' => $link['format'], |
|
432 |
'expand_css' => TRUE, |
|
433 |
'message' => $params['message'], |
|
434 |
)); |
|
308 | 435 |
|
309 |
// Img elements must be set to absolute |
|
436 |
// Img elements must be set to absolute.
|
|
310 | 437 |
$pattern = '!<(img\s[^>]*?)>!is'; |
311 | 438 |
$params['body'] = preg_replace_callback($pattern, '_print_rewrite_urls', $params['body']); |
312 | 439 |
|
313 |
// Convert the a href elements, to make sure no relative links remain |
|
440 |
// Convert the a href elements, to make sure no relative links remain.
|
|
314 | 441 |
$pattern = '!<(a\s[^>]*?)>!is'; |
315 | 442 |
$params['body'] = preg_replace_callback($pattern, '_print_rewrite_urls', $params['body']); |
316 | 443 |
|
444 |
// Enable support for third-party modules to alter the e-mail before |
|
445 |
// being sent. |
|
446 |
drupal_alter('print_mail', $params, $to); |
|
447 |
|
|
317 | 448 |
$ok = FALSE; |
318 | 449 |
$use_job_queue = variable_get('print_mail_job_queue', PRINT_MAIL_JOB_QUEUE_DEFAULT); |
450 |
$queue = NULL; |
|
319 | 451 |
if ($use_job_queue) { |
320 | 452 |
$queue = DrupalQueue::get('print_mail_send'); |
321 | 453 |
} |
322 | 454 |
|
323 |
$addresses = explode(', ', $form_state['values']['txt_to_addrs']);
|
|
455 |
$addresses = explode(', ', $form_state['values']['txt_to']['addrs']);
|
|
324 | 456 |
foreach ($addresses as $to) { |
457 |
$ret = array(); |
|
325 | 458 |
if ($use_job_queue) { |
326 |
// Use job queue to send mails during cron runs |
|
327 |
$queue->createItem(array('module' => 'print_mail', 'key' => $print_mail_send_option_default, 'to' => $to, 'language' => language_default(), 'params' => $params, 'from' => $from)); |
|
459 |
// Use job queue to send mails during cron runs. |
|
460 |
$queue->createItem(array( |
|
461 |
'module' => 'print_mail', |
|
462 |
'key' => $print_mail_send_option_default, |
|
463 |
'to' => $to, |
|
464 |
'language' => language_default(), |
|
465 |
'params' => $params, |
|
466 |
'from' => $from, |
|
467 |
)); |
|
328 | 468 |
} |
329 | 469 |
else { |
330 |
// Send mail immediately using Drupal's mail handler |
|
470 |
// Send mail immediately using Drupal's mail handler.
|
|
331 | 471 |
$ret = drupal_mail('print_mail', $print_mail_send_option_default, $to, language_default(), $params, $from); |
332 | 472 |
} |
333 | 473 |
if ($use_job_queue || $ret['result']) { |
... | ... | |
337 | 477 |
} |
338 | 478 |
if ($ok) { |
339 | 479 |
$query = empty($form_state['values']['query']) ? '' : '?' . rawurldecode(drupal_http_build_query($form_state['values']['query'])); |
340 |
watchdog('print_mail', '%name [%from] sent %page to [%to]', array('%name' => $form_state['values']['fld_from_name'], '%from' => $form_state['values']['fld_from_addr'], '%page' => $form_state['values']['path'] . $query, '%to' => $form_state['values']['txt_to_addrs'])); |
|
480 |
watchdog('print_mail', '%name [%from] sent %page to [%to]', array( |
|
481 |
'%name' => $form_state['values']['fld_from_name'], |
|
482 |
'%from' => $form_state['values']['fld_from_addr'], |
|
483 |
'%page' => $form_state['values']['path'] . $query, |
|
484 |
'%to' => $form_state['values']['txt_to']['addrs'], |
|
485 |
)); |
|
341 | 486 |
$site_name = variable_get('site_name', t('us')); |
342 |
$print_mail_text_confirmation = variable_get('print_mail_text_confirmation', t('Thank you for spreading the word about !site.')); |
|
343 |
drupal_set_message(check_plain(t($print_mail_text_confirmation, array('!site' => $site_name)))); |
|
487 |
drupal_set_message(check_plain(t('Thank you for spreading the word about !site.', array('!site' => $site_name)))); |
|
344 | 488 |
|
345 | 489 |
$nodepath = drupal_get_normal_path($form_state['values']['path']); |
346 | 490 |
db_update('print_mail_page_counter') |
347 | 491 |
->fields(array( |
348 |
'sentcount' => 1,
|
|
349 |
'sent_timestamp' => REQUEST_TIME,
|
|
492 |
'sentcount' => 1, |
|
493 |
'sent_timestamp' => REQUEST_TIME, |
|
350 | 494 |
)) |
351 | 495 |
->condition('path', $nodepath, '=') |
352 | 496 |
->expression('sentcount', 'sentcount + :inc', array(':inc' => count($addresses))) |
... | ... | |
355 | 499 |
} |
356 | 500 |
} |
357 | 501 |
|
358 |
$form_state['redirect'] = array(preg_replace('!^book/export/html/!', 'node/', $form_state['values']['path']), array('query' => $form_state['values']['query'])); |
|
502 |
$form_state['redirect'] = array( |
|
503 |
preg_replace('!^book/export/html/!', 'node/', $form_state['values']['path']), array( |
|
504 |
'query' => $form_state['values']['query'], |
|
505 |
), |
|
506 |
); |
|
359 | 507 |
} |
Also available in: Unified diff
Weekly update of contrib modules