1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Displays Printer-friendly versions of Drupal pages.
|
6
|
*
|
7
|
* @ingroup print
|
8
|
*/
|
9
|
|
10
|
define('PRINTMAIL_PATH', 'printmail');
|
11
|
|
12
|
// Defined in print.module
|
13
|
// define('PRINT_MAIL_FORMAT', 'mail');
|
14
|
|
15
|
define('PRINT_MAIL_LINK_POS_DEFAULT', '{ "link": "link", "block": "block", "help": "help" }');
|
16
|
define('PRINT_MAIL_LINK_TEASER_DEFAULT', 0);
|
17
|
define('PRINT_MAIL_SHOW_LINK_DEFAULT', 1);
|
18
|
define('PRINT_MAIL_NODE_LINK_VISIBILITY_DEFAULT', 0);
|
19
|
define('PRINT_MAIL_NODE_LINK_PAGES_DEFAULT', '');
|
20
|
define('PRINT_MAIL_LINK_CLASS_DEFAULT', 'print-mail');
|
21
|
define('PRINT_MAIL_SYS_LINK_VISIBILITY_DEFAULT', 1);
|
22
|
define('PRINT_MAIL_SYS_LINK_PAGES_DEFAULT', '');
|
23
|
define('PRINT_MAIL_LINK_USE_ALIAS_DEFAULT', 0);
|
24
|
define('PRINT_MAIL_BOOK_LINK_DEFAULT', 1);
|
25
|
define('PRINT_MAIL_HOURLY_THRESHOLD', 3);
|
26
|
define('PRINT_MAIL_USE_REPLY_TO', TRUE);
|
27
|
define('PRINT_MAIL_TEASER_DEFAULT_DEFAULT', 1);
|
28
|
define('PRINT_MAIL_TEASER_CHOICE_DEFAULT', 0);
|
29
|
define('PRINT_MAIL_SEND_OPTION_DEFAULT', 'sendpage');
|
30
|
define('PRINT_MAIL_JOB_QUEUE_DEFAULT', 0);
|
31
|
|
32
|
/**
|
33
|
* Implements hook_permission().
|
34
|
*/
|
35
|
function print_mail_permission() {
|
36
|
return array(
|
37
|
'access send by email' => array(
|
38
|
'title' => t('Access the Send by email functionality'),
|
39
|
'description' => t('Provides the ability to send pages by email and the links to them in the original pages.'),
|
40
|
),
|
41
|
'send unlimited emails' => array(
|
42
|
'title' => t('Send unlimited emails'),
|
43
|
'description' => t("Overrides the built-in hourly threshold limits when sending emails. This permission should only be granted to trusted users, due to it's potential in enabling the use of your site as a source of email spam."),
|
44
|
),
|
45
|
);
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* Implements hook_theme().
|
50
|
*/
|
51
|
function print_mail_theme() {
|
52
|
return array(
|
53
|
'print_mail_format_link' => array(
|
54
|
'variables' => array(),
|
55
|
),
|
56
|
'print_mail_form' => array(
|
57
|
'render element' => 'form',
|
58
|
'file' => 'print_mail.inc',
|
59
|
),
|
60
|
);
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* Implements hook_menu().
|
65
|
*/
|
66
|
function print_mail_menu() {
|
67
|
$items = array();
|
68
|
|
69
|
$items[PRINTMAIL_PATH] = array(
|
70
|
'title' => variable_get('print_mail_text_title', 'Send page by email'),
|
71
|
'page callback' => 'drupal_get_form',
|
72
|
'page arguments' => array('print_mail_form'),
|
73
|
'access callback' => '_print_mail_access',
|
74
|
'access arguments' => array('access send by email'),
|
75
|
'type' => MENU_CALLBACK,
|
76
|
'file' => 'print_mail.inc',
|
77
|
);
|
78
|
$items[PRINTMAIL_PATH . '/' . PRINTMAIL_PATH] = array(
|
79
|
'access callback' => FALSE,
|
80
|
);
|
81
|
$items['admin/config/user-interface/print/email'] = array(
|
82
|
'title' => 'email',
|
83
|
'description' => 'Configure the settings of the send by email functionality.',
|
84
|
'page callback' => 'drupal_get_form',
|
85
|
'page arguments' => array('print_mail_settings'),
|
86
|
'access arguments' => array('administer print'),
|
87
|
'weight' => 2,
|
88
|
'type' => MENU_LOCAL_TASK,
|
89
|
'file' => 'print_mail.admin.inc',
|
90
|
);
|
91
|
$items['admin/config/user-interface/print/email/options'] = array(
|
92
|
'title' => 'Options',
|
93
|
'weight' => 1,
|
94
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
95
|
);
|
96
|
$items['admin/config/user-interface/print/email/strings'] = array(
|
97
|
'title' => 'Text strings',
|
98
|
'description' => 'Override the user-facing strings used in the send by email version.',
|
99
|
'page callback' => 'drupal_get_form',
|
100
|
'page arguments' => array('print_mail_strings_settings'),
|
101
|
'access arguments' => array('administer print'),
|
102
|
'weight' => 2,
|
103
|
'type' => MENU_LOCAL_TASK,
|
104
|
'file' => 'print_mail.admin.inc',
|
105
|
);
|
106
|
|
107
|
return $items;
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Implements hook_requirements().
|
112
|
*/
|
113
|
function print_mail_requirements($phase) {
|
114
|
$requirements = array();
|
115
|
$t = get_t();
|
116
|
switch ($phase) {
|
117
|
// At runtime, make sure that a PDF generation tool is selected
|
118
|
case 'runtime':
|
119
|
if (module_exists('mailsystem')) {
|
120
|
$mail_system = mailsystem_get();
|
121
|
if (($mail_system['default-system'] != 'DefaultMailSystem') && (!isset($mail_system['print_mail']) || ($mail_system['print_mail'] != 'DefaultMailSystem'))) {
|
122
|
$requirements['print_mail_mailsystem'] = array(
|
123
|
'title' => $t('Printer, email and PDF versions - Send by email'),
|
124
|
'value' => $t('Incompatible Mail System setting detected'),
|
125
|
'description' => $t('The send by email module requires the use of the DefaultMailSystem, please configure it in the !url.', array('!url' => l($t('Mail System Settings page'), 'admin/config/system/mailsystem'))),
|
126
|
'severity' => REQUIREMENT_WARNING,
|
127
|
);
|
128
|
}
|
129
|
}
|
130
|
}
|
131
|
|
132
|
return $requirements;
|
133
|
}
|
134
|
|
135
|
/**
|
136
|
* Implements hook_block_info().
|
137
|
*/
|
138
|
function print_mail_block_info() {
|
139
|
$block['print_mail-top']['info'] = t('Most emailed');
|
140
|
$block['print_mail-top']['cache'] = DRUPAL_CACHE_GLOBAL;
|
141
|
return $block;
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* Implements hook_block_view().
|
146
|
*/
|
147
|
function print_mail_block_view($delta = 0) {
|
148
|
$block = array();
|
149
|
|
150
|
switch ($delta) {
|
151
|
case 'print_mail-top':
|
152
|
$block['subject'] = t('Most emailed');
|
153
|
$result = db_query_range("SELECT path FROM {print_mail_page_counter} LEFT JOIN {node} n ON path = CONCAT('node/', n.nid) WHERE status <> 0 OR status IS NULL ORDER BY sentcount DESC", 0, 3)
|
154
|
->fetchAll();
|
155
|
if (count($result)) {
|
156
|
$block['content'] = '<div class="item-list"><ul>';
|
157
|
foreach ($result as $obj) {
|
158
|
$block['content'] .= '<li>' . l(_print_get_title($obj->path), $obj->path) . '</li>';
|
159
|
}
|
160
|
$block['content'] .= '</ul></div>';
|
161
|
}
|
162
|
break;
|
163
|
}
|
164
|
return $block;
|
165
|
}
|
166
|
|
167
|
/**
|
168
|
* Implements hook_node_view().
|
169
|
*/
|
170
|
function print_mail_node_view($node, $view_mode) {
|
171
|
$print_mail_link_pos = variable_get('print_mail_link_pos', drupal_json_decode(PRINT_MAIL_LINK_POS_DEFAULT));
|
172
|
$print_mail_link_use_alias = variable_get('print_mail_link_use_alias', PRINT_MAIL_LINK_USE_ALIAS_DEFAULT);
|
173
|
|
174
|
foreach (array('node', 'comment') as $type) {
|
175
|
$allowed_type = print_mail_link_allowed(array('type' => $type, 'node' => $node, 'view_mode' => $view_mode));
|
176
|
if (($allowed_type) && !empty($print_mail_link_pos['link'])) {
|
177
|
drupal_add_css(drupal_get_path('module', 'print') . '/css/printlinks.css');
|
178
|
$links = array();
|
179
|
$format = theme('print_mail_format_link');
|
180
|
|
181
|
// Show book link
|
182
|
if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
|
183
|
$links['book_mail'] = array(
|
184
|
'href' => PRINTMAIL_PATH . '/book/export/html/' . $node->nid,
|
185
|
'title' => $format['text'],
|
186
|
'attributes' => $format['attributes'],
|
187
|
'html' => $format['html'],
|
188
|
);
|
189
|
}
|
190
|
elseif ($allowed_type === PRINT_ALLOW_NORMAL_LINK) {
|
191
|
$path = (($print_mail_link_use_alias) && ($alias = drupal_lookup_path('alias', 'node/' . $node->nid))) ? $alias : $node->nid;
|
192
|
|
193
|
$links['print_mail'] = array(
|
194
|
'href' => PRINTMAIL_PATH . '/' . $path,
|
195
|
'title' => $format['text'],
|
196
|
'attributes' => $format['attributes'],
|
197
|
'html' => $format['html'],
|
198
|
'query' => print_query_string_encode($_GET, array('q')),
|
199
|
);
|
200
|
}
|
201
|
|
202
|
$link_content = array(
|
203
|
'#theme' => 'links',
|
204
|
'#links' => $links,
|
205
|
'#attributes' => array('class' => array('links', 'inline')),
|
206
|
);
|
207
|
|
208
|
if ($type == 'node') {
|
209
|
$node->content['links']['print_mail'] = $link_content;
|
210
|
}
|
211
|
elseif (($type == 'comment') && isset($node->content['comments']['comments'])) {
|
212
|
foreach ($node->content['comments']['comments'] as $cid => $comment) {
|
213
|
if (is_numeric($cid)) {
|
214
|
$link_content['#links']['print_mail']['query']['comment'] = $cid;
|
215
|
$node->content['comments']['comments'][$cid]['links']['print_mail'] = $link_content;
|
216
|
}
|
217
|
}
|
218
|
}
|
219
|
}
|
220
|
}
|
221
|
|
222
|
// Insert content corner links
|
223
|
if (!empty($print_mail_link_pos['corner']) && ($view_mode == 'full')) {
|
224
|
$node->content['print_links']['#markup'] .= print_mail_insert_link(NULL, $node);
|
225
|
}
|
226
|
}
|
227
|
|
228
|
/**
|
229
|
* Implements hook_help().
|
230
|
*/
|
231
|
function print_mail_help($path, $arg) {
|
232
|
$print_mail_link_pos = variable_get('print_mail_link_pos', drupal_json_decode(PRINT_MAIL_LINK_POS_DEFAULT));
|
233
|
if (($path !== 'node/%') && !(empty($print_mail_link_pos['help']))) {
|
234
|
static $output = FALSE;
|
235
|
|
236
|
if ($output === FALSE) {
|
237
|
$output = TRUE;
|
238
|
|
239
|
$link = print_mail_insert_link();
|
240
|
if ($link) {
|
241
|
return "<span class='print-syslink'>$link</span>";
|
242
|
}
|
243
|
}
|
244
|
}
|
245
|
}
|
246
|
|
247
|
/**
|
248
|
* Implements hook_node_load().
|
249
|
*/
|
250
|
function print_mail_node_load($nodes, $types) {
|
251
|
$ids = array();
|
252
|
foreach ($nodes as $node) {
|
253
|
$ids[] = $node->nid;
|
254
|
}
|
255
|
|
256
|
$result = db_query('SELECT nid, link, comments, url_list FROM {print_mail_node_conf} WHERE nid IN (:nids)', array(':nids' => $ids))->fetchAllAssoc('nid');
|
257
|
|
258
|
foreach ($nodes as $node) {
|
259
|
$node->print_mail_display = isset($result[$node->nid]) ? intval($result[$node->nid]->link) : variable_get('print_mail_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
|
260
|
$node->print_mail_display_comment = isset($result[$node->nid]) ? intval($result[$node->nid]->comments) : variable_get('print_mail_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
|
261
|
$node->print_mail_display_urllist = isset($result[$node->nid]) ? intval($result[$node->nid]->url_list) : variable_get('print_mail_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
|
262
|
}
|
263
|
}
|
264
|
|
265
|
/**
|
266
|
* Implements hook_node_insert().
|
267
|
*/
|
268
|
function print_mail_node_insert($node) {
|
269
|
if (user_access('administer print') || user_access('node-specific print configuration')) {
|
270
|
if (!isset($node->print_mail_display)) $node->print_mail_display = variable_get('print_mail_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
|
271
|
if (!isset($node->print_mail_display_comment)) $node->print_mail_display_comment = variable_get('print_mail_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
|
272
|
if (!isset($node->print_mail_display_urllist)) $node->print_mail_display_urllist = variable_get('print_mail_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
|
273
|
|
274
|
_print_mail_node_conf_modify($node->nid, $node->print_mail_display, $node->print_mail_display_comment, $node->print_mail_display_urllist);
|
275
|
}
|
276
|
}
|
277
|
|
278
|
/**
|
279
|
* Implements hook_node_update().
|
280
|
*/
|
281
|
function print_mail_node_update($node) {
|
282
|
if (user_access('administer print') || user_access('node-specific print configuration')) {
|
283
|
if (!isset($node->print_mail_display) || $node->print_mail_display === NULL) {
|
284
|
$node->print_mail_display = variable_get('print_mail_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
|
285
|
}
|
286
|
if (!isset($node->print_mail_display_comment) || $node->print_mail_display_comment === NULL) {
|
287
|
$node->print_mail_display_comment = variable_get('print_mail_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
|
288
|
}
|
289
|
if (!isset($node->print_mail_display_urllist) || $node->print_mail_display_urllist === NULL) {
|
290
|
$node->print_mail_display_urllist = variable_get('print_mail_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
|
291
|
}
|
292
|
|
293
|
_print_mail_node_conf_modify($node->nid, $node->print_mail_display, $node->print_mail_display_comment, $node->print_mail_display_urllist);
|
294
|
}
|
295
|
}
|
296
|
|
297
|
/**
|
298
|
* Implements hook_node_delete().
|
299
|
*/
|
300
|
function print_mail_node_delete($node) {
|
301
|
db_delete('print_mail_node_conf')
|
302
|
->condition('nid', $node->nid)
|
303
|
->execute();
|
304
|
db_delete('print_mail_page_counter')
|
305
|
->condition('path', 'node/' . $node->nid)
|
306
|
->execute();
|
307
|
}
|
308
|
|
309
|
/**
|
310
|
* Implements hook_form_alter().
|
311
|
*/
|
312
|
function print_mail_form_alter(&$form, &$form_state, $form_id) {
|
313
|
// Add the node-type settings option to activate the mail version link
|
314
|
if ((user_access('administer print') || user_access('node-specific print configuration')) &&
|
315
|
(($form_id == 'node_type_form') || !empty($form['#node_edit_form']))) {
|
316
|
$form['print']['mail_label'] = array(
|
317
|
'#type' => 'markup',
|
318
|
'#markup' => '<p><strong>' . t('Send by email') . '</strong></p>',
|
319
|
);
|
320
|
|
321
|
$form['print']['print_mail_display'] = array(
|
322
|
'#type' => 'checkbox',
|
323
|
'#title' => t('Show link'),
|
324
|
);
|
325
|
$form['print']['print_mail_display_comment'] = array(
|
326
|
'#type' => 'checkbox',
|
327
|
'#title' => t('Show link in individual comments'),
|
328
|
);
|
329
|
$form['print']['print_mail_display_urllist'] = array(
|
330
|
'#type' => 'checkbox',
|
331
|
'#title' => t('Show Printer-friendly URLs list'),
|
332
|
);
|
333
|
|
334
|
if ($form_id == 'node_type_form') {
|
335
|
$form['print']['print_mail_display']['#default_value'] = variable_get('print_mail_display_' . $form['#node_type']->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
|
336
|
$form['print']['print_mail_display_comment']['#default_value'] = variable_get('print_mail_display_comment_' . $form['#node_type']->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
|
337
|
$form['print']['print_mail_display_urllist']['#default_value'] = variable_get('print_mail_display_urllist_' . $form['#node_type']->type, PRINT_TYPE_URLLIST_DEFAULT);
|
338
|
}
|
339
|
else {
|
340
|
$node = $form['#node'];
|
341
|
$form['print']['print_mail_display']['#default_value'] = isset($node->print_mail_display) ? $node->print_mail_display : variable_get('print_mail_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
|
342
|
$form['print']['print_mail_display_comment']['#default_value'] = isset($node->print_mail_display_comment) ? $node->print_mail_display_comment : variable_get('print_mail_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
|
343
|
$form['print']['print_mail_display_urllist']['#default_value'] = isset($node->print_mail_display_urllist) ? $node->print_mail_display_urllist : variable_get('print_mail_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
|
344
|
}
|
345
|
}
|
346
|
}
|
347
|
|
348
|
/**
|
349
|
* Implements hook_cron_queue_info().
|
350
|
*/
|
351
|
function print_mail_cron_queue_info() {
|
352
|
$queues['print_mail_send'] = array(
|
353
|
'worker callback' => 'print_mail_send',
|
354
|
'time' => 60,
|
355
|
);
|
356
|
return $queues;
|
357
|
}
|
358
|
|
359
|
function print_mail_send($data) {
|
360
|
drupal_mail($data['module'], $data['key'], $data['to'], $data['language'], $data['params'], $data['from']);
|
361
|
}
|
362
|
|
363
|
/**
|
364
|
* Implements hook_mail().
|
365
|
*/
|
366
|
function print_mail_mail($key, &$message, $params) {
|
367
|
$message['subject'] = $params['subject'];
|
368
|
|
369
|
if (isset($params['from'])) {
|
370
|
$message['headers']['Reply-To'] = $params['from'];
|
371
|
}
|
372
|
|
373
|
switch ($key) {
|
374
|
case 'sendpage':
|
375
|
$message['body'][] = check_plain($params['body']);
|
376
|
$message['headers']['Content-Type'] = 'text/html; charset=utf-8';
|
377
|
break;
|
378
|
case 'sendlink':
|
379
|
// Generate plain-text and html versions of message with link
|
380
|
$sendlink_plain = $params['message'] . '\n\n' . $params['link'];
|
381
|
$sendlink_html = $params['message'] . '<br/><br/>' . l($params['title'], $params['link']);
|
382
|
|
383
|
// Send HTML-only version if MIME library not present
|
384
|
if (!class_exists('Mail_mime')) {
|
385
|
$message['body'][] = check_plain($sendlink_html);
|
386
|
$message['headers']['Content-Type'] = 'text/html; charset=utf-8';
|
387
|
break;
|
388
|
}
|
389
|
// no break on purpose
|
390
|
case 'plain-attachment':
|
391
|
case 'inline-attachment':
|
392
|
// Configure new MIME object
|
393
|
$mime = new Mail_mime("\n");
|
394
|
$mime_params['html_encoding'] = '7bit';
|
395
|
$mime_params['html_charset'] = 'utf-8';
|
396
|
$mime_params['text_charset'] = 'utf-8';
|
397
|
|
398
|
// Pass message contents into MIME object
|
399
|
switch ($key) {
|
400
|
case 'sendlink':
|
401
|
$mime->setTxtBody($sendlink_plain);
|
402
|
$mime->setHTMLBody($sendlink_html);
|
403
|
break;
|
404
|
case 'inline-attachment':
|
405
|
$mime->setHTMLBody($params['body']);
|
406
|
// no break on purpose
|
407
|
case 'plain-attachment':
|
408
|
$mime->setTxtBody($params['message']);
|
409
|
$mime->addAttachment($params['body'], 'text/html', 'Attachment.html', FALSE);
|
410
|
break;
|
411
|
}
|
412
|
|
413
|
// Store MIME message output in message array
|
414
|
$message['body'][] = check_plain($mime->get($mime_params));
|
415
|
$message['headers'] = $mime->headers($message['headers']);
|
416
|
|
417
|
// Strip special characters from Content-Type header
|
418
|
// Required to prevent mime_header_encode() from disrupting Content-Type header
|
419
|
$message['headers']['Content-Type'] = preg_replace('/[^\x20-\x7E]/', '', $message['headers']['Content-Type']);
|
420
|
break;
|
421
|
}
|
422
|
}
|
423
|
|
424
|
/**
|
425
|
* Access callback to check a combination of user_acess() and page access
|
426
|
*
|
427
|
* @param $permission
|
428
|
* permission required to view the page
|
429
|
* @return
|
430
|
* TRUE if the user has permission to view the page, FALSE otherwise
|
431
|
*/
|
432
|
function _print_mail_access($permission) {
|
433
|
$page_access = TRUE;
|
434
|
$parts = explode('/', $_GET['q']);
|
435
|
if ($parts[0] == PRINTMAIL_PATH) {
|
436
|
if (count($parts) > 1) {
|
437
|
unset($parts[0]);
|
438
|
$path = implode('/', $parts);
|
439
|
if (ctype_digit($parts[1])) {
|
440
|
if (drupal_lookup_path('source', $path)) {
|
441
|
// This is a numeric alias
|
442
|
$path = drupal_get_normal_path($path);
|
443
|
}
|
444
|
else {
|
445
|
// normal nid
|
446
|
$path = 'node/' . $path;
|
447
|
}
|
448
|
}
|
449
|
else {
|
450
|
$path = drupal_get_normal_path($path);
|
451
|
}
|
452
|
// If the destination page is not accessible, don't show the form
|
453
|
if (!($router_item = menu_get_item($path)) || (!$router_item['access'])) {
|
454
|
$page_access = FALSE;
|
455
|
}
|
456
|
}
|
457
|
}
|
458
|
|
459
|
return (user_access($permission) && $page_access);
|
460
|
}
|
461
|
|
462
|
/**
|
463
|
* Update the print_mail_node_conf table to reflect the given attributes
|
464
|
*
|
465
|
* If updating to the default values, delete the record.
|
466
|
*
|
467
|
* @param $nid
|
468
|
* value of the nid field (primary key)
|
469
|
* @param $link
|
470
|
* value of the link field (0 or 1)
|
471
|
* @param $comments
|
472
|
* value of the comments field (0 or 1)
|
473
|
* @param $url_list
|
474
|
* value of the url_list field (0 or 1)
|
475
|
*/
|
476
|
function _print_mail_node_conf_modify($nid, $link, $comments, $url_list) {
|
477
|
db_merge('print_mail_node_conf')
|
478
|
->key(array('nid' => $nid))
|
479
|
->fields(array(
|
480
|
'link' => $link,
|
481
|
'comments' => $comments,
|
482
|
'url_list' => $url_list,
|
483
|
))
|
484
|
->execute();
|
485
|
}
|
486
|
|
487
|
/**
|
488
|
* Format the send by email link
|
489
|
*
|
490
|
* @return
|
491
|
* array of formatted attributes
|
492
|
* @ingroup themeable
|
493
|
*/
|
494
|
function theme_print_mail_format_link() {
|
495
|
$print_mail_link_class = variable_get('print_mail_link_class', PRINT_MAIL_LINK_CLASS_DEFAULT);
|
496
|
$print_mail_show_link = variable_get('print_mail_show_link', PRINT_MAIL_SHOW_LINK_DEFAULT);
|
497
|
$print_mail_link_text = filter_xss(variable_get('print_mail_link_text', t('Send by email')));
|
498
|
|
499
|
$img = drupal_get_path('module', 'print') . '/icons/mail_icon.gif';
|
500
|
$title = t('Send this page by email.');
|
501
|
$class = strip_tags($print_mail_link_class);
|
502
|
$new_window = FALSE;
|
503
|
$format = _print_format_link_aux($print_mail_show_link, $print_mail_link_text, $img);
|
504
|
|
505
|
return array('text' => $format['text'],
|
506
|
'html' => $format['html'],
|
507
|
'attributes' => print_fill_attributes($title, $class, $new_window),
|
508
|
);
|
509
|
}
|
510
|
|
511
|
/**
|
512
|
* Auxiliary function to display a formatted send by email link
|
513
|
*
|
514
|
* Function made available so that developers may call this function from
|
515
|
* their defined pages/blocks.
|
516
|
*
|
517
|
* @param $path
|
518
|
* path of the original page (optional). If not specified, the current URL
|
519
|
* is used
|
520
|
* @param $node
|
521
|
* an optional node object, to be used in defining the path, if used, the
|
522
|
* path argument is irrelevant
|
523
|
* @return
|
524
|
* string with the HTML link to the printer-friendly page
|
525
|
*/
|
526
|
function print_mail_insert_link($path = NULL, $node = NULL) {
|
527
|
if ($node !== NULL) {
|
528
|
$nid = $node->nid;
|
529
|
$path = 'node/' . $nid;
|
530
|
$allowed_type = print_mail_link_allowed(array('node' => $node));
|
531
|
}
|
532
|
else {
|
533
|
if ($path === NULL) {
|
534
|
$nid = preg_replace('!^node/([\d]+)!', '$1', $_GET['q']);
|
535
|
$path = $_GET['q'];
|
536
|
}
|
537
|
else {
|
538
|
$nid = NULL;
|
539
|
}
|
540
|
$allowed_type = print_mail_link_allowed(array('path' => $path));
|
541
|
}
|
542
|
|
543
|
if ($allowed_type) {
|
544
|
if ($nid !== NULL) {
|
545
|
if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
|
546
|
$path = 'book/export/html/' . $nid;
|
547
|
}
|
548
|
else {
|
549
|
if (variable_get('print_mail_link_use_alias', PRINT_MAIL_LINK_USE_ALIAS_DEFAULT) && ($alias = drupal_lookup_path('alias', $path))) {
|
550
|
$path = $alias;
|
551
|
}
|
552
|
else {
|
553
|
$path = $nid;
|
554
|
}
|
555
|
}
|
556
|
$path = PRINTMAIL_PATH . '/' . $path;
|
557
|
$query = print_query_string_encode($_GET, array('q'));
|
558
|
}
|
559
|
else {
|
560
|
$query = NULL;
|
561
|
}
|
562
|
drupal_add_css(drupal_get_path('module', 'print') . '/css/printlinks.css');
|
563
|
$format = theme('print_mail_format_link');
|
564
|
return '<span class="print_mail">' . l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) . '</span>';
|
565
|
}
|
566
|
else {
|
567
|
return FALSE;
|
568
|
}
|
569
|
}
|
570
|
|
571
|
/**
|
572
|
* Check if the link to send by email is allowed depending on the settings
|
573
|
*
|
574
|
* @param $args
|
575
|
* array containing the possible parameters:
|
576
|
* teaser, node, type, path
|
577
|
* @return
|
578
|
* FALSE if not allowed
|
579
|
* PRINT_ALLOW_NORMAL_LINK if a normal link is allowed
|
580
|
* PRINT_ALLOW_BOOK_LINK if a link is allowed in a book node
|
581
|
*/
|
582
|
function print_mail_link_allowed($args) {
|
583
|
$view_mode = isset($args['view_mode']) ? $args['view_mode'] : '';
|
584
|
if ((($view_mode == 'teaser') && !variable_get('print_mail_link_teaser', PRINT_MAIL_LINK_TEASER_DEFAULT))
|
585
|
|| !in_array($view_mode, array('full', 'teaser', '')) || !user_access('access send by email')) {
|
586
|
// If the teaser link is disabled or the user is not allowed
|
587
|
return FALSE;
|
588
|
}
|
589
|
if (!empty($args['path'])) {
|
590
|
$nid = preg_replace('!^node/!', '', drupal_get_normal_path($args['path']));
|
591
|
if (ctype_digit($nid)) {
|
592
|
$args['node'] = node_load($nid);
|
593
|
}
|
594
|
}
|
595
|
if (!empty($args['node'])) {
|
596
|
static $node_type = FALSE;
|
597
|
|
598
|
$node = $args['node'];
|
599
|
if (isset($node->type)) {
|
600
|
$node_type = $node->type;
|
601
|
}
|
602
|
// Node
|
603
|
$print_mail_node_link_visibility = variable_get('print_mail_node_link_visibility', PRINT_MAIL_NODE_LINK_VISIBILITY_DEFAULT);
|
604
|
$print_mail_node_link_pages = variable_get('print_mail_node_link_pages', PRINT_MAIL_NODE_LINK_PAGES_DEFAULT);
|
605
|
|
606
|
if (!_print_page_match($print_mail_node_link_visibility, "node/" . $node->nid, $print_mail_node_link_pages)) {
|
607
|
// Page not in visibility list
|
608
|
return FALSE;
|
609
|
}
|
610
|
elseif (isset($args['type']) && ($args['type'] == 'comment') && isset($node_type)) {
|
611
|
// Link is for a comment, return the configured setting
|
612
|
// Cache this statically to avoid duplicate queries for every comment.
|
613
|
static $res = array();
|
614
|
if (!isset($res[$node->nid])) {
|
615
|
$res[$node->nid] = db_query("SELECT comments FROM {print_mail_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))->fetchField();
|
616
|
}
|
617
|
$print_display_comment = ($res && ($res[$node->nid] !== FALSE)) ? $res[$node->nid] : variable_get('print_mail_display_comment_' . $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
|
618
|
if ($print_display_comment) {
|
619
|
return PRINT_ALLOW_NORMAL_LINK;
|
620
|
}
|
621
|
}
|
622
|
else {
|
623
|
// Node link
|
624
|
if (isset($node->print_mail_display) && !$node->print_mail_display) {
|
625
|
// Link for this node is disabled
|
626
|
return FALSE;
|
627
|
}
|
628
|
elseif (isset($node->book)) {
|
629
|
// Node is a book;
|
630
|
$print_mail_book_link = variable_get('print_mail_book_link', PRINT_MAIL_BOOK_LINK_DEFAULT);
|
631
|
switch ($print_mail_book_link) {
|
632
|
case 1:
|
633
|
if (user_access('access printer-friendly version')) {
|
634
|
return PRINT_ALLOW_BOOK_LINK;
|
635
|
}
|
636
|
break;
|
637
|
case 2:
|
638
|
return PRINT_ALLOW_NORMAL_LINK;
|
639
|
}
|
640
|
}
|
641
|
else {
|
642
|
return PRINT_ALLOW_NORMAL_LINK;
|
643
|
}
|
644
|
}
|
645
|
}
|
646
|
else {
|
647
|
// 'System' page
|
648
|
$print_mail_sys_link_visibility = variable_get('print_mail_sys_link_visibility', PRINT_MAIL_SYS_LINK_VISIBILITY_DEFAULT);
|
649
|
$print_mail_sys_link_pages = variable_get('print_mail_sys_link_pages', PRINT_MAIL_SYS_LINK_PAGES_DEFAULT);
|
650
|
|
651
|
return _print_page_match($print_mail_sys_link_visibility, $_GET['q'], $print_mail_sys_link_pages);
|
652
|
}
|
653
|
return FALSE;
|
654
|
}
|
655
|
|
656
|
/**
|
657
|
* Implements hook_nollom_form_list().
|
658
|
*/
|
659
|
function print_mail_mollom_form_list() {
|
660
|
$forms['print_mail_form'] = array(
|
661
|
'title' => t('Send page form'),
|
662
|
'entity' => 'print_mail',
|
663
|
);
|
664
|
return $forms;
|
665
|
}
|
666
|
|
667
|
/**
|
668
|
* Implemenents hook_mollom_form_info().
|
669
|
*/
|
670
|
function print_mail_mollom_form_info($form_id) {
|
671
|
switch ($form_id) {
|
672
|
case 'print_mail_form':
|
673
|
$form_info = array(
|
674
|
'elements' => array(
|
675
|
'fld_from_addr' => t('Sender email'),
|
676
|
'fld_from_name' => t('Sender name'),
|
677
|
'txt_to_addrs' => t('Recipients'),
|
678
|
'fld_subject' => t('Subject'),
|
679
|
'fld_title' => t('Page to be sent'),
|
680
|
'txt_message' => t('Your message'),
|
681
|
),
|
682
|
'mapping' => array(
|
683
|
'post_title' => 'fld_title',
|
684
|
'author_name' => 'fld_from_name',
|
685
|
'author_mail' => 'fld_from_addr',
|
686
|
),
|
687
|
);
|
688
|
break;
|
689
|
}
|
690
|
return $form_info;
|
691
|
}
|
692
|
|
693
|
/**
|
694
|
* Implements hook_views_api().
|
695
|
*/
|
696
|
function print_mail_views_api() {
|
697
|
return array(
|
698
|
'api' => 2.0,
|
699
|
'path' => drupal_get_path('module', 'print_mail'),
|
700
|
);
|
701
|
}
|
702
|
|
703
|
/**
|
704
|
* Implements hook_rules_action_info().
|
705
|
*
|
706
|
* @ingroup rules
|
707
|
*/
|
708
|
function print_mail_rules_action_info() {
|
709
|
return array(
|
710
|
'print_mail_action_submit' => array(
|
711
|
'label' => t('Send node as HTML formatted email'),
|
712
|
'group' => t('Send by email'),
|
713
|
'parameter' => array(
|
714
|
'from' => array('type' => 'text', 'label' => t('From email adress')),
|
715
|
'from_name' => array('type' => 'text', 'label' => t('From name')),
|
716
|
'to' => array('type' => 'text', 'label' => t('Send email to')),
|
717
|
'subject' => array('type' => 'text', 'label' => t('Subject')),
|
718
|
'message' => array(
|
719
|
'type' => 'text',
|
720
|
'label' => t('Message'),
|
721
|
'description' => t('The message that should be displayed (optional).'),
|
722
|
'optional' => TRUE,
|
723
|
),
|
724
|
'node' => array('type' => 'node', 'label' => t('Content')),
|
725
|
),
|
726
|
),
|
727
|
);
|
728
|
}
|
729
|
|
730
|
/**
|
731
|
* Action handler for the print_mail_action_submit
|
732
|
*
|
733
|
* @ingroup rules
|
734
|
*/
|
735
|
function print_mail_action_submit($from, $from_name, $to, $subject, $message, $node) {
|
736
|
module_load_include('inc', 'print_mail', 'print_mail');
|
737
|
|
738
|
$form_state['values'] = array(
|
739
|
'path' => 'node/' . $node->nid,
|
740
|
'cid' => NULL,
|
741
|
'query' => NULL,
|
742
|
'title' => $node->title,
|
743
|
'fld_from_addr' => $from,
|
744
|
'fld_from_name' => $from_name,
|
745
|
'txt_to_addrs' => $to,
|
746
|
'fld_subject' => $subject,
|
747
|
'txt_message' => $message,
|
748
|
'chk_teaser' => FALSE,
|
749
|
);
|
750
|
|
751
|
print_mail_form_submit(NULL, $form_state);
|
752
|
}
|