4 * @defgroup print Printer, e-mail and PDF versions
6 * Welcome to the print module developer's documentation. The interesting
7 * functions for themers are those that start with 'theme_'.
9 * - Printer-friendly pages
10 * - @link print.module Module main file @endlink
11 * - @link print.admin.inc Settings form @endlink
12 * - @link print.pages.inc HTML generation @endlink
13 * - @link print.install (Un)Install routines @endlink
14 * - @link print.tpl.php Page generation template @endlink
16 * - @link print_mail.module Module main file @endlink
17 * - @link print_mail.admin.inc Settings form @endlink
18 * - @link print_mail.inc Mail form and send mail routine @endlink
19 * - @link print_mail.install (Un)Install routines @endlink
21 * - @link print_pdf.module Module main file @endlink
22 * - @link print_pdf.admin.inc Settings form @endlink
23 * - @link print_pdf.pages.inc PDF generation @endlink
24 * - @link print_pdf.class.inc Auxiliary PHP5 class @endlink
25 * - @link print_pdf.class_php4.inc Auxiliary PHP4 class @endlink
26 * - @link print_pdf.install (Un)Install routines @endlink
31 * Displays Printer-friendly versions of Drupal pages.
33 * This is the core module of the PF package, with the Drupal hooks
34 * and other administrative functions.
39 define('PRINT_PATH', 'print');
41 define('PRINT_HTML_FORMAT', 'html');
43 define('PRINT_LOGO_OPTIONS_DEFAULT', 1);
44 define('PRINT_LOGO_URL_DEFAULT', '');
45 define('PRINT_FOOTER_OPTIONS_DEFAULT', 1);
46 define('PRINT_FOOTER_USER_DEFAULT', '');
47 define('PRINT_CSS_DEFAULT', '');
48 define('PRINT_URLS_DEFAULT', 1);
49 define('PRINT_URLS_ANCHORS_DEFAULT', 0);
50 define('PRINT_COMMENTS_DEFAULT', 0);
51 define('PRINT_NEWWINDOW_DEFAULT', 1);
53 define('PRINT_HTML_LINK_POS_DEFAULT', 'link');
54 define('PRINT_HTML_LINK_TEASER_DEFAULT', 0);
55 define('PRINT_HTML_SHOW_LINK_DEFAULT', 1);
56 define('PRINT_HTML_NODE_LINK_VISIBILITY_DEFAULT', 0);
57 define('PRINT_HTML_NODE_LINK_PAGES_DEFAULT', '');
58 define('PRINT_HTML_LINK_CLASS_DEFAULT', 'print-page');
59 define('PRINT_HTML_SYS_LINK_VISIBILITY_DEFAULT', 1);
60 define('PRINT_HTML_SYS_LINK_PAGES_DEFAULT', '');
61 define('PRINT_HTML_LINK_USE_ALIAS_DEFAULT', 0);
62 define('PRINT_HTML_BOOK_LINK_DEFAULT', 1);
63 define('PRINT_HTML_NEW_WINDOW_DEFAULT', 0);
64 define('PRINT_HTML_SENDTOPRINTER_DEFAULT', 0);
65 define('PRINT_HTML_WINDOWCLOSE_DEFAULT', 1);
67 define('PRINT_SOURCEURL_ENABLED_DEFAULT', 1);
68 define('PRINT_SOURCEURL_DATE_DEFAULT', 0);
69 define('PRINT_SOURCEURL_FORCENODE_DEFAULT', 0);
71 define('PRINT_ROBOTS_NOINDEX_DEFAULT', 1);
72 define('PRINT_ROBOTS_NOFOLLOW_DEFAULT', 1);
73 define('PRINT_ROBOTS_NOARCHIVE_DEFAULT', 0);
75 define('PRINT_TYPE_SHOW_LINK_DEFAULT', 1);
76 define('PRINT_TYPE_COMMENT_LINK_DEFAULT', 0);
77 define('PRINT_TYPE_URLLIST_DEFAULT', 1);
79 define('PRINT_ALLOW_NORMAL_LINK', 1);
80 define('PRINT_ALLOW_BOOK_LINK', 2);
81 define('PRINT_TYPE_FIELDS_WEIGHT', 30);
84 * Implementation of hook_perm().
86 function print_perm() {
87 return array('access print', 'administer print', 'node-specific print configuration', 'use PHP for link visibility');
91 * Implementation of hook_theme().
93 function print_theme() {
95 'print_format_link' => array(
96 'arguments' => array(),
98 'print_node' => array(
99 'arguments' => array('node' => NULL
, 'teaser' => FALSE
, 'page' => FALSE
, 'type' => PRINT_HTML_FORMAT
),
100 'template' => 'print_node',
102 'print_page' => array(
103 'arguments' => array('print' => NULL
, 'type' => PRINT_HTML_FORMAT
, 'node' => NULL
),
104 'template' => 'print',
110 * Implementation of hook_theme_registry_alter().
112 function print_theme_registry_alter(&$theme_registry) {
113 $theme_registry['print_node']['theme paths'] = array_merge($theme_registry['print_node']['theme paths'], $theme_registry['node']['theme paths']);
114 $theme_registry['print_page']['theme paths'] = array_merge($theme_registry['print_page']['theme paths'], $theme_registry['page']['theme paths']);
118 * Implementation of hook_preprocess_HOOK().
120 function print_preprocess_print_node(&$variables) {
121 $format = $variables['type'];
122 $type = $variables['node']->type
;
123 template_preprocess_node($variables);
124 $variables['template_files'][] = "node";
125 $variables['template_files'][] = "node-$type";
126 $variables['template_files'][] = "print_node";
127 $variables['template_files'][] = "print_node_$format";
128 $variables['template_files'][] = "print_node_$format.node-$type";
132 * Implementation of hook_preprocess_HOOK().
134 function print_preprocess_print_page(&$variables) {
135 $format = $variables['type'];
136 if (isset($variables['node']->type
)) {
137 $type = $variables['node']->type
;
138 $variables['show_blocks'] = FALSE
;
139 $variables['show_messages'] = FALSE
;
140 template_preprocess_page($variables);
145 $variables['template_files'][] = "print";
146 $variables['template_files'][] = "print.node-$type";
147 $variables['template_files'][] = "print_$format";
148 $variables['template_files'][] = "print_$format.node-$type";
152 * Implementation of hook_menu().
154 function print_menu() {
157 $items[PRINT_PATH
] = array(
158 'title' => 'Printer-friendly',
159 'page callback' => 'print_controller_html',
160 'access arguments' => array('access print'),
161 'type' => MENU_CALLBACK
,
162 'file' => 'print.pages.inc',
164 $items[PRINT_PATH .
'/'. PRINT_PATH
] = array(
165 'access callback' => FALSE
,
167 $items['admin/settings/print'] = array(
168 'title' => 'Printer, e-mail and PDF versions',
169 'description' => 'Adds a printer-friendly version link to content and administrative pages.',
170 'page callback' => 'drupal_get_form',
171 'page arguments' => array('print_html_settings'),
172 'access arguments' => array('administer print'),
173 'file' => 'print.admin.inc',
175 $items['admin/settings/print/html'] = array(
176 'title' => 'Web page',
178 'type' => MENU_DEFAULT_LOCAL_TASK
,
180 $items['admin/settings/print/html/options'] = array(
181 'title' => 'Options',
183 'type' => MENU_DEFAULT_LOCAL_TASK
,
185 $items['admin/settings/print/html/strings'] = array(
186 'title' => 'Text strings',
187 'page callback' => 'drupal_get_form',
188 'page arguments' => array('print_html_strings_settings'),
189 'access arguments' => array('administer print'),
191 'type' => MENU_LOCAL_TASK
,
192 'file' => 'print.admin.inc',
194 $items['admin/settings/print/common'] = array(
195 'title' => 'Settings',
196 'page callback' => 'drupal_get_form',
197 'page arguments' => array('print_main_settings'),
198 'access arguments' => array('administer print'),
200 'type' => MENU_LOCAL_TASK
,
201 'file' => 'print.admin.inc',
203 $items['admin/settings/print/common/options'] = array(
204 'title' => 'Options',
206 'type' => MENU_DEFAULT_LOCAL_TASK
,
208 $items['admin/settings/print/common/strings'] = array(
209 'title' => 'Text strings',
210 'page callback' => 'drupal_get_form',
211 'page arguments' => array('print_main_strings_settings'),
212 'access arguments' => array('administer print'),
214 'type' => MENU_LOCAL_TASK
,
215 'file' => 'print.admin.inc',
222 * Implementation of hook_block().
224 function print_block($op = 'list', $delta = 0, $edit = array()) {
227 $block[0]['info'] = t('Printer, e-mail and PDF versions');
228 $block[0]['cache'] = BLOCK_CACHE_PER_PAGE
;
229 $block[1]['info'] = t('Most printed');
230 $block[1]['cache'] = BLOCK_CACHE_GLOBAL
;
240 $nid = preg_replace('!^node/!', '', $_GET['q']);
241 if (is_numeric($nid)) {
242 $node = node_load($nid);
247 $funcs = get_defined_functions();
248 $block['content'] = '';
249 foreach ($funcs['user'] as
$func) {
250 if (preg_match('!^print.*?_insert_link$!', $func)) {
251 $link = $func(NULL
, $node);
253 $block['content'] .
= $link;
259 $block['subject'] = t('Most printed');
260 $result = db_query_range("SELECT path FROM {print_page_counter} ORDER BY totalcount DESC", 0, 3);
261 if (db_affected_rows()) {
262 $block['content'] = '<div class="item-list"><ul>';
263 while ($obj = db_fetch_object($result)) {
264 $block['content'] .
= '<li>'.
l(_print_get_title($obj->path
), $obj->path
) .
'</li>';
266 $block['content'] .
= '</ul></div>';
276 * Implementation of hook_link().
278 function print_link($type, $node = NULL
, $teaser = FALSE
) {
279 $print_html_link_pos = variable_get('print_html_link_pos', array(PRINT_HTML_LINK_POS_DEFAULT
=> PRINT_HTML_LINK_POS_DEFAULT
));
280 $print_html_link_use_alias = variable_get('print_html_link_use_alias', PRINT_HTML_LINK_USE_ALIAS_DEFAULT
);
281 $allowed_type = print_link_allowed(array('type' => $type, 'node' => $node, 'teaser' => $teaser));
282 if (($allowed_type === PRINT_ALLOW_NORMAL_LINK
) && !isset($node->book
) && !empty($print_html_link_pos['link'])) {
283 drupal_add_css(drupal_get_path('module', 'print') .
'/css/printlinks.css');
285 $format = theme('print_format_link');
288 if ($type == 'comment') {
289 $query_arr['comment'] = $node->cid
;
291 $query = print_query_string_encode($query_arr, array('q'));
292 if (empty($query)) $query = NULL
;
294 if ($print_html_link_use_alias) {
295 $path = drupal_get_path_alias('node/'.
$node->nid
);
301 $links['print_html'] = array(
302 'href' => PRINT_PATH .
'/'.
$path,
303 'title' => $format['text'],
304 'attributes' => $format['attributes'],
305 'html' => $format['html'],
317 * Implementation of hook_link_alter().
319 function print_link_alter(&$links, $node) {
320 foreach ($links as
$module => $link) {
321 if (strpos($module, 'book_printer') !== FALSE
) {
322 $print_html_book_link = variable_get('print_html_book_link', PRINT_HTML_BOOK_LINK_DEFAULT
);
324 if ($print_html_book_link) {
325 $print_html_link_pos = variable_get('print_html_link_pos', array(PRINT_HTML_LINK_POS_DEFAULT
=> PRINT_HTML_LINK_POS_DEFAULT
));
327 if (!empty($print_html_link_pos['link'])) {
328 $format = theme('print_format_link');
330 switch ($print_html_book_link) {
332 $path = $link['href'];
335 $print_html_link_use_alias = variable_get('print_html_link_use_alias', PRINT_HTML_LINK_USE_ALIAS_DEFAULT
);
336 $path = ($print_html_link_use_alias && isset($node->path
)) ?
$node->path
: $node->nid
;
340 $links[$module] = array(
341 'href' => PRINT_PATH .
'/'.
$path,
342 'title' => $format['text'],
343 'attributes' => $format['attributes'],
344 'html' => $format['html'],
348 unset($links[$module]);
356 * Implementation of hook_help().
358 function print_help($path, $arg) {
360 case
'admin/help#print':
361 // Return a line-break version of the module README
362 return filter_filter('process', 1, NULL
, file_get_contents(drupal_get_path('module', 'print') .
'/README.txt') );
365 $print_html_link_pos = variable_get('print_html_link_pos', array(PRINT_HTML_LINK_POS_DEFAULT
=> PRINT_HTML_LINK_POS_DEFAULT
));
366 if (($path !== 'node/%') && !(empty($print_html_link_pos['link']) && empty($print_html_link_pos['corner']))) {
367 static
$output = FALSE
;
369 if ($output === FALSE
) {
372 $link = print_insert_link();
374 return "<span class='print-syslink'>$link</span>";
381 * Implementation of hook_nodeapi().
383 function print_nodeapi(&$node, $op = 'view', $teaser, $page) {
386 // Insert content corner links
387 if ((!$teaser) && isset($node->build_mode
) && ($node->build_mode
=== NODE_BUILD_NORMAL
)) {
388 $node->content
['print_links'] = array(
389 '#prefix' => '<span class="print-link">',
391 '#suffix' => '</span>',
394 $print_html_link_pos = variable_get('print_html_link_pos', array(PRINT_HTML_LINK_POS_DEFAULT
=> PRINT_HTML_LINK_POS_DEFAULT
));
395 if (!empty($print_html_link_pos['corner'])) {
396 $node->content
['print_links']['#value'] .
= print_insert_link(NULL
, $node);
401 _print_set_node_fields($node);
405 if (user_access('administer print') || user_access('node-specific print configuration')) {
406 if ($node->print_display
=== NULL
) $node->print_display
= variable_get('print_display_'.
$node->type
, PRINT_TYPE_SHOW_LINK_DEFAULT
);
407 if ($node->print_display_comment
=== NULL
) $node->print_display_comment
= variable_get('print_display_comment_'.
$node->type
, PRINT_TYPE_COMMENT_LINK_DEFAULT
);
408 if ($node->print_display_urllist
=== NULL
) $node->print_display_urllist
= variable_get('print_display_urllist_'.
$node->type
, PRINT_TYPE_URLLIST_DEFAULT
);
410 _print_node_conf_modify($node->nid
, $node->print_display
, $node->print_display_comment
, $node->print_display_urllist
);
414 db_query("DELETE FROM {print_node_conf} WHERE nid = %d", $node->nid
);
415 db_query("DELETE FROM {print_page_counter} WHERE path = 'node/%d'", $node->nid
);
421 * Implementation of hook_form_alter().
423 function print_form_alter(&$form, $form_state, $form_id) {
424 // Add the node-type settings option to activate the printer-friendly version link
425 if ((user_access('administer print') || user_access('node-specific print configuration')) && (($form_id == 'node_type_form') ||
426 (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .
'_node_form' == $form_id))) {
427 $form['print'] = array(
428 '#type' => 'fieldset',
429 '#title' => t('Printer, e-mail and PDF versions'),
430 '#collapsible' => TRUE
,
431 '#collapsed' => TRUE
,
432 '#weight' => (function_exists('content_extra_field_weight') && isset($form['type'])) ?
content_extra_field_weight($form['type']['#value'], 'print') : PRINT_TYPE_FIELDS_WEIGHT
,
433 '#group' => 'additional_settings',
436 $form['print']['label'] = array(
438 '#value' => '<p><strong>'.
t('Printer-friendly version') .
'</strong></p>',
441 $form['print']['print_display'] = array(
442 '#type' => 'checkbox',
443 '#title' => t('Show link'),
445 $form['print']['print_display_comment'] = array(
446 '#type' => 'checkbox',
447 '#title' => t('Show link in individual comments'),
449 $form['print']['print_display_urllist'] = array(
450 '#type' => 'checkbox',
451 '#title' => t('Show Printer-friendly URLs list'),
454 if ($form_id == 'node_type_form') {
455 $form['print']['print_display']['#default_value'] = variable_get('print_display_'.
$form['#node_type']->type
, PRINT_TYPE_SHOW_LINK_DEFAULT
);
456 $form['print']['print_display_comment']['#default_value'] = variable_get('print_display_comment_'.
$form['#node_type']->type
, PRINT_TYPE_COMMENT_LINK_DEFAULT
);
457 $form['print']['print_display_urllist']['#default_value'] = variable_get('print_display_urllist_'.
$form['#node_type']->type
, PRINT_TYPE_URLLIST_DEFAULT
);
460 $node = $form['#node'];
461 $form['print']['print_display']['#default_value'] = isset($node->print_display
) ?
$node->print_display
: variable_get('print_display_'.
$node->type
, PRINT_TYPE_SHOW_LINK_DEFAULT
);
462 $form['print']['print_display_comment']['#default_value'] = isset($node->print_display_comment
) ?
$node->print_display_comment
: variable_get('print_display_comment_'.
$node->type
, PRINT_TYPE_COMMENT_LINK_DEFAULT
);
463 $form['print']['print_display_urllist']['#default_value'] = isset($node->print_display_urllist
) ?
$node->print_display_urllist
: variable_get('print_display_urllist_'.
$node->type
, PRINT_TYPE_URLLIST_DEFAULT
);
469 * Implementation of hook_content_extra_fields().
471 function print_content_extra_fields($type_name) {
472 $fields['print'] = array(
473 'label' => t('Printer, e-mail and PDF versions'),
474 'description' => t('Print module form.'),
475 'weight' => PRINT_TYPE_FIELDS_WEIGHT
,
481 * Implementation of hook_content_build_modes().
483 function print_content_build_modes() {
486 'title' => t('Print'),
487 'build modes' => array(
488 NODE_BUILD_PRINT
=> array(
489 'title' => t('Print'),
490 'views style' => TRUE
,
498 * Auxiliary function to assign the per-node settings to the node object fields
501 * node to be modified
503 function _print_set_node_fields(&$node) {
504 if (isset($node->nid
)) {
505 $res = db_fetch_object(db_query("SELECT link, comments, url_list FROM {print_node_conf} WHERE nid = %d", $node->nid
));
510 $node->print_display
= $res ?
intval($res->link) : variable_get('print_display_'.
$node->type
, PRINT_TYPE_SHOW_LINK_DEFAULT
);
511 $node->print_display_comment
= $res ?
intval($res->comments
) : variable_get('print_display_comment_'.
$node->type
, PRINT_TYPE_COMMENT_LINK_DEFAULT
);
512 $node->print_display_urllist
= $res ?
intval($res->url_list
) : variable_get('print_display_urllist_'.
$node->type
, PRINT_TYPE_URLLIST_DEFAULT
);
516 * Auxiliary function to discover a given page's title
519 * path of the page being identified
521 * string with the page's title
523 function _print_get_title($path) {
524 $path = drupal_get_normal_path($path);
525 $nid = preg_replace('!^node/!', '', $path);
526 if (is_numeric($nid)) {
527 $res = db_fetch_object(db_query("SELECT title FROM {node} WHERE nid = %d", $nid));
531 $res = db_fetch_object(db_query("SELECT link_title FROM {menu_links} WHERE link_path = '%s'", $path));
533 return $res->link_title
;
542 * Update the print_node_conf table to reflect the given attributes
543 * If updating to the default values, delete the record.
546 * value of the nid field (primary key)
548 * value of the link field (0 or 1)
550 * value of the comments field (0 or 1)
552 * value of the url_list field (0 or 1)
554 function _print_node_conf_modify($nid, $link, $comments, $url_list) {
555 db_query("UPDATE {print_node_conf} SET link = %d, comments = %d, url_list = %d WHERE nid = %d", $link, $comments, $url_list, $nid);
556 if (!db_affected_rows()) {
557 @
db_query("INSERT INTO {print_node_conf} (nid, link, comments, url_list) VALUES (%d, %d, %d, %d)", $nid, $link, $comments, $url_list);
562 * Auxiliary function to fill the Printer-friendly link attributes
565 * text to displayed by the link when hovering over it with the mouse
567 * class attribute to be used in the link
569 * if TRUE opens the target page in a new window
571 * array of formatted attributes
573 function print_fill_attributes($title = '', $class = '', $new_window = FALSE
) {
574 $print_newwindow = variable_get('print_newwindow', PRINT_NEWWINDOW_DEFAULT
);
575 $print_robots_noindex = variable_get('print_robots_noindex', PRINT_ROBOTS_NOINDEX_DEFAULT
);
577 $attributes = array();
578 $attributes['title'] = $title;
579 if (!empty($class)) {
580 $attributes['class'] = $class;
584 switch ($print_newwindow) {
586 $attributes['target'] = '_blank';
589 $attributes['onclick'] = 'window.open(this.href); return false';
593 if (!empty($print_robots_noindex)) {
594 $attributes['rel'] = 'nofollow';
600 * Auxiliary function to set the link text and html flag
603 * type of link: 0 or 1 for a text-only link, 2 for icon-only and 3 for
606 * text to be displayed on the link to the printer-friendly page
608 * path to the icon file
610 * array with the link text and html flag
612 function _print_format_link_aux($type = 0, $text = '', $img = '') {
617 $text = theme('image', $img, $text, $text, array('class' => 'print-icon'));
620 $text = theme('image', $img, $text, $text, array('class' => 'print-icon print-icon-margin')) .
$text;
628 return array('text' => $text,
634 * Format the Printer-friendly link
637 * array of formatted attributes
640 function theme_print_format_link() {
641 $print_html_link_class = variable_get('print_html_link_class', PRINT_HTML_LINK_CLASS_DEFAULT
);
642 $print_html_new_window = variable_get('print_html_new_window', PRINT_HTML_NEW_WINDOW_DEFAULT
);
643 $print_html_show_link = variable_get('print_html_show_link', PRINT_HTML_SHOW_LINK_DEFAULT
);
644 $print_html_link_text = filter_xss(variable_get('print_html_link_text', t('Printer-friendly version')));
646 $img = drupal_get_path('module', 'print') .
'/icons/print_icon.gif';
647 $title = t('Display a printer-friendly version of this page.');
648 $class = strip_tags($print_html_link_class);
649 $new_window = $print_html_new_window;
650 $format = _print_format_link_aux($print_html_show_link, $print_html_link_text, $img);
652 return array('text' => $format['text'],
653 'html' => $format['html'],
654 'attributes' => print_fill_attributes($title, $class, $new_window),
659 * Auxiliary function to display a formatted Printer-friendly link
661 * Function made available so that developers may call this function from
662 * their defined pages/blocks.
665 * path of the original page (optional). If not specified, the current URL
668 * an optional node object, to be used in defining the path, if used, the
669 * path argument is irrelevant
671 * string with the HTML link to the printer-friendly page
673 function print_insert_link($path = NULL
, $node = NULL
) {
674 if ($node !== NULL
) {
676 $path = 'node/'.
$nid;
677 $allowed_type = print_link_allowed(array('node' => $node));
680 if ($path === NULL
) {
681 $nid = preg_replace('!^node/!', '', $_GET['q']);
687 $allowed_type = print_link_allowed(array('path' => $path));
692 if ($allowed_type === PRINT_ALLOW_BOOK_LINK
) {
693 $path = 'book/export/html/'.
$nid;
696 if (variable_get('print_html_link_use_alias', PRINT_HTML_LINK_USE_ALIAS_DEFAULT
)) {
697 $path = drupal_get_path_alias($path);
703 $path = PRINT_PATH .
'/'.
$path;
704 $query = print_query_string_encode($_GET, array('q'));
712 drupal_add_css(drupal_get_path('module', 'print') .
'/css/printlinks.css');
713 $format = theme('print_format_link');
714 return '<span class="print_html">'.
l($format['text'], $path, array('attributes' => $format['attributes'], 'query' => $query, 'absolute' => TRUE
, 'html' => $format['html'])) .
'</span>';
722 * Determine if the provided page is enabled according to the visibility settings
725 * current visibility settings:
726 * 0 for show on every page except the listed pages
727 * 1 for show on only the listed pages
731 * TRUE if it is enabled, FALSE otherwise
733 function _print_page_match($visibility, $path, $pages) {
735 if ($visibility == 2) {
736 return drupal_eval($pages);
738 $alias = drupal_get_path_alias($path);
739 $page_match = drupal_match_path($path, $pages);
740 if ($alias != $path) {
741 $page_match = $page_match || drupal_match_path($alias, $pages);
744 return !($visibility xor
$page_match);
752 * Determine a the link to the PF version is allowed depending on all possible settings
755 * array containing the possible parameters:
756 * teaser, node, type, path
758 * FALSE if not allowed
759 * PRINT_ALLOW_NORMAL_LINK if a normal link is allowed
760 * PRINT_ALLOW_BOOK_LINK if a link is allowed in a book node
762 function print_link_allowed($args) {
763 if ((!empty($args['teaser']) && !variable_get('print_html_link_teaser', PRINT_HTML_LINK_TEASER_DEFAULT
))
764 || !user_access('access print')) {
765 // If the teaser link is disabled or the user is not allowed
769 if (!empty($args['path'])) {
770 $nid = preg_replace('!^node/!', '', drupal_get_normal_path($args['path']));
771 if (is_numeric($nid)) {
772 $args['node'] = node_load($nid);
774 else { // Not a node - is it a view?
775 $router_item = menu_get_item($args['path']);
776 $is_view = ($router_item['access_callback'] == 'views_access');
779 if (!empty($args['node'])) {
780 static
$node_type = '';
782 $node = $args['node'];
783 if (!empty($node->view
) // node is inside view
784 && !variable_get('print_html_view_contained_nodes_link_visibility', 0)) {
787 if (isset($node->type
)) {
788 $node_type = $node->type
;
792 $print_html_node_link_visibility = variable_get('print_html_node_link_visibility', PRINT_HTML_NODE_LINK_VISIBILITY_DEFAULT
);
793 $print_html_node_link_pages = variable_get('print_html_node_link_pages', PRINT_HTML_NODE_LINK_PAGES_DEFAULT
);
795 if (!_print_page_match($print_html_node_link_visibility, "node/".
$node->nid
, $print_html_node_link_pages)) {
796 // Page not in visibility list
799 elseif (isset($args['type']) && ($args['type'] == 'comment') && isset($node_type)) {
800 // Link is for a comment, return the configured setting
801 // Cache this statically to avoid duplicate queries for every comment.
802 static
$res = array();
803 if (!isset($res[$node->nid
])) {
804 $res[$node->nid
] = db_fetch_object(db_query("SELECT comments FROM {print_node_conf} WHERE nid = %d", $node->nid
));
806 $print_display_comment = $res ?
intval($res[$node->nid
]->comments
) : variable_get('print_display_comment_'.
$node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT
);
807 if ($print_display_comment) {
808 return PRINT_ALLOW_NORMAL_LINK
;
813 if (empty($node->print_display
)) {
814 // Link for this node is disabled
817 elseif (isset($node->book
)) {
819 $print_html_book_link = variable_get('print_html_book_link', PRINT_HTML_BOOK_LINK_DEFAULT
);
820 switch ($print_html_book_link) {
822 if (user_access('access printer-friendly version')) {
823 return PRINT_ALLOW_BOOK_LINK
;
827 return PRINT_ALLOW_NORMAL_LINK
;
831 return PRINT_ALLOW_NORMAL_LINK
;
835 elseif ($is_view && variable_get('print_html_views_link_visibility', 1)) {
836 return PRINT_ALLOW_NORMAL_LINK
;
840 $print_html_sys_link_visibility = variable_get('print_html_sys_link_visibility', PRINT_HTML_SYS_LINK_VISIBILITY_DEFAULT
);
841 $print_html_sys_link_pages = variable_get('print_html_sys_link_pages', PRINT_HTML_SYS_LINK_PAGES_DEFAULT
);
843 return _print_page_match($print_html_sys_link_visibility, $_GET['q'], $print_html_sys_link_pages);
849 * Parse an array into a valid urlencoded query string.
850 * Modified from drupal_query_string_encode to prevent re-encoding of
854 * The array to be processed e.g. $_GET
856 * The array filled with keys to be excluded.
858 * urlencoded string which can be appended to/as the URL query string
860 function print_query_string_encode($query, $exclude = array(), $parent = '') {
862 foreach ($query as
$key => $value) {
864 $key = $parent .
'['.
$key .
']';
867 if (in_array($key, $exclude)) {
871 if (is_array($value)) {
872 $params[] = print_query_string_encode($value, $exclude, $key);
875 $params[] = $key .
'='.
rawurlencode($value);
879 return implode('&', $params);