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


Subject Author Views Date
Thread Detail pages on the fly with static site pugdog 14291 Oct 20, 2000, 2:13 PM
Post Re: Detail pages on the fly with static site
Stealth 13979 Oct 20, 2000, 5:16 PM
Thread Re: Detail pages on the fly with static site
Dan Kaplan 13992 Oct 21, 2000, 2:53 PM
Thread Re: Detail pages on the fly with static site
pugdog 13980 Oct 22, 2000, 11:44 AM
Thread Re: Detail pages on the fly with static site
Clint 13908 Nov 19, 2000, 6:49 AM
Post Re: Detail pages on the fly with static site
phoule 13885 Nov 19, 2000, 10:20 AM
Post Re: [Clint] Detail pages on the fly with static site
digitalsea 13673 Aug 1, 2003, 1:52 PM
Post Re: Detail pages on the fly with static site
carfac 13957 Oct 23, 2000, 8:03 PM
Thread Re: Detail pages on the fly with static site
carfac 13931 Oct 23, 2000, 8:09 PM
Post Re: Detail pages on the fly with static site
Stealth 13952 Oct 23, 2000, 8:13 PM
Post Re: Detail pages on the fly with static site
Dan Kaplan 13944 Oct 24, 2000, 12:44 AM