Commit 1caf9f9d authored by jcnventura's avatar jcnventura

Separate open in new window option, so that PDF and web versions can have different settings

Use the template a bit more when using the TCPDF tool.
Make the title in the template be a heading 1.
parent 56bdd124
......@@ -56,10 +56,10 @@ function print_main_settings() {
$form['print_settings']['newwindow'] = array(
'#type' => 'radios',
'#title' => t('Open the printer-friendly version in a new window'),
'#options' => array(t("Disabled"), t("Use HTML target (does not validate as XHTML Strict)"), t("Use Javascript (requires browser support)")),
'#title' => t('New window method'),
'#options' => array(t("Use HTML target (does not validate as XHTML Strict)"), t("Use Javascript (requires browser support)")),
'#default_value' => $print_settings['newwindow'],
'#description' => t('Setting this option will make the printer-friendly version open in a new window/tab.'),
'#description' => t('Choose the method used to open pages in a new window/tab.'),
);
$print_sourceurl_settings = variable_get('print_sourceurl_settings', print_sourceurl_settings_default());
......@@ -135,6 +135,13 @@ function print_html_settings() {
'#description' => t('Activate this to have the printer-friendly link in book nodes handled by this module. Requires the (core) book module.'),
);
$form['print_html_settings']['new_window'] = array(
'#type' => 'checkbox',
'#title' => t('Open the printer-friendly version in a new window'),
'#default_value' => $print_html_settings['new_window'],
'#description' => t('Setting this option will make the printer-friendly version open in a new window/tab.'),
);
$form['print_html_settings']['sendtoprinter'] = array(
'#type' => 'checkbox',
'#title' => t('Send to printer'),
......
......@@ -21,11 +21,7 @@ a:link img, a:visited img {border: 0;}
.print-logo {border: 0;}
.print-site_name {}
.print-breadcrumb {font-size: x-small;}
.print-title {
font-size: 200%;
font-weight: bold;
margin: 0.67em 0 0.22em 0;
}
.print-title {}
.print-submitted {font-size: small;}
.print-created {font-size: small;}
.print-taxonomy ul {
......
......@@ -22,7 +22,7 @@ function print_settings_default() {
'css' => '',
'urls' => 1,
'comments' => 0,
'newwindow' => 0,
'newwindow' => 1,
);
}
......@@ -34,6 +34,7 @@ function print_html_settings_default() {
'link_class' => 'print-page',
'show_sys_link' => 1,
'book_link' => 1,
'new_window' => 0,
'sendtoprinter' => 0,
);
}
......@@ -239,7 +240,7 @@ function print_form_alter(&$form, $form_state, $form_id) {
* @return
* array of formatted attributes
*/
function print_fill_attributes($title = '', $class = '') {
function print_fill_attributes($title = '', $class = '', $new_window = FALSE) {
$print_settings = variable_get('print_settings', print_settings_default());
$robots_settings = variable_get('print_robot_settings', print_robot_settings_default());
......@@ -247,13 +248,15 @@ function print_fill_attributes($title = '', $class = '') {
$attributes['title'] = $title;
$attributes['class'] = $class;
switch ($print_settings['newwindow']) {
case 1:
$attributes['target'] = '_blank';
break;
case 2:
$attributes['onclick'] = 'window.open(this.href); return false';
break;
if ($new_window) {
switch ($print_settings['newwindow']) {
case 0:
$attributes['target'] = '_blank';
break;
case 1:
$attributes['onclick'] = 'window.open(this.href); return false';
break;
}
}
if (!empty($robots_settings['nofollow'])) {
$attributes['rel'] = 'nofollow';
......@@ -309,11 +312,12 @@ function theme_print_format_link() {
$img = base_path() . drupal_get_path('module', 'print') .'/icons/print_icon.gif';
$title = t('Display a printer-friendly version of this page.');
$class = $print_html_settings['link_class'];
$new_window = $print_html_settings['new_window'];
$format = _print_format_link_aux($print_html_settings['show_link'], $text, $img);
return array('text' => $format['text'],
'html' => $format['html'],
'attributes' => print_fill_attributes($title, $class),
'attributes' => print_fill_attributes($title, $class, $new_window),
);
}
......
......@@ -16,26 +16,26 @@ function print_pdf_controller() {
$print["logo"] = preg_replace_callback($pattern, "_print_rewrite_urls", $print["logo"]);
$print["footer_message"] = preg_replace_callback($pattern, "_print_rewrite_urls", $print["footer_message"]);
ob_start();
include_once(_print_get_template($print["type"]));
$html = ob_get_contents();
ob_end_clean();
if (basename($print_pdf_settings['pdf_tool']) == "dompdf_config.inc.php") {
_print_pdf_dompdf($print, $args .".pdf");
_print_pdf_dompdf($print, $html, $args .".pdf");
}
elseif (basename($print_pdf_settings['pdf_tool']) == "tcpdf.php") {
_print_pdf_tcpdf($print, $args .".pdf");
_print_pdf_tcpdf($print, $html, $args .".pdf");
}
else {
return drupal_not_found();
}
}
function _print_pdf_dompdf($print, $filename) {
function _print_pdf_dompdf($print, $html, $filename) {
$print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default());
require_once($print_pdf_settings['pdf_tool']);
ob_start();
include_once(_print_get_template($print["type"]));
$html = ob_get_contents();
ob_end_clean();
$url_array = parse_url($print['url']);
$protocol = $url_array['scheme'] . "://";
......@@ -51,10 +51,10 @@ function _print_pdf_dompdf($print, $filename) {
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream($filename, array("Attachment" => $print_pdf_settings['content_disposition']));
$dompdf->stream($filename, array("Attachment" => ($print_pdf_settings['content_disposition'] == 2)));
}
function _print_pdf_tcpdf($print, $filename) {
function _print_pdf_tcpdf($print, $html, $filename) {
$print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default());
require_once($print_pdf_settings['pdf_tool']);
......@@ -94,6 +94,9 @@ function _print_pdf_tcpdf($print, $filename) {
// add a page
$pdf->AddPage();
preg_match("/<body>(.*)<\/body>/sim", $html, $matches);
$matches[1] = preg_replace("/.*?(<[^<]*?print-content.*?>)/sim", "$1", $matches[1]);
$pdf->SetFont(PDF_FONT_NAME_MAIN, 'B', PDF_FONT_SIZE_MAIN * K_TITLE_MAGNIFICATION);
$pdf->writeHTML($print["title"]);
......@@ -106,12 +109,9 @@ function _print_pdf_tcpdf($print, $filename) {
}
$pdf->SetFont(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN);
$pdf->writeHTML($print["content"]);
$pdf->writeHTML('<hr class="print-hr" />');
$pdf->writeHTML($print["source_url"]);
$pdf->writeHTML($print["pfp_links"]);
$pdf->writeHTML($matches[1]);
//Close and output PDF document
$output_dest = $print_pdf_settings['content_disposition'] ? 'D' : 'I';
$output_dest = ($print_pdf_settings['content_disposition'] == 2) ? 'D' : 'I';
$pdf->Output($filename, $output_dest);
}
......@@ -15,7 +15,7 @@
<p />
<div class="print-breadcrumb"><?php print $print["breadcrumb"] ?></div>
<hr class="print-hr" />
<div class="print-title"><?php print $print["title"] ?></div>
<h1 class="print-title"><?php print $print["title"] ?></h1>
<div class="print-submitted"><?php print $print["submitted"] ?></div>
<div class="print-created"><?php print $print["created"] ?></div>
<p />
......
......@@ -62,7 +62,7 @@ function print_pdf_settings() {
$form['print_pdf_settings']['content_disposition'] = array(
'#type' => 'radios',
'#title' => t('Open PDF in'),
'#options' => array(t('Browser window'), t('Save dialog')),
'#options' => array(t('Same browser window'), t('New browser window'), t('Save dialog')),
'#default_value' => $print_pdf_settings['content_disposition'],
'#description' => t("Select the desired method for opening the PDF in the user's browser."),
);
......
......@@ -17,7 +17,7 @@ function print_pdf_settings_default() {
'show_sys_link' => 0,
'book_link' => 1,
'pdf_tool' => 0,
'content_disposition' => 0,
'content_disposition' => 2,
'paper_size' => 'A4',
'page_orientation' => 'portrait',
);
......@@ -172,11 +172,12 @@ function theme_print_pdf_format_link() {
$img = base_path() . drupal_get_path('module', 'print') .'/icons/pdf_icon.gif';
$title = t('Display a PDF version of this page.');
$class = $print_pdf_settings['link_class'];
$new_window = ($print_pdf_settings['content_disposition'] == 1);
$format = _print_format_link_aux($print_pdf_settings['show_link'], $text, $img);
return array('text' => $format['text'],
'html' => $format['html'],
'attributes' => print_fill_attributes($title, $class),
'attributes' => print_fill_attributes($title, $class, $new_window),
);
}
......
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