<?php
-// $Id$
/**
* @file
$print = print_controller($path, $cid, PRINT_HTML_FORMAT);
if ($print !== FALSE) {
$node = $print['node'];
- $html = theme('print_page', $print, PRINT_HTML_FORMAT, $node);
+ $html = theme('print', array('print' => $print, 'type' => PRINT_HTML_FORMAT, 'node' => $node));
print $html;
$nodepath = (isset($node->path)) ? drupal_get_normal_path($node->path) : 'node/' . $path;
$path = '';
}
}
- if (!is_numeric($path)) {
+ if (!ctype_digit($path)) {
// Indirect call with print/alias
// If there is a path alias with these arguments, generate a printer-friendly version for it
$path = drupal_get_normal_path($path);
}
}
$parts = explode('/', $path);
- if (is_numeric($parts[0]) && (count($parts) == 1)) {
+ if (ctype_digit($parts[0]) && (count($parts) == 1)) {
$print = _print_generate_node($path, $cid, $format, $teaser, $message);
}
else {
$print['title'] = check_plain($node->title);
$print['head'] = drupal_get_html_head();
if ($print_html_sendtoprinter) {
- drupal_add_js('misc/drupal.js', 'core');
+ drupal_add_js('misc/drupal.js', array('weight' => JS_LIBRARY));
}
$print['scripts'] = drupal_get_js();
$print['robots_meta'] = _print_robots_meta_generator();
$print['favicon'] = theme_get_setting('toggle_favicon') ? "<link rel='shortcut icon' href='" . theme_get_setting('favicon') . "' type='image/x-icon' />\n" : '';
if (!empty($print_css)) {
- $replace_pairs = array('%b' => base_path(), '%t' => path_to_theme());
- $user_css = check_url(strtr($print_css, $replace_pairs));
+ drupal_add_css(strtr($print_css, array('%t' => path_to_theme())));
}
else {
drupal_add_css(drupal_get_path('module', 'print') . '/css/print.css');
}
$drupal_css = drupal_add_css();
- foreach ($drupal_css as $key => $types) {
+ foreach ($drupal_css as $key => $css_file) {
+ if ($css_file['group'] == CSS_THEME) {
// Unset the theme's CSS
- $drupal_css[$key]['theme'] = array();
+ unset($drupal_css[$key]);
+ }
}
// If we are sending a message via e-mail, the CSS must be embedded
if (!empty($message)) {
$style = '';
- $css_files = array();
- foreach ($drupal_css as $types) {
- foreach ($types as $values) {
- $css_files = array_merge($css_files, array_keys($values));
- }
- }
- if (!empty($print_css)) {
- // Convert to a local path, by removing the base_path
- $pattern = '!^' . base_path() . '!';
- $css_files[] = preg_replace($pattern, '', $user_css);
- }
+ $css_files = array_keys($drupal_css);
foreach ($css_files as $filename) {
$res = file_exists($filename) ? file_get_contents($filename, TRUE) : FALSE;
if ($res != FALSE) {
}
else {
$print['css'] = drupal_get_css($drupal_css);
- if (!empty($print_css)) {
- $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1);
- $print['css'] .= "<link type='text/css' rel='stylesheet' media='all' href='${user_css}${query_string}' />\n";
- }
}
$window_close = ($print_html_new_window && $print_html_windowclose) ? 'window.close();' : '';
- $print['sendtoprinter'] = $print_html_sendtoprinter ? "<script type='text/javascript'>Drupal.behaviors.print = function(context) {window.print();$window_close}</script>" : '';
+ $print['sendtoprinter'] = $print_html_sendtoprinter ? "<script type='text/javascript'>(function ($) { Drupal.behaviors.print = { attach: function(context) {window.print();$window_close}};}(jQuery));</script>" : '';
switch ($print_logo_options) {
case 0: // none
$logo_url = strip_tags($print_logo_url);
break;
}
- $print['logo'] = $logo_url ? "<img class='print-logo' src='" . check_url($logo_url) . "' alt='' />\n" : '';
+ $site_name = variable_get('site_name', 'Drupal');
+ $print['logo'] = $logo_url ? "<img class='print-logo' src='" . check_url($logo_url) . "' alt='$site_name' id='logo' />\n" : '';
switch ($print_footer_options) {
case 0: // none
if (is_int($cid)) {
$url .= '#comment-$cid';
}
- $retrieved_date = format_date(REQUEST_TIME, 'small');
+ $retrieved_date = format_date(REQUEST_TIME, 'short');
$print_text_retrieved = filter_xss(variable_get('print_text_retrieved', t('retrieved on %date')));
$retrieved = t($print_text_retrieved, array('%date' => $retrieved_date));
$print['printdate'] = $print_sourceurl_date ? " ($retrieved)" : '';
$print['source_url'] = '';
}
- if (isset($node->type)) {
- $node_type = $node->type;
-
- if (theme_get_setting("toggle_node_info_$node_type")) {
- $print_text_by = filter_xss(variable_get('print_text_by', t('By %author')));
- $by_author = ($node->name ? $node->name : variable_get('anonymous', t('Anonymous')));
- $print['submitted'] = t($print_text_by, array('%author' => $by_author));
-
- $print_text_created = filter_xss(variable_get('print_text_created', t('Created %date')));
- $created_datetime = format_date($node->created, 'small');
- $print['created'] = t($print_text_created, array('%date' => $created_datetime));
- }
- else {
- $print['submitted'] = '';
- $print['created'] = '';
- }
-
- $print['type'] = $node->type;
- }
- else {
- $print['submitted'] = '';
- $print['created'] = '';
- $print['type'] = '';
- }
+ $print['type'] = (isset($node->type)) ? $node->type : '';
menu_set_active_item($path);
$breadcrumb = drupal_get_breadcrumb();
}
}
- if (module_exists('taxonomy')) {
-// TODO make this work when taxonomy works again
-// $terms = taxonomy_link('taxonomy terms', $node);
- $terms = taxonomy_preview_terms($node);
- $print['taxonomy'] = theme('links', $terms);
- }
-
- $print['content'] = $node->body;
$print['node'] = $node;
$print['message'] = $message;
$path = explode('/', $_GET['q']);
unset($path[0]);
$path = implode('/', $path);
- if (is_numeric($path)) {
+ if (ctype_digit($path)) {
$path = "node/$path";
}
// Printer-friendly URLs is on, so we need to make it absolute
* TRUE if URL list should be displayed, FALSE otherwise
*/
function _print_url_list_enabled($node, $format = PRINT_HTML_FORMAT) {
+ if (!isset($node->type)) {
+ return variable_get('print_urls', PRINT_URLS_DEFAULT);
+ }
+
switch ($format) {
case PRINT_HTML_FORMAT:
- $node_urllist = isset($node->print_display_urllist) ? $node->print_display_urllist : TRUE;
+ $node_urllist = isset($node->print_display_urllist) ? $node->print_display_urllist : variable_get('print_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
$fmt = '';
break;
case PRINT_MAIL_FORMAT:
- $node_urllist = isset($node->print_mail_display_urllist) ? $node->print_mail_display_urllist : TRUE;
+ $node_urllist = isset($node->print_mail_display_urllist) ? $node->print_mail_display_urllist : variable_get('print_mail_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
$fmt = $format . '_';
break;
case PRINT_PDF_FORMAT:
- $node_urllist = isset($node->print_pdf_display_urllist) ? $node->print_pdf_display_urllist : TRUE;
+ $node_urllist = isset($node->print_pdf_display_urllist) ? $node->print_pdf_display_urllist : variable_get('print_pdf_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
$fmt = $format . '_';
break;
}
- if (!isset($node_urllist)) $node_urllist = TRUE;
+ if (!isset($node_urllist)) $node_urllist = PRINT_TYPE_URLLIST_DEFAULT;
// Get value of Printer-friendly URLs setting
- return (variable_get('print_urls', PRINT_URLS_DEFAULT) && ($node_urllist) &&
- (isset($node->type) ? variable_get('print_' . $fmt . 'display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT) : PRINT_TYPE_URLLIST_DEFAULT));
+ return (variable_get('print_urls', PRINT_URLS_DEFAULT) && ($node_urllist));
}
/**
function _print_generate_node($nid, $cid = NULL, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
global $_print_urls;
+ if (!isset($langcode)) {
+ $langcode = $GLOBALS['language_content']->language;
+ }
+
// We can take a node id
$node = node_load($nid);
if (!$node) {
drupal_access_denied();
return FALSE;
}
+ $view_mode = $teaser ? 'teaser' : 'full';
drupal_set_title($node->title);
- //alert other modules that we are generating a printer-friendly page, so they can choose to show/hide info
- $node->printing = TRUE;
-
- //use the proper build_mode
- $node->build_mode = 'print';
-
// Turn off Pagination by the Paging module
unset($node->pages);
unset($node->page_count);
if ($cid === NULL) {
// Adapted (simplified) version of node_view
//Render the node content
- $node = node_build_content($node, $teaser, TRUE);
+ node_build_content($node, $view_mode);
+
// Disable the links area
unset($node->content['links']);
// Disable fivestar widget output
// Disable service links module output
unset($node->content['service_links']);
- $content = drupal_render($node->content);
+ $build = $node->content;
+ unset($node->content);
// Disable the AdSense module ads
- $content = preg_replace('!<div class=[\'"]adsense[\'"].*?</div>!sim', '', $content);
-
- if ($teaser) {
- $node->teaser = $content;
- unset($node->body);
- }
- else {
- $node->body = $content;
- unset($node->teaser);
- }
+// $content = preg_replace('!<div class=[\'"]adsense[\'"].*?</div>!sim', '', $content);
}
$print_comments = variable_get('print_comments', PRINT_COMMENTS_DEFAULT);
$node->body .= $comments;
}
- module_invoke_all('node_alter', $node, $teaser, TRUE);
+ $build += array(
+ '#theme' => 'node',
+ '#node' => $node,
+ '#view_mode' => $view_mode,
+ '#language' => $langcode,
+ );
- $content = theme('print_node', $node, $teaser, TRUE, $format);
+ drupal_alter('node_view', $build);
- if ($teaser) {
- $node->body = $node->teaser;
- unset($node->teaser);
- }
+ $content = render($build);
+
+ //Get rid of the annoying D7 title link
+ $pattern = '!(<h2 property="dc:title" datatype="">)\s*<a [^>]*?>(.*?)</a>\s*(</h2>)!mis';
+ $content = preg_replace($pattern, '$1$2$3', $content);
//Check URL list settings
$_print_urls = _print_url_list_enabled($node, $format);
// Convert the a href elements
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
- $node->body = preg_replace_callback($pattern, '_print_rewrite_urls', $node->body);
-
- init_theme();
+ $content = preg_replace_callback($pattern, '_print_rewrite_urls', $content);
$print = _print_var_generator($node, $message, $cid);
+ $print['content'] = $content;
return $print;
}
// Handle node tabs
$parts = explode('/', $path);
- if (is_numeric($parts[0]) && (count($parts) > 1)) {
+ if (ctype_digit($parts[0]) && (count($parts) > 1)) {
$path = 'node/' . $path;
}
menu_set_active_item($path);
// Adapted from index.php.
$node = new stdClass();
- $node->body = menu_execute_active_handler($path);
-
- // It may happen that a drupal_not_found is called in the above call
- if (preg_match('/404 Not Found/', drupal_get_headers()) == 1) {
- return FALSE;
- }
+ $node->body = menu_execute_active_handler($path, FALSE);
if (is_int($node->body)) {
switch ($node->body) {
$node->title = drupal_get_title();
$node->path = $path;
+ $node->changed = 0;
// Delete any links area
$node->body = preg_replace('!\s*<div class="links">.*?</div>!sim', '', $node->body);
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
$node->body = preg_replace_callback($pattern, '_print_rewrite_urls', $node->body);
- init_theme();
-
$print = _print_var_generator($node, $message);
+ $print['content'] = $node->body;
return $print;
}
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
$node->body = preg_replace_callback($pattern, '_print_rewrite_urls', $node->body);
- init_theme();
-
$print = _print_var_generator($node, $message);
+ $print['content'] = $node->body;
+
// The title is already displayed by the book_recurse, so avoid duplication
$print['title'] = '';