Commit f6972c51 authored by jcnventura's avatar jcnventura

Restore the print_fill_attributes function

Remove the greybox and thickbox selection
Add ability to specify customised classes to the PF links
parent f1c79951
......@@ -57,7 +57,7 @@ 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)"), t("Use Greybox Redux (requires the greybox module)"), t("Use Thickbox (requires the thickbox module)")),
'#options' => array(t("Disabled"), 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.'),
);
......@@ -112,6 +112,15 @@ function print_html_settings() {
'#description' => t("Enable or disable the printer-friendly page link for each node. Even if the link is disabled, you can still view the print version of a node by going to print/nid where nid is the numeric id of the node."),
);
$form['print_html_settings']['link_class'] = array(
'#type' => 'textfield',
'#title' => t('Link class'),
'#default_value' => $print_html_settings['link_class'],
'#size' => 60,
'#maxlength' => 250,
'#description' => t('This can be used by themers to change the link style or by jQuery modules to open in a new window (e.g. greybox or thickbox). Multiple classes can be specified, separated by spaces.'),
);
$form['print_html_settings']['show_sys_link'] = array(
'#type' => 'checkbox',
'#title' => t('Show link in system (non-content) pages'),
......
......@@ -31,6 +31,7 @@ function print_settings_default() {
*/
function print_html_settings_default() {
return array('show_link' => 1,
'link_class' => 'print-page',
'show_sys_link' => 1,
'book_link' => 1,
'sendtoprinter' => 0,
......@@ -232,16 +233,21 @@ function print_form_alter(&$form, $form_state, $form_id) {
/**
* Auxiliary function to fill the Printer-friendly link attributes
*
* @param $title
* text to displayed by the link when hovering over it with the mouse
* @param $class
* class attribute to be used in the link
* @return
* array of formatted attributes
*/
function _print_format_link_aux($type = 0, $text = '', $img = '', $title = '', $class = '') {
function print_fill_attributes($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' => $title,
'class' => $class,
);
$attributes = array();
$attributes['title'] = $title;
$attributes['class'] = $class;
switch ($print_settings['newwindow']) {
case 1:
$attributes['target'] = '_blank';
......@@ -249,17 +255,27 @@ function _print_format_link_aux($type = 0, $text = '', $img = '', $title = '', $
case 2:
$attributes['onclick'] = 'window.open(this.href); return false';
break;
case 3:
$attributes['class'] .= ' '. variable_get('greybox_class_text', 'greybox');
break;
case 4:
$attributes['class'] .= ' thickbox';
break;
}
if (!empty($robots_settings['nofollow'])) {
$attributes['rel'] = 'nofollow';
}
return $attributes;
}
/**
* Auxiliary function to set the link text and html flag
*
* @param $type
* type of link: 0 or 1 for a text-only link, 2 for icon-only and 3 for
* both text and icon
* @param $text
* text to be displayed on the link to the printer-friendly page
* @param $img
* path to the icon file
* @return
* array with the link text and html flag
*/
function _print_format_link_aux($type = 0, $text = '', $img = '') {
if ($type >= 2) {
$img = '<img width="16px" height="16px" style="vertical-align:middle" src="'. $img .'" alt="'. $text .'" />';
$html = TRUE;
......@@ -278,7 +294,6 @@ function _print_format_link_aux($type = 0, $text = '', $img = '', $title = '', $
return array('text' => $text,
'html' => $html,
'attributes' => $attributes,
);
}
......@@ -294,12 +309,12 @@ function theme_print_format_link() {
$text = t('Printer-friendly version');
$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);
$class = $print_html_settings['link_class'];
$format = _print_format_link_aux($print_html_settings['show_link'], $text, $img);
return array('text' => $format['text'],
'html' => $format['html'],
'attributes' => $format['attributes'],
'attributes' => print_fill_attributes($title, $class),
);
}
......
......@@ -133,7 +133,7 @@ function _print_var_generator($node, $cid = NULL) {
$print["favicon"] = theme_get_setting("toggle_favicon") ? "<link rel=\"shortcut icon\" href=\"". theme_get_setting("favicon") ."\" type=\"image/x-icon\"/>\n" : "";
if (!empty($print_settings['css'])) {
$css_file = $print_settings['css'];
$css_file = strip_tags($print_settings['css']);
}
else {
$css_file = base_path() . drupal_get_path('module', 'print') ."/print.css";
......@@ -142,7 +142,7 @@ function _print_var_generator($node, $cid = NULL) {
$print["sendtoprinter"] = $print_html_settings['sendtoprinter'] ? " onload=\"window.print();\"" : "";
$logo_url = !empty($print_settings['logo_url']) ? $print_settings['logo_url'] : theme_get_setting('logo');
$logo_url = !empty($print_settings['logo_url']) ? strip_tags($print_settings['logo_url']) : theme_get_setting('logo');
$print["logo"] = $logo_url ? "<img class=\"print-logo\" src=\"". $logo_url ."\" alt=\"\" />\n" : "";
$published_site = variable_get('site_name', 0);
......
......@@ -27,6 +27,15 @@ function print_pdf_settings() {
'#description' => t("Enable or disable the PDF version link for each node. Even if the link is disabled, you can still view the PDF version of a node by going to printpdf/nid where nid is the numeric id of the node."),
);
$form['print_pdf_settings']['link_class'] = array(
'#type' => 'textfield',
'#title' => t('Link class'),
'#default_value' => $print_pdf_settings['link_class'],
'#size' => 60,
'#maxlength' => 250,
'#description' => t('This can be used by themers to change the link style or by jQuery modules to open in a new window (e.g. greybox or thickbox). Multiple classes can be specified, separated by spaces.'),
);
$form['print_pdf_settings']['show_sys_link'] = array(
'#type' => 'checkbox',
'#title' => t('Show link in system (non-content) pages'),
......
......@@ -12,7 +12,13 @@ define("PRINTPDF_PATH", "printpdf");
* Default values of the print_pdf_settings variable
*/
function print_pdf_settings_default() {
return array('show_link' => 0, 'show_sys_link' => 0, 'book_link' => 1, 'pdf_tool' => 0, 'content_disposition' => 0);
return array('show_link' => 0,
'link_class' => 'print-pdf',
'show_sys_link' => 0,
'book_link' => 1,
'pdf_tool' => 0,
'content_disposition' => 0,
);
}
//*******************************************************************
......@@ -144,17 +150,24 @@ function print_pdf_form_alter(&$form, $form_state, $form_id) {
}
}
/**
* Format the PDF version link
*
* @return
* array of formatted attributes
* @ingroup themeable
*/
function theme_print_pdf_format_link() {
$print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default());
$text = t('PDF version');
$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);
$class = $print_pdf_settings['link_class'];
$format = _print_format_link_aux($print_pdf_settings['show_link'], $text, $img);
return array('text' => $format['text'],
'html' => $format['html'],
'attributes' => $format['attributes'],
'attributes' => print_fill_attributes($title, $class),
);
}
......
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