4 /********************************************************************
5 * Drupal Hooks :: Overview
6 ********************************************************************/
9 * Implementation of hook_help().
11 function print_help($section) {
13 case
'admin/modules#description':
14 $output = t('Allows users to create printer-friendly pages for nodes.');
22 * Implementation of hook_menu().
24 function print_menu($may_cache) {
28 $items[] = array('path' => 'node/'.
arg(1) .
'/print', 'title' => t('printer friendly page'),
29 'callback' => 'print_page', 'access' => user_access('access content'),
30 'type' => MENU_CALLBACK
);
36 /********************************************************************
37 * Drupal Hooks :: Core
38 ********************************************************************/
41 * Implementation of hook_link().
43 function print_link($type, $node = 0, $main) {
46 if ($node->type
== 'book' && function_exists('book_link')) {
50 if ($type == 'node' && variable_get('print_show_link', 1) && $main == 0) {
51 $links[] = theme('print_link', $node);
57 function print_settings() {
58 $output = form_textfield(t('Stylesheet URL'), 'print_css', variable_get('print_css', 'misc/print.css'), 60, 64, t('The URL to your print cascading stylesheet.'));
60 $field .
= form_checkbox(t('A list of the node\'s links at the bottom'), 'print_urls', 1, variable_get('print_urls', 0));
61 $output .
= form_group(t('Print page elements'), $field);
62 $output .
= form_radios(t('Printer friendly page link'), 'print_show_link', variable_get('print_show_link', 1), array(t("Disabled"), t("Enabled")), 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 'node/nid/print' where nid is the numeric id of the node."));
63 $output .
= form_textfield(t('Printer friendly page icon'), 'print_icon', variable_get('print_icon', 'misc/print.gif'), 60, 64, t('An optional icon to put in front of the printer friendly page link.'));
68 /********************************************************************
69 * Module Functions :: Controllers
70 ********************************************************************/
72 function print_page() {
74 if (is_numeric($nid)) {
79 /********************************************************************
81 ********************************************************************/
84 * Outputs a printer friendly page.
86 function print_generate($title) {
89 /* We can take a node id or a node title */
90 $node = (is_numeric($title)) ?
node_load(array('nid' => $title)) : node_load(array('title' => $title));
91 if (!$node->title
) return false
;
95 /* This section is ripped from node_view.
96 This does everything node_view does except theme the node! */
98 // Remove the delimiter (if any) that separates the teaser from the body.
99 // TODO: this strips legitimate uses of '<!--break-->' also.
100 $node->body
= str_replace('<!--break-->', '', $node->body
);
102 // The 'view' hook can be implemented to overwrite the default function
104 if (node_hook($node, 'view'))
105 node_invoke($node, 'view', $teaser, $page);
107 $node = node_prepare($node, $teaser);
108 // Allow modules to change $node->body before viewing.
109 node_invoke_nodeapi($node, 'view', $teaser, $page);
111 /* End of code stealing from node_view() */
113 if (variable_get('print_urls', 1)) {
115 /* Collect links and display them at the bottom of the page. Code once taken from Kjartan Mannes' project.module */
116 $pattern = "@href=([\']?[\"]?)([^\"|^\'|^|^>]*)([^>]*)>(.+?)</a>@ise";
117 $node->body
= preg_replace($pattern, "'<u>'.stripslashes('\\4').'</u> ['. print_friendly_urls(stripslashes('\\2')) .']'", $node->body
);
118 $urls = print_friendly_urls();
120 $node->pfp_links
= '';
122 for ($i = 0; $i < $max; $i++) {
123 $node->pfp_links .
= '['.
($i + 1) .
'] '.
$urls[$i] .
"<br />\n";
128 /* Grab and format the src URL */
129 $node->source_url
= $base_url.
'/'.
url("node/$node->nid");
130 $node->language
= $GLOBALS['locale'];
131 $node->printcss
= variable_get('print_css', 'misc/print.css');
133 include_once('print.tpl.php');
136 function print_friendly_urls($url = 0) {
138 static
$urls = array();
140 $urls[] = strpos($url, '://') ?
$url : $base_url.
'/'.
url($url);
146 /********************************************************************
147 * Module Functions :: Themeable Functions
148 ********************************************************************/
150 function theme_print_link($node) {
152 if ($icon = variable_get('print_icon', 1)) {
153 $links .
= l('<img src="'.
$icon.
'" alt="">', "node/$node->nid/print");
155 $links .
= l(t('printer friendly page'), "node/$node->nid/print", array('title' => t('Display a printer friendly page.')));