#!/usr/bin/perl -w # ********************************************** blog.cgi *********************************************** # *** TEMPLATE REQUIREMENTS *** # The template file should have the following, each on a line by itself at the start of the line: # BODY - The actual body of the site # # **************************************** Configuration Section **************************************** my $template = 'template.html'; # HTML filename in current directory to # use as template for results # ************************************** End Configuration Section ************************************** # script proper begins... use CGI qw(:standard); use strict; use DBI; my $navhtml; # The HTML for the navigation section my $bodyhtml; # The HTML for the body of the site my $database = "cactus_main"; my $hostname = "localhost"; my $username = "cactus_bblog"; my $password = "bblog"; my $prevCatName = ""; my $numEntriesPerPage = 5; my $firstEntryNum = 0; foreach my $entrystart (@ARGV) { $firstEntryNum = $entrystart; } my ($querystring, $db, $query); ######## Generate the Body HTML ######## $querystring = "SELECT title, body, FROM_UNIXTIME(posttime, '%M %d, %Y'), modifier, sections " . "FROM bB_posts " . "WHERE status = 'live' " . "ORDER BY posttime DESC " . "LIMIT $firstEntryNum, $numEntriesPerPage"; # Connect To Database $db = DBI->connect("DBI:mysql:$database:$hostname", $username, $password); # Execute a Query $query = $db->prepare($querystring); $query->execute; my $count = 0; $bodyhtml .=""; # Storing Results while (my @array = $query->fetchrow_array) { my $sectionnum = $array[4]; my $modifier = $array[3]; my $entryDate = $array[2]; my $entryBody = $array[1]; my $entryTitle = $array[0]; my $picName = ""; $sectionnum =~ s/\://g; if ($modifier eq 'simple') { # Make the whole thing a paragraph $entryBody = '

' . $entryBody . '

'; # Then replace any double newlines with single newlines $entryBody =~ s/\n\n/\n/g; # Then replace any single newlines with

\n

to seperate paragraphs $entryBody =~ s/\n/ <\/p>\n

/g; # Dispose of any empty paragraphs $entryBody =~ s/

<\/p>\n//g; # Catch and linkify any urls $entryBody =~ s/(www\.[\S]*\.[\S]*)/$1<\/a>/g; # Add a final newline so the html won't look so ugly $entryBody = $entryBody . "\n"; } $bodyhtml .="

"; $bodyhtml .= ""; $bodyhtml .= ""; # $bodyhtml .=""; # $bodyhtml .= ""; # $bodyhtml .= ""; $bodyhtml .= ""; $bodyhtml .= ""; $bodyhtml .=""; for (my $i = 0; $i < 2; $i++) { $bodyhtml .= ""; $bodyhtml .= ""; $bodyhtml .=""; } $count++; } $bodyhtml .="
"; $bodyhtml .= "

$entryTitle

"; $bodyhtml .= "
"; # $bodyhtml .= "     $entryDate"; # $bodyhtml .="
"; $bodyhtml .= "$entryBody"; $bodyhtml .="
"; $bodyhtml .= " "; $bodyhtml .="
"; # Cleaning Up $query->finish; $db->disconnect; $bodyhtml .= ""; $bodyhtml .= ""; $bodyhtml .= ""; $bodyhtml .= "
"; if ($firstEntryNum > ($numEntriesPerPage - 1)) { my $navnum = $firstEntryNum - $numEntriesPerPage; $bodyhtml .= '<-- Newer Entries'; } $bodyhtml .= ""; if ($count == $numEntriesPerPage) { my $navnum = $firstEntryNum + $numEntriesPerPage; $bodyhtml .= 'Older Entries -->'; } $bodyhtml .= "
"; ######## End of generating the Body HTML ######## # Output the actual HTML print header; open IN, $template or die "Can't open html for reading: $!\n"; while (my $line = ) { $line =~ s/NEWSHERE/$bodyhtml/; print $line; } close IN;