Commit b97f7b85 authored by jcnventura's avatar jcnventura

Footer can now be choice between none, site or user-defined

Add footer to the dompdf generation (themeable).
parent e02f16ac
......@@ -83,6 +83,29 @@ function print_main_settings() {
'#description' => t("If you don't have direct file access to the server, use this field to upload your logo."),
);
$form['settings']['footer'] = array(
'#type' => 'fieldset',
'#title' => t('Footer options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['settings']['footer']['print_footer_options'] = array(
'#type' => 'radios',
'#title' => t('Footer type'),
'#options' => array(t('None (Disabled)'), t("Site's footer"), t('User-specified')),
'#default_value' => variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT),
'#description' => t("Select the type of footer to display on the printer-friendly version. In case of a user-specified footer, insert it below."),
);
$form['settings']['footer']['print_footer_user'] = array(
'#type' => 'textfield',
'#title' => t('User-specified'),
'#default_value' => variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT),
'#size' => 60,
'#maxlength' => 250,
);
$form['settings']['print_sourceurl_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Source URL'),
......
......@@ -13,6 +13,8 @@ define('PRINT_PATH', 'print');
define('PRINT_LOGO_OPTIONS_DEFAULT', 1);
define('PRINT_LOGO_URL_DEFAULT', '');
define('PRINT_FOOTER_OPTIONS_DEFAULT', 1);
define('PRINT_FOOTER_USER_DEFAULT', '');
define('PRINT_CSS_DEFAULT', '');
define('PRINT_URLS_DEFAULT', 1);
define('PRINT_COMMENTS_DEFAULT', 0);
......@@ -24,7 +26,7 @@ define('PRINT_HTML_NODE_LINK_VISIBILITY_DEFAULT', 0);
define('PRINT_HTML_NODE_LINK_PAGES_DEFAULT', '');
define('PRINT_HTML_LINK_CLASS_DEFAULT', 'print-page');
define('PRINT_HTML_SYS_LINK_VISIBILITY_DEFAULT', 1);
define('PRINT_HTML_SYS_LINK_PAGES_DEFAULT', '<front>');
define('PRINT_HTML_SYS_LINK_PAGES_DEFAULT', '');
define('PRINT_HTML_BOOK_LINK_DEFAULT', 1);
define('PRINT_HTML_NEW_WINDOW_DEFAULT', 0);
define('PRINT_HTML_SENDTOPRINTER_DEFAULT', 0);
......
......@@ -138,6 +138,8 @@ function _print_var_generator($node, $message = NULL, $cid = NULL) {
$print_sourceurl_enabled = variable_get('print_sourceurl_enabled', PRINT_SOURCEURL_ENABLED_DEFAULT);
$print_sourceurl_forcenode = variable_get('print_sourceurl_forcenode', PRINT_SOURCEURL_FORCENODE_DEFAULT);
$print_sourceurl_date = variable_get('print_sourceurl_date', PRINT_SOURCEURL_DATE_DEFAULT);
$print_footer_options = variable_get('print_footer_options', PRINT_FOOTER_OPTIONS_DEFAULT);
$print_footer_user = variable_get('print_footer_user', PRINT_FOOTER_USER_DEFAULT);
$print['language'] = $language->language;
$print['title'] = $node->title;
......@@ -201,6 +203,20 @@ function _print_var_generator($node, $message = NULL, $cid = NULL) {
}
$print['logo'] = $logo_url ? "<img class='print-logo' src='$logo_url' alt='' />\n" : '';
switch ($print_footer_options) {
case 0: // none
$footer = '';
break;
case 1: // theme's
$footer = filter_xss_admin(variable_get('site_footer', FALSE)) ."\n". theme('blocks', 'footer');
$logo_url = theme_get_setting('logo');
break;
case 2: // user-specifed
$footer = $print_footer_user;
break;
}
$print['footer_message'] = $footer;
$published_site = variable_get('site_name', 0);
if ($published_site) {
$published = (empty($themed['published'])) ? t('Published on %site_name', array('%site_name' => $published_site)) : ($themed['published'] .' '. $published_site);
......@@ -290,7 +306,6 @@ function _print_var_generator($node, $message = NULL, $cid = NULL) {
$print['content'] = $node->body;
$print['node'] = $node;
$print['message'] = $message;
$print['footer_message'] = filter_xss_admin(variable_get('site_footer', FALSE)) ."\n". theme('blocks', 'footer') ;
return $print;
}
......
......@@ -31,6 +31,9 @@ function print_pdf_theme() {
'print_pdf_format_link' => array(
'arguments' => array(),
),
'print_pdf_dompdf_footer' => array(
'arguments' => array(),
),
'print_pdf_tcpdf_header' => array(
'arguments' => array(),
),
......@@ -318,6 +321,17 @@ function print_pdf_link_allowed($args) {
}
}
/**
* Format the dompdf footer contents
*
* @param $html
* contents of the body of the HTML from the original node
* @ingroup themeable
*/
function theme_print_pdf_dompdf_footer(&$html) {
return _print_pdf_dompdf_footer_aux($html);
}
/**
* Format the TCPDF header
*
......
......@@ -81,6 +81,8 @@ function _print_pdf_dompdf($print, $html, $filename) {
$dompdf->set_paper(drupal_strtolower($print_pdf_paper_size), $print_pdf_page_orientation);
$dompdf->set_protocol($protocol);
$html = theme('print_pdf_dompdf_footer', $html);
$dompdf->load_html($html);
$dompdf->render();
......@@ -163,6 +165,49 @@ function _print_pdf_tcpdf($print, $html, $filename) {
$pdf->Output($filename, $output_dest);
}
/**
* Format the dompdf footer contents
*
* @param $html
* contents of the body of the HTML from the original node
* @see theme_print_pdf_tcpdf_footer()
*/
function _print_pdf_dompdf_footer_aux(&$html) {
preg_match('!<div class="print-footer">(.*?)</div>!si', $html, $tpl_footer);
$html = str_replace($tpl_footer[0], '', $html);
$text = '<script type="text/php">
if (isset($pdf)) {
$font = Font_Metrics::get_font("verdana");;
$size = 10;
$color = array(0,0,0);
$text_height = Font_Metrics::get_font_height($font, $size);
$w = $pdf->get_width();
$h = $pdf->get_height();
$footer = $pdf->open_object();
// Draw a line along the bottom
$y = $h - 25;
$pdf->line(15, $y, $w - 15, $y, $color, 1);
$y += $text_height / 2;
$pdf->page_text(15, $y, \''. strip_tags($tpl_footer[1]) .'\', $font, $size, $color);
$pdf->close_object();
$pdf->add_object($footer, "all");
// Center the text
$width = Font_Metrics::get_text_width("Page 1 of 2", $font, $size);
$pagenumtxt = t("Page !n of !total", array("!n" => "{PAGE_NUM}", "!total" => "{PAGE_COUNT}"));
$pdf->page_text($w - 15 - $width, $y, $pagenumtxt, $font, $size, $color);
}
</script>';
return str_replace("<body>", "<body>" . $text, $html);
}
/**
* Format the TCPDF header
*
......@@ -265,7 +310,8 @@ function _print_pdf_tcpdf_content_aux(&$pdf, &$html, $font) {
* @see theme_print_pdf_tcpdf_footer()
*/
function _print_pdf_tcpdf_footer_aux(&$pdf, &$html, $font) {
preg_match('!<div class="print-footer">.*<div class="content">(.*?)</div>!si', $html, $tpl_footer);
preg_match('!<div class="print-footer">(.*?)</div>!si', $html, $tpl_footer);
$footer = trim(preg_replace('!</?div[^>]*?>!i', '', $tpl_footer[1]));
// set footer font
$font[2] *= 0.8;
......@@ -273,7 +319,7 @@ function _print_pdf_tcpdf_footer_aux(&$pdf, &$html, $font) {
// set footer margin
$pdf->SetFooterMargin(10);
// set footer data
$pdf->SetFooterData($tpl_footer[1]);
$pdf->SetFooterData($footer);
return $pdf;
}
......@@ -290,7 +336,7 @@ function _print_pdf_tcpdf_footer2_aux(&$pdf) {
$pdf->writeHTMLCell(0, 15, 15, 0, $pdf->footer, 0, 0, 0, TRUE, '');
$ormargins = $pdf->getOriginalMargins();
$pagenumtxt = t('Page') .' '. $pdf->PageNo() .' / '. $pdf->getAliasNbPages();
$pagenumtxt = t('Page !n of !total', array('!n' => $pdf->PageNo(), '!total' => $pdf->getAliasNbPages()));
//Print page number
if ($pdf->getRTL()) {
$pdf->SetX($ormargins['right']);
......
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