#!/usr/bin/perl -wT # # footer.cgi -- create "next" and "previous" links for Thursday Report articles. # # 2000/10/10 Rich Lafferty -- initial version # 2001/03/14 Rich Lafferty -- account for entities in REQUEST_URI (and output entities # while we're at it) # # Use: include at bottom of each Thursday Report article. For example: # # # # We assume that articles are found in directories of form NN-XXXXX/index.shtml where # NN is a two-digit number (padded with initial zeros if necessary) indicating # the position of the article in the issue (with article 01 being first), # and XXXXX being text suggesting the subject of the article. ## use strict; use CGI qw(:standard); use URI::Escape; sub aindex ($@) { my $grep_for = shift; my @grep_in = @_; for my $i (0 .. $#grep_in) { return $i if $grep_in[$i] eq $grep_for; } } print header(); my $uri = uri_unescape($ENV{REQUEST_URI}); $uri =~ m|(.*?)/[^/]+/[^/]*$|; my $issue = $1; $uri =~ m|([^/]+)/[^/]*$|; my $article = $1; opendir(ISSUE, $ENV{DOCUMENT_ROOT} . $issue) or die "Can't open dir $issue: $!"; my @issuedir; { my @tmpdir; while (my $dir = readdir(ISSUE)) { push @tmpdir, $dir if $dir =~ /^\d\d-/; } @issuedir = sort @tmpdir; } closedir ISSUE; my $aindex = aindex($article, @issuedir); my $prevlink; if ($aindex == 0) { $prevlink = $issue; } else { $prevlink = "$issue/" . $issuedir[$aindex - 1]; } my $nextlink; if ($aindex == $#issuedir) { $nextlink = $issue; } else { $nextlink = "$issue/" . $issuedir[$aindex + 1]; } print <<__EOT__;
-- |
Concordia's
Thursday Report
|
-- | -- |
© Copyright 2000 Concordia University |