浏览模式: 标准 | 列表分类:网站|ASP备忘

ASP生成随机验证码(可刷新)

调用方法
<img src="/getcode.asp">
<img src="/getcode.asp" alt="验证码,看不清楚?请点击刷新验证码" style="cursor : pointer;" onclick="this.src="/getcode.asp"">
<input name="vcode" type="input">
在服务器验证的时候Session("GetCode") = Request.Form("vcode")
代码:

<%
Response.expires=-1
Response.AddHeader"pragma","no-cache"
Response.AddHeader"cache-control","no-store"

Const nMaxSaturation = 100 " 最大色彩饱和度
Const nBlankNoisyDotOdds = 0.2 " 空白处噪点率
Const nColorNoisyDotOdds = 0.1 " 有色处噪点率
Const nCharCount = 4 " 产生的字符个数
Const nPixelWidth = 20 " 单个字符位图的宽度
Const nPixelHeight = 20 " 单个字符位图的高度
Const nColorHue = 220 " 显示验证码的色调(-1表示随机色调, -2表示灰度色调)
Const nAngleRandom = 10 " 角度随机量
Const nLengthRandom = 10 " 长度随机量(百分比)
Const cCharSet = "0123456789"
" 构成验证码的字符集
" 如果扩充了下边的字母矢量库,则可以相应扩充这个字符集

Dim Buf(), DigtalStr
Dim Lines(), LineCount
Dim CursorX, CursorY, DirX, DirY

Randomize
Call CreatValidCode("GetCode")

Sub CDGen_Reset()
" 复位矢量笔和环境变量
LineCount = 0
CursorX = 0
CursorY = 0
" 初始的光笔方向是垂直向下
DirX = 0
DirY = 1
End Sub

Sub CDGen_Clear()
" 清空位图阵列
Dim i, j
ReDim Buf(nPixelHeight - 1, nCharCount * nPixelWidth - 1)

For j = 0 To nPixelHeight - 1
For i = 0 To nCharCount * nPixelWidth - 1
Buf(j, i) = 0
Next
Next
End Sub

Sub CDGen_PSet(X, Y)
" 在位图阵列上画点
Buf(Y, X) = 1
End Sub

Sub CDGen_Line(X1, Y1, X2, Y2)
" 在位图阵列上画线
Dim DX, DY, DeltaT, i

DX = X2 - X1
DY = Y2 - Y1
If Abs(DX) > Abs(DY) Then DeltaT = Abs(DX) Else DeltaT = Abs(DY)
For i = 0 To DeltaT
CDGen_PSet X1 + DX * i / DeltaT, Y1 + DY * i / DeltaT
Next
End Sub

Sub CDGen_FowardDraw(nLength)
" 按当前光笔方向绘制指定长度并移动光笔,正数表示从左向右/从上向下绘制,负数表示从右向左/从下向上绘制
nLength = Sgn(nLength) * Abs(nLength) * (1 - nLengthRandom / 100 + Rnd * nLenghtRandom * 2 / 100)
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
CursorX = CursorX + DirX * nLength
CursorY = CursorY + DirY * nLength
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub

Sub CDGen_SetDirection(nAngle)
" 按指定角度设定画笔方向, 正数表示相对当前方向顺时针改变方向,负数表示相对当前方向逆时针改变方向
Dim DX, DY

nAngle = Sgn(nAngle) * (Abs(nAngle) - nAngleRandom + Rnd * nAngleRandom * 2) / 180 * 3.1415926
DX = DirX
DY = DirY
DirX = DX * Cos(nAngle) - DY * Sin(nAngle)
DirY = DX * Sin(nAngle) + DY * Cos(nAngle)
End Sub

Sub CDGen_MoveToMiddle(nActionIndex, nPercent)
" 将画笔光标移动到指定动作的中间点上,nPercent为中间位置的百分比
Dim DeltaX, DeltaY

DeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)
DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)
CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100
CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100
End Sub

Sub CDGen_MoveCursor(nActionIndex)
" 将画笔光标移动到指定动作的起始点上
CursorX = Lines(0, nActionIndex)
CursorY = Lines(1, nActionIndex)
End Sub

Sub CDGen_Close(nActionIndex)
" 将当前光笔位置与指定动作的起始点闭合并移动光笔
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
CursorX = Lines(0, nActionIndex)
CursorY = Lines(1, nActionIndex)
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub

Sub CDGen_CloseToMiddle(nActionIndex, nPercent)
" 将当前光笔位置与指定动作的中间点闭合并移动光笔,nPercent为中间位置的百分比
Dim DeltaX, DeltaY

ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
DeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)
DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)
CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100
CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub

Sub CDGen_Flush(X0, Y0)
" 按照当前的画笔动作序列绘制位图点阵
Dim MaxX, MinX, MaxY, MinY
Dim DeltaX, DeltaY, StepX, StepY, OffsetX, OffsetY
Dim i

MaxX = MinX = MaxY = MinY = 0
For i = 0 To LineCount - 1
If MaxX < Lines(0, i) Then MaxX = Lines(0, i)
If MaxX < Lines(2, i) Then MaxX = Lines(2, i)
If MinX > Lines(0, i) Then MinX = Lines(0, i)
If MinX > Lines(2, i) Then MinX = Lines(2, i)
If MaxY < Lines(1, i) Then MaxY = Lines(1, i)
If MaxY < Lines(3, i) Then MaxY = Lines(3, i)
If MinY > Lines(1, i) Then MinY = Lines(1, i)
If MinY > Lines(3, i) Then MinY = Lines(3, i)
Next
DeltaX = MaxX - MinX
DeltaY = MaxY - MinY
If DeltaX = 0 Then DeltaX = 1
If DeltaY = 0 Then DeltaY = 1
MaxX = MinX
MaxY = MinY
If DeltaX > DeltaY Then
StepX = (nPixelWidth - 2) / DeltaX
StepY = (nPixelHeight - 2) / DeltaX
OffsetX = 0
OffsetY = (DeltaX - DeltaY) / 2
Else
StepX = (nPixelWidth - 2) / DeltaY
StepY = (nPixelHeight - 2) / DeltaY
OffsetX = (DeltaY - DeltaX) / 2
OffsetY = 0
End If
For i = 0 To LineCount - 1
Lines(0, i) = Round((Lines(0, i) - MaxX + OffsetX) * StepX, 0)
If Lines(0, i) < 0 Then Lines(0, i) = 0
If Lines(0, i) >= nPixelWidth - 2 Then Lines(0, i) = nPixelWidth - 3
Lines(1, i) = Round((Lines(1, i) - MaxY + OffsetY) * StepY, 0)
If Lines(1, i) < 0 Then Lines(1, i) = 0
If Lines(1, i) >= nPixelHeight - 2 Then Lines(1, i) = nPixelHeight - 3
Lines(2, i) = Round((Lines(2, i) - MinX + OffsetX) * StepX, 0)
If Lines(2, i) < 0 Then Lines(2, i) = 0
If Lines(2, i) >= nPixelWidth - 2 Then Lines(2, i) = nPixelWidth - 3
Lines(3, i) = Round((Lines(3, i) - MinY + OffsetY) * StepY, 0)
If Lines(3, i) < 0 Then Lines(3, i) = 0
If Lines(3, i) >= nPixelHeight - 2 Then Lines(3, i) = nPixelHeight - 3
CDGen_Line Lines(0, i) + X0 + 1, Lines(1, i) + Y0 + 1, Lines(2, i) + X0 + 1, Lines(3, i) + Y0 + 1
Next
End Sub

Sub CDGen_Char(cChar, X0, Y0)
" 在指定坐标处生成指定字符的位图阵列
CDGen_Reset
Sel&#101;ct Case cChar
Case "0"
CDGen_SetDirection -60 " 逆时针60度(相对于垂直线)
CDGen_FowardDraw -0.7 " 反方向绘制0.7个单位
CDGen_SetDirection -60 " 逆时针60度
CDGen_FowardDraw -0.7 " 反方向绘制0.7个单位
CDGen_SetDirection 120 " 顺时针120度
CDGen_FowardDraw 1.5 " 绘制1.5个单位
CDGen_SetDirection -60 " 逆时针60度
CDGen_FowardDraw 0.7 " 绘制0.7个单位
CDGen_SetDirection -60 " 顺时针120度
CDGen_FowardDraw 0.7 " 绘制0.7个单位
CDGen_Close 0 " 封闭当前笔与第0笔(0开始)
Case "1"
CDGen_SetDirection -90 " 逆时针90度(相对于垂直线)
CDGen_FowardDraw 0.5 " 绘制0.5个单位
CDGen_MoveToMiddle 0, 50 " 移动画笔的位置到第0笔(0开始)的50%处
CDGen_SetDirection 90 " 逆时针90度
CDGen_FowardDraw -1.4 " 反方向绘制1.4个单位
CDGen_SetDirection 30 " 逆时针30度
CDGen_FowardDraw 0.4 " 绘制0.4个单位
Case "2"
CDGen_SetDirection 45 " 顺时针45度(相对于垂直线)
CDGen_FowardDraw -0.7 " 反方向绘制0.7个单位
CDGen_SetDirection -120 " 逆时针120度
CDGen_FowardDraw 0.4 " 绘制0.4个单位
CDGen_SetDirection 60 " 顺时针60度
CDGen_FowardDraw 0.6 " 绘制0.6个单位
CDGen_SetDirection 60 " 顺时针60度
CDGen_FowardDraw 1.6 " 绘制1.6个单位
CDGen_SetDirection -135 " 逆时针135度
CDGen_FowardDraw 1.0 " 绘制1.0个单位
Case "3"
CDGen_SetDirection -90 " 逆时针90度(相对于垂直线)
CDGen_FowardDraw 0.8 " 绘制0.8个单位
CDGen_SetDirection 135 " 顺时针135度
CDGen_FowardDraw 0.8 " 绘制0.8个单位
CDGen_SetDirection -120 " 逆时针120度
CDGen_FowardDraw 0.6 " 绘制0.6个单位
CDGen_SetDirection 80 " 顺时针80度
CDGen_FowardDraw 0.5 " 绘制0.5个单位
CDGen_SetDirection 60 " 顺时针60度
CDGen_FowardDraw 0.5 " 绘制0.5个单位
CDGen_SetDirection 60 " 顺时针60度
CDGen_FowardDraw 0.5 " 绘制0.5个单位
Case "4"
CDGen_SetDirection 20 " 顺时针20度(相对于垂直线)
CDGen_FowardDraw 0.8 " 绘制0.8个单位
CDGen_SetDirection -110 " 逆时针110度
CDGen_FowardDraw 1.2 " 绘制1.2个单位
CDGen_MoveToMiddle 1, 60 " 移动画笔的位置到第1笔(0开始)的60%处
CDGen_SetDirection 90 " 顺时针90度
CDGen_FowardDraw 0.7 " 绘制0.7个单位
CDGen_MoveCursor 2 " 移动画笔到第2笔(0开始)的开始处
CDGen_FowardDraw -1.5 " 反方向绘制1.5个单位
Case "5"
CDGen_SetDirection 90 " 顺时针90度(相对于垂直线)
CDGen_FowardDraw 1.0 " 绘制1.0个单位
CDGen_SetDirection -90 " 逆时针90度
CDGen_FowardDraw 0.8 " 绘制0.8个单位
CDGen_SetDirection -90 " 逆时针90度
CDGen_FowardDraw 0.8 " 绘制0.8个单位
CDGen_SetDirection 30 " 顺时针30度
CDGen_FowardDraw 0.4 " 绘制0.4个单位
CDGen_SetDirection 60 " 顺时针60度
CDGen_FowardDraw 0.4 " 绘制0.4个单位
CDGen_SetDirection 30 " 顺时针30度
CDGen_FowardDraw 0.5 " 绘制0.5个单位
CDGen_SetDirection 60 " 顺时针60度
CDGen_FowardDraw 0.8 " 绘制0.8个单位
Case "6"
CDGen_SetDirection -60 " 逆时针60度(相对于垂直线)
CDGen_FowardDraw -0.7 " 反方向绘制0.7个单位
CDGen_SetDirection -60 " 逆时针60度
CDGen_FowardDraw -0.7 " 反方向绘制0.7个单位
CDGen_SetDirection 120 " 顺时针120度
CDGen_FowardDraw 1.5 " 绘制1.5个单位
CDGen_SetDirection 120 " 顺时针120度
CDGen_FowardDraw -0.7 " 反方向绘制0.7个单位
CDGen_SetDirection 120 " 顺时针120度
CDGen_FowardDraw 0.7 " 绘制0.7个单位
CDGen_SetDirection 120 " 顺时针120度
CDGen_FowardDraw -0.7 " 反方向绘制0.7个单位
CDGen_SetDirection 120 " 顺时针120度
CDGen_FowardDraw 0.5 " 绘制0.5个单位
CDGen_CloseToMiddle 2, 50 " 将当前画笔位置与第2笔(0开始)的50%处封闭
Case "7"
CDGen_SetDirection 180 " 顺时针180度(相对于垂直线)
CDGen_FowardDraw 0.3 " 绘制0.3个单位
CDGen_SetDirection 90 " 顺时针90度
CDGen_FowardDraw 0.9 " 绘制0.9个单位
CDGen_SetDirection 120 " 顺时针120度
CDGen_FowardDraw 1.3 " 绘制1.3个单位
Case "8"
CDGen_SetDirection -60 " 逆时针60度(相对于垂直线)
CDGen_FowardDraw -0.8 " 反方向绘制0.8个单位
CDGen_SetDirection -60 " 逆时针60度
CDGen_FowardDraw -0.8 " 反方向绘制0.8个单位
CDGen_SetDirection 120 " 顺时针120度
CDGen_FowardDraw 0.8 " 绘制0.8个单位
CDGen_SetDirection 110 " 顺时针110度
CDGen_FowardDraw -1.5 " 反方向绘制1.5个单位
CDGen_SetDirection -110 " 逆时针110度
CDGen_FowardDraw 0.9 " 绘制0.9个单位
CDGen_SetDirection 60 " 顺时针60度
CDGen_FowardDraw 0.8 " 绘制0.8个单位
CDGen_SetDirection 60 " 顺时针60度
CDGen_FowardDraw 0.8 " 绘制0.8个单位
CDGen_SetDirection 60 " 顺时针60度
CDGen_FowardDraw 0.9 " 绘制0.9个单位
CDGen_SetDirection 70 " 顺时针70度
CDGen_FowardDraw 1.5 " 绘制1.5个单位
CDGen_Close 0 " 封闭当前笔与第0笔(0开始)
Case "9"
CDGen_SetDirection 120 " 逆时针60度(相对于垂直线)
CDGen_FowardDraw -0.7 " 反方向绘制0.7个单位
CDGen_SetDirection -60 " 逆时针60度
CDGen_FowardDraw -0.7 " 反方向绘制0.7个单位
CDGen_SetDirection -60 " 顺时针120度
CDGen_FowardDraw -1.5 " 绘制1.5个单位
CDGen_SetDirection -60 " 顺时针120度
CDGen_FowardDraw -0.7 " 反方向绘制0.7个单位
CDGen_SetDirection -60 " 顺时针120度
CDGen_FowardDraw -0.7 " 绘制0.7个单位
CDGen_SetDirection 120 " 顺时针120度
CDGen_FowardDraw 0.7 " 反方向绘制0.7个单位
CDGen_SetDirection -60 " 顺时针120度
CDGen_FowardDraw 0.5 " 绘制0.5个单位
CDGen_CloseToMiddle 2, 50 " 将当前画笔位置与第2笔(0开始)的50%处封闭
" 以下为字母的矢量动作,有兴趣的可以继续
Case "A"
CDGen_SetDirection -(Rnd * 20 + 150) " 逆时针150-170度(相对于垂直线)
CDGen_FowardDraw Rnd * 0.2 + 1.1 " 绘制1.1-1.3个单位
CDGen_SetDirection Rnd * 20 + 140 " 顺时针140-160度
CDGen_FowardDraw Rnd * 0.2 + 1.1 " 绘制1.1-1.3个单位
CDGen_MoveToMiddle 0, 30 " 移动画笔的位置到第1笔(0开始)的30%处
CDGen_CloseToMiddle 1, 70 " 将当前画笔位置与第1笔(0开始)的70%处封闭
Case "B"
CDGen_SetDirection -(Rnd * 20 + 50) " 逆时针50-70度(相对于垂直线)
CDGen_FowardDraw Rnd * 0.4 + 0.8 " 绘制0.8-1.2个单位
CDGen_SetDirection Rnd * 20 + 110 " 顺时针110-130度
CDGen_FowardDraw Rnd * 0.2 + 0.6 " 绘制0.6-0.8个单位
CDGen_SetDirection -(Rnd * 20 + 110) " 逆时针110-130度
CDGen_FowardDraw Rnd * 0.2 + 0.6 " 绘制0.6-0.8个单位
CDGen_SetDirection Rnd * 20 + 110 " 顺时针110-130度
CDGen_FowardDraw Rnd * 0.4 + 0.8 " 绘制0.8-1.2个单位
CDGen_Close 0 " 封闭当前笔与第1笔(0开始)
Case "C"
CDGen_SetDirection -60 " 逆时针60度(相对于垂直线)
CDGen_FowardDraw -0.7 " 反方向绘制0.7个单位
CDGen_SetDirection -60 " 逆时针60度
CDGen_FowardDraw -0.7 " 反方向绘制0.7个单位
CDGen_SetDirection 120 " 顺时针120度
CDGen_FowardDraw 1.5 " 绘制1.5个单位
CDGen_SetDirection 120 " 顺时针120度
CDGen_FowardDraw -0.7 " 反方向绘制0.7个单位
CDGen_SetDirection 120 " 顺时针120度
CDGen_FowardDraw 0.7 " 绘制0.7个单位
End Sel&#101;ct
CDGen_Flush X0, Y0
End Sub

Sub CDGen_Blur()
" 对产生的位图进行柔化处理
Dim i, j

For j = 1 To nPixelHeight - 2
For i = 1 To nCharCount * nPixelWidth - 2
If Buf(j, i) = 0 Then
If ((Buf(j, i - 1) o&#114; Buf(j + 1, i)) And 1) <> 0 Then
" 如果当前点是空白点,且上下左右四个点中有一个点是有色点,则该点做柔化处理
Buf(j, i) = 2
End If
End If
Next
Next
End Sub

Sub CDGen_NoisyDot()
" 对产生的位图进行噪点处理
Dim i, j, NoisyDot, CurDot

For j = 0 To nPixelHeight - 1
For i = 0 To nCharCount * nPixelWidth - 1
If Buf(j, i) <> 0 Then
NoisyDot = Int(Rnd * Rnd * nMaxSaturation)
Sel&#101;ct Case nColorNoisyDotOdds
Case 0
CurDot = nMaxSaturation
Case 1
CurDot = 0
Case Else
CurDot = NoisyDot
End Sel&#101;ct
If Rnd < nColorNoisyDotOdds Then Buf(j, i) = CurDot Else Buf(j, i) = nMaxSaturation
Else
NoisyDot = Int(Rnd * nMaxSaturation)
Sel&#101;ct Case nBlankNoisyDotOdds
Case 0
CurDot = 0
Case 1
CurDot = nMaxSaturation
Case Else
CurDot = NoisyDot
End Sel&#101;ct
If Rnd < nBlankNoisyDotOdds Then Buf(j, i) = CurDot Else Buf(j, i) = 0
End If
Next
Next
End Sub

Sub CDGen()
" 生成位图阵列
Dim i, Ch

DigtalStr = ""
CDGen_Clear
For i = 0 To nCharCount - 1
Ch = Mid(cCharSet, Int(Rnd * Len(cCharSet)) + 1, 1)
DigtalStr = DigtalStr + Ch
CDGen_Char Ch, i * nPixelWidth, 0
Next
CDGen_Blur
CDGen_NoisyDot
End Sub

Function HSBToRGB(vH, vS, vB)
" 将颜色值由HSB转换为RGB
Dim aRGB(3), RGB1st, RGB2nd, RGB3rd
Dim nH, nS, nB
Dim lH, nF, nP, nQ, nT

vH = (vH Mod 360)
If vS > 100 Then
vS = 100
ElseIf vS < 0 Then
vS = 0
End If
If vB > 100 Then
vB = 100
ElseIf vB < 0 Then
vB = 0
End If
If vS > 0 Then
nH = vH / 60
nS = vS / 100
nB = vB / 100
lH = Int(nH)
nF = nH - lH
nP = nB * (1 - nS)
nQ = nB * (1 - nS * nF)
nT = nB * (1 - nS * (1 - nF))
Sel&#101;ct Case lH
Case 0
aRGB(0) = nB * 255
aRGB(1) = nT * 255
aRGB(2) = nP * 255
Case 1
aRGB(0) = nQ * 255
aRGB(1) = nB * 255
aRGB(2) = nP * 255
Case 2
aRGB(0) = nP * 255
aRGB(1) = nB * 255
aRGB(2) = nT * 255
Case 3
aRGB(0) = nP * 255
aRGB(1) = nQ * 255
aRGB(2) = nB * 255
Case 4
aRGB(0) = nT * 255
aRGB(1) = nP * 255
aRGB(2) = nB * 255
Case 5
aRGB(0) = nB * 255
aRGB(1) = nP * 255
aRGB(2) = nQ * 255
End Sel&#101;ct
Else
aRGB(0) = (vB * 255) / 100
aRGB(1) = aRGB(0)
aRGB(2) = aRGB(0)
End If
HSBToRGB = ChrB(Round(aRGB(2), 0)) &amp; ChrB(Round(aRGB(1), 0)) &amp; ChrB(Round(aRGB(0), 0))
End Function

Sub CreatValidCode(pSN)
Dim i, j, CurColorHue

" 禁止缓存
Response.Expires = -9999
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-ctrol", "no-cache"
Response.ContentType = "image/bmp"

Call CDGen
Session(pSN) = DigtalStr "记录入Session

Dim PicWidth, PicHeight, FileSize, PicDataSize
PicWidth = nCharCount * nPixelWidth
PicHeight = nPixelHeight
PicDataSize = PicWidth * PicHeight * 3
FileSize = PicDataSize + 54

" 输出BMP文件信息头
Response.BinaryWrite ChrB(66) &amp; ChrB(77) &amp; _
ChrB(FileSize Mod 256) &amp; ChrB((FileSize \ 256) Mod 256) &amp; ChrB((FileSize \ 256 \ 256) Mod 256) &amp; ChrB(FileSize \ 256 \ 256 \ 256) &amp; _
ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; _
ChrB(54) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0)

" 输出BMP位图信息头
Response.BinaryWrite ChrB(40) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; _
ChrB(PicWidth Mod 256) &amp; ChrB((PicWidth \ 256) Mod 256) &amp; ChrB((PicWidth \ 256 \ 256) Mod 256) &amp; ChrB(PicWidth \ 256 \ 256 \ 256) &amp; _
ChrB(PicHeight Mod 256) &amp; ChrB((PicHeight \ 256) Mod 256) &amp; ChrB((PicHeight \ 256 \ 256) Mod 256) &amp; ChrB(PicHeight \ 256 \ 256 \ 256) &amp; _
ChrB(1) &amp; ChrB(0) &amp; _
ChrB(24) &amp; ChrB(0) &amp; _
ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; _
ChrB(PicDataSize Mod 256) &amp; ChrB((PicDataSize \ 256) Mod 256) &amp; ChrB((PicDataSize \ 256 \ 256) Mod 256) &amp; ChrB(PicDataSize \ 256 \ 256 \ 256) &amp; _
ChrB(18) &amp; ChrB(11) &amp; ChrB(0) &amp; ChrB(0) &amp; _
ChrB(18) &amp; ChrB(11) &amp; ChrB(0) &amp; ChrB(0) &amp; _
ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; _
ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0)

" 逐点输出位图阵列
If nColorHue = -1 Then
CurColorHue = Int(Rnd * 360)
ElseIf nColorHue = -2 Then
CurColorHue = 0
Else
CurColorHue = nColorHue
End If
For j = 0 To nPixelHeight - 1
For i = 0 To Len(DigtalStr) * nPixelWidth - 1
If nColorHue = -2 Then
Response.BinaryWrite HSBToRGB(CurColorHue, 0, 100 - Buf(nPixelHeight - 1 - j, i))
Else
Response.BinaryWrite HSBToRGB(CurColorHue, Buf(nPixelHeight - 1 - j, i), 100)
End If
Next
Next
End Sub
%>

Tags: 验证码, 随机

ASP模仿.Net的Cache

为了提高网站首页的性能,首页凡是需要调用数据库显示数据的地方都会先试图从缓存中调用数据,如果缓存中没有可用数据再打开数据库取出记录集,为了让页面显示数据和数据库在一定时间内同步,我们把缓存的过期时间设置成30秒。

声明:缓存管理类出自于动网论坛7.0

注意:最好不要在缓存里直接缓存带状态的对象和MTA模式的对象,比如说直接缓存记录集或者数据库链接对象等。
代码:

<%
Sub ShowRsArr(rsArr)
 &amp;#39;用表格显示记录集getrows生成的数组的表结构
 &amp;#39;
 Response.Write "<table width=100% border=0 cellspacing=0 cellpadding=0>"
 If Not IsEmpty(rsArr) Then
  For y=0 To Ubound(rsArr,2)
   Response.Write"<tr>"
   for x=0 to Ubound(rsArr,1)
    Response.Write "<td>"&amp;rsArr(x,y)&amp;"</td>"
   next
   Response.Write"</tr>"

  next
 Else
  Response.Write "<tr>"
  Response.Write "<td colspan="&amp;rs.fields.count-1&amp;">No Records</td>"
  Response.Write "</tr>"
 End If
 Response.Write "</table>"
End Sub
Class Cls_Cache
Rem ==================使用说明=================================================================================
Rem = 本类模块是动网先锋原创,作者:迷城浪子。如采用本类模块,请不要去掉这个说明。这段注释不会影响执行的速度。=
Rem = 作用:缓存和缓存管理类 =
Rem = 公有变量:Reloadtime 过期时间(单位为分钟)缺省值为14400, =
Rem = MaxCount 缓存对象的最大值,超过则自动删除使用次数少的对象。缺省值为300 =
Rem = CacheName 缓存组的总名称,缺省值为"Dvbbs",如果一个站点中有超过一个缓存组,则需要外部改变这个值。 =
Rem = 属性:Name 定义缓存对象名称,只写属性。 =
Rem = 属性:value 读取和写入缓存数据。 =
Rem = 函数:ObjIsEmpty()判断当前缓存是否过期。 =
Rem = 方法:DelCahe(MyCaheName)手工删除一个缓存对象,参数是缓存对象的名称。 =
Rem ===========================================================================================================
Public Reloadtime,MaxCount,CacheName
 Private LocalCacheName,CacheData,DelCount
 Private Sub Class_Initialize()
  Reloadtime=14400
  CacheName="Dvbbs"
 End Sub
Private Sub SetCache(SetName,NewValue)
 Application.Lock
 Application(SetName) = NewValue
 Application.unLock
End Sub

Private Sub makeEmpty(SetName)
 Application.Lock
 Application(SetName) = Empty
 Application.unLock
End Sub

Public Property Let Name(ByVal vNewValue)
 LocalCacheName=LCase(vNewValue)
End Property

Public Property Let Value(ByVal vNewValue)
 If LocalCacheName<>"" Then
  CacheData=Application(CacheName&amp;"_"&amp;LocalCacheName)
  If IsArray(CacheData) Then
   CacheData(0)=vNewValue
   CacheData(1)=Now()
  Else
   ReDim CacheData(2)
   CacheData(0)=vNewValue
   CacheData(1)=Now()
  End If
  SetCache CacheName&amp;"_"&amp;LocalCacheName,CacheData
 Else
  Err.Raise vbObjectError + 1, "DvbbsCacheServer", " please change the CacheName."
 End If
End Property

Public Property Get Value()
 If LocalCacheName<>"" Then
  CacheData=Application(CacheName&amp;"_"&amp;LocalCacheName)
  If IsArray(CacheData) Then
   Value=CacheData(0)
  Else
   Err.Raise vbObjectError + 1, "DvbbsCacheServer", " The CacheData Is Empty."
  End If
 Else
  Err.Raise vbObjectError + 1, "DvbbsCacheServer", " please change the CacheName."
 End If
End Property
Public Function ObjIsEmpty()
 ObjIsEmpty=True
 CacheData=Application(CacheName&amp;"_"&amp;LocalCacheName)
 If Not IsArray(CacheData) Then Exit Function
 If Not IsDate(CacheData(1)) Then Exit Function
 If DateDiff("s",CDate(CacheData(1)),Now()) < 60*Reloadtime Then
  ObjIsEmpty=False
 End If
End Function
Public Sub DelCahe(MyCaheName)
 makeEmpty(CacheName&amp;"_"&amp;MyCaheName)
End Sub
End Class
Dim strconn,rs
strconn="Driver={sql server};server=localhost;database=northwind;uid=sa;pwd=sa;"

Public Function GetEmployees()

 Dim SQL,Rs,Cache
 Set Cache=New Cls_Cache
 Cache.Reloadtime=0.5
 Cache.CacheName="wawa"
 Cache.Name="Employees"
 If Cache.ObjIsEmpty() Then
  Set rs=Server.Cr&amp;#101;ateObject("ADODB.Recordset")
  SQL = "sel&amp;#101;ct EmployeeID, LastName, FirstName from employees o&amp;#114;der by employeeid desc"
  Rs.Open SQL,strconn,1,1
  Cache.value = Rs.GetRows(5)
  Rs.Close:Set Rs=Nothing
 End If
 GetEmployees=Cache.Value
 Set Cache=Nothing
End Function
ShowRsArr(GetEmpLoyees)
%>
<script>
function TimeOut(a){
 var c=a-1;
 if(c==0) {
  window.location.href=window.location;
 }else{
  document.all.abc.innerHTML="离缓存结束还有:"+c+"秒";
  window.setTimeout(&amp;#39;TimeOut(&amp;#39;+c+&amp;#39;)&amp;#39;,1000);
 }
}
</script>
<body onload="TimeOut(&amp;#39;30&amp;#39;)">
<div id="abc"></div>

这是从天极上面转过来的..

<>都给换成<>了.

比较郁闷的了,没什么好注释的了.一个class而已.

count设得太大,小心服务器支持不了.反正有好有坏,建议如果对及时性要求不是太高,还是想办法生成HTML的吧

Tags: asp缓存

TSYS图片加水印功能最新修改版

第一步:打开  News_Mdy.asp
找到:Function ReplaceRemoteUrl(sHTML, sSaveFilePath, sFileExt)

整个函数...替换成:
Function ReplaceRemoteUrl(sHTML, sSaveFilePath, sFileExt)
    Dim s_Content
    s_Content = sHTML
    If IsObjInstalled("Microsoft.XMLHTTP") = False then
        ReplaceRemoteUrl = s_Content
        Exit Function
    End If
    
    Dim re, RemoteFile, RemoteFileurl,SaveFileName,SaveFileType,arrSaveFileNameS,arrSaveFileName,sSaveFilePaths
    Set re = new RegExp
    re.IgnoreCase = True
    re.Global = True
    re.Pattern = "((http|https|ftp|rtsp|mms):(\/\/|\\\\){1}((\w)+[.]){1,}(net|com|cn|org|cc|tv|[0-9]{1,3})(\S*\/)((\S)+[.]{1}(" &amp; sFileExt &amp; ")))"
    Set RemoteFile = re.Execute(s_Content)
    For Each RemoteFileurl in RemoteFile
        SaveFileType = Replace(Replace(RemoteFileurl,"/", "a"), ":", "a")
        arrSaveFileName = Right(SaveFileType,12)
                arrSaveFileName= Year(now) &amp; month(now) &amp; day(now) &amp; hour(now) &amp; minute(now) &amp; Second(now) &amp; "_" &amp; arrSaveFileName
                sSaveFilePaths=sSaveFilePath &amp; "/"
        SaveFileName = sSaveFilePaths &amp; arrSaveFileName
        SaveFileName=SaveRemoteFile(SaveFileName, RemoteFileurl)
        s_Content = Replace(s_Content,RemoteFileurl,SaveFileName)
    Next
    ReplaceRemoteUrl = s_Content
End Function


再找到:Function SaveRemoteFile(s_LocalFileName,s_RemoteFileUrl)
整个函数替换成:
Function SaveRemoteFile(s_LocalFileName,s_RemoteFileUrl)
    Dim Ads, Retrieval, GetRemoteData
    On Error Resume Next
    Set Retrieval = Server.Cr&#101;ateObject("Microsoft.XMLHTTP")
    With Retrieval
        .Open "Get", s_RemoteFileUrl, False, "", ""
        .Send
        GetRemoteData = .ResponseBody
    End With
    Set Retrieval = Nothing
    Set Ads = Server.Cr&#101;ateObject("Adodb.Stream")
    With Ads
        .Type = 1
        .Open
        .Write GetRemoteData
        .SaveToFile Server.MapPath(s_LocalFileName), 2
        .Cancel()
        .Close()
    End With
    Set Ads=nothing
        SaveRemoteFile=s_LocalFileName
        "加水印图片------------EditBy Minghao
        if sImage_WaterMarkAdd then
                if Not IsObjInstalled("Persits.Jpeg") then
                        Response.write "请先安装ASPJPEG组件!才能使用图片水印功能!"
                        Response.end
                end if
                Dim wmc,posX,posY
                set wmc=new Minghao_WaterMarkClass
                wmc.SourceImage=Server.MapPath(s_LocalFileName)
                wmc.open()
                if wmc.width>=sImage_MinWidth and wmc.height>=sImage_MinHeight then
                        "符合条件..开始加水印
                        sel&#101;ct case sImage_DrawPosition
                                case 0
                                        posX=sImage_DrawPosX
                                        posY=sImage_DrawPosY
                                case 1
                                        posX=wmc.width - sImage_DrawPosX - sImage_DrawWidth
                                        posY=sImage_DrawPosY
                                case 2
                                        posX=wmc.width - sImage_DrawPosX - sImage_DrawWidth
                                        posY=wmc.height - sImage_DrawPosY - sImage_DrawHeight
                                case 3
                                        posX=sImage_DrawPosX
                                        posY=wmc.height - sImage_DrawPosY - sImage_DrawHeight
                        end sel&#101;ct
                        if sImage_WaterMarkType="Image" then "图片水印
                                wmc.WaterMarkImage=Server.mappath(sImage_WaterMarkImage)
                                wmc.WaterMarkImageTransColor=sImage_WaterMarkTransColor
                                wmc.DrawImage posX,posY,sImage_WaterMarkOpacity
                        else
                                wmc.DrawText posX,posY
                        end if
                        SaveRemoteFile=GetShortFileName(s_LocalFileName) &amp; ".jpg"
                        wmc.Save Server.Mappath(GetShortFileName(s_LocalFileName) &amp; ".jpg")
                end if
                wmc.close()
                set wmc=nothing
        end if
        if SaveRemoteFile<>s_LocalFileName then Del&#101;teFile(Server.Mappath(s_LocalFileName))
End Function

"取得短文件名.比如  xxxx/xxx/xxx/yy.gif 取得结果是 yy
Function GetShortFileName(str)
        dim arr1,s
        arr1=split(str,".")
        s=len(arr1(ubound(arr1)))+1
        GetShortFileName=Left(str,len(str)-s)        
End Function

(注意看上面,有一个   Del&#101;teFile......函数.这是包含在我另一个fso的文件中的.大家能实现就自己实现,不能实现,就自己把函数复制到一个地方就行)
Function Del&#101;teFile(fName)
        Dim FSO,F
        Set FSO=server.Cr&#101;ateObject(Def_FsoObjectStr)
        if FSO.FileExists(fName) then
                Set F=FSO.GetFile(fName)
                F.Del&#101;te
                Set F=Nothing
        end if
        Set FSO=Nothing
End Function




第二步:打开  Upload.asp

修改  Editor 的 Upload.asp 文件.  (注意我的是最新版的编辑器.自己修改的.想下载到 http://77521.cn下载.)

在头部加入:
<!--#Include File="../../Include/Config.asp" -->
<!--#Include File="../../Include/Minghao_WaterMarkClass.asp" -->

然后..用DW全文查找替换..把 sFileExt 全部替换成  sFileExt2  (因为与config里面变量有冲突)

找到:Sub DoUpload_Class()
整个过程替换掉:
Sub DoUpload_Class()
        "On Error Resume Next
        Dim oUpload, oFile
        " 建立上传对象
        Set oUpload = New upfile_class
        " 取得上传数据,限制最大上传
        oUpload.GetData(nAllowSize*1024)

        If oUpload.Err > 0 Then
                Sel&#101;ct Case oUpload.Err
                Case 1
                        Call OutScript("parent.UploadError("请选择有效的上传文件!")")
                Case 2
                        Call OutScript("parent.UploadError("你上传的文件总大小超出了最大限制(" &amp; nAllowSize &amp; "KB)!")")
                End Sel&#101;ct
                Response.End
        End If

        Set oFile = oUpload.File("uploadfile")
        sFileExt2 = LCase(oFile.FileExt)
        Call CheckValidExt(sFileExt2)
        sOriginalFileName = oFile.FileName
        sSaveFileName = GetRndFileName(sFileExt2)
        oFile.SaveToFile Server.Mappath(sUploadDir &amp; sSaveFileName)
        Set oFile = Nothing
        Set oUpload = Nothing
        "若符合条件加水印图片------------EditBy Minghao
        if sImage_WaterMarkAdd and (sFileExt2="jpg" o&#114; sFileExt2="gif" o&#114; sFileExt2="bmp" o&#114; sFileExt2="png") then
                if Not IsObjInstalled("Persits.Jpeg") then
                        Response.write "请先安装ASPJPEG组件!才能使用图片水印功能!"
                        Response.end
                end if
                Dim wmc,posX,posY,newFileName
                set wmc=new Minghao_WaterMarkClass
                wmc.SourceImage=Server.MapPath(sUploadDir &amp; sSaveFileName)
                wmc.open()
                if wmc.width>=sImage_MinWidth and wmc.height>=sImage_MinHeight then
                        "符合条件..开始加水印
                        sel&#101;ct case sImage_DrawPosition
                                case 0
                                        posX=sImage_DrawPosX
                                        posY=sImage_DrawPosY
                                case 1
                                        posX=wmc.width - sImage_DrawPosX - sImage_DrawWidth
                                        posY=sImage_DrawPosY
                                case 2
                                        posX=wmc.width - sImage_DrawPosX - sImage_DrawWidth
                                        posY=wmc.height - sImage_DrawPosY - sImage_DrawHeight
                                case 3
                                        posX=sImage_DrawPosX
                                        posY=wmc.height - sImage_DrawPosY - sImage_DrawHeight
                        end sel&#101;ct
                        if sImage_WaterMarkType="Image" then "图片水印
                                wmc.WaterMarkImage=Server.mappath(sImage_WaterMarkImage)
                                wmc.WaterMarkImageTransColor=sImage_WaterMarkTransColor
                                wmc.DrawImage posX,posY,sImage_WaterMarkOpacity
                        else
                                wmc.DrawText posX,posY
                        end if
                        newFileName=GetShortFileName(sUploadDir &amp; sSaveFileName) &amp; ".jpg"
                        wmc.Save Server.Mappath(GetShortFileName(sUploadDir &amp; sSaveFileName) &amp; ".jpg")
                end if
                wmc.close()
                set wmc=nothing
                if newFileName<>(sUploadDir&amp;sSaveFileName) then Del&#101;teFile(Server.Mappath(sUploadDir &amp; sSaveFileName))
        end if
End Sub

Function Del&#101;teFile(fName)
        Dim FSO,F
        Set FSO=server.Cr&#101;ateObject(Def_FsoObjectStr)
        if FSO.FileExists(fName) then
                Set F=FSO.GetFile(fName)
                F.Del&#101;te
                Set F=Nothing
        end if
        Set FSO=Nothing
End Function
"取得短文件名.比如  xxxx/xxx/xxx/yy.gif 取得结果是 yy
Function GetShortFileName(str)
        dim arr1,s
        arr1=split(str,".")
        s=len(arr1(ubound(arr1)))+1
        GetShortFileName=Left(str,len(str)-s)        
End Function


然后最后一步:在 Include/下.新建  Minghao_WaterMarkClass.asp

<%
"////////////////////////////////////////////////////////
"//                  图片加水印功能类库
"//              明皓 77521.cn 2006.4.15
"///////////////////////////////////////////////////////

Class Minghao_WaterMarkClass
    Private Jpeg
        Private JpegMark
        Private StatFlag
        
        Public SourceImage
        Public WaterMarkImage
        Public WaterMarkImageTransColor

    Private Sub Class_Initialize
                SourceImage=""
                WaterMarkImage=""
                StatFlag=-1
        Set Jpeg = Server.Cr&#101;ateObject("Persits.Jpeg")
    End Sub
    Private Sub class_Terminate
                On Error Resume Next
                Jpeg.Close
        Set Jpeg=nothing
    End sub
        "-----------属性区----------------------------------
    Public Property Get Width()
                Call StatCheck()
        Width=Jpeg.Width
    End Property
    Public Property Let Width(byval val)
                Call StatCheck()
        Jpeg.Width=val
    End Property

    Public Property Get Height()
                Call StatCheck()
        Height=Jpeg.Height
    End Property
    Public Property Let Height(byval val)
                Call StatCheck()
        Jpeg.Height=val
    End Property

    Public Property Get o&#114;iginalWidth()
                Call StatCheck()
        Height=Jpeg.OriginalWidth
    End Property
    Public Property Get o&#114;iginalHeight()
                Call StatCheck()
        Height=Jpeg.OriginalHeight
    End Property

        "----------私函---------------------------------------------
        Private Sub StatCheck()
                if SourceImage="" then
                        Response.write "对不起,请先指定SourceImage属性!"
                        Response.end
                end if
                if StatFlag=-1 then
                        Response.write "对不起,请先使用object.Open()方法打开图像文件."
                        Response.end
                end if
        End Sub
        
        "-----------公函--------------------------------------------
        Public Sub Open()
                StatFlag=0
                Call StatCheck()
                Jpeg.Open(SourceImage)
        End Sub
        Public Sub Close()
                if StatFlag<>-1 then
                        Jpeg.Close
                end if
        End Sub
        Public Function Save(byval str)
                Jpeg.Save(str)
        End Function
        Public Function DrawImage(byval x,byval y,byval Op)
                if SourceImage="" o&#114; WaterMarkImage="" then
                        response.write "请先指定SourceImage与WaterMarkImage的值!"
                end if
                Set JpegMark=Server.Cr&#101;ateObject("Persits.Jpeg")
                JpegMark.Open(WaterMarkImage)
                if WaterMarkImageTransColor=-1 then
                        Jpeg.Canvas.DrawImage x,y,JpegMark,Op
                else
                        Jpeg.Canvas.DrawImage x,y,JpegMark,Op,WaterMarkImageTransColor
                end if
                "Jpeg.Save SourceImage
                JpegMark.close
                set JpegMark=nothing
        End Function
        Public Function DrawText(byval x,byval y)
                Call StatCheck()
                Jpeg.Canvas.Font.Color = sImage_WaterMarkFontColor
                Jpeg.Canvas.Font.Family = sImage_WaterMarkFontFamily
                Jpeg.Canvas.Font.Bold = sImage_WaterMarkFontBold
                Jpeg.Canvas.Font.Size = sImage_WaterMarkFontSize
                Jpeg.Canvas.Font.ShadowColor = sImage_WaterMarkFontShadow
                Jpeg.Canvas.Font.ShadowXoffset = sImage_WaterMarkFontShadowXoffset
                Jpeg.Canvas.Font.ShadowYoffset = sImage_WaterMarkFontShadowYoffset
                Jpeg.Canvas.Font.Quality = sImage_WaterMarkFontQuality
                Jpeg.Canvas.Print x,y,sImage_WaterMarkText
                "Jpeg.Save SourceImage
        End Function
End Class
%>


把这个文件,包含在前面  News_Mdy.asp 和  Upload.asp 里.就行了.


Upload.asp 里面要包含:
<!--#Include File="../../Include/Config.asp" -->
<!--#Include File="../../Include/Minghao_WaterMarkClass.asp" -->


============================================
到此完成了.

只生成符合条件的图片文件,对于小文件直接跳过.且保留原来的扩展名.
点击在新窗口中浏览此图片

修改 Include/Config.asp 文件 (下面是我的,自己对应做修改吧.注意编码.)
<%
Response.Charset="utf-8"
"//////////////////////////////////////////////////////////
"主要配制信息
"//////////////////////////////////////////////////////////

"FileSystemObject对象名称
Const Def_FsoObjectStr="Scripting.FileSystemObject"

"文件创建将使用的扩展名
Const Def_FileExtension=".html"

"系统主目录地址,结尾请不要加“/”
Const Def_TsysRootPath = ""

"添加资源时是否保存远程图片
Const sSaveFileSel&#101;ct=True

"远程图片保存目录,结尾请不要加“/”
Const sSaveFilePath="/UpLoadFiles/NewsPhoto"

"远程图片保存类型
Const sFileExt="jpg|gif|bmp|png"

"--远程或上传图片保存时是否使用水印功能  "############### 这是水印相关
Const sImage_WaterMarkAdd=True

"--使用水印的图片最小高度及宽度  "############### 这是水印相关
Const sImage_MinWidth=200
Const sImage_MinHeight=150

"--使用图片水印还是文字水印  "############### 这是水印相关
Const sImage_WaterMarkType="Image" " Image o&#114; Text     "Image是用图片水印

"--水印图片地址   "############### 这是水印相关
Const sImage_WaterMarkImage="/WaterMark.gif"
Const sImage_WaterMarkOpacity=1                "水印图片的透明度,取值 0 - 1 之间. 越小越透明.
Const sImage_WaterMarkTransColor=-1            "水印图片的透明色,取值为&amp;Hxxxxxx 比如红色 &amp;Hff0000 若是黑色,也就是说水印图的所有黑色会被设置为透明,

"--水印文字内容  "############### 这是水印相关
Const sImage_WaterMarkText="CopyRight(C) 77521.cn"  "文字内容
Const sImage_WaterMarkFontFamily="宋体"        "字体
Const sImage_WaterMarkFontSize=14             "文字大小
Const sImage_WaterMarkFontColor=&amp;H000000      "取值为&amp;Hxxxxxx 比如红色 &amp;Hff0000
Const sImage_WaterMarkFontBold=True           "是否粗体
Const sImage_WaterMarkFontShadow=&amp;HFFFFFF     "水印文字的阴影颜色
Const sImage_WaterMarkFontShadowXoffset=1     "水印文字阴影向右偏移的像素值,输入负值则向左偏移
Const sImage_WaterMarkFontShadowYoffset=1     "水印文字阴影向下偏移的像素值,输入负值则向上偏移
Const sImage_WaterMarkFontQuality=4           "水印文字的清晰度,从0~4

"--水印坐标  "############### 这是水印相关
Const sImage_DrawPosition=2 "0=左上角 1=右上角 2=右下角 3=左下角 --下面的x,y都是相对的偏移,比如现在就是距右下角10,10的地方
Const sImage_DrawPosX=10
Const sImage_DrawPosY=10

"--水印尺寸(图片大小或文字的大小,这个请自行用PS或其它工具取得)  "############### 这是水印相关
Const sImage_DrawWidth=74
Const sImage_DrawHeight=13

"一个管理员帐户是否允许同时多个不同IP使用
Const Def_DubleOnlineUser=False

"后台资源列表的每页显示数目
Const Def_Sys_PageSize=20

"栏目列表的每页显示数目
Const Cr&#101;ateNewsList_PageSize=20

"生成的栏目资源列表每页显示数目
Const NewsList_PageSize=20

"生成资源时允许的服务器脚本超时时间
Const Def_Cr&#101;ateNewsFiles_ScriptTimeOut=900

"生成资源中当路径不存在时是否提示
Const Def_Cr&#101;ateNewsFiles_ShowFolderError=True

"资源系统允许的关键词数目
Const Def_NewsKeyWordListNum=10

"生成的相关资源数目
Const Def_RelateNewsNumber=10

"在生成资源时是否使用模板缓冲(将提高生成速度及稳定性;同时会牺牲小部分内存,依据模板内容大小而定;)
Const Def_Buffer_WhenCreatingFile=True

Const Def_Buffer_WhenCreatingFile_DiyTemplate=True

"默认评论管理页显示大小
Const Def_Comment_PageSize=30

"//////////////////////////////////////////////////////////
"其它配制信息
"//////////////////////////////////////////////////////////

"站点名称
Const Def_MySiteTitle="Apc001娱乐吧"

"关键字
Const Def_Keywords="MP3下载,MP3歌曲免费下载,免费MP3歌曲下载,MP3音乐下载,免费电影,网通电影"

"系统标题
Const Def_SysTitle="Apc001娱乐吧-后台管理控制面板"

"系统标题
Const Def_Developer=""

"版权信息
Const Def_SoftCopyright_Script="\n\nApc001娱乐吧 二次开发\n"

"是否为下次登录自动记录管理员帐户
Const Def_IsAutoRemberLoginName=False

"自动记录管理员帐户名Cookie的超时时间(天)
Const Def_AutoRemberLoginName_ExpiresTime=5

"默认资源操作面板是否展开
Const Def_ShowNewsContorlPlane=False

"资源修改后是否需重新审枋
Const Def_ReCheckAfterModify=False

"退出Tsys信息发布系统时是否提示
Const Def_ConfirmWhenExitNewsSystem=True

"是否启用管理员登录安全登记
Const Def_UseLoginPolliceMan=True

"监视的时间范围(秒)
Const Def_StakeoutTimeRange=60

"允许登录错误的次数
Const Def_EnableLoginWrong_Number=6

"被封时间(秒)
Const Def_LoginWrongLockTimeRange=300

"//////////////////////////////////////////////////////////
"文件系统配制
"//////////////////////////////////////////////////////////

"虚拟文件目录,结尾请不要加“/”
Const Def_FileSystem_DirectoryRoot="/UpLoadFiles"

"允许上传的文件类型
Const Def_FileSystem_EnableFileExt="|TXT|HTML|HTM|TXT|GIF|JPG|JPEG|BMP|PNG|SWF|DOC|"

"//////////////////////////////////////////////////////////
"数据库配制
"//////////////////////////////////////////////////////////

"资源库文件地址
Dim Def_ResourceDBPath
    Def_ResourceDBPath=Def_TsysRootPath &amp; "/~Database~/~DataBase~.mdb"
Dim ConnStr
    ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &amp; Server.MapPath(Def_ResourceDBPath)

"评论数据库地址
Dim Def_CommentDBPath
    Def_CommentDBPath=Def_TsysRootPath &amp; "/Comment/ComDb.mdb"
Dim Comment_ConnStr
    Comment_ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &amp; Server.MapPath(Def_CommentDBPath)
%>
在  Minghao_WaterMarkClass.asp 中..找到

Jpeg.Canvas.DrawImage x,y,JpegMark,Op,WaterMarkImageTransColor

这一行.

如果你的水印图片颜色很....显过渡那种...这里可以改一下.

Jpeg.Canvas.DrawImage x,y,JpegMark,Op,WaterMarkImageTransColor,偏差值

改成上面那样...偏差值.可以取 0-255

就可以不用精确得过滤颜色了.自己调试着用吧.个人觉得没啥用.需要的就自己改一下.比如

Jpeg.Canvas.DrawImage x,y,JpegMark,Op,WaterMarkImageTransColor,20

Tags: tsys

关于eWebEditor中,完整html文档会被自动截取的BUG修正...(TSYS中也用到了)

问题是这样.
有人用编辑器,不只只是编辑内容而已,
更有的用来做整页模板,这样比如:
<html>
<somecode....>
<body>
bodyCode....
</body>
</html>

在代码模式中粘贴以上代码,然后在代码->编辑->代码 这样切换,看到效果了吧?只剩下少量的代码了.
在别的模式切换也一样....这就是一个小bug了.

别的不多了.看代码吧.

下面是我的editor.js 代码...懒的人,直接拷过去用.我的是最新的 3.8 Free 版.
闲着没事的,可以看下...
[code]
/* eWebEditor - eWebSoft在线编辑器 */

// 当前模式
var sCurrMode = null;
var bEditMode = null;
// 连接对象
var oLinkField = null;

//头尾部对象
var oTopCode =null;
var oBottomCode =null;

// 浏览器版本检测
var BrowserInfo = new Object() ;
BrowserInfo.MajorVer = navigator.appVersion.match(/MSIE (.)/)[1] ;
BrowserInfo.MinorVer = navigator.appVersion.match(/MSIE .\.(.)/)[1] ;
BrowserInfo.IsIE55OrMore = BrowserInfo.MajorVer >= 6 || ( BrowserInfo.MajorVer >= 5 &amp;&amp; BrowserInfo.MinorVer >= 5 ) ;

var yToolbars = new Array(); // 工具栏数组

// 当文档完全调入时,进行初始化
var bInitialized = false;
function document.onreadystatechange(){
  if (document.readyState!="complete") return;
  if (bInitialized) return;
  bInitialized = true;

  var i, s, curr;

  // 初始每个工具栏
  for (i=0; i<document.body.all.length;i++){
    curr=document.body.all[i];
    if (curr.className == "yToolbar"){
      InitTB(curr);
      yToolbars[yToolbars.length] = curr;
    }
  }

  oLinkField = parent.document.getElementsByName(sLinkFieldName)[0];
  if (!config.License){
    try{
      eWebEditor_License.innerHTML = "&amp;copy; <a href=&amp;#39;http://www.eWebSoft.com&am... target=&amp;#39;_blank&amp;#39;><font color=#000000>eWebSoft.com</font></a>";
    }
    catch(e){
    }
  }

  // IE5.5以下版本只能使用纯文本模式
  if (!BrowserInfo.IsIE55OrMore){
    config.InitMode = "TEXT";
  }
  
  if (ContentFlag.value=="0") {
    ContentEdit.value = oLinkField.value;
    ContentLoad.value = oLinkField.value;
    ModeEdit.value = config.InitMode;
    ContentFlag.value = "1";
  }

  setMode(ModeEdit.value);
  setLinkedField() ;
}

// 初始化一个工具栏上的按钮
function InitBtn(btn) {
  btn.onmouseover = BtnMouseOver;
  btn.onmouseout = BtnMouseOut;
  btn.onmousedown = BtnMouseDown;
  btn.onmouseup = BtnMouseUp;
  btn.ondragstart = YCancelEvent;
  btn.onsel&amp;#101;ctstart = YCancelEvent;
  btn.onsel&amp;#101;ct = YCancelEvent;
  btn.YUSERONCLICK = btn.onclick;
  btn.onclick = YCancelEvent;
  btn.YINITIALIZED = true;
  return true;
}

//Initialize a toolbar.
function InitTB(y) {
  // Set initial size of toolbar to that of the handle
  y.TBWidth = 0;
    
  // Populate the toolbar with its contents
  if (! PopulateTB(y)) return false;
  
  // Set the toolbar width and put in the handle
  y.style.posWidth = y.TBWidth;
  
  return true;
}


// Hander that simply cancels an event
function YCancelEvent() {
  event.returnValue=false;
  event.cancelBubble=true;
  return false;
}

// Toolbar button onmouseover handler
function BtnMouseOver() {
  if (event.srcElement.tagName != "IMG") return false;
  var image = event.srcElement;
  var element = image.parentElement;
  
  // Change button look based on current state of image.
  if (image.className == "Ico") element.className = "BtnMouseOverUp";
  else if (image.className == "IcoDown") element.className = "BtnMouseOverDown";

  event.cancelBubble = true;
}

// Toolbar button onmouseout handler
function BtnMouseOut() {
  if (event.srcElement.tagName != "IMG") {
    event.cancelBubble = true;
    return false;
  }

  var image = event.srcElement;
  var element = image.parentElement;
  yRaisedElement = null;
  
  element.className = "Btn";
  image.className = "Ico";

  event.cancelBubble = true;
}

// Toolbar button onmousedown handler
function BtnMouseDown() {
  if (event.srcElement.tagName != "IMG") {
    event.cancelBubble = true;
    event.returnValue=false;
    return false;
  }

  var image = event.srcElement;
  var element = image.parentElement;

  element.className = "BtnMouseOverDown";
  image.className = "IcoDown";

  event.cancelBubble = true;
  event.returnValue=false;
  return false;
}

// Toolbar button onmouseup handler
function BtnMouseUp() {
  if (event.srcElement.tagName != "IMG") {
    event.cancelBubble = true;
    return false;
  }

  var image = event.srcElement;
  var element = image.parentElement;

  if (element.YUSERONCLICK) eval(element.YUSERONCLICK + "anonymous()");

  element.className = "BtnMouseOverUp";
  image.className = "Ico";

  event.cancelBubble = true;
  return false;
}

// Populate a toolbar with the elements within it
function PopulateTB(y) {
  var i, elements, element;

  // Iterate through all the top-level elements in the toolbar
  elements = y.children;
  for (i=0; i<elements.length; i++) {
    element = elements[i];
    if (element.tagName == "SCRIPT" || element.tagName == "!") continue;
    
    switch (element.className) {
    case "Btn":
      if (element.YINITIALIZED == null) {
        if (! InitBtn(element)) {
          alert("Problem initializing:" + element.id);
          return false;
        }
      }
      
      element.style.posLeft = y.TBWidth;
      y.TBWidth += element.offsetWidth + 1;
      break;
      
    case "TBGen":
      element.style.posLeft = y.TBWidth;
      y.TBWidth += element.offsetWidth + 1;
      break;
      
    case "TBSep":
      element.style.posLeft = y.TBWidth + 2;
      y.TBWidth += 5;
      break;
      
    case "TBHandle":
      element.style.posLeft = 2;
      y.TBWidth += element.offsetWidth + 7;
      break;
      
    default:
      alert("Invalid class: " + element.className + " on Element: " + element.id + " <" + element.tagName + ">");
      return false;
    }
  }

  y.TBWidth += 1;
  return true;
}


// 设置所属表单的提交或reset事件
function setLinkedField() {
  if (! oLinkField) return ;
  var oForm = oLinkField.form ;
  if (!oForm) return ;
  // 附加submit事件
  oForm.attachEvent("onsubmit", AttachSubmit) ;
  if (! oForm.submitEditor) oForm.submitEditor = new Array() ;
  oForm.submitEditor[oForm.submitEditor.length] = AttachSubmit ;
  if (! oForm.originalSubmit) {
    oForm.originalSubmit = oForm.submit ;
    oForm.submit = function() {
      if (this.submitEditor) {
        for (var i = 0 ; i < this.submitEditor.length ; i++) {
          this.submitEditor[i]() ;
        }
      }
      this.originalSubmit() ;
    }
  }
  // 附加reset事件
  oForm.attachEvent("onreset", AttachReset) ;
  if (! oForm.resetEditor) oForm.resetEditor = new Array() ;
  oForm.resetEditor[oForm.resetEditor.length] = AttachReset ;
  if (! oForm.originalReset) {
    oForm.originalReset = oForm.reset ;
    oForm.reset = function() {
      if (this.resetEditor) {
        for (var i = 0 ; i < this.resetEditor.length ; i++) {
          this.resetEditor[i]() ;
        }
      }
      this.originalReset() ;
    }
  }
}

// 附加submit提交事件,大表单数据提交,保存eWebEditor中的内容
function AttachSubmit() {
  var oForm = oLinkField.form ;
  if (!oForm) return;
  var html = getHTML();
  ContentEdit.value = html;
  if (sCurrMode=="TEXT"){
    html = HTMLEncode(html);
  }
  splitTextField(oLinkField, html);
}

// 表单提交
function doSubmit(){
  var oForm = oLinkField.form ;
  if (!oForm) return ;
  oForm.submit();
}

// 附加Reset事件
function AttachReset() {
  if(bEditMode){
    eWebEditor.document.body.innerHTML = ContentLoad.value;
  }else{
    eWebEditor.document.body.innerText = ContentLoad.value;
  }
}

// 显示帮助
function onHelp(){
  ShowDialog(&amp;#39;dialog/help.htm&amp;#39;,&amp;#39;400&amp;#39;,&amp;#39;300&amp;#39;);
  return false;
}

// 粘贴时自动检测是否来源于Word格式
function onPaste() {
  if (sCurrMode=="VIEW") return false;

  if (sCurrMode=="EDIT"){
    var sHTML = GetClipboardHTML() ;
    if (config.AutoDetectPasteFromWord &amp;&amp; BrowserInfo.IsIE55OrMore) {
      var re = /<\w[^>]* class="?MsoNormal"?/gi ;
      if ( re.test(sHTML)){
        if ( confirm( "你要粘贴的内容好象是从Word中拷出来的,是否要先清除Word格式再粘贴?" ) ){
          cleanAndPaste( sHTML ) ;
          return false ;
        }
      }
    }
    eWebEditor.document.sel&amp;#101;ction.cr&amp;#101;ateRange().pasteHTML(sHTML) ;
    return false;
  }else{
    eWebEditor.document.sel&amp;#101;ction.cr&amp;#101;ateRange().pasteHTML(HTMLEncode( clipboardData.getData("Text"))) ;
    return false;
  }
  
}

// 快捷键
function onKeyDown(event){
  var key = String.fromCharCode(event.keyCode).toUpperCase();

  // F2:显示或隐藏指导方针
  if (event.keyCode==113){
    showBorders();
    return false;
  }
  if (event.ctrlKey){
    // Ctrl+Enter:提交
    if (event.keyCode==10){
      doSubmit();
      return false;
    }
    // Ctrl++:增加编辑区
    if (key=="+"){
      sizeChange(300);
      return false;
    }
    // Ctrl+-:减小编辑区
    if (key=="-"){
      sizeChange(-300);
      return false;
    }
    // Ctrl+1:代码模式
    if (key=="1"){
      setMode("CODE");
      return false;
    }
    // Ctrl+2:设计模式
    if (key=="2"){
      setMode("EDIT");
      return false;
    }
    // Ctrl+3:纯文本
    if (key=="3"){
      setMode("TEXT");
      return false;
    }
    // Ctrl+4:预览
    if (key=="4"){
      setMode("VIEW");
      return false;
    }
  }

  switch(sCurrMode){
  case "VIEW":
    return true;
    break;
  case "EDIT":
    if (event.ctrlKey){
      // Ctrl+D:从Word粘贴
      if (key == "D"){
        PasteWord();
        return false;
      }
      // Ctrl+R:查找替换
      if (key == "R"){
        findReplace();
        return false;
      }
      // Ctrl+Z:Undo
      if (key == "Z"){
        goHistory(-1);
        return false;
      }
      // Ctrl+Y:Redo
      if (key == "Y"){
        goHistory(1);
        return false;
      }
    }
    if(!event.ctrlKey &amp;&amp; event.keyCode != 90 &amp;&amp; event.keyCode != 89) {
      if (event.keyCode == 32 || event.keyCode == 13){
        saveHistory()
      }
    }
    return true;
    break;
  default:
    if (event.keyCode==13){
      var sel = eWebEditor.document.sel&amp;#101;ction.cr&amp;#101;ateRange();
      sel.pasteHTML("<BR>");
      event.cancelBubble = true;
      event.returnValue = false;
      sel.sel&amp;#101;ct();
      sel.moveEnd("character", 1);
      sel.moveStart("character", 1);
      sel.collapse(false);
      return false;
    }
    // 屏蔽事件
    if (event.ctrlKey){
      // Ctrl+B,I,U
      if ((key == "B")||(key == "I")||(key == "U")){
        return false;
      }
    }

  }
}

// 取剪粘板中的HTML格式数据
function GetClipboardHTML() {
  var oDiv = document.getElementById("eWebEditor_Temp_HTML")
  oDiv.innerHTML = "" ;
  
  var oTextRange = document.body.cr&amp;#101;ateTextRange() ;
  oTextRange.moveToElementText(oDiv) ;
  oTextRange.execCommand("Paste") ;
  
  var sData = oDiv.innerHTML ;
  oDiv.innerHTML = "" ;
  
  return sData ;
}

// 清除WORD冗余格式并粘贴
function cleanAndPaste( html ) {
  // Remove all SPAN tags
  html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
  // Remove Class attributes
  html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
  // Remove Style attributes
  html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
  // Remove Lang attributes
  html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
  // Remove XML elements and declarations
  html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
  // Remove Tags with XML namespace declarations: <o:p></o:p>
  html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
  // Replace the &amp;nbsp;
  html = html.replace(/&amp;nbsp;/, " " );
  // Transform <P> to <DIV>
  var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ;  // Different because of a IE 5.0 error
  html = html.replace( re, "<div$2</div>" ) ;
  
  ins&amp;#101;rtHTML( html ) ;
}

// 在当前文档位置插入.
function ins&amp;#101;rtHTML(html) {
  if (isModeView()) return false;
  if (eWebEditor.document.sel&amp;#101;ction.type.toLowerCase() != "none"){
    eWebEditor.document.sel&amp;#101;ction.clear() ;
  }
  if (sCurrMode!="EDIT"){
    html=HTMLEncode(html);
  }
  eWebEditor.document.sel&amp;#101;ction.cr&amp;#101;ateRange().pasteHTML(html) ;
}

// 设置编辑器的内容
function setHTML(html) {
  ContentEdit.value = html;
  switch (sCurrMode){
  case "CODE":
    eWebEditor.document.designMode="On";
    eWebEditor.document.open();
    eWebEditor.document.write(config.StyleEditorHeader);
    eWebEditor.document.body.innerText=oTopCode + html + oBottomCode;
    eWebEditor.document.body.contentEditable="true";
    eWebEditor.document.close();
    bEditMode=false;
    break;
  case "EDIT":
    eWebEditor.document.designMode="On";
    eWebEditor.document.open();
    //eWebEditor.document.write(config.StyleEditorHeader+html);
    var haoHtml,haoB,haoC,haoD,haoE;
    haoHtml=html.toLowerCase();
    if(haoHtml.indexOf("<body")!=-1 &amp;&amp; haoHtml.indexOf("</body>")!=-1)
    {
      haoB=haoHtml.indexOf("<body");
      haoC=haoHtml.indexOf("</body>");
      haoD=haoHtml.substring(haoB,haoC+7) //中间的长度
      haoE=haoD.substring(0,haoD.indexOf(">")+1);
      oTopCode=haoHtml.substring(0,haoB) + haoE;
      oBottomCode="</body>" + haoHtml.substring(haoC+7);
      eWebEditor.document.write(html);
    }
    else
    {
      oTopCode="";
      oBottomCode="";
      eWebEditor.document.write(config.StyleEditorHeader+html);
    }
    //alert(config.StyleEditorHeader);
    eWebEditor.document.body.contentEditable="true";
    eWebEditor.document.execCommand("2D-Position",true,true);
    eWebEditor.document.execCommand("MultipleSel&amp;#101;ction", true, true);
    eWebEditor.document.execCommand("LiveResize", true, true);
    eWebEditor.document.close();
    doZoom(nCurrZoomSize);
    bEditMode=true;
    eWebEditor.document.onsel&amp;#101;ctionchange = function () { doToolbar();}
    break;
  case "TEXT":
    eWebEditor.document.designMode="On";
    eWebEditor.document.open();
    eWebEditor.document.write(config.StyleEditorHeader);
    eWebEditor.document.body.innerText=html;
    eWebEditor.document.body.contentEditable="true";
    eWebEditor.document.close();
    bEditMode=false;
    break;
  case "VIEW":
    eWebEditor.document.designMode="off";
    eWebEditor.document.open();
    //eWebEditor.document.write(config.StyleEditorHeader+html);
    var haoHtml,haoB,haoC,haoD,haoE;
    haoHtml=html.toLowerCase();
    if(haoHtml.indexOf("<body")!=-1 &amp;&amp; haoHtml.indexOf("</body>")!=-1)
    {
      haoB=haoHtml.indexOf("<body");
      haoC=haoHtml.indexOf("</body>");
      haoD=haoHtml.substring(haoB,haoC+7) //中间的长度
      haoE=haoD.substring(0,haoD.indexOf(">")+1);
      oTopCode=haoHtml.substring(0,haoB) + haoE;
      oBottomCode="</body>" + haoHtml.substring(haoC+7);
      eWebEditor.document.write(html);
    }
    else
    {
      oTopCode="";
      oBottomCode="";
      eWebEditor.document.write(config.StyleEditorHeader+html);
    }

    eWebEditor.document.body.contentEditable="false";
    eWebEditor.document.close();
    bEditMode=false;
    break;
  }

  eWebEditor.document.body.onpaste = onPaste ;
  eWebEditor.document.body.onhelp = onHelp ;
  eWebEditor.document.onkeydown = new Function("return onKeyDown(eWebEditor.event);");
  eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);");

  if ((borderShown != "0")&amp;&amp;bEditMode) {
    borderShown = "0";
    showBorders();
  }

  initHistory();
}

// 取编辑器的内容
function getHTML() {
  var html;
  if((sCurrMode=="EDIT")||(sCurrMode=="VIEW")){
    html = eWebEditor.document.body.innerHTML;
  }else{
    html = eWebEditor.document.body.innerText;
  }
  if (sCurrMode!="TEXT"){
    if ((html.toLowerCase()=="<p>&amp;nbsp;</p>")||(html.toLowerCase()=="<p></p>")){
      html = "";
    }
  }
  return html;
}

// 在尾部追加内容
function appendHTML(html) {
  if (isModeView()) return false;
  if(sCurrMode=="EDIT"){
    eWebEditor.document.body.innerHTML += html;
  }else{
    eWebEditor.document.body.innerText += html;
  }
}

// 从Word中粘贴,去除格式
function PasteWord(){
  if (!validateMode()) return;
  eWebEditor.focus();
  if (BrowserInfo.IsIE55OrMore)
    cleanAndPaste( GetClipboardHTML() ) ;
  else if ( confirm( "此功能要求IE5.5版本以上,你当前的浏览器不支持,是否按常规粘贴进行?" ) )
    format("paste") ;
  eWebEditor.focus();
}

// 粘贴纯文本
function PasteText(){
  if (!validateMode()) return;
  eWebEditor.focus();
  var sText = HTMLEncode( clipboardData.getData("Text") ) ;
  ins&amp;#101;rtHTML(sText);
  eWebEditor.focus();
}

// 检测当前是否允许编辑
function validateMode() {
  if (sCurrMode=="EDIT") return true;
  alert("需转换为编辑状态后才能使用编辑功能!");
  eWebEditor.focus();
  return false;
}

// 检测当前是否在预览模式
function isModeView(){
  if (sCurrMode=="VIEW"){
    alert("预览时不允许设置编辑区内容。");
    return true;
  }
  return false;
}

// 格式化编辑器中的内容
function format(what,opt) {
  if (!validateMode()) return;
  eWebEditor.focus();
  if (opt=="RemoveFormat") {
    what=opt;
    opt=null;
  }
  if (opt==null) eWebEditor.document.execCommand(what);
  else eWebEditor.document.execCommand(what,"",opt);
  eWebEditor.focus();
}

// 确保焦点在 eWebEditor 内
function VerifyFocus() {
  if ( eWebEditor )
    eWebEditor.focus();
}

// 改变模式:代码、编辑、文本、预览
function setMode(NewMode){
  if (NewMode!=sCurrMode){
    if (!BrowserInfo.IsIE55OrMore){
      if ((NewMode=="CODE") || (NewMode=="EDIT") || (NewMode=="VIEW")){
        alert("HTML编辑模式需要IE5.5版本以上的支持!");
        return false;
      }
    }
    if (NewMode=="TEXT"){
      if (sCurrMode==ModeEdit.value){
        if (!confirm("警告!切换到纯文本模式会丢失您所有的HTML格式,您确认切换吗?")){
          return false;
        }
      }
    }
    document.all["Editor_CODE"].style.display = "none";
    document.all["Editor_EDIT"].style.display = "none";
    document.all["Editor_VIEW"].style.display = "none";
    document.all["Editor_"+NewMode].style.display = "block";
    var sBody = "";
    switch(sCurrMode){
    case "CODE":
      if (NewMode=="TEXT"){
        eWebEditor_Temp_HTML.innerHTML = eWebEditor.document.body.innerText;
        sBody = eWebEditor_Temp_HTML.innerText;
      }else{
        sBody = eWebEditor.document.body.innerText;
        //alert(&amp;#39;ok&amp;#39;);
      }
      break;
    case "TEXT":
      sBody = eWebEditor.document.body.innerText;
      sBody = HTMLEncode(sBody);
      break;
    case "EDIT":
    case "VIEW":
      if (NewMode=="TEXT"){
        sBody = eWebEditor.document.body.innerText;
      }else{
        sBody = eWebEditor.document.body.innerHTML;
      }
      break;
    default:
      sBody = ContentEdit.value;
      break;
    }

    // 换图片
    /*try{
      document.all["eWebEditor_CODE"].className = "StatusBarBtnOff";
      document.all["eWebEditor_EDIT"].className = "StatusBarBtnOff";
      document.all["eWebEditor_TEXT"].className = "StatusBarBtnOff";
      document.all["eWebEditor_VIEW"].className = "StatusBarBtnOff";
      document.all["eWebEditor_"+NewMode].className = "StatusBarBtnOn";
      }
    catch(e){
      }
    */
    sCurrMode = NewMode;
    ModeEdit.value = NewMode;
    setHTML(sBody);
    disableChildren(eWebEditor_Toolbar);
  }
}

// 使工具栏无效
function disableChildren(obj){
  if (obj){
    obj.disabled=(!bEditMode);
    for (var i=0; i<obj.children.length; i++){
      disableChildren(obj.children[i]);
    }
  }
}



// 显示无模式对话框
function ShowDialog(url, width, height, optValidate) {
  if (optValidate) {
    if (!validateMode()) return;
  }
  eWebEditor.focus();
  var arr = showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
  eWebEditor.focus();
}

// 全屏编辑
function Maximize() {
  if (!validateMode()) return;
  window.open("dialog/fullscreen.htm?style="+config.StyleName, &amp;#39;FullScreen&amp;#39;+sLinkFieldName, &amp;#39;toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,fullscreen=yes&amp;#39;);
}

// 创建或修改超级链接
function cr&amp;#101;ateLink(){
  if (!validateMode()) return;
  
  if (eWebEditor.document.sel&amp;#101;ction.type == "Control") {
    var oControlRange = eWebEditor.document.sel&amp;#101;ction.cr&amp;#101;ateRange();
    if (oControlRange(0).tagName.toUpperCase() != "IMG") {
      alert("链接只能是图片或文本");
      return;
    }
  }
  
  ShowDialog("dialog/hyperlink.htm", 350, 170, true);
}

// 替换特殊字符
function HTMLEncode(text){
  text = text.replace(/&amp;/g, "&amp;amp;") ;
  text = text.replace(/"/g, "&amp;quot;") ;
  text = text.replace(/</g, "&amp;lt;") ;
  text = text.replace(/>/g, "&amp;gt;") ;
  text = text.replace(/&amp;#39;/g, "&amp;#146;") ;
  text = text.replace(/\ /g,"&amp;nbsp;");
  text = text.replace(/\n/g,"<br>");
  text = text.replace(/\t/g,"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;");
  return text;
}

// 插入特殊对象
function ins&amp;#101;rt(what) {
  if (!validateMode()) return;
  eWebEditor.focus();
  var sel = eWebEditor.document.sel&amp;#101;ction.cr&amp;#101;ateRange();

  switch(what){
  case "excel":    // 插入EXCEL表格
    ins&amp;#101;rtHTML("<object classid=&amp;#39;clsid:0002E510-0000-0000-C000-000000000046&amp;#39; id=&amp;#39;Spreadsheet1&amp;#39; codebase=&amp;#39;file:\\Bob\software\office2000\msowc.cab&amp;#39; width=&amp;#39;100%&amp;#39; height=&amp;#39;250&amp;#39;><param name=&amp;#39;HTMLURL&amp;#39; value><param name=&amp;#39;HTMLData&amp;#39; value=&amp;#39;&amp;lt;html xmlns:x=&amp;quot;urn:schemas-microsoft-com:office:excel&amp;quot;xmlns=&amp;quot;http://www.w3.org/TR/REC-h... type=&amp;quot;text/css&amp;quot;&amp;gt;&amp;lt;!--tr{mso-height-source:auto;}td{black-space:nowrap;}.wc4590F88{black-space:nowrap;font-family:宋体;mso-number-format:General;font-size:auto;font-weight:auto;font-style:auto;text-decoration:auto;mso-background-source:auto;mso-pattern:auto;mso-color-source:auto;text-align:general;vertical-align:bottom;border-top:none;border-left:none;border-right:none;border-bottom:none;mso-protection:locked;}--&amp;gt;&amp;lt;/style&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;&amp;lt;!--[if gte mso 9]&amp;gt;&amp;lt;xml&amp;gt;&amp;lt;x:ExcelWorkbook&amp;gt;&amp;lt;x:ExcelWorksheets&amp;gt;&amp;lt;x:ExcelWorksheet&amp;gt;&amp;lt;x:OWCVersion&amp;gt;9.0.0.2710&amp;lt;/x:OWCVersion&amp;gt;&amp;lt;x:Label Style=&amp;#39;border-top:solid .5pt silver;border-left:solid .5pt silver;border-right:solid .5pt silver;border-bottom:solid .5pt silver&amp;#39;&amp;gt;&amp;lt;x:Caption&amp;gt;Microsoft Office Spreadsheet&amp;lt;/x:Caption&amp;gt; &amp;lt;/x:Label&amp;gt;&amp;lt;x:Name&amp;gt;Sheet1&amp;lt;/x:Name&amp;gt;&amp;lt;x:WorksheetOptions&amp;gt;&amp;lt;x:Sel&amp;#101;cted/&amp;gt;&amp;lt;x:Height&amp;gt;7620&amp;lt;/x:Height&amp;gt;&amp;lt;x:Width&amp;gt;15240&amp;lt;/x:Width&amp;gt;&amp;lt;x:TopRowVisible&amp;gt;0&amp;lt;/x:TopRowVisible&amp;gt;&amp;lt;x:LeftColumnVisible&amp;gt;0&amp;lt;/x:LeftColumnVisible&amp;gt; &amp;lt;x:ProtectContents&amp;gt;False&amp;lt;/x:ProtectContents&amp;gt; &amp;lt;x:DefaultRowHeight&amp;gt;210&amp;lt;/x:DefaultRowHeight&amp;gt; &amp;lt;x:StandardWidth&amp;gt;2389&amp;lt;/x:StandardWidth&amp;gt; &amp;lt;/x:WorksheetOptions&amp;gt; &amp;lt;/x:ExcelWorksheet&amp;gt;&amp;lt;/x:ExcelWorksheets&amp;gt; &amp;lt;x:MaxHeight&amp;gt;80%&amp;lt;/x:MaxHeight&amp;gt;&amp;lt;x:MaxWidth&amp;gt;80%&amp;lt;/x:MaxWidth&amp;gt;&amp;lt;/x:ExcelWorkbook&amp;gt;&amp;lt;/xml&amp;gt;&amp;lt;![endif]--&amp;gt;&amp;lt;table class=wc4590F88 x:str&amp;gt;&amp;lt;col width=&amp;quot;56&amp;quot;&amp;gt;&amp;lt;tr height=&amp;quot;14&amp;quot;&amp;gt;&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&amp;#39;> <param name=&amp;#39;DataType&amp;#39; value=&amp;#39;HTMLDATA&amp;#39;> <param name=&amp;#39;AutoFit&amp;#39; value=&amp;#39;0&amp;#39;><param name=&amp;#39;DisplayColHeaders&amp;#39; value=&amp;#39;-1&amp;#39;><param name=&amp;#39;DisplayGridlines&amp;#39; value=&amp;#39;-1&amp;#39;><param name=&amp;#39;DisplayHorizontalScrollBar&amp;#39; value=&amp;#39;-1&amp;#39;><param name=&amp;#39;DisplayRowHeaders&amp;#39; value=&amp;#39;-1&amp;#39;><param name=&amp;#39;DisplayTitleBar&amp;#39; value=&amp;#39;-1&amp;#39;><param name=&amp;#39;DisplayToolbar&amp;#39; value=&amp;#39;-1&amp;#39;><param name=&amp;#39;DisplayVerticalScrollBar&amp;#39; value=&amp;#39;-1&amp;#39;> <param name=&amp;#39;EnableAutoCalculate&amp;#39; value=&amp;#39;-1&amp;#39;> <param name=&amp;#39;EnableEvents&amp;#39; value=&amp;#39;-1&amp;#39;><param name=&amp;#39;MoveAfterReturn&amp;#39; value=&amp;#39;-1&amp;#39;><param name=&amp;#39;MoveAfterReturnDirection&amp;#39; value=&amp;#39;0&amp;#39;><param name=&amp;#39;RightToLeft&amp;#39; value=&amp;#39;0&amp;#39;><param name=&amp;#39;ViewableRange&amp;#39; value=&amp;#39;1:65536&amp;#39;></object>");
    break;
  case "nowdate":    // 插入当前系统日期
    var d = new Date();
    ins&amp;#101;rtHTML(d.toLocaleDateString());
    break;
  case "nowtime":    // 插入当前系统时间
    var d = new Date();
    ins&amp;#101;rtHTML(d.toLocaleTimeString());
    break;
  case "br":      // 插入换行符
    ins&amp;#101;rtHTML("<br>")
    break;
  case "code":    // 代码片段样式
    ins&amp;#101;rtHTML(&amp;#39;<table width=95% border="0" align="Center" cellpadding="6" cellspacing="0" style="border: 1px Dotted #CCCCCC; TABLE-LAYOUT: fixed"><tr><td bgcolor=#FDFDDF style="WORD-WRAP: break-word"><font style="color: #990000;font-weight:bold">以下是代码片段:</font><br>&amp;#39;+HTMLEncode(sel.text)+&amp;#39;</td></tr></table>&amp;#39;);
    break;
  case "quote":    // 引用片段样式
    ins&amp;#101;rtHTML(&amp;#39;<table width=95% border="0" align="Center" cellpadding="6" cellspacing="0" style="border: 1px Dotted #CCCCCC; TABLE-LAYOUT: fixed"><tr><td bgcolor=#F3F3F3 style="WORD-WRAP: break-word"><font style="color: #990000;font-weight:bold">以下是引用片段:</font><br>&amp;#39;+HTMLEncode(sel.text)+&amp;#39;</td></tr></table>&amp;#39;);
    break;
  case "big":      // 字体变大
    ins&amp;#101;rtHTML("<big>" + sel.text + "</big>");
    break;
  case "small":    // 字体变小
    ins&amp;#101;rtHTML("<small>" + sel.text + "</small>");
    break;
  case "SplitPage":  // 插入分页符
    ins&amp;#101;rtHTML("<HR sysPageSplitFlag>");
    break;
  default:
    if(what.substring(0,2)==&amp;#39;{$&amp;#39;){ins&amp;#101;rtHTML(what);break;}
    alert("错误参数调用!");
    break;
  }
  sel=null;
}

// 显示或隐藏指导方针
var borderShown = config.ShowBorder;
function showBorders() {
  if (!validateMode()) return;
  
  var allForms = eWebEditor.document.body.getElementsByTagName("FORM");
  var allInputs = eWebEditor.document.body.getElementsByTagName("INPUT");
  var allTables = eWebEditor.document.body.getElementsByTagName("TABLE");
  var allLinks = eWebEditor.document.body.getElementsByTagName("A");

  // 表单
  for (a=0; a < allForms.length; a++) {
    if (borderShown == "0") {
      allForms[a].runtimeStyle.border = "1px dotted #FF0000"
    } else {
      allForms[a].runtimeStyle.cssText = ""
    }
  }

  // Input Hidden类
  for (b=0; b < allInputs.length; b++) {
    if (borderShown == "0") {
      if (allInputs[b].type.toUpperCase() == "HIDDEN") {
        allInputs[b].runtimeStyle.border = "1px dashed #000000"
        allInputs[b].runtimeStyle.width = "15px"
        allInputs[b].runtimeStyle.height = "15px"
        allInputs[b].runtimeStyle.backgroundColor = "#FDADAD"
        allInputs[b].runtimeStyle.color = "#FDADAD"
      }
    } else {
      if (allInputs[b].type.toUpperCase() == "HIDDEN")
        allInputs[b].runtimeStyle.cssText = ""
    }
  }

  // 表格
  for (i=0; i < allTables.length; i++) {
      if (borderShown == "0") {
        allTables[i].runtimeStyle.border = "1px dotted #BFBFBF"
      } else {
        allTables[i].runtimeStyle.cssText = ""
      }

      allRows = allTables[i].rows
      for (y=0; y < allRows.length; y++) {
         allCellsInRow = allRows[y].cells
          for (x=0; x < allCellsInRow.length; x++) {
            if (borderShown == "0") {
              allCellsInRow[x].runtimeStyle.border = "1px dotted #BFBFBF"
            } else {
              allCellsInRow[x].runtimeStyle.cssText = ""
            }
          }
      }
  }

  // 链接 A
  for (a=0; a < allLinks.length; a++) {
    if (borderShown == "0") {
      if (allLinks[a].href.toUpperCase() == "") {
        allLinks[a].runtimeStyle.borderBottom = "1px dashed #000000"
      }
    } else {
      allLinks[a].runtimeStyle.cssText = ""
    }
  }

  if (borderShown == "0") {
    borderShown = "1"
  } else {
    borderShown = "0"
  }

  scrollUp()
}

// 返回页面最上部
function scrollUp() {
  eWebEditor.scrollBy(0,0);
}

// 缩放操作
var nCurrZoomSize = 100;
var aZoomSize = new Array(10, 25, 50, 75, 100, 150, 200, 500);
function doZoom(size) {
  eWebEditor.document.body.runtimeStyle.zoom = size + "%";
  nCurrZoomSize = size;
}

// 拼写检查
function spellCheck(){
  ShowDialog(&amp;#39;dialog/spellcheck.htm&amp;#39;, 300, 220, true)
}

// 查找替换
function findReplace(){
  ShowDialog(&amp;#39;dialog/findreplace.htm&amp;#39;, 320, 165, true)
}

// 相对(absolute)或绝对位置(static)
function absolutePosition(){
  var objReference  = null;
  var RangeType    = eWebEditor.document.sel&amp;#101;ction.type;
  if (RangeType != "Control") return;
  var sel&amp;#101;ctedRange  = eWebEditor.document.sel&amp;#101;ction.cr&amp;#101;ateRange();
  for (var i=0; i<sel&amp;#101;ctedRange.length; i++){
    objReference = sel&amp;#101;ctedRange.item(i);
    if (objReference.style.position != &amp;#39;absol