<% @ Language=VBScript %> <html><body><head><META NAME="ROBOTS" CONTENT="NOINDEX,NOFOLLOW"></head> <% '************************************************************************************************************************************ ' ' Portable Content Generator Script ' Written by Jason Salas: jason@kuam.com ' November 6, 2001 ' This script connects to a data store, creates a new text file and saves it to the Web server. The headlines can then be referenced ' in the underlying HTML code of a remote client page, using the absolute path to your file, such as: ' ' <!-- START PORTABLE HEADLINES --> ' <table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td width="100%"><font face="Arial" size="2"> ' <script language="JavaScript" src="http://www.domainname.com/ filename.js"></script></font></td></tr></table> ' <!-- END PORTABLE HEADLINES --> ' ' The only assumptions in this example are that you will have an ASP page feeding data with the following path: ' http://www.yourdomainname.com/filename.asp?id=8675309 ' ' ...and that your database has a table ("Content") with the following fields: ' DB Fields: StoryID, Title, Teaser ' ' ************************************************************************************************************************************ ' declare variables and connect to the data store Dim objConn, objRS, FSO, Headlines Set objConn = Server.CreateObject("ADODB.Connection") objConn.Open "dsn=yourDSNnamehere;uid=sa;pwd=password;" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open "SELECT TOP 10 StoryID, Title, Teaser FROM Content ORDER BY StoryID DESC", objConn Set FSO = CreateObject("Scripting.FileSystemObject") Set Headlines = FSO.CreateTextFile("C:\inetpub\wwwroot\portablecontent.js",True,False) ' the default path for IIS, you may need to change as needed based on the setup of your Web server ' write all the new headlines to a text file from the recordset (overwriting an existing file), and ' replace ASCII-type single-quotes "'" with UNICODE-style single quotes "'" so the resultant JavaScript ' file won't generate an error Headlines.Write("<!--" & vbcrlf) Do While Not objRS.EOF trimmed = Replace(Trim(Left(objRS("Teaser"),165)),"'","'",1,-1,vbTextCompare) Headlines.Write("document.writeln('<a target=""_blank"" href=""http://www.yourdomainname.com/filename.asp?id=" & objRS("StoryID") & """><b>" & Replace(objRS("Title"),"'","'",1,-1,vbTextCompare) & "</b></a><br>');") ' change this to reflect the path to your normal content files Headlines.Write(vbcrlf & "document.writeln('") ' crop the description and add "... (more)" if the description string is longer than 165 characters ' if not, then just write out the string If Len(trimmed) < 165 Then Headlines.Write(trimmed) Else Position1 = InStr(trimmed," ") Position2 = 2 While Position1 > 1 If Position2 > 1 Then Position1 = Position1+1 Position2 = InStr(Position1, trimmed, " ") Else Position2 = Position1 Position1 = 0 End If Wend Position2 = Position2-1 trimmed = left(trimmed, Position2) trimmed = trimmed & "... <a target=""_blank"" href=""http://www.yourdomainname.com/filename.asp?id=" & objRS("StoryID") & """>(more)</a>" Headlines.Write(trimmed) End If Headlines.Write("<br>');") Headlines.Write(vbcrlf) objRS.MoveNext Loop Headlines.Write("//-->") Headlines.Close ' destroy any open object references and close open connections Set Headlines = nothing Set FSO = nothing objRS.Close Set objRS = nothing objConn.Close Set objConn = nothing ' display a confirmation message Response.Write("The headlines have been updated!") %> </body></html>