⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rescreator.class.asp

📁 一个很好的asp cms管理系统
💻 ASP
字号:
<%
'#类名:TSYS-模板解析器
'#简介:
'   分析资源模板内TSYS标签,转换成最终数据保存到指定目录内。
'#属性:
'    -
'#方法:
'   CreateRes               创建资源

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

    '方法:创建资源(主方法)
    '参数:
    '   Resource    资源Rs记录对象
    '   TContent    资源所将要套用的模板内容
    '返回:
    '   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

        '具有跳链接的资源无需生成
        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

    '方法:资源生成文件、目录规则解析
    '参数:-
    '返回:
    '   路径信息数组
    '   (0) 未转成实际路径的路径的路径信息
    '   (1) 已转成实际路径的路径信息
    '   (2) 资源对外访问用的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, "{d}", 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
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -