Commit a779e64d authored by jcnventura's avatar jcnventura

Issue #953920: Stop using the print array created by_print_var_generator()....

Issue #953920: Stop using the print array created by_print_var_generator(). Instead make the print.tpl.php a real template and move most of the work into print_preprocess_print().
parent 5f38cb15
......@@ -99,8 +99,29 @@ function print_permission() {
function print_theme() {
return array(
'print' => array(
'variables' => array('print' => array(), 'type' => '', 'node' => NULL),
'variables' => array('node' => NULL, 'format' => '', 'message' => ''),
'template' => 'print',
'file' => 'print.pages.inc',
),
'print_published' => array(
'variables' => array(),
'file' => 'print.pages.inc',
),
'print_breadcrumb' => array(
'variables' => array('node' => NULL),
'file' => 'print.pages.inc',
),
'print_footer' => array(
'variables' => array(),
'file' => 'print.pages.inc',
),
'print_sourceurl' => array(
'variables' => array('url' => '', 'node' => NULL, 'cid' => NULL),
'file' => 'print.pages.inc',
),
'print_url_list' => array(
'variables' => array(),
'file' => 'print.pages.inc',
),
);
}
......@@ -121,47 +142,6 @@ function print_preprocess_node(&$variables) {
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function print_preprocess_print(&$variables) {
static $hooks = NULL;
if (!isset($hooks)) {
drupal_theme_initialize();
$hooks = theme_get_registry();
}
$variables['page']['#show_messages'] = FALSE;
// Stolen from theme() so that ALL preprocess functions are called
$hook = 'page';
$info = $hooks[$hook];
if (isset($info['preprocess functions']) || isset($info['process functions'])) {
$variables['theme_hook_suggestions'] = array();
foreach (array('preprocess functions', 'process functions') as $phase) {
if (!empty($info[$phase])) {
foreach ($info[$phase] as $processor_function) {
if (function_exists($processor_function)) {
// We don't want a poorly behaved process function changing $hook.
$hook_clone = $hook;
$processor_function($variables, $hook_clone);
}
}
}
}
}
$format = $variables['type'];
$type = (isset($variables['node']->type)) ? $variables['node']->type : '';
$nid = (isset($variables['node']->nid)) ? $variables['node']->nid : '';
$variables['theme_hook_suggestions'][] = "print__node__{$type}";
$variables['theme_hook_suggestions'][] = "print__node__{$type}__{$nid}";
$variables['theme_hook_suggestions'][] = "print__{$format}";
$variables['theme_hook_suggestions'][] = "print__{$format}__node__{$type}";
$variables['theme_hook_suggestions'][] = "print__{$format}__node__{$type}__{$nid}";
}
/**
* Implements hook_menu().
*/
......
This diff is collapsed.
......@@ -7,32 +7,41 @@
* @ingroup print
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $print['language']; ?>" xml:lang="<?php print $print['language']; ?>">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>">
<head>
<?php print $print['head']; ?>
<?php print $print['base_href']; ?>
<title><?php print $print['title']; ?></title>
<?php print $print['scripts']; ?>
<?php print $print['sendtoprinter']; ?>
<?php print $print['robots_meta']; ?>
<?php print $print['favicon']; ?>
<?php print $print['css']; ?>
<?php print $head; ?>
<base href='<?php print $url ?>' />
<title><?php print $print_title; ?></title>
<?php print $scripts; ?>
<?php if (isset($sendtoprinter)) print $sendtoprinter; ?>
<?php print $robots_meta; ?>
<?php if (theme_get_setting('toggle_favicon')): ?>
<link rel='shortcut icon' href='<?php print theme_get_setting('favicon') ?>' type='image/x-icon' />
<?php endif; ?>
<?php print $css; ?>
</head>
<body>
<?php if (!empty($print['message'])) {
print '<div class="print-message">'. $print['message'] .'</div><p />';
} ?>
<div class="print-logo"><?php print $print['logo']; ?></div>
<div class="print-site_name"><?php print $print['site_name']; ?></div>
<?php if (!empty($message)): ?>
<div class="print-message"><?php print $message; ?></div><p />
<?php endif; ?>
<?php if ($print_logo): ?>
<div class="print-logo"><?php print $print_logo; ?></div>
<?php endif; ?>
<div class="print-site_name"><?php print theme('print_published'); ?></div>
<p />
<div class="print-breadcrumb"><?php print $print['breadcrumb']; ?></div>
<div class="print-breadcrumb"><?php print theme('print_breadcrumb', array('node' => $node)); ?></div>
<hr class="print-hr" />
<div class="print-content"><?php print $print['content']; ?></div>
<div class="print-footer"><?php print $print['footer_message']; ?></div>
<div class="print-content"><?php print $content; ?></div>
<div class="print-footer"><?php print theme('print_footer'); ?></div>
<hr class="print-hr" />
<div class="print-source_url"><?php print $print['source_url']; ?></div>
<div class="print-links"><?php print $print['pfp_links']; ?></div>
<?php print $print['footer_scripts']; ?>
<?php if ($sourceurl_enabled): ?>
<div class="print-source_url">
<?php print theme('print_sourceurl', array('url' => $source_url, 'node' => $node, 'cid' => $cid)); ?>
</div>
<?php endif; ?>
<div class="print-links"><?php print theme('print_url_list'); ?></div>
<?php print $footer_scripts; ?>
</body>
</html>
......@@ -278,23 +278,22 @@ function print_mail_form_submit($form, &$form_state) {
$sender_message = t('Message from sender') . ':<br /><br /><em>' . nl2br(check_plain($form_state['values']['txt_message'])) . '</em>';
$print = print_controller($form_state['values']['path'], $link['format'], $cid, $form_state['values']['chk_teaser'], $sender_message);
$node = print_controller($form_state['values']['path'], $link['format'], $cid, $form_state['values']['chk_teaser']);
// Spaces in img URLs must be replaced with %20
$pattern = '!<(img\s[^>]*?)>!is';
$print['content'] = preg_replace_callback($pattern, '_print_mail_encode_urls', $print['content']);
$node->content = preg_replace_callback($pattern, '_print_mail_encode_urls', $node->content);
if ($print !== FALSE) {
if ($node) {
$print_mail_send_option_default = variable_get('print_mail_send_option_default', PRINT_MAIL_SEND_OPTION_DEFAULT);
$params = array();
$params['subject'] = $form_state['values']['fld_subject'];
$params['message'] = $sender_message;
$params['link'] = $print['url'];
$params['link'] = $node->url;
$params['title'] = $form_state['values']['title'];
$node = $print['node'];
$params['body'] = theme('print', array('print' => $print, 'type' => $link['format'], 'node' => $node));
$params['body'] = theme('print', array('node' => $node, 'format' => $link['format'], 'message' => $sender_message));
$ok = FALSE;
$use_job_queue = variable_get('print_mail_job_queue', PRINT_MAIL_JOB_QUEUE_DEFAULT);
......
......@@ -81,43 +81,41 @@ function print_pdf_generate_path($path, $cid = NULL, $pdf_filename = NULL) {
global $base_url;
$link = print_pdf_print_link();
$print = print_controller($path, $link['format'], $cid);
if ($print === FALSE) {
return;
}
// Img elements must be set to absolute
$pattern = '!<(img\s[^>]*?)>!is';
$print['content'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['content']);
$print['logo'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['logo']);
$print['footer_message'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['footer_message']);
$node = print_controller($path, $link['format'], $cid);
if ($node) {
// @todo node is no longer print -- verify this
// Img elements must be set to absolute
$pattern = '!<(img\s[^>]*?)>!is';
$node->content = preg_replace_callback($pattern, '_print_rewrite_urls', $node->content);
$node->logo = preg_replace_callback($pattern, '_print_rewrite_urls', $node->logo);
$node->footer_message = preg_replace_callback($pattern, '_print_rewrite_urls', $node->footer_message);
// Send to printer option causes problems with PDF
$print['sendtoprinter'] = '';
$html = theme('print', array('node' => $node, 'format' => $link['format']));
$node = $print['node'];
$html = theme('print', array('print' => $print, 'type' => $link['format'], 'node' => $node));
// Convert the a href elements, to make sure no relative links remain
$pattern = '!<(a\s[^>]*?)>!is';
$html = preg_replace_callback($pattern, '_print_rewrite_urls', $html);
// And make anchor links relative again, to permit in-PDF navigation
$html = preg_replace("!${base_url}/" . $link['path'] . '/.*?#!', '#', $html);
// Convert the a href elements, to make sure no relative links remain
$pattern = '!<(a\s[^>]*?)>!is';
$html = preg_replace_callback($pattern, '_print_rewrite_urls', $html);
// And make anchor links relative again, to permit in-PDF navigation
$html = preg_replace("!${base_url}/" . $link['path'] . '/.*?#!', '#', $html);
return print_pdf_generate_html($print, $html, $pdf_filename);
return print_pdf_generate_html($node, $html, $pdf_filename);
}
else {
return NULL;
}
}
function print_pdf_generate_html($print, $html, $filename = NULL) {
function print_pdf_generate_html($node, $html, $filename = NULL) {
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
if (basename($print_pdf_pdf_tool) == 'dompdf_config.inc.php') {
return _print_pdf_dompdf($print, $html, $filename);
return _print_pdf_dompdf($node, $html, $filename);
}
elseif (basename($print_pdf_pdf_tool) == 'tcpdf.php') {
return _print_pdf_tcpdf($print, $html, $filename);
return _print_pdf_tcpdf($node, $html, $filename);
}
elseif (drupal_substr(basename($print_pdf_pdf_tool, '.exe'), 0, 11) == 'wkhtmltopdf') {
return _print_pdf_wkhtmltopdf($print, $html, $filename);
return _print_pdf_wkhtmltopdf($node, $html, $filename);
}
elseif ($filename) {
return drupal_not_found();
......@@ -171,25 +169,28 @@ function _print_pdf_file_access_images($html) {
/**
* Generate the PDF file using the dompdf library
*
* @param $print
* array containing the configured data
* @param $node
* node to be converted
* @param $html
* contents of the post-processed template already with the node data
* @param $filename
* name of the PDF file to be generated
* @see print_pdf_controller()
*/
function _print_pdf_dompdf($print, $html, $filename = NULL) {
function _print_pdf_dompdf($node, $html, $filename = NULL) {
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
$print_pdf_paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
$print_pdf_page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
$print_pdf_content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
$print_pdf_dompdf_unicode = TRUE;
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
$print_pdf_dompdf_unicode = variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT);
define("DOMPDF_ENABLE_PHP", FALSE);
define("DOMPDF_ENABLE_REMOTE", TRUE);
define("DOMPDF_TEMP_DIR", file_directory_temp());
define("DOMPDF_UNICODE_ENABLED", variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT));
define("DOMPDF_UNICODE_ENABLED", $print_pdf_dompdf_unicode);
}
require_once(DRUPAL_ROOT . '/' . $print_pdf_pdf_tool);
......@@ -201,7 +202,7 @@ function _print_pdf_dompdf($print, $html, $filename = NULL) {
// dompdf seems to have problems with something in system.css so let's not use it
$html = preg_replace('!<link.*?modules/system/system.css.*?/>!', '', $html);
$url_array = parse_url($print['url']);
$url_array = parse_url($node->url);
$protocol = $url_array['scheme'] . '://';
$host = $url_array['host'];
......@@ -217,25 +218,25 @@ function _print_pdf_dompdf($print, $html, $filename = NULL) {
// $html = theme('print_pdf_dompdf_footer', array('html' => $html));
// If dompdf Unicode support is disabled, try to convert to ISO-8859-1 and then to HTML entities
if (!variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT)) {
// Convert the euro sign to an HTML entity
$html = str_replace('€', '&#0128;', $html);
if (!$print_pdf_dompdf_unicode) {
// Convert the euro sign to an HTML entity
$html = str_replace('€', '&#0128;', $html);
// Convert from UTF-8 to ISO 8859-1 and then to HTML entities
if (function_exists('utf8_decode')) {
// Convert from UTF-8 to ISO 8859-1 and then to HTML entities
if (function_exists('utf8_decode')) {
$html = utf8_decode($html);
}
// iconv fails silently when it encounters something that it doesn't know, so don't use it
// else if (function_exists('iconv')) {
// $html = iconv('UTF-8', 'ISO-8859-1', $html);
// }
elseif (function_exists('mb_convert_encoding')) {
$html = mb_convert_encoding($html, 'ISO-8859-1', 'UTF-8');
}
elseif (function_exists('recode_string')) {
$html = recode_string('UTF-8..ISO_8859-1', $html);
}
$html = htmlspecialchars_decode(htmlentities($html, ENT_NOQUOTES, 'ISO-8859-1'), ENT_NOQUOTES);
}
// iconv fails silently when it encounters something that it doesn't know, so don't use it
// else if (function_exists('iconv')) {
// $html = iconv('UTF-8', 'ISO-8859-1', $html);
// }
elseif (function_exists('mb_convert_encoding')) {
$html = mb_convert_encoding($html, 'ISO-8859-1', 'UTF-8');
}
elseif (function_exists('recode_string')) {
$html = recode_string('UTF-8..ISO_8859-1', $html);
}
$html = htmlspecialchars_decode(htmlentities($html, ENT_NOQUOTES, 'ISO-8859-1'), ENT_NOQUOTES);
}
// Must get rid of tbody (dompdf goes into recursion)
......@@ -256,15 +257,15 @@ function _print_pdf_dompdf($print, $html, $filename = NULL) {
/**
* Generate the PDF file using the TCPDF library
*
* @param $print
* array containing the configured data
* @param $node
* node to be converted
* @param $html
* contents of the post-processed template already with the node data
* @param $filename
* name of the PDF file to be generated
* @see print_pdf_controller()
*/
function _print_pdf_tcpdf($print, $html, $filename = NULL) {
function _print_pdf_tcpdf($node, $html, $filename = NULL) {
global $base_url, $language;
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
......@@ -310,11 +311,11 @@ function _print_pdf_tcpdf($print, $html, $filename = NULL) {
$pdf = new PrintTCPDF($orientation , 'mm', $print_pdf_paper_size, TRUE);
// set document information
if (property_exists($print['node'], 'name')) {
$pdf->SetAuthor(strip_tags($print['node']->name));
if (property_exists($node, 'name')) {
$pdf->SetAuthor(strip_tags($node->name));
}
$pdf->SetCreator(variable_get('site_name', 'Drupal'));
$pdf->SetTitle(html_entity_decode($print['title'], ENT_QUOTES, 'UTF-8'));
$pdf->SetTitle(html_entity_decode($node->title, ENT_QUOTES, 'UTF-8'));
$pdf->setPDFVersion('1.6');
$pdf->setFontSubsetting(variable_get('print_pdf_font_subsetting', PRINT_PDF_TCPDF_FONT_SUBSETTING_DEFAULT));
......@@ -351,15 +352,15 @@ function _print_pdf_tcpdf($print, $html, $filename = NULL) {
/**
* Generate the PDF file using wkhtmltopdf
*
* @param $print
* array containing the configured data
* @param $node
* node to be converted
* @param $html
* contents of the post-processed template already with the node data
* @param $filename
* name of the PDF file to be generated
* @see print_pdf_controller()
*/
function _print_pdf_wkhtmltopdf($print, $html, $filename = NULL) {
function _print_pdf_wkhtmltopdf($node, $html, $filename = NULL) {
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
$print_pdf_paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
$print_pdf_page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
......@@ -369,7 +370,7 @@ function _print_pdf_wkhtmltopdf($print, $html, $filename = NULL) {
$dpi = 96;
if (!empty($print_pdf_wkhtmltopdf_options)) {
$print_pdf_wkhtmltopdf_options = token_replace($print_pdf_wkhtmltopdf_options, array('node' => $print['node']));
$print_pdf_wkhtmltopdf_options = token_replace($print_pdf_wkhtmltopdf_options, array('node' => $node));
}
$version = _print_pdf_wkhtmltopdf_version();
......@@ -382,7 +383,7 @@ function _print_pdf_wkhtmltopdf($print, $html, $filename = NULL) {
$print_pdf_wkhtmltopdf_options = '--disallow-local-file-access ' . $print_pdf_wkhtmltopdf_options;
}
else {
drupal_goto($print['url']);
drupal_goto($node->url);
exit;
}
......
<?php
/**
* @defgroup print Printer, email and PDF versions
*
* Welcome to the print module developer's documentation. The interesting
* functions for themers are those that start with 'theme_'.
*
* - Printer-friendly pages
* - @link print.module Module main file @endlink
* - @link print.admin.inc Settings form @endlink
* - @link print.pages.inc HTML generation @endlink
* - @link print.install (Un)Install routines @endlink
* - @link print.tpl.php Page generation template @endlink
* - Send by email
* - @link print_mail.module Module main file @endlink
* - @link print_mail.admin.inc Settings form @endlink
* - @link print_mail.inc Mail form and send mail routine @endlink
* - @link print_mail.install (Un)Install routines @endlink
* - PDF version
* - @link print_pdf.module Module main file @endlink
* - @link print_pdf.admin.inc Settings form @endlink
* - @link print_pdf.pages.inc PDF generation @endlink
* - @link print_pdf.class.inc Auxiliary PHP5 class @endlink
* - @link print_pdf.class_php4.inc Auxiliary PHP4 class @endlink
* - @link print_pdf.install (Un)Install routines @endlink
*/
/**
* @file
* Displays Printer-friendly versions of Drupal pages.
* Printer-friendly pages User Interface module.
*
* This is the core module of the PF package, with the Drupal hooks
* and other administrative functions.
* This module handles the display of the printer-friendly sub-module links.
*
* @ingroup print
*/
......@@ -266,7 +239,7 @@ function print_ui_node_view($node, $view_mode) {
if (($type == 'node') && !empty($link_pos['link']) && !(isset($node->book) && ($link['format'] == 'html'))) {
$node->content['links']['print_' . $link['format']] = $link_content;
}
elseif ($type == 'comment') {
elseif (($type == 'comment') && isset($node->content['comments']['comments'])) {
foreach ($node->content['comments']['comments'] as $cid => $comment) {
if (is_numeric($cid)) {
$link_content['#links']['print_' . $link['format']]['query']['comment'] = $cid;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment