package Base::HTML; use strict; use warnings; use base 'Exporter'; our @EXPORT_OK = qw(start_html end_html print_story print_select); use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use Cwd; use File::Basename; use File::Find; use HTML::Entities qw(encode_entities); use List::Util qw(first); use URI::Encode qw(uri_encode); use lib ".."; use Base::Menu qw(push_file print_menu); use Base::Nifty qw(get_hash article_sort name_sort my_sort line); use Base::Roots qw(root_directory get_data root print_styles email file_text); my $full_path = cwd.'/'.basename($0); my $rootdir = root_directory; my $rootlink = root('link'); my $heading = file_text(basename($0)) ne 'index' ? file_text(basename($0)) : 'Home'; my $current_directory = cwd; $current_directory =~ s!$rootdir(/|)!!; my $title = join(' - ',((root('name'),map(ucfirst,split(/\//,$current_directory))),$heading)); $title =~ s/_/ /g; my $user = root('user'); my %off_site; my %off_site_data = ( csv => get_data('Base','other_sites.csv'), headings => [qw(site link)], ); get_hash(\%off_site,\%off_site_data); #Once the site is fully coded, the directory exclusions will be shorter. my %exclusions = ( directories => [qw(cgi-bin error files games personal), "Fiction/Erotic_fiction/unfinished", "Movies/Movie miscellany", "role_playing/X-Men"], file_types => [qw(pl shtml)], file_names => [qw(ssi form sitemap menu textbox thankyou evansstore)], ); my @files; sub wanted { my $directories = join '|', @{$exclusions{directories}}; my $file_types = join '|', @{$exclusions{file_types}}; my $file_names = join '|', @{$exclusions{file_names}}; my $text = $File::Find::name; $text =~ s!$rootdir/!!; if ( -f && $text =~ m!\.($file_types)$! && $text !~ m!^($directories)! && $text !~ m!\b($file_names)!) { push @files, $text; } return; } find(\&wanted, "$rootdir"); my %site; for my $file (@files) { push_file(\%site, $file); } #print_select prints out a selection box in html using a hash to get the options. sub print_select { my ($action,%options) = @_; line(2,qq{
}); line(3,qq{
}); line(4,qq{Display only…}); for my $select (sort keys %options) { my $options = $options{$select}; line(4,qq{}) } line(4,qq{}); line(4,qq{
Start over
}); line(3,qq{
}); line(2,qq{
}); } #start_html is where the printing of the html output of every module/script begins. This is the template of my site. sub start_html { my ($defined_heading) = @_; print "content-type: text/html \n\n"; line(0,qq{}); line(0,qq{}); line(0,qq{}); line(1,qq{$title}); print_styles(); line(1,qq{}); line(0,qq{}); line(0,qq{}); line(1,qq{
}); line(2,qq{

Site menu

}); print_menu(3,\%site,$rootdir,$rootlink,qq{ onclick="list_onclick(event)"},'no'); line(2,"

".root('user')." off-site

"); line(3,qq{}); line(1,qq{
}); line(1,qq{
}); if ($defined_heading eq 'no') { line(2,qq{


}); } } #end_html is where the printing of the html output of every module/script ends. This is the last part of the template. sub end_html { line(2,qq(

Contact ).email.qq(!

)); line(1,qq{
}); line(0,qq{}); line(0,qq{}); } #print_story is for pure text pages without any other formatting required. There may be a few stray tags in the __DATA__ , #but not many hopefully. More than 6 or so, and I would write a new script for the page. sub print_story { my ($source) = @_; start_html('no'); while (my $line = <$source>) { chomp $line; if ($line =~ m/^$line

)); } } line(3,qq(

written by $user

)); end_html; } 1;