?? rescreator.class.asp
字號(hào):
<%
'#類名:TSYS-模板解析器
'#簡(jiǎn)介:
' 分析資源模板內(nèi)TSYS標(biāo)簽,轉(zhuǎn)換成最終數(shù)據(jù)保存到指定目錄內(nèi)。
'#屬性:
' -
'#方法:
' CreateRes 創(chuàng)建資源
Class ResCreator
Private Sql, Fso, TParser
'初始化類
Private Sub Class_Initialize
Set Fso = Server.CreateObject(Cfg.FileSystemObject_Name)
Set TParser = New TagParser
End Sub
'注消類
Private Sub Class_Terminate
Set RsInfo = Nothing
Set ResColl = Nothing
Set Fso = Nothing
End Sub
'方法:創(chuàng)建資源(主方法)
'參數(shù):
' Resource 資源Rs記錄對(duì)象
' TContent 資源所將要套用的模板內(nèi)容
'返回:
' 0 生成失敗
' 1 生成成功
Public Function CreateRes(RsInfo, TempContent)
'模板為空及生成目錄不確定的資源不生成
If TempContent = "" Or RsInfo("directory_rule") = "" Or RsInfo("filename_rule") = "" Or IsNull(RsInfo("directory_rule")) Or IsNull(RsInfo("filename_rule")) Then
CreateRes = 0
Exit Function
End If
'具有跳鏈接的資源無(wú)需生成
If RsInfo("go_url") <> "" Then
CreateRes = 1
Exit Function
End If
'解析模板
TempContent = TParser.Parser(RsInfo, TempContent)
Dim arrFileInfo
arrFileInfo = Path_Parser(RsInfo)
Dim Fl
Set Fl = Fso.CreateTextFile(arrFileInfo(1), True)
Fl.Write TempContent
Fl.Close
If Err.Number = 0 Then
Sql = "UPDATE resource_list SET file_path='" & arrFileInfo(0) & "', visit_url='" & arrFileInfo(2) & "', created=1 WHERE id=" & RsInfo("id")
Db.ExeCute(Sql)
CreateRes = 1
Else
CreateRes = 0
End If
Err.Clear()
End Function
'方法:資源生成文件、目錄規(guī)則解析
'參數(shù):-
'返回:
' 路徑信息數(shù)組
' (0) 未轉(zhuǎn)成實(shí)際路徑的路徑的路徑信息
' (1) 已轉(zhuǎn)成實(shí)際路徑的路徑信息
' (2) 資源對(duì)外訪問(wèn)用的Url信息
Private Function Path_Parser(RsInfo)
Dim tmp_directory_rule, tmp_directory_rule2, tmp_filname_rule
Dim FileUrl '文件生成后Url地址
tmp_directory_rule = RsInfo("directory_rule")
tmp_directory_rule = Replace(tmp_directory_rule, "{class}", RsInfo("class_id"))
tmp_directory_rule = Replace(tmp_directory_rule, "{Y}", Year(RsInfo("addtime")))
tmp_directory_rule = Replace(tmp_directory_rule, "{M}", Right("00" & Month(RsInfo("addtime")), 2))
tmp_directory_rule = Replace(tmp_directory_rule, "{D}", Right("00" & Day(RsInfo("addtime")), 2))
tmp_directory_rule = Replace(tmp_directory_rule, "{W}", Right("00" & Weekday(RsInfo("addtime")), 2))
tmp_directory_rule = Replace(tmp_directory_rule, "{y}", Right(CStr(Year(RsInfo("addtime"))), 2))
tmp_directory_rule = Replace(tmp_directory_rule, "{m}", Month(RsInfo("addtime")))
tmp_directory_rule = Replace(tmp_directory_rule, "fzh3tvf", Day(RsInfo("addtime")))
tmp_directory_rule = Replace(tmp_directory_rule, "{w}", Weekday(RsInfo("addtime")))
tmp_filname_rule = RsInfo("filename_rule")
tmp_filname_rule = Replace(tmp_filname_rule, "{id}", RsInfo("id"))
tmp_filname_rule = Replace(tmp_filname_rule, "{class}", RsInfo("class_id"))
tmp_filname_rule = Replace(tmp_filname_rule, "{title}", RsInfo("title"))
tmp_filname_rule = Replace(tmp_filname_rule, "{author}", RsInfo("author"))
If RsInfo("replace_path") <> "" Then
If RsInfo("replace_path") = "{head}" Then
FileUrl = RsInfo("replace_with_url") & tmp_directory_rule
Else
FileUrl = Replace(tmp_directory_rule, RsInfo("replace_path"), RsInfo("replace_with_url"))
End If
End If
FileUrl = Replace(FileUrl, "\", "/")
If FLib.ChkPathType(tmp_directory_rule) = 2 Then
tmp_directory_rule = Replace(tmp_directory_rule, "\", "/")
tmp_directory_rule2 = Server.MapPath(tmp_directory_rule)
Else
tmp_directory_rule = Replace(tmp_directory_rule, "/", "\")
tmp_directory_rule2 = tmp_directory_rule
End If
If Not Fso.FolderExists(tmp_directory_rule2) Then
FLib.CreateFolder tmp_directory_rule2
End If
Dim arrFileInfo(3)
arrFileInfo(0) = tmp_directory_rule & "/" & tmp_filname_rule
arrFileInfo(1) = tmp_directory_rule2 & "\" & tmp_filname_rule
arrFileInfo(2) = FileUrl & "/" & tmp_filname_rule
Path_Parser = arrFileInfo
End Function
End Class
%>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -