Revision 76bdcd04
Added by Assos Assos almost 6 years ago
drupal7/sites/all/modules/print/print_mail/print_mail.module | ||
---|---|---|
7 | 7 |
* @ingroup print |
8 | 8 |
*/ |
9 | 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 | 10 |
define('PRINT_MAIL_HOURLY_THRESHOLD', 3); |
26 | 11 |
define('PRINT_MAIL_USE_REPLY_TO', TRUE); |
27 | 12 |
define('PRINT_MAIL_TEASER_DEFAULT_DEFAULT', 1); |
28 | 13 |
define('PRINT_MAIL_TEASER_CHOICE_DEFAULT', 0); |
29 | 14 |
define('PRINT_MAIL_SEND_OPTION_DEFAULT', 'sendpage'); |
30 | 15 |
define('PRINT_MAIL_JOB_QUEUE_DEFAULT', 0); |
16 |
define('PRINT_MAIL_USER_RECIPIENTS_DEFAULT', 0); |
|
17 |
|
|
18 |
/** |
|
19 |
* Implements hook_print_link(). |
|
20 |
*/ |
|
21 |
function print_mail_print_link() { |
|
22 |
return array( |
|
23 |
'format' => 'mail', |
|
24 |
'text' => t('Send by email'), |
|
25 |
'description' => t('Send this page by email.'), |
|
26 |
'path' => 'printmail', |
|
27 |
'class' => 'print-mail', |
|
28 |
'icon' => 'mail_icon.png', |
|
29 |
'module' => 'print_mail', |
|
30 |
); |
|
31 |
} |
|
31 | 32 |
|
32 | 33 |
/** |
33 | 34 |
* Implements hook_permission(). |
... | ... | |
50 | 51 |
*/ |
51 | 52 |
function print_mail_theme() { |
52 | 53 |
return array( |
53 |
'print_mail_format_link' => array( |
|
54 |
'variables' => array(), |
|
55 |
), |
|
56 | 54 |
'print_mail_form' => array( |
57 | 55 |
'render element' => 'form', |
58 | 56 |
'file' => 'print_mail.inc', |
59 | 57 |
), |
58 |
'print_mail_sendlink_html' => array( |
|
59 |
'variables' => array('params' => NULL), |
|
60 |
'file' => 'print_mail.inc', |
|
61 |
), |
|
62 |
'print_mail_sendlink_plain' => array( |
|
63 |
'variables' => array('params' => NULL), |
|
64 |
'file' => 'print_mail.inc', |
|
65 |
), |
|
60 | 66 |
); |
61 | 67 |
} |
62 | 68 |
|
... | ... | |
64 | 70 |
* Implements hook_menu(). |
65 | 71 |
*/ |
66 | 72 |
function print_mail_menu() { |
73 |
$link = print_mail_print_link(); |
|
67 | 74 |
$items = array(); |
68 | 75 |
|
69 |
$items[PRINTMAIL_PATH] = array(
|
|
70 |
'title' => variable_get('print_mail_text_title', 'Send page by email'),
|
|
76 |
$items[$link['path']] = array(
|
|
77 |
'title' => 'Send by email',
|
|
71 | 78 |
'page callback' => 'drupal_get_form', |
72 | 79 |
'page arguments' => array('print_mail_form'), |
73 | 80 |
'access callback' => '_print_mail_access', |
... | ... | |
75 | 82 |
'type' => MENU_CALLBACK, |
76 | 83 |
'file' => 'print_mail.inc', |
77 | 84 |
); |
78 |
$items[PRINTMAIL_PATH . '/' . PRINTMAIL_PATH] = array(
|
|
85 |
$items[$link['path'] . '/' . $link['path']] = array(
|
|
79 | 86 |
'access callback' => FALSE, |
80 | 87 |
); |
81 | 88 |
$items['admin/config/user-interface/print/email'] = array( |
... | ... | |
88 | 95 |
'type' => MENU_LOCAL_TASK, |
89 | 96 |
'file' => 'print_mail.admin.inc', |
90 | 97 |
); |
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 | 98 |
|
107 | 99 |
return $items; |
108 | 100 |
} |
109 | 101 |
|
110 | 102 |
/** |
111 |
* Implements hook_requirements().
|
|
103 |
* Implements hook_variable_info().
|
|
112 | 104 |
*/ |
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 |
} |
|
105 |
function print_mail_variable_info($options) { |
|
106 |
$link = print_mail_print_link(); |
|
107 |
|
|
108 |
$variable['print_mail_link_text'] = array( |
|
109 |
'title' => t('Send by email'), |
|
110 |
'description' => t('Text used in the link to the send by email form.'), |
|
111 |
'type' => 'string', |
|
112 |
'default' => t($link['text']), |
|
113 |
); |
|
131 | 114 |
|
132 |
return $requirements;
|
|
115 |
return $variable;
|
|
133 | 116 |
} |
134 | 117 |
|
135 | 118 |
/** |
136 | 119 |
* Implements hook_block_info(). |
137 | 120 |
*/ |
138 | 121 |
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;
|
|
122 |
$block['print_mail-top']['info'] = t('Most emailed'); |
|
123 |
$block['print_mail-top']['cache'] = DRUPAL_CACHE_GLOBAL; |
|
124 |
return $block; |
|
142 | 125 |
} |
143 | 126 |
|
144 | 127 |
/** |
... | ... | |
146 | 129 |
*/ |
147 | 130 |
function print_mail_block_view($delta = 0) { |
148 | 131 |
$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>'; |
|
132 |
switch ($delta) { |
|
133 |
case 'print_mail-top': |
|
134 |
$block['subject'] = t('Most emailed'); |
|
135 |
$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) |
|
136 |
->fetchAll(); |
|
137 |
if (count($result)) { |
|
138 |
$items = array(); |
|
139 |
foreach ($result as $obj) { |
|
140 |
$items[] = l(_print_get_title($obj->path), $obj->path); |
|
161 | 141 |
} |
162 |
break;
|
|
142 |
$block['content'] = theme('item_list', array('items' => $items, 'type' => 'ul'));
|
|
163 | 143 |
} |
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); |
|
144 |
break; |
|
294 | 145 |
} |
146 |
return $block; |
|
295 | 147 |
} |
296 | 148 |
|
297 | 149 |
/** |
298 | 150 |
* Implements hook_node_delete(). |
299 | 151 |
*/ |
300 | 152 |
function print_mail_node_delete($node) { |
301 |
db_delete('print_mail_node_conf') |
|
302 |
->condition('nid', $node->nid) |
|
303 |
->execute(); |
|
304 | 153 |
db_delete('print_mail_page_counter') |
305 | 154 |
->condition('path', 'node/' . $node->nid) |
306 | 155 |
->execute(); |
307 | 156 |
} |
308 | 157 |
|
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 | 158 |
/** |
349 | 159 |
* Implements hook_cron_queue_info(). |
350 | 160 |
*/ |
... | ... | |
356 | 166 |
return $queues; |
357 | 167 |
} |
358 | 168 |
|
169 |
/** |
|
170 |
* Worker callback for print_mail_cron_queue_info() |
|
171 |
* |
|
172 |
* @param array $data |
|
173 |
* An associative array containing: |
|
174 |
* - module: A module name to invoke hook_mail() on. |
|
175 |
* - key: A key to identify the e-mail sent. |
|
176 |
* - to: The e-mail address or addresses where the message will be sent to. |
|
177 |
* - language: Language object to use to compose the e-mail. |
|
178 |
* - params: Optional parameters to build the e-mail. |
|
179 |
* - from: Sets From to this value, if given. |
|
180 |
* These are the input arguments of the drupal_mail() function. |
|
181 |
*/ |
|
359 | 182 |
function print_mail_send($data) { |
360 | 183 |
drupal_mail($data['module'], $data['key'], $data['to'], $data['language'], $data['params'], $data['from']); |
361 | 184 |
} |
... | ... | |
370 | 193 |
$message['headers']['Reply-To'] = $params['from']; |
371 | 194 |
} |
372 | 195 |
|
196 |
$sendlink_plain = ''; |
|
197 |
$sendlink_html = ''; |
|
373 | 198 |
switch ($key) { |
374 | 199 |
case 'sendpage': |
375 | 200 |
$message['body'][] = check_plain($params['body']); |
376 | 201 |
$message['headers']['Content-Type'] = 'text/html; charset=utf-8'; |
377 | 202 |
break; |
203 |
|
|
378 | 204 |
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']);
|
|
205 |
// Generate plain-text and html versions of message with link.
|
|
206 |
$sendlink_plain = theme('print_mail_sendlink_plain', $params);
|
|
207 |
$sendlink_html = theme('print_mail_sendlink_html', $params);
|
|
382 | 208 |
|
383 |
// Send HTML-only version if MIME library not present |
|
209 |
// Send HTML-only version if MIME library not present.
|
|
384 | 210 |
if (!class_exists('Mail_mime')) { |
385 | 211 |
$message['body'][] = check_plain($sendlink_html); |
386 | 212 |
$message['headers']['Content-Type'] = 'text/html; charset=utf-8'; |
387 | 213 |
break; |
388 | 214 |
} |
389 |
// no break on purpose
|
|
215 |
// No break on purpose.
|
|
390 | 216 |
case 'plain-attachment': |
391 | 217 |
case 'inline-attachment': |
392 |
// Configure new MIME object |
|
218 |
// Configure new MIME object.
|
|
393 | 219 |
$mime = new Mail_mime("\n"); |
394 | 220 |
$mime_params['html_encoding'] = '7bit'; |
395 | 221 |
$mime_params['html_charset'] = 'utf-8'; |
396 | 222 |
$mime_params['text_charset'] = 'utf-8'; |
397 | 223 |
|
398 |
// Pass message contents into MIME object |
|
224 |
// Pass message contents into MIME object.
|
|
399 | 225 |
switch ($key) { |
400 | 226 |
case 'sendlink': |
401 | 227 |
$mime->setTxtBody($sendlink_plain); |
402 | 228 |
$mime->setHTMLBody($sendlink_html); |
403 | 229 |
break; |
230 |
|
|
404 | 231 |
case 'inline-attachment': |
405 | 232 |
$mime->setHTMLBody($params['body']); |
406 |
// no break on purpose
|
|
233 |
// No break on purpose.
|
|
407 | 234 |
case 'plain-attachment': |
408 | 235 |
$mime->setTxtBody($params['message']); |
409 | 236 |
$mime->addAttachment($params['body'], 'text/html', 'Attachment.html', FALSE); |
410 | 237 |
break; |
411 | 238 |
} |
412 | 239 |
|
413 |
// Store MIME message output in message array |
|
240 |
// Store MIME message output in message array.
|
|
414 | 241 |
$message['body'][] = check_plain($mime->get($mime_params)); |
415 | 242 |
$message['headers'] = $mime->headers($message['headers']); |
416 | 243 |
|
417 |
// Strip special characters from Content-Type header |
|
418 |
// Required to prevent mime_header_encode() from disrupting Content-Type header
|
|
244 |
// Strip special characters from Content-Type header. Required to prevent
|
|
245 |
// mime_header_encode() from disrupting Content-Type header.
|
|
419 | 246 |
$message['headers']['Content-Type'] = preg_replace('/[^\x20-\x7E]/', '', $message['headers']['Content-Type']); |
420 | 247 |
break; |
421 | 248 |
} |
422 | 249 |
} |
423 | 250 |
|
424 | 251 |
/** |
425 |
* Access callback to check a combination of user_acess() and page access |
|
252 |
* Access callback to check a combination of user_acess() and page access. |
|
253 |
* |
|
254 |
* @param string $permission |
|
255 |
* Permission required to view the page. |
|
426 | 256 |
* |
427 |
* @param $permission |
|
428 |
* permission required to view the page |
|
429 |
* @return |
|
257 |
* @return bool |
|
430 | 258 |
* TRUE if the user has permission to view the page, FALSE otherwise |
431 | 259 |
*/ |
432 | 260 |
function _print_mail_access($permission) { |
261 |
$link = print_mail_print_link(); |
|
433 | 262 |
$page_access = TRUE; |
434 | 263 |
$parts = explode('/', $_GET['q']); |
435 |
if ($parts[0] == PRINTMAIL_PATH) {
|
|
264 |
if ($parts[0] == $link['path']) {
|
|
436 | 265 |
if (count($parts) > 1) { |
437 | 266 |
unset($parts[0]); |
438 | 267 |
$path = implode('/', $parts); |
439 | 268 |
if (ctype_digit($parts[1])) { |
440 | 269 |
if (drupal_lookup_path('source', $path)) { |
441 |
// This is a numeric alias |
|
270 |
// This is a numeric alias.
|
|
442 | 271 |
$path = drupal_get_normal_path($path); |
443 | 272 |
} |
444 | 273 |
else { |
445 |
// normal nid
|
|
274 |
// Normal nid.
|
|
446 | 275 |
$path = 'node/' . $path; |
447 | 276 |
} |
448 | 277 |
} |
449 | 278 |
else { |
450 | 279 |
$path = drupal_get_normal_path($path); |
451 | 280 |
} |
452 |
// If the destination page is not accessible, don't show the form |
|
281 |
// If the destination page is not accessible, don't show the form.
|
|
453 | 282 |
if (!($router_item = menu_get_item($path)) || (!$router_item['access'])) { |
454 | 283 |
$page_access = FALSE; |
455 | 284 |
} |
... | ... | |
460 | 289 |
} |
461 | 290 |
|
462 | 291 |
/** |
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 |
|
292 |
* Auxiliary function to display a formatted send by email link. |
|
513 | 293 |
* |
514 | 294 |
* Function made available so that developers may call this function from |
515 | 295 |
* their defined pages/blocks. |
516 | 296 |
* |
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 |
|
297 |
* @param string $path |
|
298 |
* path to be used in the link. If not specified, the current URL is used. |
|
299 |
* @param object $node |
|
300 |
* node object, to be used in checking node access. If the path argument is |
|
301 |
* not provided, the path used will be node/nid. |
|
302 |
* @param string $location |
|
303 |
* Where in the page where the link is being inserted ('link', 'corner', |
|
304 |
* 'block', 'help'). |
|
305 |
* |
|
306 |
* @return string |
|
524 | 307 |
* string with the HTML link to the printer-friendly page |
308 |
* |
|
309 |
* @ingroup print_api |
|
525 | 310 |
*/ |
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>'; |
|
311 |
function print_mail_insert_link($path = NULL, $node = NULL, $location = '') { |
|
312 |
if (function_exists('print_ui_insert_link')) { |
|
313 |
return print_ui_insert_link(print_mail_print_link(), |
|
314 |
array('path' => $path, 'node' => $node, 'location' => $location)); |
|
565 | 315 |
} |
566 | 316 |
else { |
567 | 317 |
return FALSE; |
... | ... | |
569 | 319 |
} |
570 | 320 |
|
571 | 321 |
/** |
572 |
* Check if the link to send by email is allowed depending on the settings |
|
322 |
* Check if the link to send by email is allowed depending on the settings. |
|
323 |
* |
|
324 |
* @param array $args |
|
325 |
* Array containing the possible parameters: |
|
326 |
* view_mode, node, type, path. |
|
573 | 327 |
* |
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 |
|
328 |
* @return bool |
|
329 |
* FALSE if not allowed, TRUE otherwise. |
|
581 | 330 |
*/ |
582 | 331 |
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; |
|
332 |
return (user_access('access send by email')); |
|
654 | 333 |
} |
655 | 334 |
|
656 | 335 |
/** |
... | ... | |
658 | 337 |
*/ |
659 | 338 |
function print_mail_mollom_form_list() { |
660 | 339 |
$forms['print_mail_form'] = array( |
661 |
'title' => t('Send page form'),
|
|
340 |
'title' => t('Send by email form'),
|
|
662 | 341 |
'entity' => 'print_mail', |
663 | 342 |
); |
664 | 343 |
return $forms; |
... | ... | |
668 | 347 |
* Implemenents hook_mollom_form_info(). |
669 | 348 |
*/ |
670 | 349 |
function print_mail_mollom_form_info($form_id) { |
350 |
$form_info = array(); |
|
671 | 351 |
switch ($form_id) { |
672 | 352 |
case 'print_mail_form': |
673 | 353 |
$form_info = array( |
674 | 354 |
'elements' => array( |
675 | 355 |
'fld_from_addr' => t('Sender email'), |
676 | 356 |
'fld_from_name' => t('Sender name'), |
677 |
'txt_to_addrs' => t('Recipients'),
|
|
357 |
'txt_to' => t('Recipients'), |
|
678 | 358 |
'fld_subject' => t('Subject'), |
679 | 359 |
'fld_title' => t('Page to be sent'), |
680 | 360 |
'txt_message' => t('Your message'), |
... | ... | |
728 | 408 |
} |
729 | 409 |
|
730 | 410 |
/** |
731 |
* Action handler for the print_mail_action_submit |
|
411 |
* Action handler for the print_mail_action_submit.
|
|
732 | 412 |
* |
733 | 413 |
* @ingroup rules |
734 | 414 |
*/ |
... | ... | |
737 | 417 |
|
738 | 418 |
$form_state['values'] = array( |
739 | 419 |
'path' => 'node/' . $node->nid, |
740 |
'cid' => NULL, |
|
741 | 420 |
'query' => NULL, |
421 |
'cid' => NULL, |
|
742 | 422 |
'title' => $node->title, |
743 | 423 |
'fld_from_addr' => $from, |
744 | 424 |
'fld_from_name' => $from_name, |
745 |
'txt_to_addrs' => $to,
|
|
425 |
'txt_to' => array('addrs' => $to),
|
|
746 | 426 |
'fld_subject' => $subject, |
747 | 427 |
'txt_message' => $message, |
748 | 428 |
'chk_teaser' => FALSE, |
Also available in: Unified diff
Weekly update of contrib modules