Bob's Good Stuff Lists

Powered by Gossamer Threads

Links Version 2.0
"Updated" & 3-Level "New"
Graphic Usage Modification

Copyright © 1999 Connors
All Rights Reserved

*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*

The purpose of this modification to the Gossamer Threads Links v2.0 script is to permit use of either a "NEW" graphic for new links or an "Updated" graphic for links that are not new but have had a user viewable field recently modified. The record must have been added or modified within the period specified in the links.cfg setting, $db_new_cutoff.

Normally, you would want to use the "Updated" graphic whenever the Title, URL, or Description fields of a link are modified. The modification could be done by either a link owner or by the Links administrator. If the Links administrator performs the modification to the record(s), then he/she must ensure that the 'Date' field for the record is updated in order to display the "Updated" graphic.

These instructions are based on the assumption that you desire to use both the Updated and New graphics on your system. If this is not the case, then use one of the following mods instead:

This modification is a bit more complex that any I have previously published. It entails creating a new field in links.def, running a script to update links.db to initialize the new field, the modification of four Links scripts, and one template file. I highly recommend that you backup your files, both scripts and data, before attempting to install this mod.

This mod may be used for personal use by users of the Gossamer Threads, Inc's Links v2.0 script. All other rights to the code and documentation for this mod are reserved, under copyright, by the author. Redistribution or republication of this mod and its instructions, without permission, is prohibited.

Modification Instructions

  1. Either create your own "Updated" and "New" graphics to use with this mod, or download the ones I use by right-clicking on the following images and select "Save Image As" in your browser, using the file names shown:

    • new_1.gif

    • new_3.gif

    • new_7.gif

    • updated.gif

  2. links.def:

    1. Add the following to the end of the field names in %db_def (be sure to end the previous line with a comma):
        DateAdded => [14, 'date', 15, 15, 0, \&get_date, '']
    2. In the section that says, "# Field Number of some important fields.", add the following:
        $db_dateadded = 14;
    This new field will store the date the record was first added to your Links database. Unlike the record's Date field, which is changed anytime the link owner modifies the link, the DateAdded field is never changed. It is used to determine whether or not a link is new or if it has been modified.

    During the building process, Links will check the DateAdded field to see if a link is new. If it is, then the appropriate New graphic gets displayed for both the link and its category, as well as the parent categories of that category. If the link is not new, Links will compare the Date and DateAdded fields to see if the Date field is more recent than the DateAdded field. If it is, then Links will check the age of the Date. If it qualifies as a modified link, the "Updated" graphic is displayed for that link and for its category and parent categories of that category.

    Only a "New" or "Updated" graphic will be displayed for a link (never both) and the "New" graphic has priority. That means, if the DateAdded falls within the number of days specified by $db_new_cutoff in links.cfg, it makes no difference whether or not the Date field is more recent. The appropriate "New" graphic will be displayed in such cases for that link.

    One, or the other, or both graphics may end up being displayed for categories if the categories contain both new and modified links.

  3. add.cgi, sub process_form:

    Change:
      # Set date variable to today's date.
        $in{$db_cols[$db_modified]} = &get_date;
    To read:
      # Set modified and added date variables to today's date.
        $in{$db_cols[$db_dateadded]} = $in{$db_cols[$db_modified]} = &get_date;
  4. modify.cgi, sub process_form:

    Change:
      # Print out the modified record to a "modified database" where it is stored until
      # the admin decides to add it into the real database.
    To read:
      # Print out the modified record to a "modified database" where it is stored until
      # the admin decides to add it into the real database. Ensure we retain the original
      # date the record was added.
        $in{$db_cols[$db_dateadded]} = $original{'DateAdded'};
  5. Modifying Your links.db Database:

    The next step in this process is to initialize the DateAdded field. This is only necessary if you already have records in links.db, otherwise, there is nothing to update and you can skip this step.

    Copy the following script, save it in your Links admin/data directory as add_date.pl, and chmod it to 755. Make sure your admin/data directory is chmod 777. Then, execute the script. It will read in all the records in links.db, get the data from the Date field and put it in the DateAdded field. It will write the new record out to a file called links2.db which you may look through to confirm that all went well. When you are satisfied that all is well, remove the original links.db (you did do the backup I suggested, right?) and rename links2.db to links.db. Here's the script; be sure to change the first line to point to Perl on your system:
      #!/usr/local/bin/perl
      # -------------------------------------------
      # Change the following line to full path to links.cfg if you have problems.
      require "../links.cfg";
      require "$db_lib_path/db_utils.pl";
      require "$db_lib_path/links.def";
    
      $ENV{'REQUEST_METHOD'} and (print "Content-type: text/plain\n\n");
      print "Opening links.db for reading. . .\n";
      open (DB, "<links.db")
        or print "Unable to open links database 'links.db'. Reason: $!" and exit;
      print "Opening links2.db for writing. . .\n";
      open (DBOUT, ">links2.db")
        or print "Unable to open output database. Reason: $!" and exit;
      print "Processing database records. . .\n";
      LINE: while (<DB>) {
        /^#/    and next LINE; # Skip comment Lines.
        /^\s*$/ and next LINE; # Skip blank lines.
        chomp;                 # Remove trailing new line.
        @rec = &split_decode($_);
        $rec[$db_dateadded] = $rec[$db_modified];
        print DBOUT &join_encode(&array_to_hash(0, @rec));
      }
      print "Done, closing database files. . .\n";
      close DB;
      close DBOUT;
      print "Links database now has DateAdded field completed.\n";
      print "It is stored in links2.db\n\n";
      # ---------------------------------------------
    
  6. nph-build.cgi:

    1. sub build_update_newpop:

      1. Change (this is all one line in the script):
          $values[$db_modified] or print
            "Warning: No date for line: $_. Skipping..\n" and next LINE;
        To read:
          if ((!$values[$db_date]) || (!$values[$db_dateadded])) {
            print "Warning: No date for line: $_. Skipping..\n" and next LINE;
          }
      2. Change:
          # Calculate days old and then mark new.
            $days = &days_old($values[$db_modified], $date);
        To read:
          # Calculate days old and then mark new.
            $days = &days_old($values[$db_dateadded], $date);
    2. sub build_category_information:

      Change:
        # We also initilize the days_old variable to Jan 1. 1990 so that if
        # this category doesn't have any links, we still have a valid date
        # for it.
                $stats{$name}[1] = "1-Jan-1990";
                $stats{$name}[0] = 0;
      To Read:
        # 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
    3. sub build_stats:

      Change:
        if ((!$stats{$cat}[1]) || &compare_dates($values[$db_modified], $stats{$cat}[1])) {
          $stats{$cat}[1] = $values[$db_modified];
        }
      To read:
        # 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";
        }
    4. sub build_new_page:

      Change:
        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{'Date'}}}{$category} .= &site_html_link (%tmp) . "\n";
            $span_totals{$tmp{'Date'}}++;
          }
        }
      To Read:
        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'}}++;
          }
        }
    5. site_html.pl/site_html_templates.pl:

      1. In the Globals section, near the top of the script, add the following (each on its own line) Note for site_html_templates.pl, these lines go above the %globals hash variable; they are not part of it:
          $new_1 = qq|<img src="/path/to/new_1.gif" border="0" width=34 height=12
          alt="New0-2" align="absmiddle">|;
        
          $new_3 = qq|<img src="/path/to/new_3.gif" border="0" width=34 height=12
          alt="New3-7" align="absmiddle">|;
        
          $new_7 = qq|<img src="/path/to/new_7.gif" border="0" width=34 height=12
          alt="New8-14" align="absmiddle">|;
        
          $updated = qq|<img src="/path/to/updated.gif" width=34 height=12
          border=0 alt="Updated" align="absmiddle">|;
        Be sure to change /path/to to be the path you used when you created or downloaded the images.

      2. sub site_html_link (non-templates only):

        1. Add the following line just beneath the "my %rec = @_;" line:
            my $days_old;
        2. Change (this is one line in the script):
            if ($rec{'isNew'} eq "Yes") {
              $output .= qq~ <small><sup class="new">new</sup></small>~; }
          To read:
            # 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) { $output .= $new_1; }
              elsif ($days_old <= 7) { $output .= $new_3; }
              elsif ($days_old <= $db_new_cutoff) { $output .= $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) { $output .= qq~ $updated~; }
            }
      3. sub site_html_link (templates only):

        1. Add the following line just beneath the "my %rec = @_;" line:
            my $days_old;
            my $new_mod_img = "";
        2. Change (this is one line in the script):
            ($rec{'isNew'} eq 'Yes') ?
              ($rec{'isNew'} = 1) :
              (delete $rec{'isNew'});
          To read:
            # 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~; }
            }
        3. Change:
            return &load_template ('link.html', { 
              detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension", 
              %rec,
              %globals
            });
          To read:
            return &load_template ('link.html', {
              new_mod_img => $new_mod_img,
              detailed_url => "$build_detail_url/$rec{'ID'}$build_extension",
              %rec,
              %globals
            });
    6. sub site_html_print_cat:

      1. Change:
          foreach $subcat (sort @subcat) { 
            ($description) = @{$category{$subcat}}[2];
        To read:
          foreach $subcat (sort @subcat) { 
            my $mod = $stats{"$subcat"}[3];
            my $new_add = $stats{"$subcat"}[4];
            ($description) = @{$category{$subcat}}[2];
      2. Comment-out or delete the following line:
          $mod = $stats{"$subcat"}[1];
      3. Change (this is one line in the script):
          $output .= qq|<small><sup class="new">new</sup></small>|
          if (&days_old($mod) < $db_new_cutoff);
        To read:
          if ($new_add eq "Yes") {
            $days_old = &days_old($stats{"$subcat"}[2]); 
            if ($days_old <= 2) { $output .= qq| $new_1|; }
            elsif ($days_old <= 7) { $output .= qq| $new_3|; }
            elsif ($days_old <= 14) { $output .= qq| $new_7|; }
          }
          if ($mod eq "Yes") { $output .= qq~ $updated~; }
        
    7. link.html (templates only):

      Change:
        <%if isNew%>
          <small><sup class="new">new</sup></small>
        <%endif%>
      To read:
        <%if new_mod_img%>
         <%new_mod_img%>
        <%endif%>

    *** END OF MOD ***

    If you have any problems with this modification, either post your questions in the Gossamer Threads Forums or send email directly to Bob Connors.

*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*:=+=:*

This Site Hosted By
Orphanage Services
Powered By Apache