1, 'node_link_visibility' => 0, 'node_link_pages' => '', 'link_class' => 'print-pdf', 'sys_link_visibility' => 1, 'sys_link_pages' => '', 'book_link' => 1, 'pdf_tool' => 0, 'content_disposition' => 2, 'paper_size' => 'A4', 'page_orientation' => 'portrait', ); } //******************************************************************* // Drupal Hooks //******************************************************************* /** * Implementation of hook_theme(). */ function print_pdf_theme() { return array( 'print_pdf_format_link' => array( 'arguments' => array(), ), ); } /** * Implementation of hook_menu(). */ function print_pdf_menu() { $items = array(); $items[PRINTPDF_PATH] = array( 'title' => 'Printer-friendly PDF', 'page callback' => 'print_pdf_controller', 'access arguments' => array('access print'), 'type' => MENU_CALLBACK, 'file' => 'print.pdf.inc', ); $items['admin/settings/print/pdf'] = array( 'title' => 'PDF', 'page callback' => 'drupal_get_form', 'page arguments' => array('print_pdf_settings'), 'access arguments' => array('administer print'), 'weight' => 2, 'type' => MENU_LOCAL_TASK, 'file' => 'print_pdf.admin.inc', ); return $items; } /** * Implementation of hook_requirements(). */ function print_pdf_requirements($phase) { $requirements = array(); $t = get_t(); switch ($phase) { // At runtime, make sure that a PDF generation tool is selected case 'runtime': $print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default()); if (empty($print_pdf_settings['pdf_tool'])) { $requirements['print_pdf_tool'] = array( 'title' => $t('Print PDF'), 'value' => $t('No PDF tool selected. Please configure it in the PDF settings page.', array('@url' => url('admin/settings/print/pdf'))), 'severity' => REQUIREMENT_ERROR, ); } break; } return $requirements; } /** * Implementation of hook_link(). */ function print_pdf_link($type, $node = NULL, $teaser = FALSE) { $print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default()); static $print_pdf_display_comment = FALSE; if (($print_pdf_display_comment == FALSE) && (isset($node->type))) { $node_type = $node->type; $print_pdf_display_comment = variable_get('print_pdf_display_comment_'. $node->type, 0); $print_pdf_display = variable_get('print_pdf_display_'. $node->type, 1); } else { $node_type = ''; $print_pdf_display = 1; } if (!$teaser) { $links = array(); $format = theme('print_pdf_format_link'); // Show book link if (($print_pdf_settings['book_link']) && user_access('access printer-friendly version') && (($node_type == 'book') || isset($node->book))) { $links['book_pdf'] = array('href' => PRINTPDF_PATH ."/book/export/html/". $node->nid, 'title' => strip_tags($format['text']), 'attributes' => $format['attributes'], ); return $links; } // No link is shown for several motives... elseif (($node_type != 'book') && (!isset($node->book)) && ($print_pdf_settings['show_link']) && user_access('access print') && !(($print_pdf_settings['node_link_visibility']) xor (drupal_match_path("node/". $node->nid, $print_pdf_settings['node_link_pages']))) && (($type == 'comment' && $print_pdf_display_comment) || ($type == 'node' && $print_pdf_display))) { $query_arr = $_GET; if ($type == 'comment') { $query_arr['comment'] = $node->cid; } $query = drupal_query_string_encode($query_arr, array('q')); $links['print_pdf'] = array('href' => PRINTPDF_PATH ."/". $node->nid, 'title' => $format['text'], 'attributes' => $format['attributes'], 'html' => $format['html'], 'query' => $query, ); return $links; } } return; } /** * Implementation of hook_help(). */ function print_pdf_help($path, $arg) { $print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default()); if (($print_pdf_settings['show_link']) && user_access('access print') && !(($print_pdf_settings['sys_link_visibility']) xor (drupal_match_path($path, $print_pdf_settings['sys_link_pages']))) && (preg_match("/^node\//i", $path) == 0)) { static $output = FALSE; if ($output === FALSE) { $output = TRUE; return print_pdf_insert_link(); } } } /** * Implementation of hook_form_alter(). */ function print_pdf_form_alter(&$form, $form_state, $form_id) { // Add the node-type settings option to activate the PDF version link if ($form_id == 'node_type_form') { $form['print']['print_pdf_display'] = array( '#type' => 'checkbox', '#title' => t('Show PDF version link'), '#default_value' => variable_get('print_pdf_display_'. $form['#node_type']->type, 1), '#description' => t('Displays the link to a PDF version of the content. Further configuration is available on the !settings.', array('!settings' => l(t('settings page'), 'admin/settings/print' ))), ); $form['print']['print_pdf_display_comment'] = array( '#type' => 'checkbox', '#title' => t('Show PDF version link in individual comments'), '#default_value' => variable_get('print_pdf_display_comment_'. $form['#node_type']->type, 0), '#description' => t('Displays the link to a PDF version of the comment. Further configuration is available on the !settings.', array('!settings' => l(t('settings page'), 'admin/settings/print' ))), ); } } /** * 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 = drupal_get_path('module', 'print') .'/icons/pdf_icon.gif'; $title = t('Display a PDF version of this page.'); $class = strip_tags($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, $new_window), ); } /** * Auxiliary function to display a formatted Printer-friendly link * * @return string */ function print_pdf_insert_link($path = NULL) { if (user_access('access print')) { if ($path === NULL) { $path = PRINTPDF_PATH ."/". $_GET['q']; $query = drupal_query_string_encode($_GET, array('q')); if (empty($query)) { $query = NULL; } } $format = theme('print_pdf_format_link'); return ''. l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE, 'html' => $format['html'])) .''; } }