diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 120b25357171221de57ca7c17900205dbd557454..acaf6a75b7298acdbedf7e8ab445ba569d489ee4 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,8 @@ Print Module Changelog +October 30, 2004 + * Created a print.tpl.php template file to give site admins control of what node parts this module renders and how the pages are structured. This feature, combined with the custom print stylesheet option, gives max freedom in rendering print friendly pages. + October 27, 2004 * Updated to work with Drupal 4.5 diff --git a/INSTALL.txt b/INSTALL.txt index cd919ef6b9619c4a5dd228cf4c731748ef658138..3bae879b229b8a64cf0a5085c230e876c605af96 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -9,10 +9,13 @@ INSTALLATION: 1. Place the entire print directory into your Drupal modules/ directory. -2. Enable this module by navigating to: +2. Enable via: administer > modules -3. Configure this module by navigating to: +3. Configure via: administer > settings > print + +4. To modify the template of printer friendly pages, simply edit the + print.tpl.php file found in this directory. diff --git a/README.txt b/README.txt index d02b701b86df511f48aa5520cff3fef939d0369d..bb690bb1cd5e5b21106e096772db2c5724d9d03b 100644 --- a/README.txt +++ b/README.txt @@ -10,7 +10,8 @@ Drupal: 4.5 DESCRIPTION: This module allows you to generate printer friendly versions of -any node by navigating to example.com/node/print/[node id | node title]. +any node by navigating to www.example.com/node/nid/print, where nid +is the node id of content to render. ******************************************************************** INSTALLATION: @@ -20,9 +21,8 @@ see the INSTALL.txt file in this directory. ******************************************************************** TODO: -- code cleanup -- add ability to optionally attach comments to nodes for printing -- custom print.css +- Add ability to optionally attach comments to nodes for printing + by calling comment_render(). ******************************************************************** UPCOMING FEATURES: diff --git a/print.module b/print.module index 657a9ee9e075a64119cba8499b464becc068ea8c..f9d11559341682f1f63c5accf8b0563e80baba4b 100644 --- a/print.module +++ b/print.module @@ -24,8 +24,8 @@ function print_help($section) { function print_menu($may_cache) { $items = array(); - if ($may_cache) { - $items[] = array('path' => 'node/print', 'title' => t('printer friendly page'), + if (!$may_cache) { + $items[] = array('path' => 'node/'. arg(1) .'/print', 'title' => t('printer friendly page'), 'callback' => 'print_page', 'access' => user_access('access content'), 'type' => MENU_CALLBACK); } @@ -53,13 +53,9 @@ function print_link($type, $node = 0, $main) { function print_settings() { $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.')); - $field = form_checkbox(t('Submitted by'), 'print_submitted', 1, variable_get('print_submitted', 0)); - $field .= form_checkbox(t('Created'), 'print_created', 1, variable_get('print_created', 0)); $field .= form_checkbox(t('Printer friendly URLs'), 'print_urls', 1, variable_get('print_urls', 0)); $output .= form_group(t('Print page elements'), $field); - - $output .= form_textarea(t('Footer message'), 'print_footer', variable_get('print_footer', variable_get('site_footer', '')), 70, 5, t('This text will be displayed at the bottom of each printer friendly page. Useful for adding a copyright and disclaimers.')); - $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/print/nid' where nid is the numeric id of the node.")); + $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.")); return $output; } @@ -68,9 +64,10 @@ function print_settings() { * Module Functions :: Controllers ********************************************************************/ -function print_page($nid = null) { +function print_page() { + $nid = arg(1); if (is_numeric($nid)) { - print print_generate($nid); + print_generate($nid); } } @@ -79,25 +76,17 @@ function print_page($nid = null) { ********************************************************************/ /** - * Returns a printer friendly page. - * - * You can also configure how you want the page to look using GET parameters. + * Outputs a printer friendly page. */ function print_generate($title) { global $base_url; - if ($_GET['urls'] || variable_get('print_urls', 1)) - $print_urls = 1; - - if ($_GET['submitted'] || variable_get('print_submitted', 1)) - $print_submitted = 1; - - if ($_GET['created'] || variable_get('print_created', 1)) - $print_created = 1; - /* We can take a node id or a node title */ $node = (is_numeric($title)) ? node_load(array('nid' => $title)) : node_load(array('title' => $title)); + if (!$node->title) return false; + $teaser = false; + $page = true; /* This section is ripped from node_view. This does everything node_view does except theme the node! */ @@ -107,60 +96,35 @@ function print_generate($title) { // The 'view' hook can be implemented to overwrite the default function // to display nodes. - if (node_hook($node, 'view')) { + if (node_hook($node, 'view')) node_invoke($node, 'view', $teaser, $page); - } - else { + else $node = node_prepare($node, $teaser); - } // Allow modules to change $node->body before viewing. node_invoke_nodeapi($node, 'view', $teaser, $page); /* End of code stealing from node_view() */ - if ($node) { - - $output = '

'. $node->title .'

'; - - if ($print_submitted) { - $output .= '
'. t('By %author', array('%author' => $node->name)). '
'; - } - - if ($print_created) { - $output .= '
'. t('Created %date', array('%date' => format_date($node->created, 'small'))). '
'; - } - - $output .= '
'; - - if ($print_urls) { - /* Collect links and display them at the bottom of the page. Code once taken from Kjartan Mannes' project.module */ - $pattern = "@href=([\']?[\"]?)([^\"|^\'|^|^>]*)([^>]*)>(.+?)@ise"; - $node->body = preg_replace($pattern, "''.stripslashes('\\4').' ['. print_friendly_urls(stripslashes('\\2')) .']'", $node->body); - $urls = print_friendly_urls(); - if (count($urls)) { - $node->body .= ''; - $max = count($urls); - for ($i = 0; $i < $max; $i++) { - $node->body .= '['. ($i + 1) .'] '. $urls[$i] ."
\n"; - } + if (variable_get('print_urls', 1)) { + /* Collect links and display them at the bottom of the page. Code once taken from Kjartan Mannes' project.module */ + $pattern = "@href=([\']?[\"]?)([^\"|^\'|^|^>]*)([^>]*)>(.+?)@ise"; + $node->body = preg_replace($pattern, "''.stripslashes('\\4').' ['. print_friendly_urls(stripslashes('\\2')) .']'", $node->body); + $urls = print_friendly_urls(); + if (count($urls)) { + $node->pfp_links = ''; + $max = count($urls); + for ($i = 0; $i < $max; $i++) { + $node->pfp_links .= '['. ($i + 1) .'] '. $urls[$i] ."
\n"; } } - - $output .= $node->body; - - /* Grab and format the src URL */ - $url = $base_url. '/'. url("node/view/$node->nid"); - $output .= '

Source URL: '. $url. "

\n"; - - $output .= ''; } - $html = "$node->title"; - $html .= ""; - $html .= ""; - $html .= "". $output .""; + /* Grab and format the src URL */ + $node->source_url = $base_url. '/'. url("node/$node->nid"); + $node->language = $GLOBALS['locale']; + $node->printcss = variable_get('print_css', 'misc/print.css'); - return $html; + include_once('print.tpl.php'); } function print_friendly_urls($url = 0) { @@ -178,6 +142,6 @@ function print_friendly_urls($url = 0) { ********************************************************************/ function theme_print_link($node) { - return l(t('printer friendly page'), "node/print/$node->nid"); + return l(t('printer friendly page'), "node/$node->nid/print"); } ?> diff --git a/print.tpl.php b/print.tpl.php new file mode 100644 index 0000000000000000000000000000000000000000..5c567bfae262fbef2997b9b769b0e9750f7146b9 --- /dev/null +++ b/print.tpl.php @@ -0,0 +1,45 @@ + + + + + <?php print $node->title; ?> + + + + + + +

+ title; ?> +

+ +
+ By name; ?> +
+ +
+ Created created, 'small'); ?> +
+ +
+ body; ?> +
+ + + +
+ Source URL: source_url; ?> +
+ + + + +