Commit c67b9ed4 authored by jcnventura's avatar jcnventura

Improve the theme_print_format_link functions

parent b09f08f7
......@@ -213,12 +213,12 @@ function print_form_alter(&$form, $form_state, $form_id) {
*
* @return array of formatted attributes
*/
function print_fill_attributes() {
function _print_format_link_aux($type = 0, $text = '', $img = '', $title = '', $class = '') {
$print_settings = variable_get('print_settings', print_settings_default());
$robots_settings = variable_get('print_robot_settings', print_robot_settings_default());
$attributes = array('title' => t('Display a printer-friendly version of this page.'),
'class' => 'print-page');
$attributes = array('title' => $title,
'class' => $class);
switch ($print_settings['newwindow']) {
case 1:
$attributes['target'] = '_blank';
......@@ -230,7 +230,26 @@ function print_fill_attributes() {
if (!empty($robots_settings['nofollow'])) {
$attributes['rel'] = 'nofollow';
}
return $attributes;
if ($type >= 2) {
$img = '<img width="16px" height="16px" style="vertical-align:middle" src="'. $img .'" alt="'. $text .'" />';
$html = TRUE;
switch ($type) {
case 2:
$text = $img;
break;
case 3:
$text = $img .' '. $text;
break;
}
}
else {
$html = FALSE;
}
return array('text' => $text,
'html' => $html,
'attributes' => $attributes);
}
function theme_print_format_link() {
......@@ -238,20 +257,14 @@ function theme_print_format_link() {
$print_html_settings = variable_get('print_html_settings', print_html_settings_default());
$text = t('Printer-friendly version');
$img = '<img width="16px" height="16px" style="vertical-align:middle" src="'. $base_path . drupal_get_path('module', 'print') .'/icons/print_icon.gif" alt="'. $text .'">';
$html = TRUE;
switch ($print_html_settings['show_link']) {
case 2:
$text = $img;
break;
case 3:
$text = $img .' '. $text;
break;
}
return array('text' => $text,
'html' => $html,
'attributes' => print_fill_attributes());
$img = $base_path . drupal_get_path('module', 'print') .'/icons/print_icon.gif';
$title = t('Display a printer-friendly version of this page.');
$class = 'print-page';
$format = _print_format_link_aux($print_html_settings['show_link'], $text, $img, $title, $class);
return array('text' => $format['text'],
'html' => $format['html'],
'attributes' => $format['attributes']);
}
function theme_print_text() {
......
<?php
/* $Id$ */
require_once(drupal_get_path('module', 'print') . '/print.pages.inc');
require_once(drupal_get_path('module', 'print') .'/print.pages.inc');
function print_pdf_controller() {
$print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default());
$print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default());
$print = print_controller();
// Img elements must be set to absolute
......@@ -25,7 +25,7 @@ function print_pdf_controller() {
}
function _print_pdf_dompdf($print, $filename, $directives = array()) {
$print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default());
$print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default());
require_once($print_pdf_settings['pdf_tool']);
ob_start();
......@@ -34,9 +34,9 @@ function _print_pdf_dompdf($print, $filename, $directives = array()) {
ob_end_clean();
$allowed_directives = array(
'set_base_path',
'set_host',
'set_paper',
'set_base_path',
'set_host',
'set_paper',
'set_protocol',
);
......@@ -54,7 +54,7 @@ function _print_pdf_dompdf($print, $filename, $directives = array()) {
}
function _print_pdf_tcpdf($print, $filename) {
$print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default());
$print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default());
require_once($print_pdf_settings['pdf_tool']);
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
......@@ -72,7 +72,7 @@ function _print_pdf_tcpdf($print, $filename) {
$pdf->SetHeaderData("", 0, $print["title"], strip_tags($print["site_name"]));
// set auto page breaks
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->AliasNbPages();
......@@ -90,7 +90,7 @@ function _print_pdf_tcpdf($print, $filename) {
$pdf->Ln(5);
if ($print["submitted"]) {
$pdf->SetFont(PDF_FONT_NAME_MAIN,'BI', PDF_FONT_SIZE_MAIN);
$pdf->SetFont(PDF_FONT_NAME_MAIN, 'BI', PDF_FONT_SIZE_MAIN);
$pdf->MultiCell(0, 5, $print["submitted"], 0, 'L', 0);
}
......
......@@ -136,38 +136,19 @@ function print_pdf_form_alter(&$form, $form_state, $form_id) {
}
}
/**
* Auxiliary function to fill the Printer-friendly link attributes
*
* @return array of formatted attributes
*/
function print_pdf_fill_attributes() {
$attributes = print_fill_attributes();
$attributes['title'] = t('Display a PDF version of this page.');
$attributes['class'] = 'print-pdf';
return $attributes;
}
function theme_print_pdf_format_link() {
global $base_path;
$print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default());
$text = t('PDF version');
$img = '<img width="16px" height="16px" style="vertical-align:middle" src="'. $base_path . drupal_get_path('module', 'print') .'/icons/pdf_icon.gif" alt="'. $text .'">';
$html = TRUE;
switch ($print_pdf_settings['show_link']) {
case 2:
$text = $img;
break;
case 3:
$text = $img .' '. $text;
break;
}
return array('text' => $text,
'html' => $html,
'attributes' => print_pdf_fill_attributes());
$img = $base_path . drupal_get_path('module', 'print') .'/icons/pdf_icon.gif';
$title = t('Display a PDF version of this page.');
$class = 'print-pdf';
$format = _print_format_link_aux($print_pdf_settings['show_link'], $text, $img, $title, $class);
return array('text' => $format['text'],
'html' => $format['html'],
'attributes' => $format['attributes']);
}
/**
......
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