<%
Public include, Include_vars
Set include = new Cls_include
Class Cls_include
Private Sub Class_Initialize ()
Set include_vars = Server.CreateObject ("Scripting.Dictionary")
End Sub
Private Sub Class_deactivate ()
Arr_variables.removeall
Set include_vars = Nothing
Set include = Nothing
End Sub
Public default function include (ByVal str_path)
Dim Str_source
If Str_path <> "" Then
Str_source = ReadFile (Str_path)
If Str_source <> "" Then
Processincludes Str_source
Convert2code Str_source
Formatcode Str_source
If Str_source <> "" Then
If Request.QueryString ("Debug") = 1 Then
Response.Write Str_source
Response.End
Else
Executeglobal Str_source
Include_vars.removeall
End If
End If
End If
End If
End Function
Private Sub Convert2code (Str_source)
Dim i, Str_temp, Arr_temp, Int_len
If Str_source <> "" Then
If InStr (Str_source, "%" & ">") > InStr (Str_source, "<" & "%") then
Str_temp = replace (Str_source, "<" & "%", "|%")
Str_temp = replace (str_temp, "%" & ">", "|")
If left (str_temp,1) = ' | ' Then str_temp = Right (Str_temp,len (str_temp)-1)
If Right (str_temp,1) = "|" Then Str_temp = Left (Str_temp,len (str_temp)-1)
Arr_temp = Split (str_temp, "|")
Int_len = UBound (arr_temp)
if (Int_len + 1) > 0 Then
For i = 0 to Int_len
Str_temp = Trim (arr_temp (i))
Str_temp = replace (Str_temp,vbcrlf & Vbcrlf,vbcrlf)
If left (str_temp,2) = vbCrLf Then str_temp = Right (Str_temp,len (str_temp)-2)
If Right (str_temp,2) = vbCrLf Then Str_temp = Left (Str_temp,len (str_temp)-2)
If left (str_temp,1) = "%" Then
Str_temp = Right (Str_temp,len (str_temp)-1)
If left (str_temp,1) = "=" Then
Str_temp = Right (Str_temp,len (str_temp)-1)
Str_temp = "Response.Write" & Str_temp
End If
Else
If Str_temp <> "" Then
Include_vars.add I, str_temp
Str_temp = "Response.Write Include_vars.item" ("& I &") "
End If
End If
Str_temp = replace (STR_TEMP,CHR) & Chr (+) & "&", "")
Str_temp = replace (str_temp, "&" & Chr () & Chr (34), "")
If Right (str_temp,2) <> vbCrLf Then str_temp = Str_temp
Arr_temp (i) = Str_temp
Next
Str_source = Join (ARR_TEMP,VBCRLF)
End If
Else
If Str_source <> "" Then
Include_vars.add "var", Str_source
Str_source = "Response.Write Include_vars.item (" "Var") "
End If
End If
End If
End Sub
Private Sub Processincludes (Str_source)
Dim Int_start, Str_path, Str_mid, str_temp
Str_source = replace (Str_source, "<!--#", "<!--#")
Int_start = InStr (Str_source, "<!--#include")
Str_mid = LCase (Getbetween (Str_source, "<!--#include", "-->"))
Do Until Int_start = 0
Str_mid = LCase (Getbetween (Str_source, "<!--", "-->"))
Int_start = InStr (Str_mid, "#include")
If Int_start > 0 Then
Str_temp = LCase (Getbetween (STR_MID,CHR), Chr (34))
Str_temp = Trim (str_temp)
Str_path = ReadFile (str_temp)
Str_source = replace (Str_source, "<!--" & Str_mid & "-->", Str_path & vbCrLf)
End If
Int_start = InStr (Str_source, "#include")
Loop
End Sub
Private Sub Formatcode (Str_code)
Dim i, Arr_temp, Int_len
Str_code = replace (Str_code,vbcrlf & Vbcrlf,vbcrlf)
If left (str_code,2) = vbCrLf Then Str_code = Right (Str_code,len (Str_code)-2)
Str_code = Trim (Str_code)
If InStr (STR_CODE,VBCRLF) > 0 Then
Arr_temp = Split (STR_CODE,VBCRLF)
For i = 0 To UBound (arr_temp)
Arr_temp (i) = LTrim (Arr_temp (i))
If Arr_temp (i) <> "" Then arr_temp (i) = Arr_temp (i) & vbCrLf
Next
Str_code = Join (Arr_temp, "")
Arr_temp = vbnull
End If
End Sub
Private function ReadFile (Str_path)
Dim objFSO, objFILE
If Str_path <> "" Then
If InStr (Str_path, ":") = 0 Then Str_path = Server.MapPath (Str_path)
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
If Objfso.fileexists (Str_path) Then
Set objfile = objFSO.OpenTextFile (Str_path, 1, false)
If Err.Number = 0 Then
ReadFile = Objfile.readall
Objfile.close
End If
Set objfile = Nothing
End If
Set objFSO = Nothing
End If
End Function
Private Function Getbetween (strdata, Strstart, Strend)
Dim Lngstart, Lngend
Lngstart = InStr (Strdata, Strstart) + len (strstart)
if (lngstart <> 0) Then
Lngend = InStr (Lngstart, Strdata, Strend)
if (lngend <> 0) Then
Getbetween = Mid (Strdata, Lngstart, Lngend-lngstart)
End If
End If
End Function
End Class
%> |