function print_generate_node in Printer, email and PDF versions 5
Same name and namespace in other branches
- 5.2 print.module \print_generate_node()
Outputs a printer friendly page.
1 call to print_generate_node()
File
- ./
print.module, line 352 - Display printer friendly versions of nodes (except books)
Code
function print_generate_node($title) {
global $base_url;
/* We can take a node id or a node title */
$node = is_numeric($title) ? node_load(array(
'nid' => $title,
)) : node_load(array(
'title' => $title,
));
if (!$node->title) {
return false;
}
// To work with other node types, use drupal's render engine instead of the old node_view method
$node->body = drupal_render(node_build_content($node)->content);
// Convert the a href elements
$pattern = "@<(a[^>]*?)>(.*?)</a>@is";
$node->body = preg_replace_callback($pattern, "print_rewrite_urls", $node->body);
// Now the img elements
$pattern = "@<(img[^>]*?)>@is";
$node->body = preg_replace_callback($pattern, "print_rewrite_urls", $node->body);
// associative array settings
$print_settings = variable_get('print_settings', print_settings_default());
$print_sourceurl_settings = variable_get('print_sourceurl_settings', print_sourceurl_settings_default());
// Display the collected links at the bottom of the page.
if (!empty($print_settings['urls'])) {
$urls = print_friendly_urls();
if (count($urls)) {
$node->pfp_links = '';
$max = count($urls);
for ($i = 0; $i < $max; $i++) {
$node->pfp_links .= '[' . ($i + 1) . '] ' . $urls[$i] . "<br />\n";
}
}
}
init_theme();
$node->logo = !empty($print_settings['logo_url']) ? $print_settings['logo_url'] : theme_get_setting('logo');
/* Grab and format the src URL */
if ($print_sourceurl_settings['enabled'] == 1) {
if (empty($print_sourceurl_settings['forcenode'])) {
$node->source_url = url("node/{$node->nid}", NULL, NULL, TRUE);
}
else {
$clean_url = (bool) variable_get('clean_url', '0');
$node->source_url = $base_url . '/' . ($clean_url ? '' : '?q=') . 'node/' . $node->nid;
}
}
else {
$node->source_url = 0;
}
$node->language = $GLOBALS['locale'];
$node->undefcss = empty($print_settings['css']);
$node->printcss = !empty($print_settings['css']) ? $print_settings['css'] : drupal_get_path('module', 'print') . '/' . 'print.css';
$node->printdate = $print_sourceurl_settings['date'];
$node->sendtoprinter = $print_settings['sendtoprinter'];
$robots_meta = _print_robots_meta_generator();
include_once drupal_get_path('module', 'print') . '/' . 'print.node.tpl.php';
}