Fix #358838: use template_preprocess_node() to initialize node.tpl.php variables
[project/print.git] / print.pages.inc
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Contains the functions to generate Printer-friendly pages.
7 *
8 * This file is included by the core PF module, and includes all the
9 * functions necessary to generate a PF version of the original page
10 * in HTML format.
11 *
12 * @ingroup print
13 */
14
15 $_print_urls = PRINT_URLS_DEFAULT;
16
17 /**
18 * Generate an HTML version of the printer-friendly page
19 *
20 * @see print_controller()
21 */
22 function print_controller_html() {
23 $args = func_get_args();
24 $path = implode('/', $args);
25 $cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL;
26
27 $print = print_controller($path, $cid, PRINT_HTML_FORMAT);
28 if ($print !== FALSE) {
29 $node = $print['node'];
30 $html = theme('print_page', $print, PRINT_HTML_FORMAT, $node);
31 print $html;
32
33 $nodepath = (isset($node->path)) ? drupal_get_normal_path($node->path) : 'node/' . $path;
34 db_merge('print_page_counter')
35 ->key(array('path' => $nodepath))
36 ->fields(array(
37 'totalcount' => 1,
38 'timestamp' => REQUEST_TIME,
39 ))
40 ->expression('totalcount', 'totalcount + :inc', array(':inc' => 1))
41 ->execute();
42 }
43 }
44
45 /**
46 * Select the print generator function based on the page type
47 *
48 * Depending on the type of node, this functions chooses the appropriate
49 * generator function.
50 *
51 * @param $path
52 * path of the original page
53 * @param $cid
54 * comment ID of the individual comment to be rendered
55 * @param $format
56 * format of the page being generated
57 * @param $teaser
58 * if set to TRUE, outputs only the node's teaser
59 * @param $message
60 * optional sender's message (used by the send e-mail module)
61 * @return
62 * array with the fields to be used in the template
63 * @see _print_generate_node()
64 * @see _print_generate_path()
65 * @see _print_generate_book()
66 */
67 function print_controller($path, $cid = NULL, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
68 if (empty($path)) {
69 // If no path was provided, let's try to generate a page for the referer
70 global $base_url;
71
72 $ref = $_SERVER['HTTP_REFERER'];
73 $path = preg_replace("!^$base_url/!", '', $ref);
74 if ($path === $ref) {
75 $path = '';
76 }
77 }
78 if (!is_numeric($path)) {
79 // Indirect call with print/alias
80 // If there is a path alias with these arguments, generate a printer-friendly version for it
81 $path = drupal_get_normal_path($path);
82 $ret = preg_match('!^node/(.*)!i', $path, $matches);
83 if ($ret == 1) {
84 $path = $matches[1];
85 }
86 }
87 $parts = explode('/', $path);
88 if (is_numeric($parts[0]) && (count($parts) == 1)) {
89 $print = _print_generate_node($path, $cid, $format, $teaser, $message);
90 }
91 else {
92 $ret = preg_match('!^book/export/html/(.*)!i', $path, $matches);
93 if ($ret == 1) {
94 // This is a book PF page link, handle trough the book handling functions
95 $print = _print_generate_book($matches[1], $format, $teaser, $message);
96 }
97 else {
98 // If no content node was found, handle the page printing with the 'printable' engine
99 $print = _print_generate_path($path, $format, $teaser, $message);
100 }
101 }
102
103 return $print;
104 }
105
106 /**
107 * Generates a robots meta tag to tell them what they may index
108 *
109 * @return
110 * string with the meta robots tag
111 */
112 function _print_robots_meta_generator() {
113 $print_robots_noindex = variable_get('print_robots_noindex', PRINT_ROBOTS_NOINDEX_DEFAULT);
114 $print_robots_nofollow = variable_get('print_robots_nofollow', PRINT_ROBOTS_NOFOLLOW_DEFAULT);
115 $print_robots_noarchive = variable_get('print_robots_noarchive', PRINT_ROBOTS_NOARCHIVE_DEFAULT);
116 $robots_meta = array();
117
118 if (!empty($print_robots_noindex)) {
119 $robots_meta[] = 'noindex';
120 }
121 if (!empty($print_robots_nofollow)) {
122 $robots_meta[] = 'nofollow';
123 }
124 if (!empty($print_robots_noarchive)) {
125 $robots_meta[] = 'noarchive';
126 }
127
128 if (count($robots_meta) > 0) {
129 $robots_meta = implode(', ', $robots_meta);
130 $robots_meta = "<meta name='robots' content='$robots_meta' />\n";
131 }
132 else {
133 $robots_meta = '';
134 }
135
136 return $robots_meta;
137 }
138
139 /**
140 * Post-processor that fills the array for the template with common details
141 *
142 * @param $node
143 * generated node with a printer-friendly node body
144 * @param $message
145 * optional sender's message (used by the send e-mail module)
146 * @param $cid
147 * id of current comment being generated (NULL when not generating
148 * an individual comment)
149 * @return
150 * array with the fields to be used in the template
151 */
152 function _print_var_generator($node, $message = NULL, $cid = NULL) {
153 global $base_url, $language, $_print_urls;
154
155 $path = empty($node->nid) ? $node->path : "node/$node->nid";
156
157 // print module settings
158 $print_css = variable_get('print_css', PRINT_CSS_DEFAULT);
159 $print_logo_options = variable_get('print_logo_options', PRINT_LOGO_OPTIONS_DEFAULT);
160 $print_logo_url = variable_get('print_logo_url', PRINT_LOGO_URL_DEFAULT);
161 $print_html_new_window = variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT);
162 $print_html_sendtoprinter = variable_get('print_html_sendtoprinter', PRINT_HTML_SENDTOPRINTER_DEFAULT);
163 $print_html_windowclose = variable_get('print_html_windowclose', PRINT_HTML_WINDOWCLOSE_DEFAULT);
164 $print_sourceurl_enabled = variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT);
165 $print_sourceurl_forcenode = variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT);
166 $print_sourceurl_date = variable_get('print_sourceurl_date', PRINT_SOURCEURL_DATE_DEFAULT);
167 $print_footer_options = variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT);
168 $print_footer_user = variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT);
169
170 $print['language'] = $language->language;
171 $print['title'] = check_plain($node->title);
172 $print['head'] = drupal_get_html_head();
173 if ($print_html_sendtoprinter) {
174 drupal_add_js('misc/drupal.js', array('weight' => JS_LIBRARY));
175 }
176 $print['scripts'] = drupal_get_js();
177 $print['robots_meta'] = _print_robots_meta_generator();
178 $print['url'] = url($path, array('absolute' => TRUE));
179 $print['base_href'] = "<base href='" . $print['url'] . "' />\n";
180 $print['favicon'] = theme_get_setting('toggle_favicon') ? "<link rel='shortcut icon' href='" . theme_get_setting('favicon') . "' type='image/x-icon' />\n" : '';
181
182 if (!empty($print_css)) {
183 $replace_pairs = array('%b' => base_path(), '%t' => path_to_theme());
184 $user_css = check_url(strtr($print_css, $replace_pairs));
185 }
186 else {
187 drupal_add_css(drupal_get_path('module', 'print') . '/css/print.css');
188 }
189 $drupal_css = drupal_add_css();
190 foreach ($drupal_css as $key => $types) {
191 // Unset the theme's CSS
192 $drupal_css[$key]['theme'] = array();
193 }
194
195 // If we are sending a message via e-mail, the CSS must be embedded
196 if (!empty($message)) {
197 $style = '';
198 $css_files = array();
199 foreach ($drupal_css as $types) {
200 foreach ($types as $values) {
201 $css_files = array_merge($css_files, array_keys($values));
202 }
203 }
204 if (!empty($print_css)) {
205 // Convert to a local path, by removing the base_path
206 $pattern = '!^' . base_path() . '!';
207 $css_files[] = preg_replace($pattern, '', $user_css);
208 }
209 foreach ($css_files as $filename) {
210 $res = file_exists($filename) ? file_get_contents($filename, TRUE) : FALSE;
211 if ($res != FALSE) {
212 $style .= $res;
213 }
214 }
215 $print['css'] = "<style type='text/css' media='all'>$style</style>\n";
216 }
217 else {
218 $print['css'] = drupal_get_css($drupal_css);
219 if (!empty($print_css)) {
220 $query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1);
221 $print['css'] .= "<link type='text/css' rel='stylesheet' media='all' href='${user_css}${query_string}' />\n";
222 }
223 }
224
225 $window_close = ($print_html_new_window && $print_html_windowclose) ? 'window.close();' : '';
226 $print['sendtoprinter'] = $print_html_sendtoprinter ? "<script type='text/javascript'>Drupal.behaviors.print = function(context) {window.print();$window_close}</script>" : '';
227
228 switch ($print_logo_options) {
229 case 0: // none
230 $logo_url = 0;
231 break;
232 case 1: // theme's
233 $logo_url = theme_get_setting('logo');
234 break;
235 case 2: // user-specifed
236 $logo_url = strip_tags($print_logo_url);
237 break;
238 }
239 $print['logo'] = $logo_url ? "<img class='print-logo' src='" . check_url($logo_url) . "' alt='' />\n" : '';
240
241 switch ($print_footer_options) {
242 case 0: // none
243 $footer = '';
244 break;
245 case 1: // theme's
246 $footer = variable_get('site_footer', FALSE) . "\n" . theme('blocks', 'footer');
247 break;
248 case 2: // user-specifed
249 $footer = $print_footer_user;
250 break;
251 }
252 $print['footer_message'] = filter_xss_admin($footer);
253
254 $published_site = variable_get('site_name', 0);
255 if ($published_site) {
256 $print_text_published = filter_xss(variable_get('print_text_published', t('Published on %site_name')));
257 $published = t($print_text_published, array('%site_name' => $published_site));
258 $print['site_name'] = $published . ' (' . l($base_url, $base_url) . ')';
259 }
260 else {
261 $print['site_name'] = '';
262 }
263
264 if ($print_sourceurl_enabled == 1) {
265 /* Grab and format the src URL */
266 if (empty($print_sourceurl_forcenode)) {
267 $url = $print['url'];
268 }
269 else {
270 $url = $base_url . '/' . (((bool)variable_get('clean_url', '0')) ? '' : '?q=') . $path;
271 }
272 if (is_int($cid)) {
273 $url .= '#comment-$cid';
274 }
275 $retrieved_date = format_date(REQUEST_TIME, 'small');
276 $print_text_retrieved = filter_xss(variable_get('print_text_retrieved', t('retrieved on %date')));
277 $retrieved = t($print_text_retrieved, array('%date' => $retrieved_date));
278 $print['printdate'] = $print_sourceurl_date ? " ($retrieved)" : '';
279
280 $source_url = filter_xss(variable_get('print_text_source_url', t('Source URL')));
281 $print['source_url'] = '<strong>' . $source_url . $print['printdate'] . ':</strong> ' . l($url, $url);
282 }
283 else {
284 $print['source_url'] = '';
285 }
286
287 if (isset($node->type)) {
288 $node_type = $node->type;
289
290 if (theme_get_setting("toggle_node_info_$node_type")) {
291 $print_text_by = filter_xss(variable_get('print_text_by', t('By %author')));
292 $by_author = ($node->name ? $node->name : variable_get('anonymous', t('Anonymous')));
293 $print['submitted'] = t($print_text_by, array('%author' => $by_author));
294
295 $print_text_created = filter_xss(variable_get('print_text_created', t('Created %date')));
296 $created_datetime = format_date($node->created, 'small');
297 $print['created'] = t($print_text_created, array('%date' => $created_datetime));
298 }
299 else {
300 $print['submitted'] = '';
301 $print['created'] = '';
302 }
303
304 $print['type'] = $node->type;
305 }
306 else {
307 $print['submitted'] = '';
308 $print['created'] = '';
309 $print['type'] = '';
310 }
311
312 menu_set_active_item($path);
313 $breadcrumb = drupal_get_breadcrumb();
314 if (!empty($breadcrumb)) {
315 $breadcrumb[] = menu_get_active_title();
316 $print['breadcrumb'] = filter_xss(implode(' > ', $breadcrumb));
317 }
318 else {
319 $print['breadcrumb'] = '';
320 }
321
322 // Display the collected links at the bottom of the page. Code once taken from Kjartan Mannes' project.module
323 $print['pfp_links'] = '';
324 if (!empty($_print_urls)) {
325 $urls = _print_friendly_urls();
326 $max = count($urls);
327 $pfp_links = '';
328 if ($max) {
329 for ($i = 0; $i < $max; $i++) {
330 $pfp_links .= '[' . ($i + 1) . '] ' . check_plain($urls[$i]) . "<br />\n";
331 }
332 $links = filter_xss(variable_get('print_text_links', t('Links')));
333 $print['pfp_links'] = "<p><strong>$links:</strong><br />$pfp_links</p>";
334 }
335 }
336
337 if (module_exists('taxonomy')) {
338 // TODO make this work when taxonomy works again
339 // $terms = taxonomy_link('taxonomy terms', $node);
340 $terms = taxonomy_preview_terms($node);
341 $print['taxonomy'] = theme('links', $terms);
342 }
343
344 $print['node'] = $node;
345 $print['message'] = $message;
346
347 return $print;
348 }
349
350 /**
351 * Callback function for the preg_replace_callback for URL-capable patterns
352 *
353 * Manipulate URLs to make them absolute in the URLs list, and to add a
354 * [n] footnote marker.
355 *
356 * @param $matches
357 * array with the matched tag patterns, usually <a...>+text+</a>
358 * @return
359 * tag with re-written URL and when appropriate the [n] index to the
360 * URL list
361 */
362 function _print_rewrite_urls($matches) {
363 global $base_url, $base_root, $_print_urls;
364
365 $include_anchors = variable_get('print_urls_anchors', PRINT_URLS_ANCHORS_DEFAULT);
366
367 // first, split the html into the different tag attributes
368 $pattern = '!\s*(\w+\s*=\s*"(?:\\\"|[^"])*")\s*|\s*(\w+\s*=\s*\'(?:\\\\\'|[^\'])*\')\s*|\s*(\w+\s*=\s*\w+)\s*|\s+!';
369 $attribs = preg_split($pattern, $matches[1], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
370 foreach ($attribs as $key => $value) {
371 $attribs[$key] = preg_replace('!(\w)\s*=\s*(.*)!', '$1=$2', $value);
372 }
373
374 $size = count($attribs);
375 for ($i=1; $i < $size; $i++) {
376 // If the attribute is href or src, we may need to rewrite the URL in the value
377 if (preg_match('!^(?:href|src)\s*?=(.*)!i', $attribs[$i], $urls) > 0) {
378 $url = trim($urls[1], " \t\n\r\0\x0B\"'");
379
380 if (strpos(html_entity_decode($url), '://') || preg_match('!^mailto:.*?@.*?\..*?$!iu', html_entity_decode($url))) {
381 // URL is absolute, do nothing
382 $newurl = $url;
383 }
384 else {
385 if ($url[0] == '#') {
386 // URL is an anchor tag
387 if ($include_anchors && (!empty($_print_urls))) {
388 $path = explode('/', $_GET['q']);
389 unset($path[0]);
390 $path = implode('/', $path);
391 if (is_numeric($path)) {
392 $path = "node/$path";
393 }
394 // Printer-friendly URLs is on, so we need to make it absolute
395 $newurl = url($path, array('fragment' => substr($url, 1), 'absolute' => TRUE));
396 }
397 // Because base href is the original page, change the link to
398 // still be usable inside the print page
399 $matches[1] = str_replace($url, base_path() . $_GET['q'] . $url, $matches[1]);
400 }
401 else {
402 // URL is relative, convert it into absolute URL
403 if ($url[0] == '/') {
404 // If it starts with '/' just append it to the server name
405 $newurl = $base_root . '/' . trim($url, '/');
406 }
407 elseif (preg_match('!^(?:index.php)?\?q=!i', $url)) {
408 // If it starts with ?q=, just prepend with the base URL
409 $newurl = $base_url . '/' . trim($url, '/');
410 }
411 else {
412 $newurl = url(trim($url, '/'), array('absolute' => TRUE));
413 }
414 $matches[1] = str_replace($url, $newurl, $matches[1]);
415 }
416 }
417 }
418 }
419
420 $ret = '<' . $matches[1] . '>';
421 if (count($matches) == 4) {
422 $ret .= $matches[2] . $matches[3];
423 if ((!empty($_print_urls)) && (isset($newurl))) {
424 $ret .= ' <span class="print-footnote">[' . _print_friendly_urls(trim($newurl)) . ']</span>';
425 }
426 }
427
428 return $ret;
429 }
430
431 /**
432 * Auxiliary function to store the Printer-friendly URLs list as static.
433 *
434 * @param $url
435 * absolute URL to be inserted in the list
436 * @return
437 * list of URLs previously stored if $url is 0, or the current count
438 * otherwise.
439 */
440 function _print_friendly_urls($url = 0) {
441 static $urls = array();
442 if ($url) {
443 $url_idx = array_search($url, $urls);
444 if ($url_idx !== FALSE) {
445 return ($url_idx + 1);
446 }
447 else {
448 $urls[] = $url;
449 return count($urls);
450 }
451 }
452 $ret = $urls;
453 $urls = array();
454 return $ret;
455 }
456
457 /**
458 * Check URL list settings for this node
459 *
460 * @param node
461 * node object
462 * @param $format
463 * format of the page being generated
464 * @return
465 * TRUE if URL list should be displayed, FALSE otherwise
466 */
467 function _print_url_list_enabled($node, $format = PRINT_HTML_FORMAT) {
468 switch ($format) {
469 case PRINT_HTML_FORMAT:
470 $node_urllist = isset($node->print_display_urllist) ? $node->print_display_urllist : TRUE;
471 $fmt = '';
472 break;
473 case PRINT_MAIL_FORMAT:
474 $node_urllist = isset($node->print_mail_display_urllist) ? $node->print_mail_display_urllist : TRUE;
475 $fmt = $format . '_';
476 break;
477 case PRINT_PDF_FORMAT:
478 $node_urllist = isset($node->print_pdf_display_urllist) ? $node->print_pdf_display_urllist : TRUE;
479 $fmt = $format . '_';
480 break;
481 }
482 if (!isset($node_urllist)) $node_urllist = TRUE;
483
484 // Get value of Printer-friendly URLs setting
485 return (variable_get('print_urls', PRINT_URLS_DEFAULT) && ($node_urllist) &&
486 (isset($node->type) ? variable_get('print_' . $fmt . 'display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT) : PRINT_TYPE_URLLIST_DEFAULT));
487 }
488
489 /**
490 * Prepare a Printer-friendly-ready node body for content nodes
491 *
492 * @param $nid
493 * node ID of the node to be rendered into a printer-friendly page
494 * @param $cid
495 * comment ID of the individual comment to be rendered
496 * @param $format
497 * format of the page being generated
498 * @param $teaser
499 * if set to TRUE, outputs only the node's teaser
500 * @param $message
501 * optional sender's message (used by the send e-mail module)
502 * @return
503 * filled array ready to be used in the template
504 */
505 function _print_generate_node($nid, $cid = NULL, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
506 global $_print_urls;
507 global $language;
508 //var_dump($language);
509
510 // We can take a node id
511 $node = node_load($nid);
512 if (!$node) {
513 // Node not found
514 drupal_not_found();
515 return FALSE;
516 }
517 elseif (!node_access('view', $node)) {
518 // Access is denied
519 drupal_access_denied();
520 return FALSE;
521 }
522 $view_mode = $teaser ? 'teaser' : 'full';
523 drupal_set_title($node->title);
524
525 // Turn off Pagination by the Paging module
526 unset($node->pages);
527 unset($node->page_count);
528
529 // Make this page a member of the original page's organic group
530 if (function_exists('og_set_group_context') && isset($node->og_groups)) {
531 og_set_group_context($node->og_groups);
532 }
533
534 if ($cid === NULL) {
535 // Adapted (simplified) version of node_view
536 //Render the node content
537 node_build_content($node, $view_mode);
538
539 // Disable the links area
540 unset($node->content['links']);
541 // Disable fivestar widget output
542 unset($node->content['fivestar_widget']);
543 // Disable service links module output
544 unset($node->content['service_links']);
545
546 $build = $node->content;
547 unset($node->content);
548
549 // Disable the AdSense module ads
550 // $content = preg_replace('!<div class=[\'"]adsense[\'"].*?</div>!sim', '', $content);
551 }
552
553 $print_comments = variable_get('print_comments', PRINT_COMMENTS_DEFAULT);
554
555 if (function_exists('comment_render') && (($cid != NULL) || ($print_comments))) {
556 //Print only the requested comment (or if $cid is NULL, all of them)
557 $comments = comment_render($node, $cid);
558
559 //Remove the comment forms
560 $comments = preg_replace('!<form.*?id="comment-.*?">.*?</form>!sim', '', $comments);
561 //Remove the 'Post new comment' title
562 $comments = preg_replace('!<h2.*?>' . t('Post new comment') . '</h2>!', '', $comments);
563 //Remove the comment title hyperlink
564 $comments = preg_replace('!(<h3.*?>.*?)<a.*?>(.*?)</a>(.*?</h3>)!i', '$1$2$3', $comments);
565 //Remove the comment author link
566 $pattern = '!(<(?:span|div) class="submitted">.*?)<a.*?>(.*?)</a>(.*?</(?:span|div)>)!sim';
567 if (preg_match($pattern, $comments)) {
568 $comments = preg_replace($pattern , '$1$2$3', $comments);
569 }
570 //Remove the comment links
571 $comments = preg_replace('!\s*<ul class="links">.*?</ul>!sim', '', $comments);
572 if ($cid != NULL) {
573 // Single comment requested, output only the comment
574 unset($node->body);
575 }
576 $node->body .= $comments;
577 }
578
579 $build += array(
580 '#theme' => 'print_node',
581 '#node' => $node,
582 '#view_mode' => $view_mode,
583 );
584
585 drupal_alter('node_view', $build);
586
587 //Check URL list settings
588 $_print_urls = _print_url_list_enabled($node, $format);
589
590 // Convert the a href elements
591 $pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
592 $node->body['und'][0]['value'] = preg_replace_callback($pattern, '_print_rewrite_urls', $node->body['und'][0]['value']);
593
594 $print = _print_var_generator($node, $message, $cid);
595 $print['content'] = $node->body['und'][0]['value'];
596
597 return $print;
598 }
599
600 /**
601 * Prepare a Printer-friendly-ready node body for non-content pages
602 *
603 * @param $path
604 * path of the node to be rendered into a printer-friendly page
605 * @param $format
606 * format of the page being generated
607 * @param $teaser
608 * if set to TRUE, outputs only the node's teaser
609 * @param $message
610 * optional sender's message (used by the send e-mail module)
611 * @return
612 * filled array ready to be used in the template
613 */
614 function _print_generate_path($path, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
615 global $_print_urls;
616
617 // Handle node tabs
618 $parts = explode('/', $path);
619 if (is_numeric($parts[0]) && (count($parts) > 1)) {
620 $path = 'node/' . $path;
621 }
622
623 $path = drupal_get_normal_path($path);
624
625 menu_set_active_item($path);
626 // Adapted from index.php.
627 $node = new stdClass();
628 $node->body = menu_execute_active_handler($path);
629
630 // It may happen that a drupal_not_found is called in the above call
631 if (preg_match('/404 Not Found/', drupal_get_headers()) == 1) {
632 return FALSE;
633 }
634
635 if (is_int($node->body)) {
636 switch ($node->body) {
637 case MENU_NOT_FOUND:
638 drupal_not_found();
639 return FALSE;
640 break;
641 case MENU_ACCESS_DENIED:
642 drupal_access_denied();
643 return FALSE;
644 break;
645 }
646 }
647
648 $node->title = drupal_get_title();
649 $node->path = $path;
650
651 // Delete any links area
652 $node->body = preg_replace('!\s*<div class="links">.*?</div>!sim', '', $node->body);
653
654 //Check URL list settings
655 $_print_urls = _print_url_list_enabled($node, $format);
656
657 // Convert the a href elements
658 $pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
659 $node->body = preg_replace_callback($pattern, '_print_rewrite_urls', $node->body);
660
661 $print = _print_var_generator($node, $message);
662 $print['content'] = $node->body;
663
664 return $print;
665 }
666
667
668 /**
669 * Prepare a Printer-friendly-ready node body for book pages
670 *
671 * @param $nid
672 * node ID of the node to be rendered into a printer-friendly page
673 * @param $format
674 * format of the page being generated
675 * @param $teaser
676 * if set to TRUE, outputs only the node's teaser
677 * @param $message
678 * optional sender's message (used by the send e-mail module)
679 * @return
680 * filled array ready to be used in the template
681 */
682 function _print_generate_book($nid, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
683 global $_print_urls;
684
685 $node = node_load($nid);
686 if (!$node) {
687 // Node not found
688 drupal_not_found();
689 return FALSE;
690 }
691 elseif (!node_access('view', $node) || (!user_access('access printer-friendly version'))) {
692 // Access is denied
693 drupal_access_denied();
694 return FALSE;
695 }
696
697 $tree = book_menu_subtree_data($node->book);
698 $node->body = book_export_traverse($tree, 'book_node_export');
699
700 //Check URL list settings
701 $_print_urls = _print_url_list_enabled($node, $format);
702
703 // Convert the a href elements
704 $pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
705 $node->body = preg_replace_callback($pattern, '_print_rewrite_urls', $node->body);
706
707 $print = _print_var_generator($node, $message);
708 $print['content'] = $node->body;
709
710 // The title is already displayed by the book_recurse, so avoid duplication
711 $print['title'] = '';
712
713 return $print;
714 }