for 2 years of pages a database (not necessarily a full blown CMS) would make the task a little simple but hey! Nothing like a challenge.
The only prerequisite is that all your existing pages MUST be able to run ASP code, ie: all have an extension of .asp or your server application mappings have been set to allow .htm(l) to run as ASP.
Put the text for each day in a text file, the file extension doesn't matter because were are not going to get the server to parse the file.
Use a fixed naming convention for the files yearnumber-monthnumber-daynumber.ext (eg: 01-12-25.ext would be Christmas Day) or better still a folder structure of
/text/yearnumber/monthnumber/daynumber.ext
this would look like -> /text/01/12/25.ext (01.ext ... to ... 31.ext) <- and so on through the year.
The files can have HTML code in them, it will just be streamed into the browser and rendered there.
the three functions below should be put into a file say "inc_file-funcs.asp" and included in
every one of your existing pages with ->
Code:
<!--#include virtual="/path_to_file/inc_file-funcs.asp" -->
Code:
<%
const c_sRootFolder = "\text\"
const c_sFileExt = ".ext"
const c_sSeparator = "\"
function setFileName()
' get a string for the year (random number between 1 and 2)
dim l_iYearNo : l_iYearNo = setLeadZero(int((2-1+1)*rnd+1))
' get a string for the month
dim l_iMonthNo : l_iMonthNo = setLeadZero(month(date))
' get a string for the day
dim l_iDayNo : l_iDayNo = setLeadZero(day(date))
StreamText( l_iYearNo & c_sSeparator & l_iMonthNo & c_sSeparator & l_iDayNo & c_sFileExt)
end function
sub StreamText(p_sFileName)
' read in a file and stream it out to the browser
dim l_oFSO : set l_oFSO = createobject("Scripting.FileSystemObject")
dim l_oFSFile : set l_oFSFile = l_oFSO.OpenTextFile(server.mappath(c_sRootFolder & p_sFileName))
'write the file out line by line plus a line break
do until l_oFSFile.AtEndOfStream
with response
.write (l_oFSFile.ReadLine)
.write vbCrLf
end with
Loop
l_oFSFile.close
set l_oFSFile = nothing
set l_oFSO = nothing
end sub
function setLeadZero(p_iValue)
p_iValue = trim(cstr(p_iValue))
if len(p_iValue) = 1 then
setLeadZero = p_iValue & "0"
end if
end function
%>
Then, wherever you need the text to appear simply put
on your existing page.
The three constants will need editing to suit your particular setup,
const c_sRootFolder = "\text\" is the root path to where the files are or the folder structure starts
const c_sFileExt = ".ext" obviously your chosen file extension
const c_sSeparator = "\" this is the file name separator.
If you are using the folder structure this will be the backslash.
If you are using file names then this should the character used to separate the numbers, or empty ("") if they are butted up to each other (011225.ext).
Avoid using spaces!
I originally wrote the base of this code to get around the limitations of ASP being unable to handle variable includes.
In ASP, because includes are evaluated on a first pass through the interpretor when the variables are instantiated but NOT assigned, you cannot have code like this:
dim variable: variable = "some_calculated_value"
...
...
more of the page is here
...
...
<!--#include virtual=variable -->
The only drawback is you cannot have ASP code in the file you are streaming in and have it run directly. You could of course use "eval()" and "execute()" inside the stream function on a line where there were code delimiters, should you so wish and have a masochistic approach to programming
