Share a good dongdong, dynamic include file (Dynamics File Includes) _ Application Tips

Source: Internet
Author: User
Tags chr readfile
As early as 03 in the blue ideal to see the dynamic include article, was already feeling very powerful, but the actual application, inconvenient and include the effect is not good.

Later on a website to see the improved version, but also not very good ~ ~ ~

Hey, I really feel a little want to give up ASP, but because the company is still using ASP to develop, I also have no way ...

Today, I must remember today ~ ~ ~ in a foreign website I unexpectedly found such a good dongdong, great ~~~great works!!!

Some of the dynamic include codes that were previously tried could not include a class, or even a function ~ ~ ~ or the Include in the include file could not be included ...

Now this ghost (Dselkirk) Writing class can do this for us ~ ~ ~ ~
Copy Code code 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) & 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
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.