'', 'css' => '', 'urls' => 1, 'comments' => 0, 'newwindow' => 0, ); } /** * Default values of the print_html_settings variable */ function print_html_settings_default() { return array('show_link' => 1, 'show_sys_link' => 1, 'book_link' => 1, 'sendtoprinter' => 0, ); } /** * Default values of the print_sourceurl_settings variable */ function print_sourceurl_settings_default() { return array('enabled' => 1, 'date' => 0, 'forcenode' => 0); } /** * Default values of the print_robot_settings variable */ function print_robot_settings_default() { return array('noindex' => 1, 'nofollow' => 1, 'noarchive' => 0, 'nocache' => 0); } //******************************************************************* // Drupal Hooks //******************************************************************* /** * Implementation of hook_perm() */ function print_perm() { return array('access print', 'administer print'); } /** * Implementation of hook_theme() */ function print_theme() { return array( 'print_format_link' => array( 'arguments' => array(), ), 'print_text' => array( 'arguments' => array(), ), ); } /** * Implementation of hook_menu() */ function print_menu() { $items = array(); $items[PRINT_PATH] = array( 'title' => 'Printer-friendly', 'page callback' => 'print_controller_html', 'access arguments' => array('access print'), 'type' => MENU_CALLBACK, 'file' => 'print.pages.inc', ); $items['admin/settings/print'] = array( 'title' => 'Printer-friendly', 'description' => 'Adds a printer-friendly version link to node pages.', 'page callback' => 'drupal_get_form', 'page arguments' => array('print_html_settings'), 'access arguments' => array('administer print'), 'file' => 'print.admin.inc', ); $items['admin/settings/print/html'] = array( 'title' => 'Web page', 'weight' => 0, 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items['admin/settings/print/common'] = array( 'title' => 'Settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('print_main_settings'), 'access arguments' => array('administer print'), 'weight' => 10, 'type' => MENU_LOCAL_TASK, 'file' => 'print.admin.inc', ); return $items; } /** * Implementation of hook_link(). */ function print_link($type, $node = NULL, $teaser = FALSE) { static $print_display = FALSE; static $print_display_comment = FALSE; if ($print_display == FALSE) { $nodetype = isset($node->type) ? $node->type : ''; $print_display_comment = variable_get('print_display_comment_'. $nodetype, '0'); $print_display = variable_get('print_display_'. $nodetype, '1'); } $print_html_settings = variable_get('print_html_settings', print_html_settings_default()); // No link is shown for several motives... if ( !($teaser) && (isset($node->type) && ($node->type != 'book')) && (!isset($node->book)) && ($print_html_settings['show_link']) && user_access('access print') && (($type == 'comment' && $print_display_comment) || ($type == 'node' && $print_display))) { $links = array(); $format = theme('print_format_link'); $queryArr = $_GET; if ($type == 'comment') { $queryArr['comment'] = $node->cid; } $query = drupal_query_string_encode($queryArr, array('q')); $links['print'] = array('href' => PRINT_PATH ."/". $node->nid, 'title' => $format['text'], 'attributes' => $format['attributes'], 'html' => $format['html'], 'query' => $query); return $links; } else { return; } } /** * Implementation of hook_link_alter(). */ function print_link_alter(&$links, $node) { foreach ($links AS $module => $link) { if (strstr($module, 'book_printer')) { $print_html_settings = variable_get('print_html_settings', print_html_settings_default()); if ($print_html_settings['book_link']) { $format = theme('print_format_link'); $format['attributes']['title'] = $link['attributes']['title']; $links[$module]['href'] = PRINT_PATH ."/". $link['href']; $links[$module]['attributes'] = $format['attributes']; } } } } /** * Implementation of hook_help() */ function print_help($path, $arg) { $print_html_settings = variable_get('print_html_settings', print_html_settings_default()); if (($print_html_settings['show_link']) && ($print_html_settings['show_sys_link']) && user_access('access print') && (preg_match("/^node\//i", $path) == 0)) { static $output = FALSE; if ($output === FALSE) { $output = TRUE; return print_insert_link(); } } } /** * Implementation of hook_form_alter() */ function print_form_alter(&$form, $form_state, $form_id) { // Add the node-type settings option to activate the printer-friendly version link if ('node_type_form' == $form_id) { $form['workflow']['print_display'] = array( '#type' => 'checkbox', '#title' => t('Show printer-friendly version link'), '#return_value' => 1, '#default_value' => variable_get('print_display_'. $form['#node_type']->type, '1'), '#description' => t('Displays the link to a printer-friendly version of the content. Further configuration is available on the !settings.', array('!settings' => l(t('settings page'), 'admin/settings/print' ))), ); $form['comment']['print_display_comment'] = array( '#type' => 'checkbox', '#title' => t('Show printer-friendly version link in individual comments'), '#return_value' => 1, '#default_value' => variable_get('print_display_comment_'. $form['#node_type']->type, '0'), '#description' => t('Displays the link to a printer-friendly version of the comment. Further configuration is available on the !settings.', array('!settings' => l(t('settings page'), 'admin/settings/print' ))), ); } } /** * Auxiliary function to fill the Printer-friendly link attributes * * @return array of formatted 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' => $title, 'class' => $class); switch ($print_settings['newwindow']) { case 1: $attributes['target'] = '_blank'; break; 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'; } if ($type >= 2) { $img = ''. $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() { global $base_path; $print_html_settings = variable_get('print_html_settings', print_html_settings_default()); $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); return array('text' => $format['text'], 'html' => $format['html'], 'attributes' => $format['attributes']); } function theme_print_text() { return array('retrieved' => t('retrieved on'), 'sourceURL' => t('Source URL'), 'published' => t('Published on'), 'by' => t('By'), 'created' => t('Created'), 'links' => t('Links:')); } /** * Auxiliary function to display a formatted Printer-friendly link * * @return string */ function print_insert_link($path = NULL) { if (user_access('access print')) { if ($path === NULL) { $path = PRINT_PATH ."/". $_GET['q']; $query = drupal_query_string_encode($_GET, array('q')); if (empty($query)) { $query = NULL; } } $format = theme('print_format_link'); return ''. l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) .''; } }