As early as 03 years ago, I saw dynamic include on the blue ideal. Article At that time, I thought it was very good, but it was inconvenient to use it and the effect of include was not good.
Later, I saw the ghost version on a website, but it is not very easy to use ~~~
Ah, at that time, I really felt a little anxious to give up ASP, but since the company still uses ASP for development, I also have no way...
Today, I must remember today ~~~ On a foreign website, I found such a good stuff. It's amazing ~~~ Great works !!!
Some of the previous dynamic include testsCodeAnd cannot include a class or even function ~~~ Or the include file cannot be included...
Now the dselkirk class can do this for us ~~~Copy codeThe Code is as follows: <%
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 (34) & CHR (34 )&"&","")
Str_temp = Replace (str_temp, "&" & CHR (34) & 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," str_mid = lcase (getbetween (str_source," ")
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 (34), CHR (34)
str_temp = trim (str_temp)
str_path = readfile (str_temp)
str_source = Replace (str_source, " ", 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
%>