‘====================================================’ 类名:One
‘ 作者:mqycn
‘ 博客:http://www.miaoqiyuan.cn
‘ 源码:http://www.miaoqiyuan.cn/p/one-php
‘ 说明:多项目 函数库、类库 统一为一个版本的方法
‘====================================================Class OneAsp
Private FSO
Private Root
Private Sub Class_Initialize()
Set FSO=Server.CreateObject(“Scripting.FileSystemObject”)
End Sub
Private Sub Class_Terminate()
Set FSO=Nothing
End Sub
Public Function Run(ByVal sourceFile, ByVal saveFile)
Run=”<hr><b>Input:</b>” & sourceFile & “<br><b>Result:</b>” & Save(saveFile, Include(sourceFile))
End Function
Public Function Include(ByVal path)
Dim tmpPath, tmpItem, arrPath, index
tmpPath=””
arrPath=Split(path, “/”)
For index=0 To UBound(arrPath) – 1
tmpItem=arrPath(index)
tmpPath=tmpPath & tmpItem & “/”
Next
Include=Parse(tmpPath, arrPath(UBound(arrPath)))
End Function
Private Function Parse(ByVal root, ByVal fileName)
Call SetRoot(root)
Dim html
html=OpenRead(fileName)
Dim preg, pregResult
Set preg=New Regexp
preg.pattern=”<!–#include file=””([^””]*)””–>”
preg.global=True
preg.ignorecase=True
Dim htmlInclude
Set pregResult=preg.execute(html)
For Each htmlInclude In pregResult
html=Replace(html, htmlInclude, Include(root & htmlInclude.submatches(0)))
Next
Parse=”<% ‘” & root & fileName & ” Start %” & “>” & vbCrLf & html & vbCrLf & “<% ‘” & root & fileName & ” End %” & “>” & vbCrLf
End Function
Private Function SetRoot(ByVal rootPath)
If Right(rootPath, 1) <> “/” Then rootPath=rootPath & “/”
Root=rootPath
End Function
Private Function RealPath(ByVal path)
RealPath=Server.Mappath(Root & path)
End Function
Private Function OpenRead(ByVal path)
Dim txtFile
Set txtFile=FSO.OpenTextFile(RealPath(path))
OpenRead=txtFile.ReadAll()
txtFile.close
On Error GoTo 0
End Function
Public Function Save(ByVal path, ByVal body)
Dim txtFile
Set txtFile=FSO.CreateTextFile(Server.Mappath(path))
txtFile.write body
txtFile.close
Set txtFile=Nothing
Save=path
End Function
End Class