%
'///////////////////////////////////////////////////////////////////////////////
'// Z-Blog
'// 作 者: 朱煊(zx.asd)
'// 版权所有: RainbowSoft Studio
'// 技术支持: rainbowsoft@163.com
'// 程序名称:
'// 程序版本:
'// 单元名称: c_function.asp
'// 开始时间: 2004.07.28
'// 最后修改:
'// 备 注: 函数模块
'///////////////////////////////////////////////////////////////////////////////
'*********************************************************
' 目的: 显示错误页面
' 输入: id
' 返回: 无
'*********************************************************
Dim ShowError_Custom
Sub ShowError(id)
If IsEmpty(ShowError_Custom)=False Then
Execute(ShowError_Custom)
Exit Sub
End If
Response.Redirect ZC_BLOG_HOST & "function/c_error.asp?errorid=" & id & "&number=" & Err.Number & "&description=" & Server.URLEncode(Err.Description) & "&source=" & Server.URLEncode(Err.Source)
End Sub
'*********************************************************
'*********************************************************
' 目的: XML-RPC显示错误页面
'*********************************************************
Function RespondError(faultCode,faultString)
Dim strXML
Dim strError
strXML="faultCode$1faultString$2"
strError=strXML
strError=Replace(strError,"$1",TransferHTML(faultCode,"[html-format]"))
strError=Replace(strError,"$2",TransferHTML(faultString,"[html-format]"))
Response.Clear
Response.BinaryWrite ChrB(&HEF) & ChrB(&HBB) & ChrB(&HBF)
Response.Write strError
Response.End
End Function
'*********************************************************
'*********************************************************
' 目的: 检查正则式
' 输入: id
' 返回: 成功为True
'*********************************************************
Function CheckRegExp(source,para)
If para="[username]" Then
para="^[.A-Za-z0-9\u4e00-\u9fa5]+$"
End If
If para="[password]" Then
para="^[a-z0-9]+$"
End If
If para="[email]" Then
para="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*\.)+[a-zA-Z]*)$"
End If
If para="[homepage]" Then
para="^[a-zA-Z]+://[a-zA-z0-9\-\./]+?/*$"
End If
If para="[nojapan]" Then
para="[\u3040-\u30ff]+"
End If
If para="[guid]" Then
para="^\w{8}\-\w{4}\-\w{4}\-\w{4}\-\w{12}$"
End If
Dim re
Set re = New RegExp
re.Global = True
re.Pattern = para
re.IgnoreCase = False
CheckRegExp = re.Test(source)
End Function
'*********************************************************
'*********************************************************
' 目的: 检查参数
' 返回: 出错则转到ShowError(3)
'*********************************************************
Function CheckParameter(byRef source,strType,default)
On Error Resume Next
If strType="int" Then
'数值
If IsNull(source) Then
source=default
ElseIf IsEmpty(source) Then
source=default
ElseIf IsNumeric(source) Then
source=CLng(source)
ElseIf source="" Then
source=default
Else
Call ShowError(3)
End if
If Err.Number<>0 Then Call ShowError(3)
CheckParameter=True
ElseIf strType="dtm" Then
'日期
If IsNull(source) Then
source=default
ElseIf IsEmpty(source) Then
source=default
ElseIf IsDate(source) Then
source=source
Call FormatDateTime(source,vbLongDate)
Call FormatDateTime(source,vbShortDate)
ElseIf source="" Then
source=default
Else
Call ShowError(3)
End if
If Err.Number<>0 Then Call ShowError(3)
CheckParameter=True
ElseIf strType="sql" Then
'SQL
If IsNull(source) Or Trim(source)="" Or IsEmpty(source) Then
source=default
Else
source=CStr(Replace(source,Chr(39),Chr(39)&Chr(39)))
End If
ElseIf strType="bool" Then
'Boolean
source=CBool(source)
If Err.Number<>0 Then
Err.Clear
If IsEmpty(source)=True Then
source=True
Else
source=False
End If
End If
Else
Call ShowError(0)
End If
End Function
'*********************************************************
'*********************************************************
' 目的: 检查引用
' 返回: 无
'*********************************************************
Sub CheckReference(strDestination)
Exit Sub
Dim strReferer
strReferer=CStr(Request.ServerVariables("HTTP_REFERER"))
If Instr(strReferer,ZC_BLOG_HOST)=0 Then
ShowError(5)
End If
End Sub
'*********************************************************
'*********************************************************
' 目的: 搜索字符串
' 返回:
' 备注: 不区分大小写
'*********************************************************
Function Search(strText,strQuestion)
Dim s
Dim i
Dim j
s=strText
i=Instr(1,s,strQuestion,vbTextCompare)
If i>0 Then
s=Left(s,i+Len(strQuestion)+100)
s=Right(s,Len(strQuestion)+200)
Else
s=""
End If
If s<>"" Then
i=1
Do While InStr(i,s,strQuestion,vbTextCompare)>0
j=InStr(i,s,strQuestion,vbTextCompare)
If Len(s)-j-Len(strQuestion)<0 Then
s=Left(s,j-1) & "" & strQuestion & ""
Exit Do
Else
s=Left(s,j-1) & "" & strQuestion & "" & Right(s,Len(s)-j-Len(strQuestion)+1)
End If
i=j+Len("" & strQuestion & "")-1
If i>=Len(s) Then Exit Do
Loop
End If
If s="" Then
Search=strText
Else
Search=s
End If
End Function
'*********************************************************
'*********************************************************
' 目的: 检查引用
' 输入: SQL值(引用)
' 返回:
'*********************************************************
Function FilterSQL(strSQL)
FilterSQL=CStr(Replace(strSQL,chr(39),chr(39)&chr(39)))
End Function
'*********************************************************
'*********************************************************
' 目的: 检查引用
' 输入:
' 输入: 要替换的字符代号
' 返回:
'*********************************************************
Function TransferHTML(source,para)
Dim objRegExp
'先换"&"
If Instr(para,"[&]")>0 Then source=Replace(source,"&","&")
If Instr(para,"[<]")>0 Then source=Replace(source,"<","<")
If Instr(para,"[>]")>0 Then source=Replace(source,">",">")
If Instr(para,"[""]")>0 Then source=Replace(source,"""",""")
If Instr(para,"[space]")>0 Then source=Replace(source," "," ")
If Instr(para,"[enter]")>0 Then
source=Replace(source,vbCrLf," ")
source=Replace(source,vbLf," ")
End If
If Instr(para,"[vbCrlf]")>0 And ZC_AUTO_NEWLINE Then
Set objRegExp=New RegExp
objRegExp.IgnoreCase =True
objRegExp.Global=True
objRegExp.Pattern="((?form[^\n<]*>)|(