#!/usr/bin/perl -w use strict; # Program Name: musings.cgi # Description of Program: # This is a Perl script which creates the page # for viewing a list of my web log entries. # set libraries, scripts, & paths require './library/main.pl'; require './library/musings.pl'; my $scripts = &get_script_variables(); # main.pl # capture user input my $musing_id = param('musing_id') || ''; my $ref_id = param('ref_id') || ''; # musing category # reroute user to musing if given an id if($musing_id =~ m|\d|g) { print redirect($scripts->{'musing'}->{'script'} . '?musing_id=' . $musing_id); exit; } if(!$ref_id) { # if no category requested, $ref_id = 'all'; # select all categories } # get web log entries and related info from MySQL my $entries = &get_musings_entries($musing_id,$ref_id); # musings.pl my $comment_cnt = &get_comments_count(); # musings.pl my $musing_stats = &get_reader_stats(); # musings.pls my $musing_cats = &get_musings_categories(); # musings.pls # get general text for web page from MySQL my $genl_text = &get_general_text('musings',1); # center.pl my ($pg_head,$pg_text,$pg_image) = @{$genl_text->[0]}; my $n = "\015\012"; # start web page &heading('musing',undef,$pg_head,undef,$pg_text); # header.pl # left margin &panel_start(1); # main.pl &fiction(); # left_margin.pl &miscellany(); # left_margin.pl &musings_sites(); # left_margin.pl &panel_end(); # main.pl # center panel of web page &panel_start(2); # main.pl # display page heading print start_div({id=>'page_heading'}), $n; if($musing_id =~ /[a-z]/ && $musing_id ne 'all') { my $cat_head = ucfirst($musing_cats->{$musing_id}->{'ref_name'}); $pg_head = $cat_head . $pg_head; my $sub_genl_text = &get_general_text('musing_cat',1); # center.pl my ($sub_pg_head,$sub_pg_text) = @{$sub_genl_text->[0]}; $pg_text = $sub_pg_text; &page_heading($pg_head,$pg_text,undef); # center.pl } else { &page_heading($pg_head,$pg_text,undef); # center.pl } print end_div(), $n,$n; # end div#page_heading # display web log entries foreach (@$entries) { my ($entry_id, $ref_id, $log_head, $entry, $entry_date) = @$_; my $category = lc($musing_cats->{$ref_id}->{'ref_name'}); my $count = $comment_cnt->{$entry_id}->{'comment_cnt'} || 'no'; my $reader_stat = $musing_stats->{$entry_id}->{'stat'}; $entry_date = lc($entry_date); print div({class=>'content_item'}, $n, div({class=>'musing_abstract'}, $n, h3( a({href=>$scripts->{'musing'}->{'script'} . '?musing_id=' . $entry_id}, $log_head) ), $n, span($entry), $n ), $n, div({class=>'item_stats'}, $n, qq|posted: $entry_date ;  readers: $reader_stat |, $n, a({id=>'comment_notation', href=>$scripts->{'musing'}->{'script'} . '?musing_id=' . $entry_id}, $count, 'comments; '), $n, 'category: ', a({id=>'comment_notation', href=>$scripts->{'musings'}->{'script'} . '?ref_id=' . $ref_id}, $category) ), $n ), $n,$n; } &panel_end(); # main.pl # right margin &panel_start(3); # main.pl &display_page_image($pg_image); # right_margin.pl &get_display_category_data(); # musings.pl &stats_musings(); # right_margin.pl &panel_end(); # main.pl &footer(); # main.pl exit; #### sub get_musings_entries { # get musings from MySQL my ($musing_id,$ref_id) = @_; if($ref_id && $ref_id eq 'all') { $sql_stmnt = qq|SELECT musing_id, ref_id, heading,abstract, DATE_FORMAT(entry_date, '%M %e, %Y') FROM musings ORDER BY entry_date DESC|; } elsif($ref_id) { $sql_stmnt = qq|SELECT musing_id, ref_id, heading, abstract, DATE_FORMAT(entry_date, '%M %e, %Y') FROM musings WHERE ref_id = '$ref_id' ORDER BY entry_date DESC LIMIT 10|; } else { $sql_stmnt = qq|SELECT musing_id, ref_id, heading, entry, DATE_FORMAT(entry_date, '%M %e, %Y') FROM musings WHERE musing_id = '$musing_id'|; } $sth = $dbh->prepare($sql_stmnt); $sth->execute(); my $entries = $dbh->selectall_arrayref($sql_stmnt); $sth->finish(); return $entries; }