Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Detail pages on the fly with static site

Quote Reply
Detail pages on the fly with static site
This is something I've been meaning to do for awhile. I want to dynamically generate my detail pages on some sites, where the build takes 10 minutes for pages that no one ever looks at.

Premise: I want to use a standard detailed.html file, and auto-generate it (like Search or Add) with none of the paths turned into dynamic stuff.

So, I cut page.cgi apart, and got the following script.

Cut the following script, call it detailed.cgi, and you call it by:

detailed.cgi?ID=nnn

instead of using a hard-link or jump.cgi to call the detailed page (if you were using my modified jump.cgi) use detailed.cgi?ID=<%ID%> instead. It even works with page.cgi sites... though why you'd want to do that, I don't have a clue <G>

--------
Code:
#!/usr/bin/perl
# ==============================================================
# -------------
# Links SQL
# -------------
# Links Manager - detailed.cgi
# Generate detailed pages on the "fly" with a STATIC site!!
#
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Web: http://www.gossamer-threads.com/
# Base Version: 1.13 Modified 10/20/00 by PUGDOG Enterprises, Inc.
#
# COPYRIGHT NOTICE:
#
# Copyright 1999 Gossamer Threads Inc. All Rights Reserved.
# No redistribution of this script may be made without prior
# written consent.
#
# By using this program you agree to indemnify Gossamer Threads
# Inc. from any liability.
#
# Please see the README for full license details.
#
# ==============================================================

# Load required modules.
# ---------------------------------------------------
use CGI ();
use CGI::Carp qw/fatalsToBrowser/;
use lib 'admin';
use Links;
use Links::DBSQL;
use Links::DB_Utils;
use Links::HTML_Templates;
use strict;
use vars qw!$LINKDB $CATDB $GRAND_TOTAL $USE_HTML!;
&main;
# ==============================================================

sub main {
# --------------------------------------------------------------
# Wrap in a subroutine to prevent possible mod_perl probs.
#
my $in = new CGI;
my $id;

# Create our database objects.
$LINKDB = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Links.def";
$CATDB = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Category.def";
$GRAND_TOTAL = $LINKDB->total();

# Make sure we set dynamic mode off.
$in->param('d' => undef);
$in->param('g' => undef);

$id = $in->param('ID');

if ($id) {
&generate_detailed_page ($in);
} else {
print $in->header();
&site_html_error ( { error => "Sorry, I'm not sure what link you are asking for: '$id'" });
}
}

sub generate_detailed_page {
# --------------------------------------------------------
# This routine build a single page for every link.
#
my $in = shift;
my ($id, $link, $category, $title_linked, $total, $output, $detail_match);

$id = $in->param('ID');

if (!$id) {
print $in->header();
&site_html_error ( { error => "Sorry, I'm not sure what link you are asking for: '$id'" }, $in);
return;
}

$link = $LINKDB->get_record ($id, 'HASH');

if (!$link) {
print $in->header();
&site_html_error ( { error => "Sorry, we don't seem to have link '$id'" }, $in);
return;
}
$category = $CATDB->get_record ($link->{'CategoryID'}, 'HASH');
$title_linked = &build_linked_title ($category->{'Name'} . "/" . $link->{'Title'});

###########################################################################################################
## taken from jump.cgi to track hits to detail pages!
my $sth = $LINKDB->prepare ("SELECT 1 FROM Hits_Track WHERE LinkID = $id AND IP = '$ENV{'REMOTE_ADDR'}'");
$sth->execute();
if (! $sth->rows) { ## if the record isn't already in the HitsTrack table
$sth = $LINKDB->prepare ("SELECT 1 FROM Build_Update WHERE LinkID = $id");
$sth->execute();
($sth->rows) ?
$LINKDB->do ("UPDATE Build_Update SET Hits = Hits + 1 WHERE LinkID = $id") :
$LINKDB->do ("INSERT INTO Build_Update (LinkID, Hits, Votes, Rating) VALUES ($id, 1, 0, 0)");
$LINKDB->do ("INSERT INTO Hits_Track (LinkID, IP) VALUES ($id, '$ENV{'REMOTE_ADDR'}')");
}
###########################################################################################################

print $in->header();
print &site_html_detailed ($link, { grand_total => $GRAND_TOTAL, title_linked => $title_linked });
}
PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Detail pages on the fly with static site In reply to
Yea...I have a similar script on my site...yet, it pulls data from three tables: Category, Links, Users.

Thanks for posting the script though...it may be quite useful for other Links SQL users.

Regards,

Eliot Lee

Quote Reply
Re: Detail pages on the fly with static site In reply to
Thanks, Pugdog. That does look like a useful addition.

There may be other more efficient ways of copying large blocks of code from this forum (w3t formats the copied text as being all one line), but this works for anyone struggling with it: View the source code and copy the appropriate section, then do a find and replace, replacing
tags with a hard enter. Not all editors allow multi-line replacements (needed for the hard enter to serve its purpose), but the Arachnophilia HTML editor is one that does so quite nicely.

Hope that little hint helps someone along the way. Smile

Dan

Quote Reply
Re: Detail pages on the fly with static site In reply to
Yeah, copying the lines is a problem.... but I've found sometimes that pasting to Notepad will preserve the line-ends. (Sometimes it won't).

It would be nice if we could have a "textarea" display box, for code.

Maybe that will be something Alex will add in.



PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Detail pages on the fly with static site In reply to
Pugdog:

Great Idea. I hadn't thought about it, but now that you have posted it, I see how worthwhile it is. Thanks!

Did not realize PugdogŪ was registered... I will try to refer to you with the symbol in the future. (Or maybe just as "The webmaster formerly none as Pugdog...") ;)

Thanks again!

Dave

Quote Reply
Re: Detail pages on the fly with static site In reply to
Oh: I forgot!

When I went to snag the code, I remembered the earler topic of how to snag the code- formated- from this site. Here is what I do...

I use IE, so I just hit the edit button at the top of the browser, send it to Frontpage, then cut it out of there into my web editor. I do not know if that is more or less work.... but it works!

Regards!

dave

Quote Reply
Re: Detail pages on the fly with static site In reply to
More work if you ask me. Wink

Regards,

Eliot Lee
Quote Reply
Re: Detail pages on the fly with static site In reply to
In Reply To:
I use IE, so I just hit the edit button at the top of the browser
Isn't that referring to the old method when this forum was UBB? W3T doesn't allow you to view or click on an edit link for someone else's post, as far as I know...

Dan

Quote Reply
Re: Detail pages on the fly with static site In reply to
Pugdog:

Try this (if you have it) it works fine. Save the page to your hard drive, load it up in MS Word (stays as HTML) and then save it in ascii.txt format with line breaks. Takes a couple of minutes and works like a charm!

ALSO, on page.cgi - I use .shtml as I use SSI extensively. It appears as though page.cgi will not work with the SSI extension. It leads me around the garden path when I try to use it.

Any suggestions?

BTW - will detailed.cgi work with LinksSQL NG? I am impressed with it!

All the best,


Clint.

--------------------------
http://www.AffiliatesDirectory.com - Affiliate Programs Directory
Quote Reply
Re: Detail pages on the fly with static site In reply to
Clint...as far as getting the SSI's you want to use working, you could extend the SSI script(s) to update to a seperate storage file whenever additions/modifications are made by that SSI, then use <%include /path/2/ssi_file.txt%> it's the only way I could figure it, but I couldn't find ways to extend all the SSI's to do it (Banners, etc...). It Would be nice if there was a perl module (cgi.pm style) that could parse included SSI routines into a cgi script [&ssi_into_cgi($ssi_script)]. But until then this is probably the only way to get them working together; besides because of the output and the handling method differences between CGI and SSI I don't see it as being possible.

Quote Reply
Re: [Clint] Detail pages on the fly with static site In reply to
I have another way to get code from the forums...

Just click on 'Quote' (at the top of the post) and copy the code from the textbox that is designed for replies.

That way all the text formatting is saved and then just paste it to Notepad or another app.

:) Hope that helps someone out!

-digitalsea
http://www.digital-sea.com/