<% 'article.asp - Program to display one of Louie Celerier's Bits & Pieces articles.. ' The default script (default.asp) displays a table of contents of the articles, and then ' calls this script to display one article. It passes one query string parameter: ' id=the base filename. ' There should be a .htm file with that base filename. ' The base filename is a date in yyyy-mm-ddx format, with x being an optional letter that ' allows multiple articles to occur on the same date. ' This script is VERY similar to article.asp in the letters subdirectory, and the terms ' "article" and "letter" are synonymous. ' Option Explicit Const ForReading = 1, ForWriting = 2, ForAppending = 3 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 dim articles, articleDate(100), articleTitle(100) 'Up to 100 articles articles = 0 'Counts the articles as they are read, and then as they are displayed Dim dashdate, pagetitle, slashdate, shortdate, thisarticle shortdate = "(Requested article is not in the index!?!)" 'Build our own array of month names for date conversion. dim months months = Array("","January","February","March","April","May","June","July","August","September","October","November","December") '**** Read the index file into an array of file identifiers (essentially, dates), and an array of titles. '**** We need these arrays to help with links to the next and previous article. dim FSO, filename, Filepath, file, TextStream, Line filename = "index.txt" ' Create the filesystem object, then map the logical path to the physical system path set FSO = server.createObject("Scripting.FileSystemObject") Filepath = Server.MapPath(Filename) if FSO.FileExists(Filepath) Then ' Get file handle and open the file. set file = FSO.GetFile(Filepath) Set TextStream = file.OpenAsTextStream(ForReading, TristateUseDefault) ' Read the index file line by line, and store every line in the arrays articleDate() and articleTitle() Do While Not TextStream.AtEndOfStream Line = TextStream.readline 'Read 11 characters. One character after the date allows more than one article to appear on the same date. dashdate = trim(left(line,11)) 'yyyy-mm-ddx pagetitle = mid(line,12) 'may contain
tags articles = articles + 1 articleDate(articles) = dashdate articleTitle(articles) = pagetitle 'If this is the article that has been requested, save its index number in thisarticle, and 'convert its date to a MMMMMM dd, yyyy format. If request.querystring("id")=dashdate Then thisarticle = articles ' if right(dashdate,1)="x" Then shortdate="" 'For articles that don't have a valid date. else shortdate = months(cint(mid(dashdate,6,2))) & " " & trim(cint(mid(dashdate,9,2))) & ", " & left(dashdate,4) End If End If Loop articleDate(articles+1)="" 'Make sure the list ends with an empty entry, not "null" Set TextStream = nothing Else %> Response.Write "

Major error!! The index of articles is missing. Please try again later.
" Response.Write "If this error persists, please notify us

" & vbcrlf <% Response.End End If Set FSO = nothing %> Bits & Pieces: <%=articletitle(thisarticle)%>

Bits & Pieces

<% '*** Page heading - Display links to the previous and next articles, using graphic arrows. dim nextfile,prevfile nextfile="gifs/next2.png" prevfile="gifs/prev2.png" 'First, display a left arrow to link to the previous artile (if there is one). '(Remember, the array is in reverse chronological order, so the "previous" articles comes ' after this one in the array. If thisArticle>0 and articleDate(thisArticle+1)<>"" Then response.write "" response.write "" Else 'Even if there is no previous article to link to (and thus no arrow), we need to display a space 'with padding so that the navigation remains centered. response.write " " End If 'Display this article's date between the navigation arrows. Response.write shortdate 'Display a right arrow to link to the subsequent article (if there is one). If thisArticle>1 Then response.write "" response.write "" Else response.write " " End If response.write vbcrlf & "
" & vbcrlf ' End of the page heading div. response.write "

" & articleTitle(thisArticle) & "

" & vbcrlf dashdate = request("id") If right(dashdate,1)="P" Then '***** Embed a PDF file ***** filename = "htmfiles/" & dashdate & ".pdf" response.write "

Link directly to the PDF for printing

" & vbcrlf response.write "
" response.write ""& vbcrlf response.write "
" & vbcrlf Else '**** Embed an HTML file ***** 'Read the HTM file that contains the selected letter/article. 'Define a File System object, and get the physical system filespec for this filename. filename = "htmfiles/" & dashdate & ".htm" Filepath = Server.MapPath(Filename) set FSO = server.createObject("Scripting.FileSystemObject") if FSO.FileExists(Filepath) Then ' Get a handle to the file and open the file set file = FSO.GetFile(Filepath) Set TextStream = file.OpenAsTextStream(ForReading, TristateUseDefault) ' Read & display the file line by line Do While Not TextStream.AtEndOfStream Line = TextStream.readline 'Repoint all images, since the html files and their images are in a subdirectory. line = replace(Line, "src=""20", "src=""htmfiles/20") response.write line & vbcrlf Loop Set TextStream = nothing response.write "

- Luis R. Celerier" response.write "
Longview, Texas

" & vbcrlf Else Response.Write "

Sorry - there is no article at " & request("id") & ".htm

" & vbcrlf End If Set FSO = nothing End If %> <%'================================================================= ' Functions and Subroutines '=================================================================== 'Convert the yyyy-mm-ddx-formatted date stored in the array into a parenthesized ddMMMyy format. 'The array of months gives full month names; we just want the first 3 letters here. Function linkdate(i) dim thedate thedate = articledate(i) linkdate = "(" & mid(thedate,9,2) & left(months(cint(mid(thedate,6,2))),3) & left(thedate,4) & ")" End Function %>