summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Westgate2004-10-30 17:49:22 (GMT)
committer Matt Westgate2004-10-30 17:49:22 (GMT)
commit30ff938cfec746714341b5d40157c097423cef9e (patch)
treec43befc6e4542072340078e163f1d98d2b3e51cc
parent1aaa7127ac2b87b1b987e03ec57668d6b34cf519 (diff)
* 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.
-rw-r--r--CHANGELOG.txt3
-rw-r--r--INSTALL.txt7
-rw-r--r--README.txt8
-rw-r--r--print.module92
-rw-r--r--print.tpl.php45
5 files changed, 85 insertions, 70 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 120b253..acaf6a7 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 cd919ef..3bae879 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 d02b701..bb690bb 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 657a9ee..f9d1155 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 = '<h1 class="title">'. $node->title .'</h1>';
-
- if ($print_submitted) {
- $output .= '<div class="submitted">'. t('By %author', array('%author' => $node->name)). '</div>';
- }
-
- if ($print_created) {
- $output .= '<div class="created">'. t('Created %date', array('%date' => format_date($node->created, 'small'))). '</div>';
- }
-
- $output .= '<div class="content">';
-
- if ($print_urls) {
- /* Collect links and display them at the bottom of the page. Code once taken from Kjartan Mannes' project.module */
- $pattern = "@href=([\']?[\"]?)([^\"|^\'|^|^>]*)([^>]*)>(.+?)</a>@ise";
- $node->body = preg_replace($pattern, "'<u>'.stripslashes('\\4').'</u> ['. print_friendly_urls(stripslashes('\\2')) .']'", $node->body);
- $urls = print_friendly_urls();
- if (count($urls)) {
- $node->body .= '<h2 class="links">Links</h2>';
- $max = count($urls);
- for ($i = 0; $i < $max; $i++) {
- $node->body .= '['. ($i + 1) .'] '. $urls[$i] ."<br />\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=([\']?[\"]?)([^\"|^\'|^|^>]*)([^>]*)>(.+?)</a>@ise";
+ $node->body = preg_replace($pattern, "'<u>'.stripslashes('\\4').'</u> ['. 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] ."<br />\n";
}
}
-
- $output .= $node->body;
-
- /* Grab and format the src URL */
- $url = $base_url. '/'. url("node/view/$node->nid");
- $output .= '<p class="source_url"><strong>Source URL:</strong> <a href="'. $url .'">'. $url. "</a></p>\n";
-
- $output .= '<div class="footer">'. variable_get('print_footer', variable_get('site_footer', '')). '</div>';
}
- $html = "<html><head><title>$node->title</title>";
- $html .= "<base href=\"$base_url/\" />";
- $html .= "<style type=\"text/css\">\n@import url(". variable_get('print_css', 'misc/print.css') .");\n</style>";
- $html .= "</head><body>". $output ."</body></html>";
+ /* 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 0000000..5c567bf
--- /dev/null
+++ b/print.tpl.php
@@ -0,0 +1,45 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $node->language; ?>" xml:lang="<?php print $node->language; ?>">
+
+ <head>
+ <title><?php print $node->title; ?></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <base href="<?php print $base_url ?>/" />
+ <style type="text/css">
+ @import url "<?php print $node->printcss; ?>";
+ </style>
+ </head>
+ <body>
+
+ <h1 class="title">
+ <?php print $node->title; ?>
+ </h1>
+
+ <div class="submitted">
+ By <?php print $node->name; ?>
+ </div>
+
+ <div class="created">
+ Created <?php print format_date($node->created, 'small'); ?>
+ </div>
+
+ <div class="content">
+ <?php print $node->body; ?>
+ </div>
+
+ <div class="pfp-links">
+ <!-- Output printer friendly links -->
+ <h2 class="links">Links</h2>
+ <?php print $node->pfp_links; ?>
+ </div>
+
+ <div class="source_url">
+ <strong>Source URL:</strong> <a href="<?php print $node->source_url; ?>"><?php print $node->source_url; ?></a>
+ </div>
+
+ <div class="footer">
+ <!-- Add your custom footer here. -->
+ </div>
+
+ </body>
+</html>