Function.asp
上传用户:jisenq
上传日期:2014-06-29
资源大小:7216k
文件大小:29k
源码类别:

数据库编程

开发平台:

ASP/ASPX

  1. <%
  2. '脚本超时
  3. Server.ScriptTimeout=600
  4. Session.Timeout = 50
  5. Function Add_Root_Dir(f_Path)
  6. Dim f_All_Path
  7. If Left(f_Path,1)="/" Then
  8. f_All_Path = G_VIRTUAL_ROOT_DIR & f_Path
  9. Else
  10. f_All_Path = G_VIRTUAL_ROOT_DIR & "/" & f_Path
  11. End If
  12. If Trim(G_VIRTUAL_ROOT_DIR) <> "" Then
  13. f_All_Path = "/" & f_All_Path
  14. End If
  15. Add_Root_Dir = f_All_Path
  16. End Function
  17. Function Lose_Html(f_Str)
  18. Dim regEx
  19. if Not IsNull(f_Str) Then
  20. f_Str=f_Str&""
  21. Set regEx = New RegExp
  22. regEx.Pattern = "</*[^<>]*>"
  23. regEx.IgnoreCase = True
  24. regEx.Global = True
  25. f_Str = regEx.Replace(f_Str,"")
  26. Lose_Html = f_Str
  27. Else
  28. Lose_Html=""
  29. End If
  30. End Function
  31. Function Intercept_Char(f_Str,f_Length,f_Flag)
  32. 'f_Flag为1,一个中文字符的长度算1;f_Flag为2,一个中文字符的长度算2
  33. Dim f_Str_Total_Len,f_i,f_Str_Curr_Len,f_One_Char
  34. If f_Length = 0  Or f_Str = "" Or IsNull(f_Str) Then
  35. Intercept_Char = ""
  36. Exit Function
  37. End If
  38. f_Str=Replace(Replace(Replace(Replace(f_Str,"&nbsp;"," "),"&quot;",Chr(34)),"&gt;",">"),"&lt;","<")
  39. f_Str_Total_Len = Len(f_Str)
  40. If f_Flag = 1 Then
  41. If f_Length>=f_Str_Total_Len Then
  42. Intercept_Char = f_Str
  43. Else
  44. Intercept_Char = Left(f_Str,f_Length)
  45. End If
  46. Else
  47. For f_i = 1 To f_Str_Total_Len
  48. f_One_Char = Mid(f_Str,f_i,1)
  49. If Abs(Asc(f_One_Char)) > 255 then
  50. f_Str_Curr_Len=f_Str_Curr_Len+2
  51. Else
  52. f_Str_Curr_Len=f_Str_Curr_Len+1
  53. End If
  54. If f_Str_Curr_Len >= f_Length Then
  55. Intercept_Char = Left(f_Str,f_i)
  56. Exit For
  57. End If
  58. Next
  59. If f_Str_Curr_Len < f_Length Then
  60. Intercept_Char = f_Str
  61. End If
  62. End If
  63. Intercept_Char = Replace(Replace(Replace(Replace(Intercept_Char," ","&nbsp;"),Chr(34),"&quot;"),">","&gt;"),"<","&lt;")
  64. End Function
  65. Function Mod_IS_Installed_Bool(f_Mod_Str)
  66. On Error Resume Next
  67. Mod_IS_Installed_Bool = False
  68. Err = 0
  69. Dim f_TestObj
  70. Set f_TestObj = Server.CreateObject(f_Mod_Str)
  71. If Err = 0 Then
  72. Mod_IS_Installed_Bool = True
  73. End If
  74. Set f_TestObj = Nothing
  75. Err = 0
  76. End Function
  77. Function SendMail(f_Mailto_Address,f_Mailto_Name,f_Subject,f_Mail_Body,f_From_Name,f_Mail_From,f_Priority)
  78. On Error Resume Next
  79. Dim f_JMail,f_True_Mail_From,f_Mail_Server,f_Server_Domain
  80. Set f_JMail=Server.CreateObject("JMail.Message")
  81. If Err Then
  82. SendMail= "<br><li>没有安装JMail组件</li>"
  83. Err.Clear
  84. Exit Function
  85. End If
  86. f_Mail_Server = Get_Cache_Value("MF","MF_Mail_Server")
  87. f_True_Mail_From = Get_Cache_Value("MF","MF_Mail_Name")
  88. f_JMail.Silent = True
  89. f_JMail.Logging = True
  90. f_JMail.Charset = "gb2312"
  91. f_JMail.MailServerUserName = f_True_Mail_From
  92. f_JMail.MailServerPassword = Get_Cache_Value("MF","MF_Mail_Pass_Word")
  93. f_JMail.ContentType = "text/html"
  94. f_True_Mail_From =f_True_Mail_From & "@"
  95. f_Server_Domain = Left(f_Mail_Server,InStrRev(f_Mail_Server,".")-1)
  96. f_Server_Domain = Left(f_Server_Domain,InStrRev(f_Server_Domain,"."))
  97. f_True_Mail_From =f_True_Mail_From & Right(f_Mail_Server,Len(f_Mail_Server)-Len(f_Server_Domain))
  98. f_JMail.From = f_True_Mail_From
  99. f_JMail.FromName = f_From_Name & "(" & f_Mail_From & ")"
  100. f_JMail.Subject = f_Subject
  101. f_JMail.AddRecipient f_Mailto_Address
  102. f_JMail.Body = f_Mail_Body
  103. f_JMail.Priority = 3
  104. f_JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")
  105. f_JMail = ObjJmail.Send(f_Mail_Server)
  106. f_JMail.Close
  107. Set f_JMail=nothing
  108. End Function
  109. Function NoSqlHack(FS_inputStr)
  110. Dim f_NoSqlHack_AllStr,f_NoSqlHack_Str,f_NoSqlHack_i
  111. f_NoSqlHack_AllStr="*|%|'|;|(|)|and |exec |insert |select |delete |update |count |master |truncate |declare |and |exec |insert |select |delete |update |count |master |truncate |declare |char(|mid(|chr("
  112. f_NoSqlHack_Str = Split(f_NoSqlHack_AllStr,"|")
  113. For f_NoSqlHack_i=LBound(f_NoSqlHack_Str) To Ubound(f_NoSqlHack_Str)
  114. If Instr(LCase(FS_inputStr),f_NoSqlHack_Str(f_NoSqlHack_i))<>0 Then
  115. If f_NoSqlHack_Str(f_NoSqlHack_i)="'" Then f_NoSqlHack_Str(f_NoSqlHack_i)=" ' "
  116. Response.Write "<html><title>警告</title><body bgcolor=""EEEEEE"" leftmargin=""60"" topmargin=""30""><font style=""font-size:16px;font-weight:bolder;color:blue;""><li>您提交的数据有恶意字符</li></font><font style=""font-size:14px;font-weight:bolder;color:red;""><br><li>您的数据已经被记录!</li><br><li>您的IP:"&Request.ServerVariables("Remote_Addr")&"</li><br><li>操作日期:"&Now&"</li></font></body></html><!--Powered by Foosun Inc.,AddTime:"&now&"-->"
  117. Response.End
  118. End if
  119. Next
  120. NoSqlHack = FS_inputStr
  121. End Function
  122. Function CheckIpSafe(ip)
  123. Dim test,test_i,test_j,ascnum,safe,iplen
  124. test=Split(ip,".")
  125. safe=True
  126. For test_i=LBound(test) To UBound(test)
  127. iplen=Len(test(test_i))
  128. For test_j=1 To iplen
  129. ascnum=Asc(Mid(test(test_i),test_j,1))
  130. If Not (ascnum>=48 And ascnum<=57) Then
  131. Response.Write "<html><title>警告</title><body bgcolor=""EEEEEE"" leftmargin=""60"" topmargin=""30""><font style=""font-size:16px;font-weight:bolder;color:blue;""><li>您提交的数据有恶意字符</li></font><font style=""font-size:14px;font-weight:bolder;color:red;""><br><li>您的数据已经被记录!</li><br><li>您的IP:"&Request.ServerVariables("Remote_Addr")&"</li><br><li>操作日期:"&Now&"</li></font></body></html><!--Powered by Foosun Inc.,AddTime:"&now&"-->"
  132. Response.End
  133. End If
  134. Next
  135. Next
  136. CheckIpSafe=ip
  137. End Function
  138. Function NoHtmlHackInput(Str) '过滤跨站脚本和HTML标签
  139. Dim regEx
  140. Set regEx = New RegExp
  141. regEx.IgnoreCase = True
  142. regEx.Pattern = "<|>|(script)|on(mouseover|mouseon|mouseout|click|dblclick|blur|focus|change)|eval|t"
  143. If regEx.Test(LCase(Str)) Then
  144. Response.Write "<html><title>警告</title><body bgcolor=""EEEEEE"" leftmargin=""60"" topmargin=""30""><font style=""font-size:16px;font-weight:bolder;color:blue;""><li>您提交的数据有恶意字符</li></font><font style=""font-size:14px;font-weight:bolder;color:red;""><br><li>提交的内容不能包括[<|>|(script)|on(mouseover|mouseon|mouseout|click|dblclick|blur|focus|change)|eval]</li><li>您的数据已经被记录!</li><br><li>您的IP:"&Request.ServerVariables("Remote_Addr")&"</li><br><li>操作日期:"&Now&"</li></font></body></html><!--Powered by Foosun Inc.,AddTime:"&now&"-->"
  145. Response.End
  146. End If
  147. Set regEx = Nothing
  148. NoHtmlHackInput = Str
  149. End Function
  150. '获得中文字数,1个中文站2个字符,codez by Simpwind
  151. Function GotTopic(Str,StrLen)
  152. Dim l,t,c, i,LableStr,regEx,Match,Matches
  153. If StrLen=0 then
  154. GotTopic=""
  155. exit function
  156. End If
  157. if IsNull(Str) then
  158. GotTopic = ""
  159. Exit Function
  160. end if
  161. if Str = "" then
  162. GotTopic=""
  163. Exit Function
  164. end If
  165. Str=Replace(Replace(Replace(Replace(Str,"&nbsp;"," "),"&quot;",Chr(34)),"&gt;",">"),"&lt;","<")
  166. l=len(str)
  167. t=0
  168. strlen=Clng(strLen)
  169. for i=1 to l
  170. c=Abs(Asc(Mid(str,i,1)))
  171. if c>255 then
  172. t=t+2
  173. else
  174. t=t+1
  175. end if
  176. if t>=strlen then
  177. GotTopic=left(str,i)
  178. exit for
  179. else
  180. GotTopic=str
  181. end if
  182. Next
  183. GotTopic = Replace(Replace(Replace(Replace(GotTopic," ","&nbsp;"),Chr(34),"&quot;"),">","&gt;"),"<","&lt;")
  184. End Function
  185. '返回中文字符的前StrLen位字符 By Wen Yongzhong
  186. Function GetCStrLen(Str,StrLen)
  187. Dim l,t,c, i,LableStr,regEx,Match,Matches
  188. If StrLen=0 Then
  189. GetCStrLen=""
  190. Exit Function
  191. End If
  192. If IsNull(Str) Then
  193. GetCStrLen = ""
  194. Exit Function
  195. End If
  196. If Str = "" Then
  197. GetCStrLen=""
  198. Exit Function
  199. End If
  200. l=len(str)
  201. t=0
  202. strlen=Clng(strLen)
  203. For i=1 To l
  204. c=Abs(Asc(Mid(str,i,1)))
  205. If c>255 Then
  206. t=t+2
  207. Else
  208. t=t+1
  209. End If
  210. If t>=strlen Then
  211. GetCStrLen=left(str,i)
  212. Exit For
  213. Else
  214. GetCStrLen=str
  215. End If
  216. Next
  217. End Function
  218. '远程存图
  219. Function ReplaceRemoteUrl(NewsContent,SaveFilePath,FunDoMain,DummyPath)
  220. Dim re,RemoteFile,RemoteFileurl,SaveFileName,FileName,FileExtName,SaveImagePath,tNewsContent
  221. Set re = New RegExp
  222. re.IgnoreCase = True
  223. re.Global=True
  224. re.Pattern = "((http|https|ftp|rtsp|mms):(//|\\){1}((w)+[.]){1,}(net|com|cn|org|cc|tv|[0-9]{1,3})(S*/)((S)+[.]{1}(gif|jpg|png|bmp)))"
  225. tNewsContent = NewsContent
  226. Set RemoteFile = re.Execute(tNewsContent)
  227. Set re = Nothing
  228. For Each RemoteFileurl in RemoteFile
  229. SaveFileName = Mid(RemoteFileurl,InstrRev(RemoteFileurl,"/")+1)
  230. Call SaveRemoteFile(DummyPath & SaveFilePath & "/" & SaveFileName,RemoteFileurl)
  231. tNewsContent = Replace(tNewsContent,RemoteFileurl,FunDoMain & SaveFilePath & "/" & SaveFileName)
  232. Next
  233. ReplaceRemoteUrl = tNewsContent
  234. End Function
  235. Sub SaveRemoteFile(LocalFileName,RemoteFileUrl)
  236. LocalFileName=Server.MapPath(replace(LocalFileName,"//","/"))
  237. 'PathExistCheck LocalFileName
  238. On Error Resume Next
  239. Dim StreamObj,Retrieval,GetRemoteData
  240. Set Retrieval = Server.CreateObject(G_FS_XMLHTTP)
  241. If Err Then
  242. Response.Write "<script language='JavaScript'>alert('你的系统不支持"&G_FS_XMLHTTP&"n,无法保存远程文件!');</script>"
  243. Err.clear
  244. Set Retrieval = Nothing
  245. Exit Sub
  246. End If
  247. With Retrieval
  248. .Open "Get", RemoteFileUrl, False, "", ""
  249. .Send
  250. if Err.Number <> 0 then
  251. Err.Clear
  252. Set Retrieval = Nothing
  253. Exit Sub
  254. end if
  255. GetRemoteData = .ResponseBody
  256. End With
  257. Set Retrieval = Nothing
  258. If Err Then Err.clear
  259. Set StreamObj = Server.CreateObject(G_FS_STREAM)
  260. If Err Then
  261. Response.Write "<script language='JavaScript'>alert('你的系统不支持"&G_FS_STREAM&"n,无法保存远程文件!');</script>"
  262. Err.clear
  263. Set StreamObj = Nothing
  264. Exit Sub
  265. End If
  266. With StreamObj
  267. .Type = 1
  268. .Open
  269. .Write GetRemoteData
  270. .SaveToFile LocalFileName,2
  271. .Cancel()
  272. .Close()
  273. End With
  274. Set StreamObj = Nothing
  275. End Sub
  276. '创建
  277. Function CreateDateDir(Path)
  278. Dim sBuild,FSO
  279. sBuild=path&""&year(Now())&"-"&month(now())
  280. Set FSO = Server.CreateObject(G_FS_FSO)
  281. If FSO.FolderExists(sBuild)=false then
  282. FSO.CreateFolder(sBuild)
  283. End IF
  284. sBuild=sBuild&""&day(Now())
  285. If FSO.FolderExists(sBuild)=false then
  286. FSO.CreateFolder(sBuild)
  287. End IF
  288. set FSO=Nothing
  289. End Function
  290. '创建目录
  291. Sub savePathdirectory(Path)
  292. Dim FSO
  293. Set FSO = Server.CreateObject(G_FS_FSO)
  294. if Trim(G_VIRTUAL_ROOT_DIR) ="" then
  295. FSO.CreateFolder(Path)
  296. Else
  297. FSO.CreateFolder(G_VIRTUAL_ROOT_DIR)
  298. FSO.CreateFolder(Path)
  299. End if
  300. End Sub
  301. ' 传入:字符串、位置、长度
  302. ' 返回:在字符串指定位置取出指定长度的字符串,如果位置大于等于字符串长度,返回空值
  303. Function getStrLoc(FS_Str,FS_StrLoc,FS_StrLen)
  304. Dim FS_CharFind
  305. If Len(FS_Str)>=FS_StrLoc Then
  306. FS_CharFind = Mid(FS_Str,FS_StrLoc,FS_StrLen)
  307. getStrLoc = FS_CharFind
  308. Else
  309. getStrLoc = ""
  310. End If
  311. End Function
  312. '======================================================================
  313. ' 用AspJpeg组件建立带有新闻标题的图片
  314. ' 参数说明
  315. ' NumCanvasWidth画布宽度,NumCanvasHeight画布高度,bgColor背景颜色,borderColor图片边框颜色(为空或者0不显示边框)
  316. ' TextColor文字颜色,TextFamily文字字体,BoldTF是否粗体(1为加粗),TextSize文字大小,StrTitle文字内容
  317. ' NumTopMargin文字垂直距离画布的顶边距(横向默认是居中的),StrSavePath图片保存路径(需要绝对路径)
  318. ' 测试代码如下:
  319. ' AspJpegCreateTextPic 400,60,&Hcccccc,&H0000ff,&H000000,"宋体",1,40,"文字转换图片AspJpeg",8,server.mappath("frontpage.jpg")
  320. ' response.write "<img src='frontpage.jpg'><br>"
  321. '======================================================================
  322. Function AspJpegCreateTextPic(NumCanvasWidth,NumCanvasHeight,bgColor,borderColor,TextColor,TextFamily,BoldTF,TextSize,StrTitle,NumTopMargin,StrSavePath)
  323. If Not IsObjInstalled("Persits.Jpeg") Then Response.write "<script>alert('对不起,n您需要先安装AspJpeg组件n操作成功,但生成水印图片失败');window.location.href='javascript:history.back();'</script>":Response.End
  324. If IsExpired("Persits.Jpeg") Then Response.write "<script>alert('对不起,n您的AspJpeg组件已经过期n操作成功,但生成水印图片失败');window.location.href='javascript:history.back();'</script>":Response.End
  325. Dim Title,objJpeg,TitleWidth
  326. Title = StrTitle
  327. Set objJpeg = Server.CreateObject("Persits.Jpeg")
  328. objJpeg.New NumCanvasWidth, NumCanvasHeight, bgColor
  329. If borderColor<>"" And borderColor<>0 Then
  330. objJpeg.Canvas.Pen.Color = borderColor
  331. objJpeg.Canvas.Brush.Solid = False
  332. objJpeg.Canvas.DrawBar 1, 1, objJpeg.Width, objJpeg.Height
  333. End If
  334. objJpeg.Canvas.Font.Color = TextColor
  335. objJpeg.Canvas.Font.Family = TextFamily
  336. If BoldTF=1 Then objJpeg.Canvas.Font.Bold = True
  337. objJpeg.Canvas.Font.Size = TextSize
  338. objJpeg.Canvas.Font.Quality = 4
  339. TitleWidth = objJpeg.Canvas.GetTextExtent( Title )
  340. objJpeg.Canvas.Print (objJpeg.Width-TitleWidth)/2, NumTopMargin, Title
  341. objJpeg.Save StrSavePath
  342. Set objJpeg = Nothing
  343. End Function
  344. '======================================================================
  345. ' 用WsImage组件建立带有新闻标题的图片
  346. ' 参数说明:
  347. ' NumCanvasWidth画布宽度,NumCanvasHeight画布高度,,TextColor文字颜色,TextFamily文字字体,TextSize文字大小
  348. ' NumRotation旋转角度(文字保持水平请填0),StrTitle文字内容
  349. ' NumLeft,文字水平与画布的左边距,NumTop文字垂直距离画布的顶边距,StrSavePath图片保存路径(需要绝对路径)
  350. ' 返回值:
  351. ' 如果发生错误,返回错误代码
  352. ' 测试代码如下:
  353. ' x = WsImgWatermarkText(440,300,&H0000FF&,"宋体",20,0,110,300,"测试水印WsImage",server.MapPath("apple111.jpg"))
  354. ' response.write x&server.mappath("../admin/Images/wsimg.jpg")&"<br><img src='../admin/Images/wsimg.jpg'><img src='apple111.jpg'>"
  355. '======================================================================
  356. Function WsImgWatermarkTextToPic(NumCanvasWidth,NumCanvasHeight,TextColor,TextFamily,TextSize,NumRotation,NumLeft,NumTop,StrTitle,StrSavePath)
  357. On Error Resume Next
  358. Dim StrPicPath
  359. If Not IsObjInstalled("wsImage.Resize") Then Response.write "<script>alert('对不起,n您需要先安装WsImage组件');</script>":Response.End
  360. If IsExpired("wsImage.Resize") Then Response.write "<script>alert('对不起,n您的WsImage组件已经过期');</script>":Response.End
  361. StrPicPath = server.mappath("../Images/wsimg.jpg")
  362. WsImgIndentPicSize1 StrPicPath,NumCanvasWidth,NumCanvasHeight
  363. Dim objWsImg,strError
  364. set objWsImg=server.CreateObject("wsImage.Resize")
  365. objWsImg.LoadSoucePic StrPicPath
  366. objWsImg.Quality=75
  367. objWsImg.TxtMarkFont = TextFamily
  368. objWsImg.TxtMarkBond = false
  369. objWsImg.MarkRotate = NumRotation
  370. objWsImg.TxtMarkHeight = TextSize
  371. objWsImg.AddTxtMark CStr(StrSavePath), StrTitle, TextColor, NumTop, NumLeft
  372. strError=objWsImg.errorinfo
  373. If strError<>"" Then WsImgIndentPicScale = strError
  374. objWsImg.free:Set objWsImg=Nothing
  375. IF Err Then
  376. WsImgWatermarkTextToPic=False
  377. End If
  378. End Function
  379. Function WsImgIndentPicSize1(StrPicPath,NumWidth,NumHeight)
  380. On Error Resume Next
  381. Dim objWsImg,strError,NumType
  382. NumType = 0
  383. If NumHeight<=0 Then NumHeight=0:NumType=1
  384. If NumWidth<=0 Then NumWidth=0:NumType=2
  385. set objWsImg=server.CreateObject("wsImage.Resize")
  386. objWsImg.LoadSoucePic CStr(StrPicPath)
  387. objWsImg.Quality=75
  388. objWsImg.OutputSpic CStr(StrPicPath),NumWidth,NumHeight,NumType
  389. strError=objWsImg.errorinfo
  390. If strError<>"" Then WsImgIndentPicSize1 = strError
  391. objWsImg.free:Set objWsImg=Nothing
  392. End Function
  393. '======================================================================
  394. ' 用SA-ImgWriter组件建立带有新闻标题的图片
  395. ' 参数说明
  396. ' NumCanvasWidth画布宽度,NumCanvasHeight画布高度,bgColor背景颜色
  397. ' TextColor文字颜色,TextFamily文字字体,TextSize文字大小,StrTitle文字内容
  398. ' NumleftMargin文字水平与画布的左边距,NumTopMargin文字垂直距离画布的顶边距,StrSavePath图片保存路径(需要绝对路径)
  399. ' 测试代码如下:
  400. ' ImageGenCreateTextPic 420,60,rgb(255,255,255),rgb(0,0,0),"宋体",40,"文字转换图片ImageGen",8,8,server.mappath("frontpage.jpg")
  401. ' response.write "<img src='frontpage.jpg'><br>"
  402. '======================================================================
  403. Function ImageGenCreateTextPic(NumCanvasWidth,NumCanvasHeight,bgColor,TextColor,TextFamily,TextSize,StrTitle,NumleftMargin,NumTopMargin,StrSavePath)
  404. If Not IsObjInstalled("softartisans.ImageGen") Then Response.write "<script>alert('对不起,n您需要先安装SA-ImgWriter组件');</script>":Response.End
  405. If IsExpired("softartisans.ImageGen") Then Response.write "<script>alert('对不起,n您的SA-ImgWriter组件已经过期');</script>":Response.End
  406. Dim objImageGen,objFont
  407. Set objImageGen = Server.CreateObject("softartisans.ImageGen")
  408. 'Response.Write "<br>"&NumCanvasWidth &"<br>"& NumCanvasHeight&"<br>"& bgColor
  409. 'Response.end
  410. objImageGen.CreateImage NumCanvasWidth, NumCanvasHeight, bgColor 'rgb(255,255,255)注意格式
  411. Set objFont = objImagegen.Font
  412. objFont.name = TextFamily
  413. objFont.Color = TextColor 'rgb(0,0,0) '注意格式
  414. objFont.height = TextSize
  415. objImageGen.DrawTextOnImage NumleftMargin, NumTopMargin, objImageGen.Width-NumleftMargin, objImageGen.Height-NumTopMargin, StrTitle
  416. 'Response.Write "<br>" &StrSavePath
  417. objImageGen.SaveImage 0, 3, StrSavePath
  418. Set objFont = Nothing
  419. Set objImageGen = Nothing
  420. End Function
  421. Function GetStrLengthE(Str)
  422. '按英文计算字符串的长度,计算头条新闻图片大小用
  423. Dim i,StrLenth
  424. For i = 1 to len(Str)
  425. If Abs(Asc(Mid(Str,i,1)))>255 Then
  426. StrLenth=StrLenth+1
  427. Else
  428. StrLenth=StrLenth+0.5
  429. End If
  430. Next
  431. GetStrLengthE=StrLenth
  432. End Function
  433. '判断组件是否可用
  434. Function IsObjInstalled(strClassString)
  435. IsObjInstalled = False
  436. Dim xTestObj
  437. On Error Resume Next
  438. Set xTestObj = Server.CreateObject(strClassString)
  439. If Err Then
  440. IsObjInstalled = False
  441. Err.Clear
  442. Else
  443. IsObjInstalled = True
  444. End If
  445. Set xTestObj = Nothing
  446. End Function
  447. '组件是否过期
  448. Function IsExpired(strClassString)
  449. IsExpired = True
  450. Dim xTestObj
  451. On Error Resume Next
  452. Err.Clear
  453. Set xTestObj = Server.CreateObject(strClassString)
  454. Select Case LCase(strClassString)
  455. Case "persits.jpeg"
  456. If DateDiff("s",xTestObj.Expires,now)<0 Then
  457. IsExpired = False
  458. End if
  459. Case "wsimage.resize"
  460. If instr(xTestObj.errorinfo,"已经过期") = 0 Then
  461. IsExpired = False
  462. End if
  463. Case "softartisans.imagegen"
  464. xTestObj.CreateImage 500, 500, rgb(255,255,255)
  465. If Err Then
  466. Err.Clear
  467. IsExpired = False
  468. End if
  469. End Select
  470. Set xTestObj = Nothing
  471. End Function
  472. '去掉首尾,号
  473. Function DelHeadAndEndDot(Str)
  474. Dim StrLen
  475. StrLen=Len(Str)
  476. if StrLen>0 then
  477. if instr(str,",")=1 then
  478. Str=right(str,StrLen-1)
  479. end if
  480. StrLen=Len(Str)
  481. if instrrev(str,",")=StrLen then
  482. Str=left(str,StrLen-1)
  483. end if
  484. end if
  485. DelHeadAndEndDot=Str
  486. End Function
  487. '验证字符串是否合法,匹配到即为合法
  488. Function IsValidStr(Str,FilterStr)
  489. IsValidStr=False
  490. If Str<>"" Then
  491. Dim regEx
  492. Set regEx = New RegExp
  493. regEx.IgnoreCase = True
  494. regEx.Pattern = FilterStr
  495. If regEx.Test(LCase(Str)) Then
  496. IsValidStr=True
  497. End If
  498. Set regEx = Nothing
  499. End If
  500. End Function
  501. '检查是否外部输入
  502. Function IsSelfRefer()
  503. Dim sHttp_Referer, sServer_Name
  504. sHttp_Referer = CStr(Request.ServerVariables("HTTP_REFERER"))
  505. sServer_Name = CStr(Request.ServerVariables("SERVER_NAME"))
  506. If Mid(sHttp_Referer, 8, Len(sServer_Name)) = sServer_Name Then
  507. IsSelfRefer = True
  508. Else
  509. IsSelfRefer = False
  510. End If
  511. End Function
  512. '得到多少位数的随机函数
  513. Function GetRamCode(f_number)
  514. Randomize
  515. Dim f_Randchar,f_Randchararr,f_RandLen,f_Randomizecode,f_iR
  516. f_Randchar="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
  517. f_Randchararr=split(f_Randchar,",")
  518. f_RandLen=f_number '定义密码的长度或者是位数
  519. for f_iR=1 to f_RandLen
  520. f_Randomizecode=f_Randomizecode&f_Randchararr(Int((21*Rnd)))
  521. next
  522. GetRamCode = f_Randomizecode
  523. End Function
  524. '检查英文名称是否合法
  525. Function chkinputchar(f_char)
  526. Dim f_name, i, c
  527. f_name = f_char
  528. chkinputchar = True
  529. If Len(f_name) <= 0 Then
  530. chkinputchar = False
  531. Exit Function
  532. End If
  533. For i = 1 To Len(f_name)
  534.    c = Mid(f_name, i, 1)
  535. If InStr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@,.0123456789|-_", c) <= 0  Then
  536.    chkinputchar = False
  537. Exit Function
  538.    End If
  539.    Next
  540. End Function
  541. ''替换成自己想显示的信息
  542. ''格式:Replacestr(Hs_Rs("FloorType"),"1:多层,2:单层")
  543. ''格式:Replacestr(Rs("Audited"),"1:已通过审核,0:<span class=""tx"">未通过审核</span>")
  544. Function Replacestr(dbvalue,strlist)
  545. Dim f_oldstr,f_tmpstr,f_tmparr,f_tmparr1
  546. f_oldstr = strlist
  547. if isnull(dbvalue) then dbvalue=""
  548. f_tmparr = split(f_oldstr,",")
  549. for each f_tmpstr in f_tmparr
  550. f_tmparr1 = split(f_tmpstr,":")
  551. if ubound(f_tmparr1) = 1 then
  552. if trim(dbvalue) = trim(f_tmparr1(0)) then
  553. f_oldstr = trim(f_tmparr1(1)) : exit for
  554. elseif trim(f_tmparr1(0)) = "else" then
  555. f_oldstr = trim(f_tmparr1(1))
  556. else
  557. f_oldstr = dbvalue
  558. end if
  559. else
  560. end if
  561. next
  562. Replacestr = f_oldstr
  563. End Function
  564. ''显示下拉
  565. ''格式PrintOption(rs("language"),":<font color=#999999>请选择</font>,英语:英语,日语:日语,法语:法语")
  566. Function PrintOption(Equvalue,valuelist)
  567. Dim f_oldstr,f_tmpstr,f_tmparr,f_tmparr1,isselected
  568. isselected=false:f_oldstr=""
  569. if isnull(Equvalue) then Equvalue=""
  570. f_tmparr = split(valuelist,",")
  571. for each f_tmpstr in f_tmparr
  572. f_tmparr1 = split(f_tmpstr,":")
  573. if ubound(f_tmparr1) = 1 then
  574. if trim(Equvalue) = trim(f_tmparr1(0)) and isselected=false then
  575. f_oldstr = f_oldstr & "<option value="""&f_tmparr1(0)&""" selected>"&f_tmparr1(1)&"</option>"
  576. isselected=true
  577. elseif trim(f_tmparr1(0))+trim(f_tmparr1(1))<>"" then
  578. f_oldstr = f_oldstr & "<option value="""&f_tmparr1(0)&""">"&f_tmparr1(1)&"</option>"
  579. end if
  580. else
  581. end if
  582. next
  583. PrintOption = f_oldstr
  584. End Function
  585. ''文本框查询处理,方式可 “A B*”“A *B*”“A B”
  586. ''查询的时候 FildValue为空,显示的时候的 FildValue 不为空,则会将关键字颜色替换
  587. Function Search_TextArr(StrKey,FildName,FildValue)
  588. Dim StrTmp,ArrTmp,New_StrTmp,Bol_Xin
  589. StrTmp = "" : New_StrTmp = ""
  590. Bol_Xin = False
  591. ArrTmp = split(StrKey,chr(32))
  592. for each StrTmp in ArrTmp
  593.   if Trim(StrTmp)<>"" then
  594. if FildValue <> "" then
  595. StrTmp = replace(StrTmp,"*","")
  596. StrTmp = replace(StrTmp,"*","")
  597. FildValue = replace(FildValue,StrTmp,"<font color=""red"">"&StrTmp&"</font>")
  598. New_StrTmp = FildValue
  599. else
  600. if left(StrTmp,1) = "*" then StrTmp = "%"&mid(StrTmp,2) : Bol_Xin = True
  601. if right(StrTmp,1) = "*" then StrTmp = mid(StrTmp,1,len(StrTmp) - 1)&"%" : Bol_Xin = True
  602. if not Bol_Xin then StrTmp = "%"&StrTmp&"%"
  603. New_StrTmp = New_StrTmp & " And "&FildName&" like '"&StrTmp&"' "
  604. end if
  605.   end if
  606.   Bol_Xin = False
  607. next
  608. ''去掉得sql模式时的第一个and
  609. if FildValue="" and New_StrTmp<>"" then New_StrTmp = " ("&mid(New_StrTmp,len(" And ")+1)&") "
  610. Search_TextArr = New_StrTmp
  611. End Function
  612. ''暂不支持中文
  613. '可配合server.URLEncode如:server.URLEncode(Encrypt(防止被转化成'报错。
  614. Function Encrypt(ecode)
  615. ''加密
  616. dim texts
  617. dim i
  618. for i=1 to len(ecode)
  619. texts=texts & chr(asc(mid(ecode,i,1))+3)
  620. next
  621. Encrypt = texts
  622. End Function
  623. ''暂不支持中文
  624. Function Decrypt(dcode)
  625. ''解密
  626. dim texts
  627. dim i
  628. for i=1 to len(dcode)
  629. texts=texts & chr(asc(mid(dcode,i,1))-3)
  630. next
  631. Decrypt=texts
  632. End Function
  633. Function and_where(sql)
  634. if instr(lcase(sql)," where ")>0 then
  635. and_where = sql & " and "
  636. else
  637. and_where = sql & " where "
  638. end if
  639. End Function
  640. Function Get_Date(f_getDate,f_datestyle)
  641. dim tmp_f_datestyle
  642. tmp_f_datestyle = f_datestyle
  643. if instr(1,f_datestyle,"YY02",1)>0 then
  644. tmp_f_datestyle= replace(tmp_f_datestyle,"YY02",right(year(f_getDate),2))
  645. end if
  646. if instr(f_datestyle,"YY04")>0 then
  647. tmp_f_datestyle= replace(tmp_f_datestyle,"YY04",year(f_getDate))
  648. end if
  649. if instr(f_datestyle,"MM")>0 then
  650. if month(f_getDate)<10 then
  651. tmp_f_datestyle= replace(tmp_f_datestyle,"MM","0"&month(f_getDate))
  652. else
  653. tmp_f_datestyle= replace(tmp_f_datestyle,"MM",month(f_getDate))
  654. end if
  655. end if
  656. if instr(f_datestyle,"DD")>0 then
  657. if day(f_getDate)<10 then
  658. tmp_f_datestyle= replace(tmp_f_datestyle,"DD","0"&day(f_getDate))
  659. else
  660. tmp_f_datestyle= replace(tmp_f_datestyle,"DD",day(f_getDate))
  661. end if
  662. end if
  663. if instr(f_datestyle,"HH")>0 then
  664. if hour(f_getDate)<10 then
  665. tmp_f_datestyle= replace(tmp_f_datestyle,"HH","0"&hour(f_getDate))
  666. else
  667. tmp_f_datestyle= replace(tmp_f_datestyle,"HH",hour(f_getDate))
  668. end if
  669. end if
  670. if instr(f_datestyle,"MI")>0 then
  671. if minute(f_getDate)<10 then
  672. tmp_f_datestyle= replace(tmp_f_datestyle,"MI","0"&minute(f_getDate))
  673. else
  674. tmp_f_datestyle= replace(tmp_f_datestyle,"MI",minute(f_getDate))
  675. end if
  676. end if
  677. if instr(f_datestyle,"SS")>0 then
  678. if second(f_getDate)<10 then
  679. tmp_f_datestyle= replace(tmp_f_datestyle,"SS","0"&second(f_getDate))
  680. else
  681. tmp_f_datestyle= replace(tmp_f_datestyle,"SS",second(f_getDate))
  682. end if
  683. end if
  684. Get_Date = tmp_f_datestyle
  685. End Function
  686. 'html转换函数
  687. Function Encode(str)
  688. str=Replace(str,"&","&amp;")
  689. str=Replace(str,"'","''")
  690. str=Replace(str,"""","&quot;")
  691. str=Replace(str," ","&nbsp;")
  692. str=Replace(str,"<","&lt;")
  693. str=Replace(str,">","&gt;")
  694. str=Replace(str,"n","<br>")
  695. Encode=str
  696. End Function
  697. ''删除相关文件.
  698. Function fso_DeleteFile(PhFileName)
  699. On Error Resume Next
  700. if isnull(PhFileName) or PhFileName = "" or instr(lcase(PhFileName),"http://")>0 then fso_DeleteFile=true:exit function
  701. Dim Fso,MyFile,isTrue
  702. isTrue = False
  703. Set Fso = CreateObject(G_FS_FSO)
  704. If Fso.FileExists(server.MapPath(PhFileName)) Then
  705. set MyFile = Fso.GetFile(server.MapPath(PhFileName))
  706. MyFile.Delete(True)
  707. set MyFile = nothing
  708. isTrue = True
  709. End If
  710. Set Fso = Nothing
  711. if Err.number<>0 then
  712. isTrue = False
  713. else
  714. isTrue = True
  715. end if
  716. fso_DeleteFile = isTrue
  717. End Function
  718. ''长新闻自动分页
  719. Function AutoSplitPages(StrNewsContent,Page_Split_page,AutoPagesNum)
  720. Dim Inti,StrTrueContent,iPageLen,DLocation,XLocation,FoundStr
  721.  If StrNewsContent<>"" and AutoPagesNum<>0 and instr(1,StrNewsContent,Page_Split_page)=0 then
  722.   Inti=instr(1,StrNewsContent,"<")
  723.   If inti>=1 then '新闻中存在Html标记
  724.    StrTrueContent=left(StrNewsContent,Inti-1)
  725.    iPageLen=IStrLen(StrTrueContent)
  726.    inti=inti+1
  727.   Else   '新闻中不存在Html标记,对内容直接分页即可
  728.    dim i,c,t
  729.    do while i< len(StrNewsContent)
  730.    i=i+1
  731. c=Abs(Asc(Mid(StrNewsContent,i,1)))
  732. if c>255 then '判断为汉字则为两个字符,英文为一个字符
  733.  t=t+2
  734. else
  735.  t=t+1
  736. end if
  737. if t>=AutoPagesNum then  '如果字数达到了分页的数量则插入分页符号
  738.  StrNewsContent=left(StrNewsContent,i)&Page_Split_page&mid(StrNewsContent,i+1)
  739.  i=i+6
  740.  t=0
  741. end if
  742.    loop
  743.    AutoSplitPages=StrNewsContent '返回插入分页符号的内容
  744.    Exit Function
  745.   End If
  746.   iPageLen=0
  747. ''新闻中存在Html标记时,则用下面的语句来处理
  748. do while instr(Inti,StrNewsContent,">")<>0
  749.    DLocation=instr(Inti,StrNewsContent,">")  '只计算Html标记之外的字符数量
  750.    XLocation=instr(DLocation,StrNewsContent,"<")
  751.    If XLocation>DLocation+1 then
  752. Inti=XLocation
  753. StrTrueContent=mid(StrNewsContent,DLocation+1,XLocation-DLocation-1)
  754. iPageLen=iPageLen+IStrLen(StrTrueContent) '统计Html之外的字符的数量
  755. If iPageLen>AutoPagesNum then    '如果达到了分页的数量则插入分页字符
  756.  FoundStr=Lcase(left(StrNewsContent,XLocation-1))
  757.  If AllowSplitPages(FoundStr,"table|a|b>|i>|strong|div")=true then
  758.   StrNewsContent=left(StrNewsContent,XLocation-1)&Page_Split_page&mid(StrNewsContent,XLocation)
  759.   iPageLen=0        '重新统计Html之外的字符
  760.  End If
  761. End If
  762.    ElseIf XLocation=0 then       '在后面再也找不到<,即后面没有Html标记了
  763. Exit Do
  764.    ElseIf XLocation=DLocation+1 then    '找到的Html标记之间的内容为空,则继续向后找
  765. Inti=XLocation
  766.    End If
  767.   loop
  768.  End If
  769. AutoSplitPages=StrNewsContent
  770. End Function
  771. Function IStrLen(TempStr)
  772. Dim iLen,i,StrAsc
  773. iLen=0
  774. for i=1 to len(TempStr)
  775. StrAsc=Abs(Asc(Mid(TempStr,i,1)))
  776. if StrAsc>255 then
  777. iLen=iLen+2
  778. else
  779. iLen=iLen+1
  780. end if
  781. next
  782. IStrLen=iLen
  783. End Function
  784. Function AllowSplitPages(TempStr,FindStr)
  785. Dim Inti,BeginStr,EndStr,BeginStrNum,EndStrNum,ArrStrFind,i
  786. If TempStr<>"" and FindStr<>"" then
  787. ArrStrFind=split(FindStr,"|")
  788. For i = 0 to Ubound(ArrStrFind)
  789. BeginStr="<"&ArrStrFind(i)
  790. EndStr  ="</"&ArrStrFind(i)
  791. Inti=0
  792. do while instr(Inti+1,TempStr,BeginStr)<>0
  793. Inti=instr(Inti+1,TempStr,BeginStr)
  794. BeginStrNum=BeginStrNum+1
  795. Loop
  796. Inti=0
  797. do while instr(Inti+1,TempStr,EndStr)<>0
  798. Inti=instr(Inti+1,TempStr,EndStr)
  799. EndStrNum=EndStrNum+1
  800. Loop
  801. If EndStrNum=BeginStrNum then
  802. AllowSplitPages=true
  803. Else
  804. AllowSplitPages=False
  805. Exit Function
  806. End If
  807. Next
  808. Else
  809. AllowSplitPages=False
  810. End If
  811. End Function
  812. %>