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

📄 functionlib.class.asp

📁 一个很好的asp cms管理系统
💻 ASP
📖 第 1 页 / 共 2 页
字号:
<%
'////////////////////////////////////////////////////////////////////////
'本页:
'   Tsys 公用函数库
'说明:
'   
'////////////////////////////////////////////////////////////////////////

Class FunctionLib

    '*******************************************************************************************************
    '                                       系统默认的常用功能函数 - 开始
    '*******************************************************************************************************
    '函数:Cookie写
    '参数:Cookie名, Cookie值, 有效时间
    Public Function SetCookie(Key, Val, ExpTime)
        Response.Cookies("TSYS_" & Key) = Val
        Response.Cookies("TSYS_" & Key).Expires = ExpTime
    End Function

    '函数:Cookie读
    '参数:Cookie名
    '返回:cookie值
    Public Function GetCookie(Key)
        GetCookie = Request.Cookies("TSYS_" & Key)
    End Function

    '函数:验证权限标识Key格式
    '参数:用户名
    '返回:bool (true:有效的用户名)
    Public Function Check_PopedomKey(str)
        Dim regEx
        '创建正则对象
        Set regEx = New RegExp
        regEx.IgnoreCase = True
        regEx.Global = True
        regEx.MultiLine = True

        regEx.Pattern = "^[a-z0-9_]{2,50}$"
        Check_PopedomKey = regEx.Test(str)
        Set regEx = Nothing
    End Function

    '函数:验证用户名格式有效性
    '参数:用户名
    '返回:bool (true:有效的用户名)
    Public Function Check_UserName(str)
        Dim regEx
        '创建正则对象
        Set regEx = New RegExp
        regEx.IgnoreCase = True
        regEx.Global = True
        regEx.MultiLine = True

        regEx.Pattern = "^[a-z0-9_]{2,20}$"
        Check_UserName = regEx.Test(str)
        Set regEx = Nothing
    End Function

    '函数:危险Sql过滤
    '参数:Sql
    '返回:过滤结果'
    Public Function SafeSql(str)
        SafeSql = Replace(trim(str), "'", "''")
    End Function

    '函数:过滤Html标签
    '参数:字符串
    '返回:过滤后字符串
    Public Function FilterHtml(str)
        Dim regEx
        '创建正则对象
        Set regEx = New RegExp
        regEx.IgnoreCase = True
        regEx.Global = True
        regEx.MultiLine = True

        regEx.Pattern = "<.+?>"
        FilterHtml = regEx.Replace(str,"")
        Set regEx = Nothing
    End Function

    '函数:验证邮件地址格式
    '参数:字符串
    '返回:bool (true:正确)
    Public Function CheckEmail(str)
        Dim regEx
        '创建正则对象
        Set regEx = New RegExp
        regEx.IgnoreCase = True
        regEx.Global = True
        regEx.MultiLine = True

        regEx.Pattern = "^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$"
        CheckEmail = regEx.Test(str)
        Set regEx = Nothing
    End Function

    '函数:是否为服务实际路径
    Public Function IsReallyPath(str)
        Dim regEx
        '创建正则对象
        Set regEx = New RegExp
        regEx.IgnoreCase = True
        regEx.Global = True
        regEx.MultiLine = True

        regEx.Pattern = "^[c-z]\:.+$"
        IsReallyPath = regEx.Test(str)
        Set regEx = Nothing
    End Function

    '函数:判断路径类型
    '返回:
    '   1   物理路径
    '   2   站点虚路径
    '   3   网络路径
    Public Function ChkPathType(strPath)
        Dim regEx
        '创建正则对象
        Set regEx = New RegExp
        regEx.IgnoreCase = True
        regEx.Global = True
        regEx.MultiLine = False

        regEx.Pattern = "^[c-z]{1,1}\:.+$"
        If regEx.Test(strPath) Then
            ChkPathType = 1
            Exit Function
        End If

        regEx.Pattern = "^(?:http|https){1,1}\:.+$"
        If regEx.Test(strPath) Then
            ChkPathType = 3
            Exit Function
        End If

        ChkPathType = 2

        Set regEx = Nothing
    End Function

    '函数:Html编码
    '参数:字符串
    '返回:编码后字符串'
    Public Function HTMLEncode(str)
        If Not Isnull(str) Then
            str = Replace(str, CHR(13), "")
            str = Replace(str, CHR(10) & CHR(10), "<P></P>")
            str = Replace(str, CHR(10), "<BR>")
            str = replace(str, ">", "&gt;")
            str = replace(str, "<", "&lt;")
            str = replace(str, "&",    "&amp;")
            str = replace(str, " ",    "&nbsp;")
            str = replace(str, """", "&quot;")
            HTMLEncode = str
        End If
    End Function

    '函数:字符串截断(可识别中英文)
    '参数:预截字符串,长度
    '返回:截断后的字符串'
    Public Function CutStr(str,strlen)
        DIM l,t,c,m_i
        l=len(str)
        t=0
        For m_i = 1 To l
            c = Abs(Asc(Mid(str,m_i,1)))
            If c > 255 Then
                t = t+2
            Else
                t = t+1
            End If
    
            If t >= strlen Then
                CutStr = left(str,m_i) & "..."
                exit for
            Else
                CutStr = str
            End if
        Next
    End Function

    '函数:转义javascript特殊字符
    '参数:html串
    '返回:转义后的串'
    Public Function HTMLToJS(strHtml)
        If Trim(strHtml)="" Then
            HTMLToJS=""
            Exit Function
        End If

        strHtml=Replace(strHtml,"\","\\")
        strHtml=Replace(strHtml,"""","\""")
        strHtml=Replace(strHtml,vbCrLf,"")

        HTMLToJS=strHtml
    End Function

    '函数:时间格式化
    '参数:时间,格式模板
    '返回:格式化后的字符串
    '备注:格式化关键词详解:
    '   "{Y}" : 4位年
    '   "{y}" : 2位年
    '   "{M}" : 不补位的月
    '   "{m}" : 补位的月,如03,01
    '   "{D}" : 不补位的日
    '   "{d}" : 补位的日
    '   "{H}" : 不补位的小时
    '   "{h}" : 补位的小时
    '   "{MI}": 不补位的分钟
    '   "{mi}": 补位的分钟
    '   "{S}" : 不补位的秒
    '   "{s}" : 补位的秒
    Public Function FormatMyDate(myDate,Template)
        If Not IsDate(myDate) Or Template = "" Then
            FormatMyDate = Template
            Exit Function
        End If

        Dim mYear,mMonth,mDay,mHour,mMin,mSec
            mYear = Year(myDate)
            mMonth = Month(myDate)
            mDay = Day(myDate)
            mHour = Hour(myDate)
            mMin = Minute(myDate)
            mSec = Second(myDate)

        Template = Replace(Template,"{Y}",Year(myDate))
        Template = Replace(Template,"{y}",Right(Year(myDate),2))
        Template = Replace(Template,"{M}",Month(myDate))
        Template = Replace(Template,"{m}",Right("00" & Month(myDate),2))
        Template = Replace(Template,"{D}",Day(myDate))
        Template = Replace(Template,"{d}",Right("00" & Day(myDate),2))
        Template = Replace(Template,"{H}",Hour(myDate))
        Template = Replace(Template,"{h}",Right("00" & Hour(myDate),2))
        Template = Replace(Template,"{MI}",Minute(myDate))
        Template = Replace(Template,"{mi}",Right("00" & Minute(myDate),2))
        Template = Replace(Template,"{S}",Second(myDate))
        Template = Replace(Template,"{s}",Right("00" & Second(myDate),2))

        FormatMyDate = Template
    End Function

    '函数:通用信息提示框
    '参数:
    '   提示内容
    '   返回地址,详细值类型如下:
    '       "#"      只提示,其它不做任何操作
    '       "BACK"   提示后返回前一页
    '       "CLOSE"  提示后关闭窗口
    '       "网址"    提示后返回指定页面
    '   是否父窗口'
    Public Function Alert(str,backUrl,TopWindow)

        If str <> "" Then
            Response.Write "<script>alert(""" & str & """);"
        End If

        Dim WinName
        If TopWindow = 1 Then
            WinName = "top"
        Else
            WinName = "self"
        End If

        Select Case backUrl
            Case "#"
            Case "BACK"
                Response.Write WinName & ".history.back();"
            Case "CLOSE"
                Response.Write "window.close();"
            Case Else
                If backUrl <> "" Then
                    Response.Write WinName & ".location.href = """ & backUrl & """;"
                End If
        End Select
        Response.Write "</script>"
    End Function

    '函数:创建完整目录
    '参数:目录串
    Public Function CreateFolder(strPath)
        strPath = Replace(strPath,"/", "\")
        arrPath = Split(strPath, "\")
        Dim Fso, I, tmpPath, arrPath
        Set Fso = Server.CreateObject(Cfg.FileSystemObject_Name)
        tmpPath = arrPath(0)
        For I=1 To UBound(arrPath)
            tmpPath  = tmpPath & "\" & arrPath(I)
            If Not Fso.FolderExists(tmpPath) Then
                Fso.CreateFolder tmpPath
            End If
        Next
    End Function

    Public Function FormatEmpty(str, fstr)
        If IsNull(str) Or str = "" Then
            FormatEmpty = fstr
        Else
            FormatEmpty = str
        End If
    End Function

    '函数:日制记录
    '参数:日制内容
    Public Function AddLog(msg)
        Dim Sql
        Sql = "INSERT INTO sys_log_list(remark, creator, ip, addtime)VALUES('" & Server.HtmlEncode(msg) & "', '" & Admin.UserName & "', '" & Admin.UserIp & "', GETDATE())"
        Db.ExeCute(Sql)
    End Function

    '函数:资源子分类ID列表
    '参数:
    '返回:ID列,如: 23,23,11,32
    Public Function ChildenList(Parent)
        Dim Sql, Rs, Result
        Sql = "SELECT id FROM res_class_list WHERE parent = " & Parent
        Set Rs = Db.ExeCute(Sql)
        While Not Rs.Eof
            If ChildenList <> "" Then
                ChildenList = ChildenList & "," & Rs("id")
            Else
                ChildenList = Rs("id")
            End If
            Result = ChildenList(Rs("id"))
            If Result <> "" Then
                ChildenList = ChildenList & "," & Result
            End If

⌨️ 快捷键说明

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