#!/usr/local/bin/perl # ------------- # Links # ------------- # Links Manager # # File: nph-build.cgi # Description: Builds a set of HTML pages from the template directory. This is a # non parsed header script, and should display the output directly as it may # take quite a while to perform. It can also be called from the # command line or via a cron routine. Read the README for more details. # Author: Alex Krohn # Email: [url "mailto:alex@gossamer-threads.com"]alex@gossamer-threads.com[/url] # Web: [url "http://www.gossamer-threads.com/"]http://www.gossamer-threads.com/[/url] # Version: 2.01 # # (c) 1998 Gossamer Threads Inc. # # This script is not freeware! Please read the README for full details # on registration and terms of use. # ===================================================================== # # # Required Librariers # -------------------------------------------------------- eval { ($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX / ($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \ require "links.cfg"; # Change this to full path to links.cfg if you have problems. require "$db_lib_path/db_utils.pl"; require "$db_lib_path/links.def"; $build_use_templates ? require "$db_lib_path/site_html_templates.pl" : require "$db_lib_path/site_html.pl"; use vars qw(%category %subcategories @links @new_links @cool_links @pick_links %stats $grand_total $use_html $nph $date $time); }; if ($@) { print "HTTP/1.0 200 OK\n"; print "Content-type: text/plain\n\n"; print "Error including libraries: $@\n[/url]"; print "Make sure they exist, permissions are set properly, and paths are set correctly."; exit; } # ======================================================== eval { &main; }; # Trap any fatal errors so the program hopefully if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page. exit; # There are only two exit calls in the script, here and in in &cgierr. sub main { # -------------------------------------------------------- # $|++; $use_html = 0; $ENV{'REQUEST_METHOD'} and $use_html++; $use_html and (%in = &parse_form); # Either build the whole directory, parts of it, or just the new/popular section. if ($use_html) { if ($in{'staggered'}) { &build_staggered; } else { &build_all; } } else { &build_all; } } sub build_staggered { # -------------------------------------------------------- # Builds the directory in steps. # $nph++; &html_print_headers() if ($use_html); my %steps = ( 1 => 'Updating New and Popular Records and rebuilding URL database', 2 => 'Rebuilding Category Pages', 3 => 'Building Detailed View Pages', 4 => 'Updating Home/New/Cool Pages' ); my $step = $in{'step'} || 1; my $limit = $in{'limit'} || 20; my $offset = $in{'offset'} || 0; my $auto = $in{'auto'} || 0; my $start = time(); my $date = &get_date; my $time = &get_time; my $header = qq~ Rebuilding Directory -- Phase $phase ~; my $sub_head = qq~

Building Pages

Step: $steps{$step}

Pages built on $date at $time
-------------------------------------------------------- 


~;
    CASE: { 

        ($step == 1) and do {
                print $header;
                print qq~~ if ($auto);
                print $sub_head; 

                my $t1 = time();
                print "Backing up database . . .\n";
                    &build_backup;
                print "Done (", time - $t1, " s)\n\n"; 

                $t1 = time();
                print "Building URL Index . . .\n";
                    &build_url_index;
                print "Done (", time - $t1, " s)\n\n"; 

                print "Updating New and Popular Records . . .\n";
                $t1 = time();
                    &build_update_newpop;
                print "Done (", time - $t1, " s)\n\n"; 

                print "Updating ratings .. \n";
                    $t1 = time();
                    &build_update_ratings;
                print "Done (", time - $t1, " s)\n\n"; 

                my $elapsed = time() - $start;
                print "------------------------------------------------\n";
                print "Step 1 took $elapsed seconds.\n\n";
                print qq~

On to Step 2

~; last CASE; }; ($step == 2) and do { my @category_list = &category_list; my $i; print $header; if ($auto) { ($offset > $#category_list) ? (print qq~~) : (print qq~~); } print $sub_head; print "Rebuilding Categories $offset -> ", $offset + $limit - 1, ".\n\n"; for ($i = $offset; $i <= $offset + $limit -1; $i++) { last unless ($category_list[$i] =~ /\w+/); %category = (); %subcategories = (); @links = (); @new_links = (); @cool_links = (); @pick_links = (); %stats = (); $grand_total = 0; my $t1 = time(); print "** Building Category: $category_list[$i] ... \n"; &build_single_category ($category_list[$i]); print "** Done (", time - $t1, " s)!\n\n"; } $offset = $offset + $limit; my $elapsed = time() - $start; print "------------------------------------------------\n"; print "This phase of step 2 took $elapsed seconds.\n\n"; ($offset > $#categories) ? print qq~

Go on to Step 3!

~ : print qq~

Next $limit Categories!

~; last CASE; }; ($step == 3) and do { print $header; print qq~~ if ($auto); print $sub_head; if ($build_detailed) { my $t1 = time(); print "Generating detailed view pages . . . \n"; &build_detailed_view; print "** Done (", time - $t1, " s)!\n"; } else { print "Detailed Building is not turned on -- Skipping!\n\n"; } my $elapsed = time() - $start; print "------------------------------------------------\n"; print "Step 3 took $elapsed seconds.\n\n"; print qq~

Go on to Step 4!

~; last CASE; }; ($step == 4) and do { print $header, $sub_head; my $t1 = time(); print "** Loading Category information . . .\n"; &build_category_information; print "** Done (", time - $t1, " s)!\n\n"; $t1 = time(); print "** Loading Summary information . . .\n"; &build_stats (1); print "** Done (", time - $t1, " s)!\n\n"; $t1 = time(); print "** Creating Home Page . . .\n"; &build_home_page; print "** Done (", time - $t1, " s)!\n\n"; $t1 = time(); print "** Creating What's New Pages . . .\n"; &build_new_page; print "** Done (", time - $t1, " s)!\n\n"; $t1 = time(); print "** Creating What's Cool Page. . .\n"; &build_cool_page; print "** Done (", time - $t1, " s)!\n\n"; $t1 = time(); print "** Creating Pick Page . . .\n"; &build_pick_page; print "** Done (", time - $t1, " s)!\n\n"; $t1 = time(); print "** Creating Top Rated Page. . .\n"; &build_rate_page; print "** Done (", time - $t1, " s)!\n\n"; $t1 = time(); print "** Creating Top Sites in Affliates Categories. . .\n"; &build_topaffliate_x; print "** Done (", time - $t1, " s)!\n\n"; $t1 = time(); print "** Creating Category Top Entries . . .\n"; &build_top_x;print "** Done (", time - $t1, " s)!\n\n"; my $elapsed = time() - $start; print "------------------------------------------------\n"; print qq~Step 4 took $elapsed seconds.\n\nYour site is now up to date!~; last CASE; }; &cgierr("Unkown step: $step."); }; } sub build_all { # -------------------------------------------------------- # Rebuild the entire directory. # Determine if we are printing to command line, or to browser. $nph++; &html_print_headers() if ($use_html); my $start = time(); my $date = &get_date; my $time = &get_time; # Print HTML Header $use_html ? print qq|Links Manager: Building Pages

Building Pages

| :
        print qq|Building Pages\n|;
    print "Pages built on " . $date . " at " . $time . "\n";
    print "--------------------------------------------------------\n\n"; 

# Backup the database.
    print "Backing up database . . .\n";
    &build_backup;
    print "Done.\n\n"; 

# Rebuild URL Index (This file is auto-generated, you will never need to touch it!
    print "Building URL Index . . .\n";
    &build_url_index;
    print "Done.\n\n";
 
# Rebuild DOWNLOADURL Index (This file is auto-generated, you will never need to touch it! 
 print "Building DOWNLOAD URL Index . . .\n"; 
 &build_download_url_index; 
 print "Done.\n\n";  

# Update New and Popular Records..
    print "Updating New and Popular Records . . .\n";
    &build_update_newpop;
    print "Done.\n\n"; 

# Update voting information ..
    print "Updating ratings .. \n";
    &build_update_ratings;
    print "Done.\n\n"; 

# Load Category Information
    print "Loading Category Information . . .\n";
    &build_category_information;
    print "Done.\n\n"; 

# Generate some stats for future pages...
    print "Gathering Category and Link information . . .\n";
    &build_stats;
    print "Done\n\n"; 

# Create Category Select List if appropriate
  if (@exclude_categories) {
    print "Building Category Select List . . .\n";
    &build_category_select_list;
    print "\tDone\n\n";
  }
  else {
    print "No Categories to Exclude\n";
    print "Category Select List not built\n";
    print "Default category list will be used\n\n";
  } 

# Generate detailed view pages.
    if ($build_detailed) {
        print "Generating detailed view pages . . . \n";
        &build_detailed_view;
        print "Done\n\n";
    }
# Create Home Page
    $use_html ?
        print qq|Building Home Pages . . .\n| :
        print qq|Building Home Page . . .\n|;
    &build_home_page;
    print "\tDone\n\n"; 

# Create What's New Page
    $use_html ?
        print "Building What's New Page . . .\n" :
        print "Building What's New Page . . .\n";
    &build_new_page;
    print "Done\n\n"; 

# Create What's Cool Page
    $use_html ?
        print "Building What's Cool Page . . .\n" :
        print "Building What's Cool Page . . .\n";
    &build_cool_page;
    print "Done\n\n"; 

# Create Pick Page
    $use_html ?
        print "Building Picks Page . . .\n" :
        print "Building Picks Page . . .\n";
    &build_pick_page;
    print "Done\n\n"; 

# Create Top Rated Page
    $use_html ?
        print "Building Top Rated Page . . .\n" :
        print "Building Top Rated . . .\n";
    &build_rate_page;
    print "Done\n\n";
 
 # Create Top Sites in Affliate Category 
 print "Building Top Sites in Affliated Category . . .\n"; 
 &build_topaffliate_x; 
 print "Done\n\n"; 


# Create Category Top Entries
    print "Building Category Top Entries . . .\n";
    &build_top_x;
    print "Done\n\n"; 

# Create Category Pages
    print "Building Category Pages . . .\n";
    &build_category_pages;
    print "Done\n\n"; 

# We are finished!
    print "Pages Built (", time() - $start, " s)!";
    print "
" if ($use_html); } sub build_backup { # -------------------------------------------------------- # Backs up important database files. # my $date = &get_date; if (-e "$db_script_path/backup/$date.links.db") { print "\tBackup exists for today.. Skipping\n"; return; } # Try to do it the right way.. eval { require File::Copy; }; if (!$@) { print "\tBacking up links, category, email and url database (File::Copy) ... \n"; &File::Copy::copy ("$db_script_path/data/links.db", "$db_script_path/backup/$date.links.db") or &cgierr ("Unable to copy links backup. Reason: $!"); &File::Copy::copy ("$db_script_path/data/categories.db", "$db_script_path/backup/$date.category.db") or &cgierr ("Unable to copy category backup. Reason: $!"); &File::Copy::copy ("$db_script_path/data/email.db", "$db_script_path/backup/$date.email.db") or &cgierr ("Unable to copy email backup. Reason: $!"); &File::Copy::copy ("$db_script_path/data/url.db", "$db_script_path/backup/$date.url.db") or &cgierr ("Unable to copy url backup. Reason: $!"); } # Otherwise, the ugly way. else { print "\tBacking up links, category, email and url database (Regular - $@) ... \n"; foreach (qw!links categories email url!) { open (TMP, "$db_script_path/data/$_.db") or &cgierr ("Unable to open $db_script_path/data/$_.db. Reason: $!"); open (TMPOUT, ">$db_script_path/backup/$date.$_.db") or &cgierr ("Unable to open $db_script_path/$date.$_.db. Reason: $!"); while () { print TMPOUT; } close TMP; close TMPOUT; } } } sub build_url_index { # -------------------------------------------------------- # This routine builds a quick URL lookup database so the script # does not have to search the links.db for every hit. my $time = time(); my @values = (); my $count = 0; open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name.\nReason: $!"); open (URL, ">$db_url_name") or &cgierr("unable to open url index: $db_url_name. Reason: $!"); if ($db_use_flock) { flock (URL, 2) or &cgierr ("unable to get exclusive lock. Reason: $!"); } LINE: while () { /^#/ and next LINE; # Skip comment Lines. /^\s*$/ and next LINE; # Skip blank lines. chomp; # Remove trailing new line. @values = &split_decode($_); print URL "$values[$db_key_pos]$db_delim$values[$db_url]\n"; $count++; } close DB; close URL; # Build the count file used to do random links. open (CNT, ">$db_hits_path/index.count") or &cgierr("unable to open count file: '$db_hits_path/index.count'. Reason: $!"); if ($db_use_flock) { flock (CNT, 2) or &cgierr ("unable to get exclusive lock on $db_hits_path/index.count. Reason: $!"); } print CNT $count; close CNT; } sub build_download_url_index { # -------------------------------------------------------- # This routine builds a quick URL lookup database so the script # does not have to search the links.db for every hit. my $time = time(); my @values = (); my $count = 0; open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name.\nReason: $!"); open (DOWNLOADURL, ">$db_download_url_name") or &cgierr("unable to open url index: $db_download_url_name. Reason: $!"); if ($db_use_flock) { flock (DOWNLOADURL, 24) or &cgierr ("unable to get exclusive lock. Reason: $!"); } LINE: while () { /^#/ and next LINE; # Skip comment Lines. /^\s*$/ and next LINE; # Skip blank lines. chomp; # Remove trailing new line. @values = &split_decode($_); print DOWNLOADURL "$values[$db_key_pos]$db_delim$values[$db_download_url]\n"; $count++; } close DB; close DOWNLOADURL; # Build the count file used to do random links. open (CNT, ">$db_hits_path/index.count") or &cgierr("unable to open count file: '$db_hits_path/index.count'. Reason: $!"); if ($db_use_flock) { flock (CNT, 2) or &cgierr ("unable to get exclusive lock on $db_hits_path/index.count. Reason: $!"); } print CNT $count; close CNT; } sub build_update_ratings { # -------------------------------------------------------- # Updates the ratings of each link. # # Let's collect the ratings. my ($id, %rating, %votes, @values, $input); opendir (HITS, $db_rates_path) or &cgierr ("unable to open ratings directory: $db_rates_path. Reason: $!"); while (defined ($id = readdir HITS)) { next unless ($id =~ /^\d+$/); open (HIT, "$db_rates_path/$id") or &cgierr ("unable to open rating counter: $db_rates_path/$id. Reason: $!"); my $input = ; chomp $input; ($votes{$id}, $rating{$id}) = split /\s/, $input; close HIT; } closedir HITS; # Update the links database. open (DB, "$db_links_name") or &cgierr ("unable to open links database: $db_links_name. Reason: $!"); open (DBTMP, ">$db_links_name.bak") or &cgierr ("unable to open temp links database: $db_links_name.bak. Reason: $!"); LINE: while () { /^#/ and print OUT and next LINE; # Skip comment Lines. /^\s*$/ and next LINE; # Skip blank lines. chomp; # Remove trailing new line. @values = split /\Q$db_delim\E/; $id = $values[0]; if (exists $votes{$id}) { $values[$db_rating] = (($values[$db_rating] * $values[$db_votes]) + $rating{$id}) / ($values[$db_votes] + $votes{$id}); $values[$db_rating] = sprintf ("%.2f", $values[$db_rating]); $values[$db_votes] = $values[$db_votes] + $votes{$id}; print "\tUpdating rating to $values[$db_rating] for link id $id\n"; } print DBTMP &join_encode(&array_to_hash(0, @values)); } close DB; close DBTMP; if (-s "$db_links_name.bak" > 0) { if (! rename ("$db_links_name.bak", $db_links_name)) { print "\tCouldn't rename! Had to copy. Strange: $!\n"; open (DBTMP, ">$db_links_name") or &cgierr ("unable to open links database: $db_links_name. Reason: $!"); open (DB, "$db_links_name.bak") or &cgierr ("unable to open temp links database: $db_links_name.bak. Reason: $!"); while () { print DBTMP; } close DB; close DBTMP; } } else { &cgierr ("Error building! Links database is 0 bytes!"); } # Delete the ratings. foreach (keys %votes) { unlink ("$db_rates_path/$_") or &cgierr ("unable to remove rating: $db_rates_path/$_. Reason: $!"); } } sub build_update_newpop { # -------------------------------------------------------- # This routines updates the database, and marks new records new, # old records old, popular records popular, and unpopular records, # unpopular. my ($id, %hits, @values, $days, @popular, $cutoff); # Let's collect how many hits we've gotten. opendir (HITS, $db_hits_path) or &cgierr ("unable to open hits directory: $db_hits_path. Reason: $!"); while (defined ($id = readdir HITS)) { next unless ($id =~ /^\d+$/); open (HIT, "$db_hits_path/$id") or &cgierr ("unable to open hit counter: $db_hits_path/$id. Reason: $!"); $hits{$id} = int ; close HIT; } closedir HITS; # Now go through the links database and update new links, and # add the hits. open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name.\nReason: $!"); if ($db_use_flock) { flock(DB, 1); } LINE: while () { /^#/ and next LINE; /^\s*$/ and next LINE; chomp; @values = &split_decode($_); if ((!$values[$db_date]) || (!$values[$db_dateadded])) { print "ACHTUNG: Kein Datum angegeben für Position: $_. Überspringe..\n" and next LINE; } # Calculate days old and then mark new. $days = &days_old($values[$db_dateadded], $date); ($days <= $db_new_cutoff) and ($new_records{$values[$db_key_pos]}++); # Build an array of popular hits. exists $hits{$id} ? push (@popular, $values[$db_hits] + $hits{$id}) : push (@popular, $values[$db_hits]); } close DB; # Sort the popular list, and set the cutoff mark. @popular = sort { $b <=> $a } @popular; ($db_popular_cutoff < 1) ? ($cutoff = $popular[int($db_popular_cutoff * $#popular)]) : ($cutoff = $popular[$db_popular_cutoff - 1]); ($cutoff < 2) and ($cutoff = 2); # Display our cutoffs. print "\tWhat's New Cutoff: $db_new_cutoff days\n"; print "\tPopular Cutoff: $cutoff hits\n"; # Now update the New and Cool tags on the links. open (DB, "$db_links_name") or &cgierr ("unable to open links database: $db_links_name. Reason: $!"); open (DBTMP, ">$db_links_name.bak") or &cgierr ("unable to open temp links database: $db_links_name.bak. Reason: $!"); LINE: while () { /^#/ and print OUT and next LINE; # Skip comment Lines. /^\s*$/ and next LINE; # Skip blank lines. chomp; # Remove trailing new line. @values = split /\Q$db_delim\E/; $id = $values[0]; # Store the new number of hits. exists $hits{$id} and ($values[$db_hits] = $values[$db_hits] + $hits{$id}); # Check to see if the record is popular... if ($values[$db_hits] >= $cutoff) { print "\tUpdating record: $id, marking as popular ($values[$db_hits]).\n"; $values[$db_ispop] = "Yes"; } else { $values[$db_ispop] = "No"; } # Check to see if the record is new... if ($new_records{$id}) { print "\tUpdating record: $id, marking as new.\n"; $values[$db_isnew] = "Yes"; } else { $values[$db_isnew] = "No"; } print DBTMP &join_encode (&array_to_hash(0, @values)); } close DB; close DBTMP; if (-s "$db_links_name.bak" > 0) { if (! rename ("$db_links_name.bak", $db_links_name)) { print "\tCouldn't rename! Had to copy. Strange: $!\n"; open (DBTMP, ">$db_links_name") or &cgierr ("unable to open links database: $db_links_name. Reason: $!"); open (DB, "$db_links_name.bak") or &cgierr ("unable to open temp links database: $db_links_name.bak. Reason: $!"); while () { print DBTMP; } close DB; close DBTMP; } } else { &cgierr ("Error building! Links database is 0 bytes!"); } # Finally, clean out the hits directory. foreach (keys %hits) { next unless /^\d+$/; unlink ("$db_hits_path/$_") or &cgierr ("Can't remove hit file: '$db_hits_path/$_'. Reason: $!"); } } sub build_category_information { # -------------------------------------------------------- # This routine loads the category information into memory and # does some grouping. my ($name, @values, @base, $base,); open (DB, "<$db_category_name") or &cgierr("unable to open database: $db_category_name. Reason: $!"); LINE: while () { /^#/ and next LINE; # Skip comment Lines. /^\s*$/ and next LINE; # Skip blank lines. chomp; @values = &split_decode ($_); $name = $values[$db_main_category]; # We store the category information in a globally accessable hash %category, indexed by category name. @{$category{$name}} = @values; # We also need to intialize a links counter for the category, # flags for new or modified links, and date fields (set to 1-Jan-1990) # in case there are no links in the category to get a date from. $stats{$name}[0] = 0; # storage for number of links $stats{$name}[1] = "1-Jan-1990"; # storage for date modified $stats{$name}[2] = "1-Jan-1990"; # storage for date added $stats{$name}[3] = "No"; # modified record flag $stats{$name}[4] = "No"; # new record flag # We now figure out if this category is a subcategory of something, # and if so, store it in the hash of arrays %subcategories. (@base) = split (/\//, $name); pop @base; $base = join ("/", @base); if ($base) { push (@{$subcategories{$base}}, $name); } } close DB; } sub build_stats { # -------------------------------------------------------- # This routine does a lot of the messy work. It builds globally accessible # arrays of new_links and cool_links. It finds out how many links are in each # category, and whether a category contains a new/modified link. my (@values, $category, $cat, @alt_categories, @categorylist, $depth, $i, $cat); my $staggered_mode = shift || undef; open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name. Reason: $!"); LINE: while () { /^#/ and next LINE; # Skip comment Lines. /^\s*$/ and next LINE; # Skip blank lines. chomp; @values = &split_decode ($_); $category = $values[$db_category]; # Add the link to the list of links. push (@{$links{$category}}, @values) if (!$staggered_mode); $grand_total++; # Add the link to the alternate categories as well. if (defined $db_alt) { @alt_categories = split(/\Q$db_delim\E/, $values[$db_alt]); foreach (@alt_categories) { push (@{$links{$_}}, @values); } } # Add the link to the list of new links if it is new. push (@{$new_links{$category}}, @values) if ($values[$db_isnew] eq "Yes"); # Add the link to the list of cool links if it is popular. push (@{$cool_links{$category}}, @values) if ($values[$db_ispop] eq "Yes"); # Add the link to the list of recommended links if it is a pick. push (@{$pick_links{$category}}, @values) if ($values[$db_ispick] eq "Yes"); # This adds one to the total of each category above the current category. # We have to caluclate the affect of the link on each alt category as well as the main. foreach $cat ($category, @alt_categories) { # Calculate the stats: the number of links and the newest link. @categorylist = split (/\//, $cat); $depth = $#categorylist; # This adds one to the total of each category above the current category, # and also marks any above categories new, if this link is new. for $i (0 .. $depth) { $stats{$cat}[0]++; # Store the most recent modification date for links in this category. if ((!$stats{$cat}[1]) || &compare_dates($values[$db_modified], $stats{$cat}[1])) { $stats{$cat}[1] = $values[$db_modified]; } # Store the most recent add date for links in this category. if ((!$stats{$cat}[2]) || &compare_dates($values[$db_dateadded], $stats{$cat}[2])) { $stats{$cat}[2] = $values[$db_dateadded]; } # Is (modified) Date more recent than DateAdded? if (&compare_dates($stats{$cat}[1], $stats{$cat}[2])) { # Yes, so does it qualify as an "updated" link? if (&days_old($stats{$cat}[1]) <= $db_new_cutoff) { # Yes, so set updated link flag for this category. $stats{$cat}[3] = "Yes"; } } # Is this a new link? if (&days_old($stats{$cat}[2]) <= $db_new_cutoff) { # Yes, so set new link flag for this category. $stats{$cat}[4] = "Yes"; } pop (@categorylist); $cat = join("/", @categorylist); } } } close DB; if (!$staggered_mode) { foreach $link ( keys %links ) { @{$links{$link}} = &build_sorthit (@{$links{$link}}); } foreach $cat ( keys %subcategories ) { @{$subcategories{$cat}} = sort @{$subcategories{$cat}}; } } $grand_total ||= 0; } sub build_detailed_view { # -------------------------------------------------------- # This routine build a single page for every link. # my (@values, $id, %rec, $count); if ($build_detail_path =~ m,^$build_root_path/(.*)$,) { &build_dir ($1); } print "\t"; open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name. Reason: $!"); LINE: while () { /^#/ and next LINE; # Skip comment Lines. /^\s*$/ and next LINE; # Skip blank lines. chomp; @values = &split_decode ($_); $id = $values[$db_key_pos]; %rec = &array_to_hash (0, @values); $title_linked = &build_linked_title ("$rec{'Category'}/$rec{'Title'}"); open (DETAIL, ">$build_detail_path/$id$build_extension") or &cgierr ("Unable to build detail page: $build_detail_path/$id$build_extension. Reason: $!"); print DETAIL &site_html_detailed (%rec); close DETAIL; $use_html ? print qq~$id ~ : print qq~$id ~; (++$count % 10) or print "\n\t"; } close DB; print "\n"; } sub build_category_pages { # -------------------------------------------------------- # This routine builds all the category pages. Each category uses # the same template which is defined in &site_html_category. # my $build_single = shift; my ($cat, $url, $dir, @related, $relation, $page_num, $prev_page, $next_page, $numlinks); local ($category, $links, $title_linked, $title, $total, $category_name, $category_name_escaped, $category_name_title); local ($description, $related, $meta_name, $meta_keywords, $header, $footer, $span, $foundlinks, $displayed1, $displayed2); # Go through each category and build the appropriate page. CATEGORY: foreach $cat (sort keys %category) { next CATEGORY if ($cat =~ /^\s*$/); # How'd that get in here? =) next CATEGORY if ($build_single and ($build_single ne $cat)); $url = "$build_root_url/" . &urlencode($cat) . "/"; $use_html ? print qq|Building Category: $cat\n| : print qq|Building Category: $cat\n|; print "\tSubcategories: " . ($#{$subcategories{$cat}} + 1) . "\n"; print "\tLinks: " . (($#{$links{$cat}}+1) / ($#db_cols+1)) . "\n"; # Let's make sure the directory exists, build it if it doesn't. $dir = &build_dir ($cat); print "\tDirectory: $dir\n"; print "\tFilename : $dir/$build_index\n"; # We set up all the variables people can use in &site_html.pl. ($description, $related, $meta_name, $meta_keywords, $header, $cat_template) = @{$category{$cat}}[2..7]; # Calculate the related entries and put in a
  • list. @related = split(/\Q$db_delim\E/, $related); $related = ""; foreach $relation (@related) { $related .= qq|
  • |; $related .= &build_clean($relation); $related .= " ($stats{$relation}[0])
  • "; ### mod $stats{$relation}[0]) added to display number of related links } # Get the header and footer from file if it exists, otherwise assume it is html. if ($header && (length($header) < 20) && ($header !~ /\s+/) && (-e "$db_header_path/$header")) { open (HEAD, "<$db_header_path/$header") or &cgierr ("Unable to open header file: $db_header_path/$header. Reason: $!"); $header = ""; while ( ) { $header .= $_; } close HEAD; } if ($footer && (length($footer) < 20) && ($footer !~ /\s+/) && (-e "$db_footer_path/$footer")) { open (FOOT, "<$db_footer_path/$footer") or &cgierr ("Unable to open footer file: $db_footer_path/$footer. Reason: $!"); $footer = ""; while ( ) { $footer .= $_; } close FOOT; } $title_linked = &build_linked_title ($cat); $title = &build_unlinked_title ($cat); $total = ($#{$links{$cat}} + 1) / ($#db_cols + 1); $category_name = $cat; $category_name_escaped = &urlencode ($cat); $category_clean = &build_clean ($cat); $thiscat = $cat; $top = &build_top_x ($cat); $topaff = &build_topaffliate_x ($cat); # Store all the category html info in $category. if ($#{$subcategories{$cat}} >= 0) { $category = &site_html_print_cat (@{$subcategories{$cat}}); } else { $category = ""; } $numlinks = ($#{$links{$cat}} + 1) / ($#db_cols + 1); $foundlinks = $numlinks; $span = $links = $displayed1 = $displayed2 = ""; if (($numlinks > $build_links_per_page) && $build_span_pages) { $total_pages=(int($numlinks/$build_links_per_page)); if ($total_pages < $numlinks/$build_links_per_page) { $total_pages++; } $span .= qq~< Prev ~; $span .= "1 "; for $j(2..($total_pages)) { $span .= qq~$j ~; } $page_num = 2; $span .= qq~Next >~; $displayed1 = ($build_links_per_page - ($build_links_per_page - 1)); $displayed2 = $build_links_per_page; $l = 0; for ($i = 0; $i < $build_links_per_page; $i++) { %tmp = &array_to_hash ($i, @{$links{$cat}}); $links .= &site_html_link (%tmp); } @{$links{$cat}} = @{$links{$cat}}[(($#db_cols+1)*$build_links_per_page) .. $#{$links{$cat}}]; $numlinks = ($#{$links{$cat}}+1) / ($#db_cols + 1); } # Otherwise we either only have less then x number of links, or we are not # splitting pages, so let's just build them all. else { $l = 0; for ($i = 0; $i < $numlinks; $i++) { %tmp = &array_to_hash ($i, @{$links{$cat}}); $links .= &site_html_link (%tmp); } $displayed1 = ($build_links_per_page - ($build_links_per_page - 1)); $displayed2 = ($build_links_per_page - ($build_links_per_page - $numlinks)) if ($numlinks != $build_links_per_page); $displayed2 = $build_links_per_page if ($numlinks == $build_links_per_page); } # Create the main page. open (CAT, ">$dir/$build_index") or &cgierr ("unable to open category page: $dir/$build_index. Reason: $!"); print CAT &site_html_category; close CAT; # Then we go through the list of links and build on the remaining pages. while ($span && $build_span_pages) { $span = $next_page = $prev_page = $displayed1 = $displayed2 = ""; $next_page = $page_num+1; $prev_page = $page_num-1; if ($numlinks > $build_links_per_page) { $span .= qq~< Prev ~ if ($prev_page > 1); $span .= qq~< Prev ~ if ($prev_page == 1); $span .= qq~1 ~; if ($prev_page > 1) { for $k(2..$prev_page){ $span .= qq~$k ~; } } $span .= qq~$page_num ~; for $m($next_page..$total_pages){ $span .= qq~$m ~; } $span .= qq~Next >~; $displayed1 = (($build_links_per_page * $page_num) - ($build_links_per_page - 1)); $displayed2 = ($build_links_per_page * $page_num); } elsif ($page_num == $total_pages) { $span .= qq~< Prev ~ if ($prev_page > 1); $span .= qq~< Prev ~ if ($prev_page == 1); $span .= qq~1 ~; if ($prev_page > 1) { for $k(2..$prev_page){ $span .= qq~$k ~; } } $span .= qq~$page_num ~; $span .= qq~Next >~; $displayed1 = (($build_links_per_page * $page_num) - ($build_links_per_page - 1)); $displayed2 = (($build_links_per_page * $page_num) - ($build_links_per_page - $numlinks)); } else { $span = ""; } $links = ""; $l = 0; LINK: for ($i = 0; $i < $build_links_per_page; $i++) { %tmp = &array_to_hash ($i, @{$links{$cat}}); last LINK if ($tmp{$db_key} eq ""); $links .= &site_html_link (%tmp); } $title_linked = &build_linked_title ("$cat/Page_$page_num/"); $title = &build_unlinked_title ("$cat/Page_$page_num/"); $use_html ? print qq|\tSubpage : $dir/more$page_num$build_extension\n| : print qq|\tSubpage : $dir/more$page_num$build_extension\n|; open (CAT, ">$dir/more$page_num$build_extension") or &cgierr ("unable to open category page: $dir/index$page_num$build_extension. Reason: $!"); print CAT &site_html_category; close CAT; @{$links{$cat}} = @{$links{$cat}}[(($#db_cols+1)*$build_links_per_page) .. $#{$links{$cat}}]; $numlinks = ($#{$links{$cat}}+1) / ($#db_cols + 1); if ($page_num == $total_pages) { last; } else { $page_num++; } } print "\n"; } } sub build_single_category { # -------------------------------------------------------- # Builds a single category. # my $category = shift; my ($name, @values, @base, $base,); # Get category information for this one category. open (DB, "<$db_category_name") or &cgierr("unable to open database: $db_category_name. Reason: $!"); LINE: while () { /^#/ and next LINE; # Skip comment Lines. /^\s*$/ and next LINE; # Skip blank lines. chomp; @values = &split_decode ($_); $name = $values[$db_main_category]; if ($name eq $category) { @{$category{$name}} = @values; $stats{$name}[1] = "1-Jan-1990"; $stats{$name}[0] = 0; } elsif ($name =~ m,^$category/([^/]+)$,) { @{$category{$name}} = @values; push @{$subcategories{$category}}, $name; $stats{$name}[1] = "1-Jan-1990"; $stats{$name}[0] = 0; } else { next; } } close DB; # Gather link information for just this one category. open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name.\nReason: $!"); if ($db_use_flock) { flock(DB, 1); } LINE: while () { /^#/ and next LINE; # Skip comment Lines. /^\s*$/ and next LINE; # Skip blank lines. chomp; # Remove trailing new line. @values = &split_decode($_); $link_cat = $values[$db_category]; next unless ($link_cat =~ /^$category/); # This link is either in the category, or in a subcategory. if ($link_cat =~ m,^$category/([^/]+)/*,) { $stats{$link_cat}[0]++; if ((!$stats{$link_cat}[1]) || &compare_dates($values[$db_modified], $stats{$link_cat}[1])) { $stats{$link_cat}[1] = $values[$db_modified]; } } elsif ($link_cat eq $category) { push (@{$links{$category}}, @values); } else { &cgierr ("Unkown Category: $link_cat."); } } close DB; # Sort the links. foreach $link ( keys %links ) { @{$links{$link}} = &build_sorthit (@{$links{$link}}); } foreach $cat ( keys %subcategories ) { @{$subcategories{$cat}} = sort @{$subcategories{$cat}}; } # Now let's build the category page. &build_category_pages($category); } sub build_home_page { # -------------------------------------------------------- my ($subcat, @rootcat); local ($total); # Check to see which categories are off of the root. foreach $subcat (sort keys %category) { if ($subcat =~ m,^([^/]*)$,) { push (@rootcat, $subcat); } } print "\tSubcategories: "; print $#rootcat+1; print "\n"; print "\tTotal Links: $grand_total\n"; print "\tOpening page: $build_root_path/$build_index\n"; #- Begin Lastlink Mod -------------------------------------------- my $LASTX = $newlinks; open (DB, "<$db_file_name") or &cgierr("unable to open home page: $db_file_name.\nReason: $!"); my @lines = ; close DB; for ($i=$#lines; $i>=$#lines - $LASTX + 1; $i--) { chomp $lines[$i]; @tmp = &split_decode ($lines[$i]); %tmp = &array_to_hash (0, @tmp); $lastlink .= &site_html_lastlink (%tmp); } #- End Lastlink Mod ---------------------------------------------- open (HOME, ">$build_root_path/$build_index") or &cgierr ("unable to open home page: $build_root_path/$build_index. Reason: $!"); $category = &site_html_print_cat (@rootcat) if ($#rootcat >= 0); $total = $grand_total; print HOME &site_html_home; close HOME; print "\tClosing page.\n"; } sub build_new_page { # -------------------------------------------------------- # Creates a "What's New" page. Set $build_span_pages to 1 in links.cfg # and it will create a seperate page for each date. # my (%link_output, $category_clean, $long_date, $category, $date, $number_links, $main_link_results, $main_total, %span_totals); local ($total, $link_results, $title_linked); # Let's build the What's New directory. if ($build_new_path =~ m,^$build_root_path/(.*)$,) { &build_dir ($1); } # Now we go through all the new_links (which are organized by category), and # build the html in array indexed by date then category. $total = 0; CATEGORY: foreach $category (sort keys %new_links) { LINK: for ($i = 0; $i < ($#{$new_links{$category}}+1) / ($#db_cols + 1); $i++) { $total++; %tmp = &array_to_hash ($i, @{$new_links{$category}}); ${$link_output{$tmp{'DateAdded'}}}{$category} .= &site_html_link (%tmp) . "\n"; $span_totals{$tmp{'DateAdded'}}++; } } # Then we go through each date, and build the links for that date. If we are spanning # pages, we will create a seperate page for each date and need to set up a few other # variables (like title and total). We will also want to reset links_results each time. DATE: foreach $date (sort { &date_to_unix($b) <=> &date_to_unix($a) } keys %link_output) { $long_date = &long_date ($date); if ($build_new_span_pages) { $link_results = ""; $total = $span_totals{$date}; $title_linked = &build_linked_title ("New/$long_date"); } else { $link_results .= ""; } CATEGORY: foreach $category (sort keys %{$link_output{$date}}) { $category_clean = &build_clean ($category); $link_results .= qq|$long_date in: $category_clean\n|; $link_results .= ${$link_output{$date}}{$category}; } # Create the new page, and do a bit of HTML work for the main page. if ($build_new_span_pages) { open (NEW, ">$build_new_path/$date$build_extension") or cgierr ("unable to open what's new page: $build_new_path/$build_index. Reason: $!"); $use_html ? print qq|\tNew Links for $date: $total\n| : print qq|\tNew Links for $date: $total\n|; print NEW &site_html_new; close NEW; $main_link_results .= qq|
  • $long_date ($total).|; $main_total += $total; } else { $link_results .= ""; } } if ($build_new_span_pages) { $link_results = "$main_link_results"; $total = $main_total; } $title_linked = &build_linked_title ("New"); # Build the main What's New page. open (NEW, ">$build_new_path/$build_index") or cgierr ("unable to open what's new page: $build_new_path/$build_index. Reason: $!"); print "\tTotal New Links: $total\n"; print NEW &site_html_new(@new_links); close NEW; } sub build_cool_page { # -------------------------------------------------------- # Creates spanned "What's Cool" pages. local ($total, $hits, $percent, $link_results, $title_linked, $title, $next, $prev); my (%link_output, $category_clean, $url, $page_num, $prev_page, $next_page, $numlinks); if ($build_cool_path =~ m,^$build_root_path/(.*)$,) { &build_dir ($1); } $total = 0; $numlinks = 0; CATEGORY: foreach $category (sort keys %cool_links) { LINK: for ($i = 0; $i < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $i++) { $total++; } } $numlinks = $total; $title_linked = &build_linked_title ("Cool"); open (COOL, ">$build_cool_path/$build_index") or cgierr ("unable to open what's cool page: $build_cool_path/$build_index. Reason: $!"); print "\tCool Links: $total\n"; ($db_popular_cutoff < 1) ? ($percent = $db_popular_cutoff * 100 . "%") : ($percent = $db_popular_cutoff); close COOL; $url = $build_cool_url; $next = $prev = $link_results = ""; if (($numlinks > $build_links_per_page) && $build_span_pages) { $total_pages=(int($numlinks/$build_links_per_page)); if ($total_pages < $numlinks/$build_links_per_page) {$total_pages++} $next .= "1"; # new added for $j(2..($total_pages)){ $next .= qq~ $j~; } # end of for #added $page_num = 2; $next .= qq~ Next >~; $p = 1; $t = 0; $i = 0; $r = 0; foreach $category (sort keys %cool_links) { $category_clean = &build_clean ($category); if ($i < $build_links_per_page) { LINK: for ($q = 0; $q < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $q++) { if ($i < $build_links_per_page) { %tmp = &array_to_hash ($q, @{$cool_links{$category}}); $link_output{$category} .= &site_html_link (%tmp) . "\n"; $i++; } else { $r--; $t = $q; last; } } # --------------------------------------------------------------------- $link_results .= qq|$category_clean\n|; # ---------------------------------------------------------------- $link_results .= $link_output{$category}; $r++; } } $p++; $numlinks = $numlinks - $i; } # Otherwise we either only have less then x number of links, or we are not # splitting pages, so let's just build them all. else { foreach $category (sort keys %cool_links) { $category_clean = &build_clean ($category); LINK: for ($q = 0; $q < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $q++) { %tmp = &array_to_hash ($q, @{$cool_links{$category}}); $link_output{$category} .= &site_html_link (%tmp) . "\n"; } # --------------------------------------------------------------------- $link_results .= qq|$category_clean\n|; # ---------------------------------------------------------------- $link_results .= $link_output{$category}; } } # Create the main page. open (COOL, ">$build_cool_path/$build_index") or &cgierr ("unable to open what's cool page: $build_cool_path/$build_index. Reason: $!"); print COOL &site_html_cool(@cool_links); close COOL; # Then we go through the list of links and build on the remaining pages. while ($next && $build_span_pages) { if ($numlinks > $build_links_per_page) { $prev=$next=$next_page=$prev_page=""; $next_page = $page_num+1; $prev_page = $page_num-1; if ($page_num == 2){ $prev .= qq~ < Prev ~; $prev .= qq~ 1 ~;} else {$prev .= qq~ < Prev ~; $prev .= qq~ 1 ~; for $k(2..$prev_page){$prev .= qq~ $k~;}} $next .= qq~ $page_num ~; for $m($next_page..$total_pages){$next .= qq~ $m~;} $next .= qq~ Next >~; } # end of if else { if ($page_num == $total_pages) { $prev = $next = $next_page = $prev_page= ""; $prev_page=$total_pages-1; if ($page_num == 2){ $prev .= qq~ < Prev ~; $prev .= qq~ 1 ~;} else {$prev .= qq~ < Prev ~; $prev .= qq~ 1 ~; for $k(2..$prev_page){$prev .= qq~ $k~;} } # end of else $prev .= qq~ $page_num ~; } # end of if } # end of else $link_results = ""; $i = 0; $s = 1; foreach $category (sort keys %cool_links) { if (($s > $r) && ($i < $build_links_per_page)) { $category_clean = &build_clean ($category); $link_output{$category} = ""; LINK: for ($q = $t; $q < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $q++) { if ($i < $build_links_per_page) { %tmp = &array_to_hash ($q, @{$cool_links{$category}}); $link_output{$category} .= &site_html_link (%tmp) . "\n"; $i++; $t = 0; } else { $r--; $t = $q; last; } } # --------------------------------------------------------------------- $link_results .= qq|$category_clean\n|; # ---------------------------------------------------------------- $link_results .= $link_output{$category}; $r++; } $s++; } $title_linked = &build_linked_title ("$cat/Page_$page_num/"); $title = &build_unlinked_title ("$cat/Page_$page_num/"); $use_html ? print qq|\tSubpage : $build_cool_path/more$page_num$build_extension\n| : print qq|\tSubpage : $build_cool_path/more$page_num$build_extension\n|; open (COOL, ">$build_cool_path/more$page_num$build_extension") or &cgierr ("unable to open what's cool page: $build_cool_path/index$page_num$build_extension. Reason: $!"); print COOL &site_html_cool(@cool_links); close COOL; $p++; $numlinks = $numlinks - $i; if ($page_num == $total_pages) { last; } else { $page_num++; } } print "\n"; } sub build_pick_page { # -------------------------------------------------------- # # Creates spanned "Editors Pick" pages. local ($total, $link_results, $title_linked, $title, $next, $prev); my (%link_output, $category_clean, $url, $page_num, $prev_page, $next_page, $numlinks); if ($build_pick_path =~ m,^$build_root_path/(.*)$,) { &build_dir ($1); } $total = 0; $numlinks = 0; CATEGORY: foreach $category (sort keys %pick_links) { LINK: for ($i = 0; $i < ($#{$pick_links{$category}}+1) / ($#db_cols + 1); $i++) { $total++; } } $numlinks = $total; $title_linked = &build_linked_title ("Pick"); open (PICK, ">$build_pick_path/$build_index") or cgierr ("unable to open picks page: $build_cool_path/$build_index. Reason: $!"); print "\tPicks: $total\n"; close PICK; $url = $build_pick_url; $next = $prev = $link_results = ""; if (($numlinks > $build_links_per_page) && $build_span_pages) { $total_pages=(int($numlinks/$build_links_per_page)); if ($total_pages < $numlinks/$build_links_per_page) {$total_pages++} $next .= "1"; # new added for $j(2..($total_pages)){ $next .= qq~ $j~; } # end of for #added $page_num = 2; $next .= qq~ Next >~; $p = 1; $t = 0; $i = 0; $r = 0; foreach $category (sort keys %pick_links) { $category_clean = &build_clean ($category); if ($i < $build_links_per_page) { LINK: for ($q = 0; $q < ($#{$pick_links{$category}}+1) / ($#db_cols + 1); $q++) { if ($i < $build_links_per_page) { %tmp = &array_to_hash ($q, @{$pick_links{$category}}); $link_output{$category} .= &site_html_link (%tmp) . "\n"; $i++; } else { $r--; $t = $q; last; } } # --------------------------------------------------------------------- $link_results .= qq|$category_clean\n|; # ---------------------------------------------------------------- $link_results .= $link_output{$category}; $r++; } } $p++; $numlinks = $numlinks - $i; } # Otherwise we either only have less then x number of links, or we are not # splitting pages, so let's just build them all. else { foreach $category (sort keys %pick_links) { $category_clean = &build_clean ($category); LINK: for ($q = 0; $q < ($#{$pick_links{$category}}+1) / ($#db_cols + 1); $q++) { %tmp = &array_to_hash ($q, @{$pick_links{$category}}); $link_output{$category} .= &site_html_link (%tmp) . "\n"; } # --------------------------------------------------------------------- $link_results .= qq|$category_clean\n|; # ---------------------------------------------------------------- $link_results .= $link_output{$category}; } } # Create the main page. open (PICK, ">$build_pick_path/$build_index") or &cgierr ("unable to open what's pick page: $build_pick_path/$build_index. Reason: $!"); print PICK &site_html_pick(@pick_links); close PICK; # Then we go through the list of links and build on the remaining pages. while ($next && $build_span_pages) { if ($numlinks > $build_links_per_page) { $prev=$next=$next_page=$prev_page=""; $next_page = $page_num+1; $prev_page = $page_num-1; if ($page_num == 2){ $prev .= qq~ < Prev ~; $prev .= qq~ 1 ~;} else {$prev .= qq~ < Prev ~; $prev .= qq~ 1 ~; for $k(2..$prev_page){$prev .= qq~ $k~;}} $next .= qq~ $page_num ~; for $m($next_page..$total_pages){$next .= qq~ $m~;} $next .= qq~ Next >~; } # end of if else { if ($page_num == $total_pages) { $prev = $next = $next_page = $prev_page= ""; $prev_page=$total_pages-1; if ($page_num == 2){ $prev .= qq~ < Prev ~; $prev .= qq~ 1 ~;} else {$prev .= qq~ < Prev ~; $prev .= qq~ 1 ~; for $k(2..$prev_page){$prev .= qq~ $k~;} } # end of else $prev .= qq~ $page_num ~; } # end of if } # end of else $link_results = ""; $i = 0; $s = 1; foreach $category (sort keys %pick_links) { if (($s > $r) && ($i < $build_links_per_page)) { $category_clean = &build_clean ($category); $link_output{$category} = ""; LINK: for ($q = $t; $q < ($#{$pick_links{$category}}+1) / ($#db_cols + 1); $q++) { if ($i < $build_links_per_page) { %tmp = &array_to_hash ($q, @{$pick_links{$category}}); $link_output{$category} .= &site_html_link (%tmp) . "\n"; $i++; $t = 0; } else { $r--; $t = $q; last; } } # --------------------------------------------------------------------- $link_results .= qq|$category_clean\n|; # ---------------------------------------------------------------- $link_results .= $link_output{$category}; $r++; } $s++; } $title_linked = &build_linked_title ("$cat/Page_$page_num/"); $title = &build_unlinked_title ("$cat/Page_$page_num/"); $use_html ? print qq|\tSubpage : $build_pick_path/more$page_num$build_extension\n| : print qq|\tSubpage : $build_pick_path/more$page_num$build_extension\n|; open (PICK, ">$build_pick_path/more$page_num$build_extension") or &cgierr ("unable to open what's pick page: $build_pick_path/index$page_num$build_extension. Reason: $!"); print PICK &site_html_pick(@pick_links); close PICK; $p++; $numlinks = $numlinks - $i; if ($page_num == $total_pages) { last; } else { $page_num++; } } print "\n"; } sub build_rate_page { # -------------------------------------------------------- # Creates a Top 10 ratings page. my (@values, $id, $votes, $rate, @top_votes, %top_votes, @top_rate, %top_rate); local ($top_rated, $top_votes); if ($build_ratings_path =~ m,^$build_root_path/(.*)$,) { &build_dir ($1); } $total = 0; open (LINKS, $db_links_name) or &cgierr ("unable to open links database: $db_links_name. Reason: $!"); LINE: while () { /^#/ and next LINE; # Skip comment Lines. /^\s*$/ and next LINE; # Skip blank lines. chomp; @values = &split_decode ($_); $id = $values[$db_key_pos]; $votes = $values[$db_votes]; $rate = $values[$db_rating]; next if ($votes < 10); if (($#top_votes < 9) or ($votes > $top_votes[$#top_votes])) { push (@{$top_votes{$votes}}, @values); if ($#top_votes <= 10) { push (@top_votes, $votes); @top_votes = sort { $b <=> $a } @top_votes; } else { splice (@{$top_votes{$#top_votes}}, 0, $#db_cols); $#{$top_votes{$#top_votes}} or delete $top_votes{$#top_votes}; delete $top_votes{$top_votes[$#top_votes]-$id}; $top_votes[$#top_votes] = $votes; @top_votes = sort { $b <=> $a } @top_votes; } } if (($#top_rate < 9) or ($rate > $top_rate[$#top_rate])) { push (@{$top_rate{$rate}}, @values); if ($#top_rate <= 10) { push (@top_rate, $rate); @top_rate = sort { $b <=> $a } @top_rate; } else { splice (@{$top_rate{$#top_rate}}, 0, $#db_cols); $#{$top_rate{$#top_rate}} or delete $top_rate{$#top_rate}; delete $top_rate{$top_rate[$#top_rate]-$id}; $top_rate[$#top_rate] = $rate; @top_rate = sort { $b <=> $a } @top_rate; } } } close LINKS; $top_rated = ''; $top_votes = ''; foreach (sort { $b <=> $a } @top_votes) { $seen{$_}++; %link = &array_to_hash ($seen{$_} - 1, @{$top_votes{$_}}); $top_votes .= qq~$link{'Rating'}$link{'Votes'}$link{'Title'}\n~; } foreach (sort { $b <=> $a } @top_rate) { $seen{$_}++; %link = &array_to_hash ($seen{$_} - 1, @{$top_rate{$_}}); $top_rated .= qq~$link{'Rating'}$link{'Votes'}$link{'Title'}\n~; } open (RATE, ">$build_ratings_path/$build_index") or &cgierr ("unable to open top rated page: $build_ratings_path/$build_index. Reason: $!"); print "\tVote Range: $top_votes[0] .. $top_votes[$#top_votes]\n"; print "\tRate Range: $top_rate[0] .. $top_rate[$#top_rate]\n"; print RATE &site_html_ratings; close RATE; } sub build_dir { # -------------------------------------------------------- # Verifies that all neccessary directories have been created # before we create the category file. Takes as input, the category # to verify, and returns the full directory path. my $input = shift; my ($dir, $path) = ''; my @dirs = split /\//, $input; foreach $dir (@dirs) { $path .= "/$dir"; &build_check_dir ($build_root_path, $path); if (! (-e "$build_root_path$path")) { print "\tMaking Directory ($build_dir_per): '$build_root_path$path' ..."; if (mkdir ("$build_root_path$path", "$build_dir_per")) {; print "Made. CHMOD ($build_dir_per) ..."; if (chmod ($build_dir_per, "$build_root_path$path")) {; print "Done."; } else { print "CHMOD ($build_dir_per) failed! Reason: $!."; } } else { print "mkdir failed! Reason: $!."; } print "\n"; } } return "$build_root_path$path"; } sub build_linked_title { # -------------------------------------------------------- # Returns a string of the current category broken up # by section, with each part linked to the respective section. my $input = shift; my (@dirs, $dir, $output, $path, $last); @dirs = split (/\//, $input); $last = &build_clean(pop @dirs); $output = qq| Top :|; foreach $dir (@dirs) { $path .= "/$dir"; $dir = &build_clean ($dir); $output .= qq| $dir :|; } $output .= " $last"; return $output; } sub build_unlinked_title { # -------------------------------------------------------- # Returns a string of the current category broken up by section. # Useful for printing in the title. my $input = shift; my (@dirs, $dir, $output); @dirs = split (/\//, $input); foreach $dir (@dirs) { $dir = &build_clean ($dir); $output .= " $dir:"; } chop ($output); return $output; } sub build_check_dir { # -------------------------------------------------------- # Checks the directory before we create it to make sure there # are no funncy characters in it. my ($root, $dir) = @_; my $chrs = quotemeta (",\&\'\+/_-"); if (! -e $root) { &cgierr ("Root directory: $root does not exist!"); } if ($dir !~ m,^[\w\d$chrs]+$,) { &cgierr ("Invalid characters in category name: $dir. Must contain only letters, numbers, \,, \&, \', \@, _, / and -."); } return $input; } sub build_category_select_list { # -------------------------------------------------------- # This subroutine will build a category select list of only desired subcategories. my ($subcat, @rootcat); my $cat_select_list = $db_script_path . "/data/cat_sel.txt"; print "\tOpening file: $cat_select_list\n"; open (SELECT, ">$cat_select_list") or &cgierr ("unable to open $cat_select_list. Reason: $!"); print SELECT qq|\n|; print "\tClosing file.\n"; close SELECT; } sub build_top_x { # -------------------------------------------------------- my ($category) = @_; my (@values, $top_cat, @topx, $topxhtml, $count); $original = $db_sort_links; $db_sort_links = $db_hits; @topx = &build_sorthit (@{$links{$category}}); $db_sort_links = $original; $topxhtml = qq~\n~; my $display = 3; (($#topx+1) / ($#db_cols+1) >= 3) or $display = ($#topx+1)/($#db_cols+1); for ($i = 0; $i < $display; $i++) { %tmp = &array_to_hash ($i, @topx); $count = $i+1; $topxhtml .= qq~~; $topxhtml .= qq~\n~; } $topxhtml .= qq~
    Popular Downloads:
    $count.~; $topxhtml .= qq~$tmp{'Title'}$tmp{'Hits'} Downloads
    ~; return $topxhtml; } sub build_topaffliate_x { # -------------------------------------------------------- my ($category) = @_; my (@values, $topaffcat, $topaff, $topaffhtml, $count); $original = $db_sort_links; $db_sort_links = $db_hits; $topaff = &build_sorthit (@{$links{$category}}); $db_sort_links = $original; $topaffhtml = qq~\n~; my $display = 3; (($#topaff+1) / ($#db_cols+1) >= 3) or $display = ($#topaff+1)/($#db_cols+1); for ($i = 0; $i < $display; $i++) { %tmp = &array_to_hash ($i, $topaff); $count = $i+1; $topaffhtml .= qq~~; $topaffhtml .= qq~\n~; } $topaffhtml .= qq~
    Popular Downloads:
    $count.~; $topaffhtml .= qq~$tmp{'Title'}$tmp{'Hits'} Downloads
    ~; return $topaffhtml; } 1; ----------------------------------------------------------------------------------------------------- site_html_templates.html # ------------- # Links # ------------- # Links Manager # # File: site_html.pl # Description: This library contains all the HTML that will be generated in # the finished directory. # Author: Alex Krohn # Email: [url "mailto:alex@gossamer-threads.com"]alex@gossamer-threads.com[/url] # Web: [url "http://www.gossamer-threads.com/"]http://www.gossamer-threads.com/[/url] # Version: 2.01 # # (c) 1998 Gossamer Threads Inc. # # This script is not freeware! Please read the README for full details # on registration and terms of use. # ===================================================================== # You can put variables here that you would like to use in any # of your templates. %globals = ( date => &get_date, time => &get_time, db_cgi_url => $db_cgi_url, build_root_url => $build_root_url, site_title => $build_site_title, css => $build_css_url, build_image_url => $build_image_url, banner => '' ); # New/Updated info. You can also use images. $new_1 = qq|new|; $new_3 = qq|new|; $new_7 = qq|new|; $updated = qq|update|; $newcat_1 = qq|+|; $newcat_3 = qq|+|; $newcat_7 = qq|+|; $updated = qq|Update|; sub site_html_link { # -------------------------------------------------------- # This routine is used to display what a link should look # like. my %rec = @_; my $days_old; my $new_mod_img = ""; $nr = int($rec{'Rating'}); $rate_img = qq|Rating = $rec{'Rating'}|; # The record is either New, Updated, or neither. Only a New or Updated # graphic can be displayed for a link, but never both. # First, check to see if the link is new. if ($rec{'isNew'} eq "Yes") { # Calculate age of link based on Date Added, not Date Modified. $days_old = &days_old($rec{'DateAdded'}); # Display appropriate New graphic based on age of link. if ($days_old <= 2) { $new_mod_img = $new_1; } elsif ($days_old <= 7) { $new_mod_img = $new_3; } elsif ($days_old <= $db_new_cutoff) { $new_mod_img = $new_7; } } # If the link is not new, check to see if it has been updated. elsif (&compare_dates($rec{'Date'}, $rec{'DateAdded'})) { # Calculate age of link based on Date Modified, not Date Added. $days_old = &days_old($rec{'Date'}); if ($days_old <= $db_new_cutoff) { $new_mod_img = qq~ $updated~; } } ($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'}); ($rec{'isPick'} eq 'Yes') ? ($rec{'isPick'} = 1) : (delete $rec{'isPick'}); return &load_template ('link.html', { detailed_url => "$build_detail_url/$rec{'ID'}$build_extension", new_update => $new_mod_img, flag => $langimg, rate_img => $rate_img, %rec, %globals }); } sub site_html_lastlink { # -------------------------------------------------------- my %rec = @_; my $days_old; my $new_mod_img = ""; $nr = int($rec{'Rating'}); $rate_img = qq|Rating = $rec{'Rating'}|; # The record is either New, Updated, or neither. Only a New or Updated # graphic can be displayed for a link, but never both. # First, check to see if the link is new. if ($rec{'isNew'} eq "Yes") { # Calculate age of link based on Date Added, not Date Modified. $days_old = &days_old($rec{'DateAdded'}); # Display appropriate New graphic based on age of link. if ($days_old <= 2) { $new_mod_img = $new_1; } elsif ($days_old <= 7) { $new_mod_img = $new_3; } elsif ($days_old <= $db_new_cutoff) { $new_mod_img = $new_7; } } # If the link is not new, check to see if it has been updated. elsif (&compare_dates($rec{'Date'}, $rec{'DateAdded'})) { # Calculate age of link based on Date Modified, not Date Added. $days_old = &days_old($rec{'Date'}); if ($days_old <= $db_new_cutoff) { $new_mod_img = qq~ $updated~; } } ($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'}); ($rec{'isPick'} eq 'Yes') ? ($rec{'isPick'} = 1) : (delete $rec{'isPick'}); return &load_template ('lastlink.html', { detailed_url => "$build_detail_url/$rec{'ID'}$build_extension", new_update => $new_mod_img, flag => $langimg, rate_img => $rate_img, %rec, %globals }); } sub site_html_home { # -------------------------------------------------------- # This routine will build a home page. It is not meant to have any # links on it, only subcategories. return &load_template ('home.html', { category => $category, grand_total => $grand_total, lastlink => $lastlink, %globals }); } sub site_html_new { # -------------------------------------------------------- # This routine will build a what's new page. return &load_template ('new.html', { total => $total, grand_total => $grand_total, prev => $prev, next => $next, link_results => $link_results, title_linked => $title_linked, %globals } ); } sub site_html_cool { # -------------------------------------------------------- # This routine will build a what's cool page. return &load_template ('cool.html', { total => $total, grand_total => $grand_total, percent => $percent, prev => $prev, next => $next, link_results => $link_results, title_linked => $title_linked, %globals } ); } sub site_html_pick { # -------------------------------------------------------- # This routine will build a pick page. return &load_template ('pick.html', { total => $total, grand_total => $grand_total, prev => $prev, next => $next, link_results => $link_results, title_linked => $title_linked, %globals } ); } sub site_html_detailed { # -------------------------------------------------------- # This routine will build a single page per link. It's only # really useful if you have a long review for each link -- # or more information then can be displayed in a summary. # my %rec = @_; $nr = int($rec{'Rating'}); $rate_img = qq|Rating = $rec{'Rating'}|; # The record is either New, Updated, or neither. Only a New or Updated # graphic can be displayed for a link, but never both. # First, check to see if the link is new. if ($rec{'isNew'} eq "Yes") { # Calculate age of link based on Date Added, not Date Modified. $days_old = &days_old($rec{'DateAdded'}); # Display appropriate New graphic based on age of link. if ($days_old <= 2) { $new_mod_img = $new_1; } elsif ($days_old <= 7) { $new_mod_img = $new_3; } elsif ($days_old <= $db_new_cutoff) { $new_mod_img = $new_7; } } # If the link is not new, check to see if it has been updated. elsif (&compare_dates($rec{'Date'}, $rec{'DateAdded'})) { # Calculate age of link based on Date Modified, not Date Added. $days_old = &days_old($rec{'Date'}); if ($days_old <= $db_new_cutoff) { $new_mod_img = qq~ $updated~; } } ($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'}); ($rec{'isPick'} eq 'Yes') ? ($rec{'isPick'} = 1) : (delete $rec{'isPick'}); return &load_template ('detailed.html', { total => $total, grand_total => $grand_total, title_unlinked => $title_unlinked, title_linked => $title_linked, grand_total => $grand_total, category_name => $category_name, category_name_escaped => $category_name_escaped, category_clean => $category_clean, thiscat => $thiscat, flag => $langimg, new_update => $new_mod_img, rate_img => $rate_img, %rec, %globals } ); } sub site_html_detailed_error { # -------------------------------------------------------- # This routine determines how the modify failure page will look like. my $error = shift; &html_print_headers; print &load_template ('detailed_error.html', { error => $error, %in, %globals }); } sub site_html_category { # -------------------------------------------------------- # This rountine will build a page based for the current category. my $ext = ".html"; if ($cat_template) { $cattemplate = "$cat_template$ext"; } else { $cattemplate = 'category.html'; } return &load_template ( $cattemplate, { date => $date, time => $time, category => $category, links => $links, title_linked => $title_linked, title => $title, total => $total, grand_total => $grand_total, category_name => $category_name, category_name_escaped => $category_name_escaped, category_clean => $category_clean, thiscat => $thiscat, description => $description, meta_name => $meta_name, meta_keywords => $meta_keywords, header => $header, footer => $footer, span => $span, site_link1 => &site_html_sort_link("Title"), site_link2 => &site_html_sort_link("Votes"), site_link3 => &site_html_sort_link("Rating"), site_link4 => &site_html_sort_link("Hits"), site_link5 => &site_html_sort_link("Date"), site_link6 => &site_html_sort_link("isNew"), site_link7 => &site_html_sort_link("Licence"), site_link8 => &site_html_sort_link("Size"), foundlinks => $foundlinks, displayed1 => $displayed1, displayed2 => $displayed2, related => $related, build_links_per_page => $build_links_per_page, lastlink => $lastlink, top => $top, topaff => $topaff, %globals } ); } sub site_html_ratings { # -------------------------------------------------------- # This routine determines how the top rated page will look like. return &load_template ( 'rate_top.html', { top_rated => $top_rated, top_votes => $top_votes, %globals }); } ######################################################################################## # THE FOLLOWING ARE CGI GENERATED PAGES AND THE TEMPLATE MUST BE PRINTED, NOT RETURNED!# ######################################################################################## sub site_html_add_form { # -------------------------------------------------------- # This routine determines how the add form page will look like. # &html_print_headers; my $category = shift; if ($category) { ($category = qq~$category~); } else { if ([url "mailto:!@exclude_categories"]!@exclude_categories[/url]) { ($category = &build_select_field ("Category")); } else { ($category = &get_cat_select_list); } } my $system = &build_select_field ("System", "$in{'System'}"); my $licence = &build_select_field ("Licence", "$in{'Licence'}"); print &load_template ('add.html', { Category => $category, System => $system, Licence => $licence, flag => $language, %globals }); } sub site_html_add_success { # -------------------------------------------------------- # This routine determines how the add success page will look like. # Checkboxes for Language Options --------------------------------------------------- if ($in{'Language'} =~/en/i) { $en_img = qq| |; } if ($in{'Language'} =~/fr/i) { $fr_img = qq| |; } if ($in{'Language'} =~/es/i) { $es_img = qq| |; } if ($in{'Language'} =~/ge/i) { $fr_img = qq| |; } if ($in{'Language'} =~/multi/i) { $multi_img = qq| |; } # Ende Checkboxes for Language Options ---------------------------------------------- &html_print_headers; print &load_template ('add_success.html', { %in, en_img => $en_img, fr_img => $fr_img, es_img => $es_img, ge_img => $ge_img, multi_img => $multi_img, %globals }); } sub site_html_add_failure { # -------------------------------------------------------- # This routine determines how the add failure page will look like. my ($errormsg) = shift; if (defined $in{'Category'}) { $category = &build_select_field ("Category", $in{'Category'}); } else { if ([url "mailto:!@exclude_categories"]!@exclude_categories[/url]) { $category = &build_select_field ("Category", $in{'Category'}); } else { $category = &get_cat_select_list; } } $in{'System'} = &build_select_field ("System", $in{'System'}); $in{'Licence'} = &build_select_field ("Licence", $in{'Licence'}); # Checkboxes for Language Options --------------------------------------------------- if ($in{'Language'} =~/en/i) { $en_checked = qq| checked |; } if ($in{'Language'} =~/fr/i) { $fr_checked = qq| checked |; } if ($in{'Language'} =~/es/i) { $es_checked = qq| checked |; } if ($in{'Language'} =~/ge/i) { $ge_checked = qq| checked |; } if ($in{'Language'} =~/multi/i) { $multi_checked = qq| checked |; } # End Checkboxes for Language Options ---------------------------------------------- &html_print_headers; print &load_template ('add_error.html', { error => $errormsg, %in, en_checked => $en_checked, fr_checked => $fr_checked, es_checked => $es_checked, ge_checked => $ge_checked, multi_checked => $multi_checked, Category => $category, %globals }); } sub site_html_modify_form { # -------------------------------------------------------- # This routine determines how the modify form page will look like. &html_print_headers; if ([url "mailto:!@exclude_categories"]!@exclude_categories[/url]) { ($category = &build_select_field ("Category")); } else { ($category = &get_cat_select_list); } my $system = &build_select_field ("System", "$in{'System'}"); my $licence = &build_select_field ("Licence", "$in{'Licence'}"); print &load_template ('modify.html', { Category => $category, System => $system, Licence => $licence, Language => $language, %globals }); } sub site_html_modify_success { # -------------------------------------------------------- # This routine determines how the modify success page will look like. &html_print_headers; print &load_template ('modify_success.html', { %in, en_img => $en_img, fr_img => $fr_img, es_img => $es_img, ge_img => $ge_img, multi_img => $multi_img, %globals }); } sub site_html_modify_failure { # -------------------------------------------------------- # This routine determines how the modify failure page will look like. my $errormsg = shift; if (defined $in{'Category'}) { $category = &build_select_field ("Category", $in{'Category'}); } else { if ([url "mailto:!@exclude_categories"]!@exclude_categories[/url]) { $category = &build_select_field ("Category", $in{'Category'}); } else { $category = &get_cat_select_list; } } $in{'System'} = &build_select_field ("System", $in{'System'}); $in{'Licence'} = &build_select_field ("Licence", $in{'Licence'}); &html_print_headers; print &load_template ('modify_error.html', { error => $errormsg, %in, en_checked => $en_checked, fr_checked => $fr_checked, es_checked => $es_checked, ge_checked => $ge_checked, multi_checked => $multi_checked, Category => $category, %globals }); } sub site_html_search_results { # -------------------------------------------------------- # This routine displays the search results. # my $term = &urlencode ($in{'query'}); &html_print_headers; print &load_template ('search_results.html', { term => $term, link_results => $link_results, category_results => $category_results, span => $span, cat_hits => $cat_hits, link_hits => $link_hits, displaying => $displaying, site_link1 => &site_html_sort_link("Title"), site_link2 => &site_html_sort_link("Votes"), site_link3 => &site_html_sort_link("Rating"), site_link4 => &site_html_sort_link("Hits"), site_link5 => &site_html_sort_link("Date"), site_link6 => &site_html_sort_link("isNew"), site_link7 => &site_html_sort_link("Licence"), site_link8 => &site_html_sort_link("isNew"), %in, %globals }); } sub site_html_search_failure { # -------------------------------------------------------- # This routine displays a failed search page with error in $error. # my $error = shift; my $term = &urlencode ($in{'query'}); &html_print_headers; print &load_template ('search_error.html', { term => $term, error => $error, %in, %globals }); } sub site_html_search_form { # -------------------------------------------------------- # This routine displays the search form. &html_print_headers; print &load_template ('search.html', { term => $term, error => $error, %in, %globals }); } sub site_html_mailing { # -------------------------------------------------------- # This routine displays your mailing list subscribe/unsubscribe form. # my $action = shift; my $message; ($action eq 'subscribe') and ($message = qq~You've been successfully subscribed to the mailing list!~); ($action eq 'unsubscribe') and ($message = qq~You've been successfully removed from the mailing list!~); &html_print_headers; print &load_template ('email.html', { message => $message, %in, %globals }); } sub site_html_mailing_error { # -------------------------------------------------------- # This routine is displayed if there was a problem subscribing. # my $error = shift; &html_print_headers(); print &load_template ('email_error.html', { error => $error, %in, %globals }); } sub site_html_rate_form { # -------------------------------------------------------- # This routine determines how the rate form page will look like. # my %rec = @_; &html_print_headers; print &load_template ('rate.html', { %rec, %globals }); } sub site_html_rate_success { # -------------------------------------------------------- # This routine determines how the rate success page will look like. &html_print_headers; print &load_template ('rate_success.html', { %in, %globals }); } sub site_html_rate_failure { # -------------------------------------------------------- # This routine determines how the rate failure page will look like. my ($errormsg) = shift; &html_print_headers; print &load_template ('rate_error.html', { error => $errormsg, %in, %globals }); } sub site_html_my_home { # -------------------------------------------------------- # This routine shows the layout of the MY Link Home Page my $my_link; my $tags = shift; print &load_template ('my_home.html', { %$tags, %globals }); } sub site_html_my_add { #-------------------------------------------------------- my %rec = @_; print &load_template ('my_add.html', { %rec, %globals }); } sub site_html_my_add_error { #------------------------------------------------------- my $message = shift; print &load_template ('my_add_error.html', { message => $message, %globals }); } sub site_html_my_delete { #------------------------------------------------------ my %rec = @_; print &load_template ('my_delete.html', { %rec, %globals }); } sub site_html_my_delete_all { #------------------------------------------------------ print &load_template ('my_delete_all.html', { %globals }); } sub site_html_my_delete_error { #--------------------------------------------------------- my $message = shift; print &load_template ('my_delete_error.html', { message => $message, %globals }); } sub site_html_my_link { #--------------------------------- my %rec = @_; ($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'}); ($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'}); return &load_template ('my_link.html', { %rec, %globals }); } sub site_html_my_help { #------------------------------------------------------ my %rec = @_; print &load_template ('my_help.html', { %rec, %globals }); } ######################################################################################## # THE FOLLOWING DETERMINES YOUR CATEGORY LISTING, IT'S NOT TEMPLATE BASED (YET)! # ######################################################################################## sub site_html_print_cat { # -------------------------------------------------------- # This routine determines how the list of categories will look. # We now use a table to split the category name up into two columns. # For each category you can use the following variables: # # $url : The URL to go to that category # $category_name : The category name with _ and / removed. # $category_descriptions{$subcat}: The category description (if any). # $numlinks : The number of links inside that category (and subcategories). # $mod : The newest link inside of that category. # my (@subcat) = @_; my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i); my ($half) = int (($#subcat+2) / 2); # Print Header. $output = qq|
    \n|; foreach $subcat (sort @subcat) { my $mod = $stats{"$subcat"}[3]; my $new_add = $stats{"$subcat"}[4]; ($description) = @{$category{$subcat}}[2]; my ($subcats) = @{$category{$subcat}}[8]; @subcats = split(/\Q$db_delim\E/, $subcats); $subcats = ""; foreach $scat (@subcats) { $subcats .= qq||; if ($scat =~ m,.*/([^/]+)$,) { $subcats .= &build_clean($1);} else { $subcats .= &build_clean($scat); } $subcats .= qq| |; } # First let's get the name, number of links, and last modified date... $url = "$build_root_url/" . &urlencode($subcat) . "/"; if ($subcat =~ m,.*/([^/]+)$,) { $category_name = &build_clean($1); } else { $category_name = &build_clean($subcat); } $numlinks = $stats{"$subcat"}[0]; # $mod = $stats{"$subcat"}[1]; # We check to see if we are half way through, if so we stop this table cell # and begin a new one (this lets us have category names in two columns). if ($i == $half) { $output .= qq|\n|; } $i++; # Then we print out the name linked, new if it's new, and popular if its popular. $output .= qq|$category_name ($numlinks) |; if ($new_add eq "Yes") { $days_old = &days_old($stats{"$subcat"}[2]); if ($days_old <= 2) { $output .= qq| $newcat_1|; } elsif ($days_old <= 7) { $output .= qq| $newcat_3|; } elsif ($days_old <= 14) { $output .= qq| $newcat_7|; } } if ($mod eq "Yes") { $output .= qq~ $updated~; } $output .= qq|
    |; $output .= qq|$description | if (!($description =~ /^[\s\n]*$/)); $output .= qq|$subcats |; $output .= qq||; } # Don't forget to end the unordered list.. $output .= "
    \n"; return $output; } sub site_html_sort_link { my ($sort_name) = @_; my ($ascend, $descend, $sort_title, $sort_order, $sort_image, $sort_script, $sort_url, $output); $sort_title = $sort_name; if ($db_def{$sort_name}[0]) { $sort_order = "a"; if ($db_def{$sort_name}[0] == $db_sort_links) { $sort_title = "$sort_title"; $sort_image = qq~~ if ($in{'order'} eq "d"); if ($in{'order'} eq "a" || $ENV{'SCRIPT_NAME'} =~ /nph-build.cgi$/) { $sort_order = "d"; $sort_image = qq~~; } } $sort_script = $ENV{'SCRIPT_NAME'}; if ($ENV{'SCRIPT_NAME'} =~ /nph-build.cgi$/) { $query = "category=$category_name_escaped"; $sort_script = $build_category_url; } $sort_url = qq~$sort_script?$query&order=$sort_order&sort=$db_def{$sort_name}[0]~; $output = qq~$sort_title~; $output .= qq~ $sort_image~ if ($sort_image); } else { $output = qq~$sort_title~; } return $output; } sub site_html_cat_select_list { # -------------------------------------------------------- # This routine builds the options for the category select list. my (@subcat) = @_; my $output; CAT: foreach $subcat (sort @subcat) { if (@exclude_categories) { foreach (@exclude_categories) { ($subcat eq $_) and next CAT; } } $category_name = &build_clean($subcat); $output .= qq|