Gossamer Forum
Home : Products : Links 2.0 : Customization :

Printer-Friendly Print out Links 2.0

Quote Reply
Printer-Friendly Print out Links 2.0
I was wondering, is there a mod to have a printer-friendly version of a detailed page. If not, are there instructions I can following on setting it up for intermediate person, not programmers?

Thanks!!!!!

David
Quote Reply
Re: [webwizzz] Printer-Friendly Print out Links 2.0 In reply to
I have seen a few of these scripts around, and have the url for one. Check places like HotScripts, CGI Resource, etc.


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Printer-Friendly Print out Links 2.0 In reply to
Quote:
I have seen a few of these scripts around


So have I, but the problem is either the script doesn't allow you to do full url's: www.website.com/cgi-bin/printerfriendly.cgi?page=/test/hi.html

If you notice it has /test/hi.html at the end of page= that only does dir's on the server. I need full url's example: http://www.website.com/test/hi.html because there are web pages on our server that are dynamic not, static that is the don't exist in HTML form, only in PERL forum.

David
Quote Reply
Re: [webwizzz] Printer-Friendly Print out Links 2.0 In reply to
I have not used the script I referrenced, but it seems that, if you put the right HTML output tags in your perl code (output=) then it would still work. The reason the printable page does not have an absolute URL is because each page is proccessed through the printpage.cgi, and is not static.

I have operated Ikonboard, which is generated 'on the fly,' and it has a printpage function. Shouldn't be too hard to make something work.

Just a few thoughts...Unimpressed


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Printer-Friendly Print out Links 2.0 In reply to
How can I make a printer friendly template script for Links 2.0 and just have a link to a script that will let me just input fields like the detailed.html?

Example: url: www.tartsg.com/cgi-bin/db/print.cgi?id=13 then it will go to that page and it will load a printer friendly template through the print.cgi script. Can some one come up with some code like that?

David
Quote Reply
Re: [webwizzz] Printer-Friendly Print out Links 2.0 In reply to
1) Go to the following thread: http://www.gossamer-threads.com/...ing=info.cgi;#213612

2) Copy the codes in the thread and paste them into a text editor, save the file as print.cgi. Remembering to change the "site_detailed_page" stuff to another subroutine that you'll need to create in the site_html_templates.pl file.

3) Create a new subroutine modelled after the sub site_detailed_page routine and name the sub something like sub site_print_page and remember to change detailed.html to something like print.html.

4) Create a new template called print.html file in the templates folder.

That's really all you need to do.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Stealth] Printer-Friendly Print out Links 2.0 In reply to
Stealth I did everything you said. Here is print.cgi

Code:
#!/usr/bin/perluse CGI qw(:standard);
use lib "admin"; #change to full path if you have problems
require "links.cfg";
require "links.def";
require "site_html_templates.pl";
my $id = param(id);
$id =~ /^\d+$/ or die "invalid ID";
my %rec = get_record($id);
print header();
print site_printer_friendly(%rec);


Here is site_html_templates.pl:

Code:
# -------------
# Links
# -------------
# Links Manager
#
# File: site_html.pl
# Description: This library contains all the HTML that will be generated in
# the finished directory.
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Web: http://www.gossamer-threads.com/
# Version: 2.01
#
# (c) 1998 Gossamer Threads Inc.
#
# This script is not freeware! Please read the README for full details
# on registration and terms of use.
# ===================================================================== # ----------------------------------------------------------------------
# The HTML in this file and the style sheet (links.css) have been authored
# by Chris Croome of webarchitects.
#
# Email: chris@atomism.demon.co.uk
# Web: http://www.webarchitects.co.uk/
# ----------------------------------------------------------------------



# You can put variables here that you would like to use in any
# of your templates.



%globals = (
date => &get_date,
time => &get_time,
db_cgi_url => $db_cgi_url,
build_root_url => $build_root_url,
site_title => $build_site_title,
css => $build_css_url,
banner => ''
);




sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.



my %rec = @_;

# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});



return &load_template ('link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
%rec,
%globals
});
}



sub site_html_link_two {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.



my %rec = @_;

# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});



return &load_template ('link_detailed.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
%rec,
%globals
});
}



sub site_html_home {
# --------------------------------------------------------
# This routine will build a home page. It is not meant to have any
# links on it, only subcategories.



return &load_template ('home.html', {
category => $category,
grand_total => $grand_total,
%globals
});
}



sub site_html_new {
# --------------------------------------------------------
# This routine will build a what's new page.



return &load_template ('new.html', {
total => $total,
grand_total => $grand_total,
link_results => $link_results,
title_linked => $title_linked,
%globals
} );
}



sub site_html_cool {
# --------------------------------------------------------
# This routine will build a what's new page.



return &load_template ('cool.html', {
total => $total,
grand_total => $grand_total,
percent => $percent,
link_results => $link_results,
title_linked => $title_linked,
%globals
} );
}



sub site_html_detailed {
# --------------------------------------------------------
# This routine will build a single page per link. It's only
# really useful if you have a long review for each link --
# or more information then can be displayed in a summary.
#
my %rec = @_;
return &load_template ('detailed.html', {
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
%rec,
%globals
} );
}



sub site_html_category {
# --------------------------------------------------------
# This rountine will build a page based for the current category.



return &load_template ( 'category.html', {
date => $date,
time => $time,
category => $category,
links => $links,
title_linked => $title_linked,
title => $title,
total => $total,
grand_total => $grand_total,
category_name => $category_name,
category_name_escaped => $category_name_escaped,
category_clean => $category_clean,
description => $description,
meta_name => $meta_name,
meta_keywords => $meta_keywords,
header => $header,
footer => $footer,
prev => $prev,
next => $next,
related => $related,
build_links_per_page => $build_links_per_page,
%globals
} );
}



sub site_html_ratings {
# --------------------------------------------------------
# This routine determines how the top rated page will look like.



return &load_template ( 'rate_top.html', {
top_rated => $top_rated,
top_votes => $top_votes,
%globals
});
}



########################################################################################
# THE FOLLOWING ARE CGI GENERATED PAGES AND THE TEMPLATE MUST BE PRINTED, NOT RETURNED!#
########################################################################################



sub site_html_add_form {
# --------------------------------------------------------
# This routine determines how the add form page will look like.
#
&html_print_headers;



my $category = shift;
$category ?
($category = qq~$category <input type=hidden name="Category" value="$category">~) :
($category = &build_select_field ("Category", "$in{'Category'}"));

print &load_template ('add.html', {
Category => $category,
%globals
});
}



sub site_html_add_success {
# --------------------------------------------------------
# This routine determines how the add success page will look like.



&html_print_headers;

print &load_template ('add_success.html', {
%in,
%globals
});
}



sub site_html_add_failure {
# --------------------------------------------------------
# This routine determines how the add failure page will look like.



my ($errormsg) = shift;
$in{'Category'} ?
($in{'Category'} = qq~<input type=hidden name="Category" value="$in{'Category'}">$in{'Category'}~) :
($in{'Category'} = &build_select_field ("Category"));

&html_print_headers;
print &load_template ('add_error.html', {
error => $errormsg,
%in,
%globals
});



}

sub site_html_modify_form {
# --------------------------------------------------------
# This routine determines how the modify form page will look like.



my $category = &build_select_field ("Category", "$in{'Category'}");

&html_print_headers;
print &load_template ('modify.html', {
Category => $category,
%globals
});
}



sub site_html_modify_success {
# --------------------------------------------------------
# This routine determines how the modify success page will look like.



&html_print_headers;
print &load_template ('modify_success.html', {
%in,
%globals
});
}



sub site_html_modify_failure {
# --------------------------------------------------------
# This routine determines how the modify failure page will look like.



my $errormsg = shift;
$in{'Category'} = &build_select_field ("Category", $in{'Category'});



&html_print_headers;
print &load_template ('modify_error.html', {
error => $errormsg,
%in,
%globals
});
}



sub site_html_search_results {
# --------------------------------------------------------
# This routine displays the search results.
#
my $term = &urlencode ($in{'query'});
&html_print_headers;
print &load_template ('search_results.html', {
term => $term,
link_results => $link_results,
category_results => $category_results,
next => $next,
cat_hits => $cat_hits,
link_hits => $link_hits,
%in,
%globals
});
}



sub site_html_search_failure {
# --------------------------------------------------------
# This routine displays a failed search page with error in $error.
#
my $error = shift;
my $term = &urlencode ($in{'query'});
&html_print_headers;



print &load_template ('search_error.html', {
term => $term,
error => $error,
%in,
%globals
});
}



sub site_html_search_form {
# --------------------------------------------------------
# This routine displays the search form.



&html_print_headers;
print &load_template ('search.html', {
term => $term,
error => $error,
%in,
%globals
});
}



sub site_html_mailing {
# --------------------------------------------------------
# This routine displays your mailing list subscribe/unsubscribe form.
#
my $action = shift;
my $message;
($action eq 'subscribe') and ($message = qq~You've been successfully subscribed to the mailing list!~);
($action eq 'unsubscribe') and ($message = qq~You've been successfully removed from the mailing list!~);



&html_print_headers;
print &load_template ('email.html', {
message => $message,
%in,
%globals
});
}



sub site_html_mailing_error {
# --------------------------------------------------------
# This routine is displayed if there was a problem subscribing.
#
my $error = shift;



&html_print_headers();
print &load_template ('email_error.html', {
error => $error,
%in,
%globals
});
}



sub site_html_rate_form {
# --------------------------------------------------------
# This routine determines how the rate form page will look like.
#
my %rec = @_;

&html_print_headers;
print &load_template ('rate.html', {
%rec,
%globals
});
}



sub site_html_rate_success {
# --------------------------------------------------------
# This routine determines how the rate success page will look like.



&html_print_headers;
print &load_template ('rate_success.html', {
%in,
%globals
});
}



sub site_html_rate_failure {
# --------------------------------------------------------
# This routine determines how the rate failure page will look like.



my ($errormsg) = shift;

&html_print_headers;
print &load_template ('rate_error.html', {
error => $errormsg,
%in,
%globals
});



}

########################################################################################
# THE FOLLOWING DETERMINES YOUR CATEGORY LISTING, IT'S NOT TEMPLATE BASED (YET)! #
########################################################################################



sub site_html_print_cat {
# --------------------------------------------------------
# This routine determines how the list of categories will look.
# We now use a table to split the category name up into two columns.
# For each category you can use the following variables:
#
# $url : The URL to go to that category
# $category_name : The category name with _ and / removed.
# $category_descriptions{$subcat}: The category description (if any).
# $numlinks : The number of links inside that category (and subcategories).
# $mod : The newest link inside of that category.
#



my (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);
my ($half) = int (($#subcat+2) / 2);

# Print Header.
$output = qq|<div class="margin"><table width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n|;

foreach $subcat (sort @subcat) {
($description) = @{$category{$subcat}}[2];

# First let's get the name, number of links, and last modified date...
$url = "$build_root_url/" . &urlencode($subcat) . "/";
if ($subcat =~ m,.*/([^/]+)$,) { $category_name = &build_clean($1); } else { $category_name = &build_clean($subcat); }
$numlinks = $stats{"$subcat"}[0];
$mod = $stats{"$subcat"}[1];



# We check to see if we are half way through, if so we stop this table cell
# and begin a new one (this lets us have category names in two columns).
if ($i == $half) {
$output .= qq|</td><td class="catlist" valign="top">\n|;
}
$i++;

# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<dl><dt><strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
$output .= qq|<dd><span class="descript">$description </span></dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|</dl>|;
}



# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
}



sub site_html_home_toplist{
# --------------------------------------------------------
# This routine will build a home page. It is not meant to have any
# links on it, only subcategories.
my $toplist=shift;
return &load_template ('toplisting.html', {
toplisting => $toplist
});
}



sub site_printer_friendly {
# --------------------------------------------------------
# This routine will creat a dynamic printer friendly page.
my %rec = @_;
return &load_template ('printerfriendly.html', {
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
%rec,
%globals
} );
}
1;
And here is the error:
Quote:
Undefined subroutine &main::get_date called at admin/site_html_templates.pl line 31.
[Fri Sep 6 18:09:08 2002] [error] [client 148.78.248.10] Premature end of script headers: /usr/local/etc/httpd/htdocs/tartsgcom/cgi-bin//db/print.cgi
Quote Reply
Re: [webwizzz] Printer-Friendly Print out Links 2.0 In reply to
First, notice in your error this address:
Quote:
Premature end of script headers: /usr/local/etc/httpd/htdocs/tartsgcom/cgi-bin//db/print.cgi


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Printer-Friendly Print out Links 2.0 In reply to
Hello, and thank you for your reply!

Right, I noticed it is in print.cgi but I don't understand thoughthe problem? I can't fix it?

David
Quote Reply
Re: [PerlFlunkie] Printer-Friendly Print out Links 2.0 In reply to
In Reply To:
First, notice in your error this address:
Quote:
Premature end of script headers: /usr/local/etc/httpd/htdocs/tartsgcom/cgi-bin//db/print.cgi
Quote Reply
Re: [stu2000] Printer-Friendly Print out Links 2.0 In reply to
Try the attached script.

Be aware thet you will have to change /full/path/ to your FULL physical path where your links.cfg file is located.

Also, you may need to change the PERL PATH in the first line of codes.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Stealth] Printer-Friendly Print out Links 2.0 In reply to
Well, there was more to my last post when I hit the 'post reply' button, but it dissappeared. From now on I will see what my posts look like after posting! Stealth said the same thing: in the links.cfg, the paths should not have trailing slashes (which is where your // came from), and it's agood idea to put the full path to links.cfg in avery .cgi or .pl script that call for it.

I will now see if this posts correctly...Frown


OK, it looked OK.Cool

Next question is for Stealth: In the printfriendly mod I looked at (referenced in my first post in this string), the script looks for markers in your text, which is how it knows to leave out certain sections (header, navigation, etc). Just what does the print.cgi you posted do?

Please don't be offended, just curious, as I am also looking into adding it to my site. Stealth, thanks for all the help you have provided in this forum, to myself and many others. These forums are a valuable resource for us Links tinkerers.


Leonard
aka PerlFlunkie

Last edited by:

PerlFlunkie: Sep 7, 2002, 12:28 PM
Quote Reply
Re: [PerlFlunkie] Printer-Friendly Print out Links 2.0 In reply to
Quote:

Just what does the print.cgi you posted do?


Could've been asked a little nicer. Like,"Out of curiousity, I am wondering what the script does?", even with the disclaimer you posted (after editing your post).

Basically, what "it does" is prints out the link information in an "alternative" format, like a print format.

To access the script, you simply put the following link in the link.html template:

Quote:

<a href="<%db_cgi_url%>/print.cgi?id=<%ID%>">Print View</a>


AFter clicking on the link, the script will query your links database and get the relevant information and then print out the data via the print template that you create, which is EXACTLY the same as the detailed.html, but you can remove header and footer and other junk in the page if you want to be a "printer-friendly" page.

Understand?
========================================
Buh Bye!

Cheers,
Me