#!/usr/bin/perl -w ############################################################################### # News Presenter; web based news board system. # # by Richard G Townsend # rtee@btinternet.com # Copyright 2000 - 2002 Richard G Townsend # $main::version = 2; $main::revision = '$Revision: 1.29 $'; # Script type: Commercial. # Script name: display.cgi. # OS : Unix # $Date: 2002/12/15 11:49:33 $ # ################## Copyright Richard G Townsend 2000 - 2002 ################## # # # *** All rights reserved. *** # # # # Selling or distributing this script without the express permission of # # Richard G Townsend (rtee@btinternet.com) or making any changes to it is # # forbidden and will be regarded as a breach of copyright. # # # # By using this script you agree to the above and to indemnify Richard # # G Townsend from any liability including merchantable quality. # # # ################################################################################ # # # DO NOT CHANGE ANYTHING IN THIS SCRIPT. # # # ################################################################################ # Unbuffer the output; $| = 1; # Get the current working dir and add it to @INC if($0 && $0 !~ /^config\.cgi$/i) { $main::cgi_path = $0; } elsif($ENV{'SCRIPT_FILENAME'} && $ENV{'SCRIPT_FILENAME'} !~ /cgiwrap/) { $main::cgi_path = $ENV{'SCRIPT_FILENAME'}; } elsif($ENV{'PATH_TRANSLATED'}) { $main::cgi_path = $ENV{'PATH_TRANSLATED'}; } $main::cgi_path =~ s/\/[^\/]*$// && unshift(@INC,$main::cgi_path); # Turn debugging on if(-e "../debug.pl") { require '../debug.pl'; } use CGI::Carp "fatalsToBrowser"; use strict; use Fcntl ':flock'; use CGI qw/:standard/; # Use the CGI module for parsing form input. use File::Copy; use NEWSP::keys; require 'NEWSP/ffdb.pl'; require 'NEWSP/common.pl'; print "Content-type: text/html\r\n"; print "Cache-Control: public, no-cache, must-revalidate\r\n"; print "\r\n"; CGI::ReadParse(*main::FORM); # Get the form data, GET or POST require "$main::FORM{'b'}.dat"; # Site config Variables use vars qw($base_dir $image_url $cgi_url $data_dir $nb_template $language $admin $board_name); if($language) { require "langs/$language.txt" or &html_die("Language file not found", "langs/$language.txt", __FILE__,__LINE__); use vars qw(%MSG @months @days); } else { require "langs/en.txt" or &html_die("Default language file not found", "langs/en.txt", __FILE__,__LINE__); use vars qw(%MSG @months @days); } ################################################################################ # Global vars $main::imageurl = "$image_url"; $main::datadir = "$base_dir/$data_dir/$main::FORM{'b'}"; $main::cfgdir = "$main::datadir/config"; $main::tmpltdir = "$main::datadir/templates"; $main::nb_html = "$main::datadir/templates/$nb_template"; $main::scripturl= "$cgi_url/display.cgi"; # Flags $main::header = 0; $main::exit = 1; # Errors are fatal # Main control if(defined($main::FORM{'c'})) { if ($main::FORM{'c'} eq 'r') { &print_article; } elsif($main::FORM{'c'} eq 'p') { &show_previous; } elsif($main::FORM{'c'} eq 'l') { &show_newsarea; } exit; } # Default action &display_newsboard; exit; #################### Sub Print Article ################## sub print_article { print &show_article($main::FORM{'a'}, 0); } #################### END Print Article ################## ################## Sub Display Newsboard ################ sub display_newsboard { my($ok, $advert, @db, %new_db, @new_db, @newspage, @newsarea_cfg, @temp); my($line, $area_name, $newsarea, $article_num, $dummy, $num_of_articles, $last); my($flag) = 1; # Read the newsboard.html open(NB, "$main::nb_html") or &html_die("$MSG{'err_nbtmp'}", "$main::nb_html", __FILE__,__LINE__); flock(NB, 1); @newspage = ; close(NB); chomp @newspage; foreach $line(@newspage) { # Find the newsarea markers if($line =~ s///) { $area_name = $1; # Get the news area name @db = &get_database($area_name); @new_db = reverse(@db); print "\n\n"; # Read the config for the news area. # Done this way as we don't want to exit if the config is missing. if(!(@newsarea_cfg = &get_newsarea_cfg($area_name))) { print "
$MSG{'err_nbcfg'}
\n"; next; } # Get the number of articles setting for this news area $num_of_articles = $newsarea_cfg[$knum_arts]; $flag = 1; foreach(@new_db) { ($article_num, $dummy) = split /\|/, $_; if($num_of_articles > 0) { print ""; # Format & print the article &make_nbentry($area_name, $article_num, @newsarea_cfg) or print "$MSG{'err_artmiss'}: $article_num\n"; $last = $article_num; # One article done so decrement the article count $num_of_articles--; print "\n"; $flag = 0; # No   needed } # If we've done all articles for this newsarea then exit the loop else { last; } } # If the number of articles for this news area is greater than the number set in the config # then add the 'Previous articles...' link to the archive page. if(@new_db > $newsarea_cfg[$knum_arts]) { print "

"; print ""; print &html_format("$MSG{'more'} ...", $newsarea_cfg[$ka_urlstyle]); print "

\n"; } print " \n" if $flag; # No articles for this area print "\n"; } #if($line =~ m/<\/body>/i) #{ #$advert = &go_back; #print $advert; #} print "$line\n"; } } ################## END Display Newsboard ################ ################ Sub Make Newsboard Entry ############### sub make_nbentry { my($area_name, $article_num, @newsarea_cfg) = @_; my($day_date) = ""; my($date, @article); # Read the article file @article = &get_article($area_name, $article_num) or return; # Format the date $date = &format_date($article[$kdate], $newsarea_cfg[$kd_ord], $newsarea_cfg[$kd_form]); # Format and print the headline, date and add image tags & links # Print day of the week print &html_format("$days[$article[$kdow]]", $newsarea_cfg[$kd_style]) if $newsarea_cfg[$kuse_dow]; # Print the date print &html_format(" $date", $newsarea_cfg[$kd_style]) if $newsarea_cfg[$kuse_date]; # Print the time print &html_format(" $article[$ktime]
", $newsarea_cfg[$kd_style]) if $newsarea_cfg[$kuse_time]; # Print the headline print &html_format($article[$kheadline], $newsarea_cfg[$khstyle]) if $newsarea_cfg[$kuse_h]; # Print the subtitle print &html_format($article[$ksubtitle], $newsarea_cfg[$ksubstyle]) if $article[$ksubtitle]; # Print the lead print &html_format($article[$klead], $newsarea_cfg[$klstyle]) if $newsarea_cfg[$kuse_l]; # Print the story print &html_format($article[$kstory], $newsarea_cfg[$ksstyle]) if $newsarea_cfg[$kuse_s]; # Print the authors name print &html_format($article[$knic], $newsarea_cfg[$knmstyle]) if $newsarea_cfg[$kuse_name]; # If we did not print the story then add a link print &html_format($article[$klink ], $newsarea_cfg[$kr_urlstyle])if (!($newsarea_cfg[$kuse_s])); print "$MSG{'read'}"; return(1); } ################# END Make Newsboard Entry ############### ############### Sub Show previous articles ############### sub show_previous { my(@db, @new_db, @archive, @archive_cfg); my($line, $newsarea, $article_num, $dummy, $go_back); my($i) = 0; my($last) = $main::FORM{'last'}; # Read the news database @db = &get_database($main::FORM{'area'}) or &html_die("$MSG{'err_opndb'}", "news.db", __FILE__,__LINE__); @new_db = reverse(@db); # Read the config for the history page @archive_cfg = &get_newsarea_cfg("archive") or &html_die("$MSG{'err_arccfg'}", "archive.cfg", __FILE__,__LINE__); # Read the archive.html open(TMP, "$main::tmpltdir/$archive_cfg[$ktmplt].html") or &html_die("$MSG{'err_arctmp'}", "$main::tmpltdir/$archive_cfg[$ktmplt].html", __FILE__,__LINE__); flock(TMP, 1); @archive = ; close(TMP); chomp @archive; $archive_cfg[$ktmplt] = $main::FORM{'t'}; foreach $line(@archive) { $line =~ s/DATE//; # Find the ARTICLES marker. if($line =~ s/ARTICLES//) { print "\n\n"; foreach(@new_db) { ($article_num, $dummy) = split /\|/, $_; if($article_num <= $last-1) { $i++; print "\n"; } $article_num--; # If the number of articles for this news area is greater than the number set in # the archive config then add the 'Previous articles...' link. if($i == $archive_cfg[$knum_arts]) { print "\n"; last; } } print "
"; # Format and print the article &make_nbentry($main::FORM{'area'}, $article_num, @archive_cfg) or print "$MSG{'err_artmiss'}: $article_num\n"; $last = $article_num; print "
"; print ""; print &html_format("$MSG{'more'} ...", $archive_cfg[$ka_urlstyle]); print ""; print "
\n"; } if($line =~ m/<\/body>/i) { $go_back = &go_back; print $go_back; } print "$line\n"; } } ############### Sub Show previous articles ############### ################### Sub Show newsarea #################### # This routine should work as a SSI. sub show_newsarea { my($num_of_articles, $num_cpy, @db, @new_db, @ssi_cfg); my($article_num, $date, $dummy, $last); my($flag) = 1; # Read the news database @db = &get_database($main::FORM{'area'}) or &html_die("$MSG{'err_opndb'}", "$main::FORM{'area'} db", __FILE__,__LINE__); @new_db = reverse(@db); # Read the config for the news area # Don't exit if the config is missing. @ssi_cfg = &get_newsarea_cfg($main::FORM{'area'}) or print "$MSG{'err_nbcfg'}
"; # Any config specified in the ssi command is used instead of # the news area config settings. (1 = off 2 = on) $ssi_cfg[$kuse_h] = ($main::FORM{'sh'} - 1) if $main::FORM{'sh'}; $ssi_cfg[$kuse_l] = ($main::FORM{'sl'} - 1) if $main::FORM{'sl'}; $ssi_cfg[$kuse_s] = ($main::FORM{'ss'} - 1) if $main::FORM{'ss'}; $ssi_cfg[$kuse_name] = ($main::FORM{'nm'} - 1) if $main::FORM{'nm'}; $ssi_cfg[$ktmplt] = ($main::FORM{'t'} - 1) if $main::FORM{'t'}; # Get the number of articles setting for this news area, if 'x' is set then use # 'x' else use the news area config. $num_of_articles = ($main::FORM{'x'}) ? $main::FORM{'x'} : $ssi_cfg[$knum_arts]; $num_cpy = $num_of_articles; print "\n\n"; foreach (@new_db) { ($article_num, $dummy) = split /\|/, $_; if($num_of_articles > 0) { print "\n"; $flag = 0; } else { last; } } if($flag) { print "\n"; } # No articles for this area # If the number of articles for this news area is greater than the number set in the SSI # or the news area config then add the 'Previous articles...' link. if(@new_db > $num_cpy) { print "\n"; } print "

"; # Format & print the article &make_nbentry($main::FORM{'area'}, $article_num, @ssi_cfg) or print "$MSG{'err_artmiss'}: $article_num\n"; $last = $article_num; # One article done so decrement the article count $num_of_articles--; print "

 
"; print ""; print &html_format("$MSG{'more'} ...", $ssi_cfg[$ka_urlstyle]); print ""; print "
\n"; } #################### END Show newsarea ################### # END OF FILE