asp常用函数集合,非常不错以后研究第14页

2018-09-06 12:22

阅读:425

  <%
functionloadtempletfile(byvalpath)
onerrorresumenext
dimobjstream
setobjstream=server.createobject(adodb.stream)
withobjstream
.type=2
.mode=3
.open
.loadfromfileserver.mappath(path)
iferr.number<>0then
err.clear
response.write(预加载的模板[&path&]不存在!)
response.end()
endif
.charset=&chrset&
.position=2
loadtempletfile=.readtext
.close
endwith
setobjstream=nothing
endfunction

functionmovefiles(sFolder,dFolder)
onerrorresumenext
dimfso
setfso=server.createobject(scripting.filesystemobject)
iffso.folderexists(server.mappath(sFolder))andfso.folderexists(server.mappath(dFolder))then
movefiles=true
else
movefiles=false
setfso=nothing
callalertbox(系统没有找到指定的路径[&sFolder&]!,2)
endif
setfso=nothing
endfunction

functionrenamefolder(sFolder,dFolder)
onerrorresumenext
dimfso
setfso=server.createobject(scripting.filesystemobject)
iffso.folderexists(server.mappath(sFolder))then
fso.movefolderserver.mappath(sFolder),server.mappath(dFolder)
renamefolder=true
else
renamefolder=false
setfso=nothing
callalertbox(系统没有找到指定的路径[&sFolder&]!,2)
endif
setfso=nothing
endfunction

functioncheckfolder(sPATH)
onerrorresumenext
dimfso
setfso=server.createobject(scripting.filesystemobject)
iffso.folderexists(server.mappath(sPATH))then
checkfolder=true
else
checkfolder=false
endif
setfso=nothing
endfunction

functioncheckfile(sPATH)
onerrorresumenext
dimfso
setfso=server.createobject(scripting.filesystemobject)
iffso.fileexists(server.mappath(sPATH))then
checkfile=true
else
checkfile=false
endif
setfso=nothing
endfunction

functioncreatedir(sPATH)
dimfso,pathArr,i,path_Level,pathTmp,cPATH
onerrorresumenext
sPATH=replace(sPATH,\,/)
setfso=server.createobject(scripting.filesystemobject)
pathArr=split(sPATH,/)
path_Level=ubound(pathArr)
fori=0topath_Level
ifi=0thenpathTmp=pathArr(0)&/elsepathTmp=pathTmp&pathArr(i)&/
cPATH=left(pathTmp,len(pathTmp)-1)
ifnotfso.folderexists(cPATH)thenfso.createfolder(cPATH)
next
setfso=nothing
iferr.number<>0then
err.clear
createdir=false
else
createdir=true
endif
endfunction

functiondelclassfolder(sPATH)
onerrorresumenext
dimfso
setfso=server.createobject(scripting.filesystemobject)
iffso.folderexists(server.mappath(sPATH))then
fso.deletefolder(server.mappath(sPATH))
endif
setfso=nothing
endfunction

functiondelnewsfile(sPATH,filename)
onerrorresumenext
dimfso,tempArr,cPATH,ePATH,i:i=0
setfso=server.createobject(scripting.filesystemobject)
sPATH=sPATH&filename&site_extname
iffso.fileexists(server.mappath(sPATH))then
fso.deletefile(server.mappath(sPATH))
while(i<>-1)
i=i+1
ePATH=replace(sPATH,filename&.,filename&_&i+1&.)
iffso.fileexists(server.mappath(ePATH))then
fso.deletefile(server.mappath(ePATH))
else
i=-1
endif
wend
endif
endfunction

classstringclass
publicfunctiongetstr(strhtml)
dimPatrnStr
PatrnStr=<.*?>
dimobjRegEx
setobjRegEx=newRegExp
objRegEx.pattern=PatrnStr
objRegEx.ignorecase=true
objRegEx.global=true
getstr=objRegEx.replace(strhtml,)
setobjRegEx=nothing
endfunction
publicfunctionreplacestr(patrn,mstr,replstr)
dimobjRegEx
setobjRegEx=newRegExp
objRegEx.pattern=patrn
objRegEx.ignorecase=true
objRegEx.global=true
replacestr=objRegEx.replace(mstr,replstr)
setobjRegEx=nothing
endfunction
publicfunctionclasscustomtag(byvalpatrn,byvalmstr,byvalclassid,byvalindexid,byvalpagestr)
dimobjRegEx,match,matches
setobjRegEx=newRegExp
objRegEx.pattern=patrn
objRegEx.ignorecase=true
objRegEx.global=true
setmatches=objRegEx.execute(mstr)
foreachmatchinmatches
mstr=replace(mstr,match.value,parseclasstag(match.value,classid,indexid,pagestr))
next
setmatches=nothing
setobjRegEx=nothing
classcustomtag=mstr
endfunction
publicfunctionnewscustomtag(byvalpatrn,byvalmstr,byvalclassid,byvalnewsid,byvalkeywords)
dimobjRegEx,match,matches
setobjRegEx=newRegExp
objRegEx.pattern=patrn
objRegEx.ignorecase=true
objRegEx.global=true
setmatches=objRegEx.execute(mstr)
foreachmatchinmatches
mstr=replace(mstr,match.value,parsenewstag(match.value,classid,newsid,keywords))
next
setmatches=nothing
setobjRegEx=nothing
newscustomtag=mstr
endfunction
endclass

functionprocesscustomtag(byvalscontent)
dimobjRegEx,match,matches
setobjRegEx=newRegExp
objRegEx.pattern={ncms:[^<>]+?\/}
objRegEx.ignorecase=true
objRegEx.global=true
setmatches=objRegEx.execute(scontent)
foreachmatchinmatches
scontent=replace(scontent,match.value,parsetag(match.value))
next
setmatches=nothing
setobjRegEx=nothing
processcustomtag=scontent
endfunction

functionX_processcustomtag(byvalscontent)
dimobjRegEx,match,matches
setobjRegEx=newRegExp
objRegEx.pattern=(\[ncms:).+?(\])(.\n)+?(\[\/ncms\])
objRegEx.ignorecase=true
objRegEx.global=true
setmatches=objRegEx.execute(scontent)
foreachmatchinmatches
scontent=replace(scontent,match.value,parsetag(match.value))
next
setmatches=nothing
setobjRegEx=nothing
X_processcustomtag=scontent
endfunction

functiongetattribute(byvalstrattribute,byvalstrtag)
dimobjRegEx,matches
setobjRegEx=newRegExp
objRegEx.pattern=lcase(strattribute)&=[0-9a-zA-Z]*
objRegEx.ignorecase=true
objRegEx.global=true
setmatches=objRegEx.execute(strtag)
ifmatches.count>0then
getattribute=split(matches(0).value,)(1)
else
getattribute=
endif
setmatches=nothing
setobjRegEx=nothing
endfunction

functiongetinnerhtml(byvalstrhtml)
dimobjregex,matches,str
setobjregex=newregexp
objregex.pattern=(\])(.\n)+?(\[\/ncms\])
objregex.ignorecase=true
objregex.global=false
setmatches=objregex.execute(strhtml)
ifmatches.count>0then
str=trim(matches.item(0).value)
endif
setmatches=nothing
iflen(str)>8then
getinnerhtml=mid(str,2,len(str)-8)
endif
endfunction

functionparsetag(byvalstrtag)
dimarrresult,classname,arrattributes,objclass
iflen(strtag)=0thenexitfunction
arrresult=split(strtag,:)
classname=split(arrresult(1),)(0)
selectcaselcase(classname)
casenews
setobjclass=newncmsnewstag
ifnotisnumeric(getattribute(id,strtag))then
response.write(标签[ncms:news]参数错误!参数[id]必须是数字!)
response.end()
endif
objclass.id=getattribute(id,strtag)
ifnotisnumeric(getattribute(num,strtag))then
response.write(标签[ncms:news]参数错误!参数[num]必须是数字!)
response.end()
endif
objclass.num=getattribute(num,strtag)
ifnotisnumeric(getattribute(len,strtag))then
response.write(标签[ncms:news]参数错误!参数[len]必须是数字!)
response.end()
endif
objclass.len=getattribute(len,strtag)
objclass.show=getattribute(show,strtag)
ifgetattribute(lih,strtag)<>andnotisnumeric(getattribute(lih,strtag))then
response.write(标签[ncms:news]参数错误!参数[lih]必须是数字!)
response.end()
endif
objclass.lih=getattribute(lih,strtag)
ifgetattribute(imgw,strtag)<>andnotisnumeric(getattribute(imgw,strtag))then
response.write(标签[ncms:news]参数错误!参数[imgw]必须是数字!)
response.end()
endif
objclass.imgw=getattribute(imgw,strtag)
ifgetattribute(imgh,strtag)<>andnotisnumeric(getattribute(imgh,strtag))then
response.write(标签[ncms:news]参数错误!参数[imgh]必须是数字!)
response.end()
endif
objclass.imgh=getattribute(imgh,strtag)
ifgetattribute(tgt,strtag)<>andgetattribute(tgt,strtag)<>blankthen
response.write(标签[ncms:news]参数错误!参数[tgt]必须是[<fontcolor=red>blank</font>]!)
response.end()
endif
objclass.tgt=getattribute(tgt,strtag)
ifgetattribute(hit,strtag)<>andnotisnumeric(getattribute(hit,strtag))then
response.write(标签[ncms:free]参数错误!参数[hit]必须是数字!)
response.end()
endif
objclass.hit=getattribute(hit,strtag)
ifnotisnumeric(getattribute(col,strtag))then
response.write(标签[ncms:news]参数错误!参数[col]必须是数字!)
response.end()
endif
parsetag=objclass.newsshow(getattribute(ty,strtag),getattribute(col,strtag))
setobjclass=nothing
casefree
setobjclass=newX_ncmsnewstag
ifnotisnumeric(getattribute(id,strtag))then
response.write(标签[ncms:free]参数错误!参数[id]必须是数字!)
response.end()
endif
objclass.id=getattribute(id,strtag)
ifnotisnumeric(getattribute(num,strtag))then
response.write(标签[ncms:free]参数错误!参数[num]必须是数字!)
response.end()
endif
objclass.num=getattribute(num,strtag)
ifnotisnumeric(getattribute(len,strtag))then
response.write(标签[news:free]参数错误!参数[len]必须是数字!)
response.end()
endif
objclass.len=getattribute(len,strtag)
objclass.show=getattribute(show,strtag)
ifgetattribute(lih,strtag)<>andnotisnumeric(getattribute(lih,strtag))then
response.write(标签[ncms:free]参数错误!参数[lih]必须是数字!)
response.end()
endif
objclass.lih=getattribute(lih,strtag)
ifgetattribute(hit,strtag)<>andnotisnumeric(getattribute(hit,strtag))then
response.write(标签[ncms:free]参数错误!参数[hit]必须是数字!)
response.end()
endif
objclass.hit=getattribute(hit,strtag)
ifnotisnumeric(getattribute(col,strtag))then
response.write(标签[ncms:free]参数错误!参数[col]必须是数字!)
response.end()
endif
parsetag=objclass.newsshow(getattribute(ty,strtag),getattribute(col,strtag),getinnerhtml(strtag))
casemenu
setobjclass=newncmsmenutag
setobjclass=nothing
caseinfo
setobjclass=newncmsinfotag
ifnotisnumeric(getattribute(num,strtag))then
response.write(标签[ncms:info]参数错误!参数[num]必须是数字!)
response.end()
endif
objclass.num=getattribute(num,strtag)
ifnotisnumeric(getattribute(len,strtag))then
response.write(标签[ncms:info]参数错误!参数[len]必须是数字!)
response.end()
endif
objclass.len=getattribute(len,strtag)
setobjclass=nothing
casehead
setobjclass=newncmsheadtag
ifnotisnumeric(getattribute(num,strtag))then
response.write(标签[ncms:head]参数错误!参数[num]必须是数字!)
response.end()
elseifgetattribute(num,strtag)>6then
response.write(标签[ncms:head]参数错误!参数[num]在[1-6]之间!)
response.end()
endif
objclass.num=getattribute(num,strtag)
ifnotisnumeric(getattribute(len,strtag))then
response.write(标签[ncms:head]参数错误!参数[len]必须是数字!)
response.end()
endif
objclass.len=getattribute(len,strtag)
ifgetattribute(imgw,strtag)<>andnotisnumeric(getattribute(imgw,strtag))then
response.write(标签[ncms:head]参数错误!参数[imgw]必须是数字!)
response.end()
endif
objclass.imgw=getattribute(imgw,strtag)
ifgetattribute(imgh,strtag)<>andnotisnumeric(getattribute(imgh,strtag))then
response.write(标签[ncms:head]参数错误!参数[imgh]必须是数字!)
response.end()
endif
objclass.imgh=getattribute(imgh,strtag)
ifgetattribute(size,strtag)<>andnotisnumeric(getattribute(size,strtag))then
response.write(标签[ncms:head]参数错误!参数[size]必须是数字!)
response.end()
endif
objclass.size=getattribute(size,strtag)
parsetag=objclass.headshow(getattribute(ty,strtag))
setobjclass=nothing
caselink
setobjclass=newncmslinktag
ifnotisnumeric(getattribute(num,strtag))then
response.write(标签[ncms:link]参数错误!参数[num]必须是数字!)
response.end()
endif
objclass.num=getattribute(num,strtag)
ifnotisnumeric(getattribute(col,strtag))then
response.write(标签[ncms:link]参数错误!参数[col]必须是数字!)
response.end()
endif
parsetag=objclass.linkshow(getattribute(ty,strtag),getattribute(col,strtag))
setobjclass=nothing
caseelse
response.write(标签[ncms:xxx]构造错误!)
response.end()
endselect
endfunction

functionparseclasstag(byvalstrtag,byvalclassid,byvalindexid,byvalpagestr)
dimarrresult,classname,arrattributes,objclass
iflen(strtag)=0thenexitfunction
arrresult=split(strtag,:)
classname=split(arrresult(1),)(0)
selectcaselcase(classname)
caselist
setobjclass=newncmsclasstag
ifnotisnumeric(getattribute(len,strtag))then
response.write(标签[news:list]参数错误!参数[len]必须是数字!)
response.end()
endif
objclass.len=getattribute(len,strtag)
objclass.order=getattribute(order,strtag)
ifgetattribute(lih,strtag)<>andnotisnumeric(getattribute(lih,strtag))then
response.write(标签[news:list]参数错误!参数[lih]必须是数字!)
response.end()
endif
objclass.lih=getattribute(lih,strtag)
ifnotisnumeric(getattribute(col,strtag))then
response.write(标签[news:list]参数错误!参数[col]必须是数字!)
response.end()
endif
parseclasstag=objclass.classshow(getattribute(ty,strtag),getattribute(col,strtag),classid,indexid,pagestr)
setobjclass=nothing
caseelse
response.write(标签[news:xxxx]构造错误!)
response.end()
endselect
endfunction

functionparsenewstag(byvalstrtag,byvalclassid,byvalnewsid,byvalkeywords)
dimarrresult,classname,arrattributes,objclass
iflen(strtag)=0thenexitfunction
arrresult=split(strtag,:)
classname=split(arrresult(1),)(0)
selectcaselcase(classname)
caserelate
setobjclass=newncmsrelatetag
ifnotisnumeric(getattribute(num,strtag))then
response.write(标签[news:relate]参数错误!参数[num]必须是数字!)
response.end()
endif
objclass.num=getattribute(num,strtag)
ifnotisnumeric(getattribute(len,strtag))then
response.write(标签[news:relate]参数错误!参数[len]必须是数字!)
response.end()
endif
objclass.len=getattribute(len,strtag)
ifgetattribute(lih,strtag)<>andnotisnumeric(getattribute(lih,strtag))then
response.write(标签[news:relate]参数错误!参数[lih]必须是数字!)
response.end()
endif
objclass.lih=getattribute(lih,strtag)
ifnotisnumeric(getattribute(col,strtag))then
response.write(标签[news:relate]参数错误!参数[col]必须是数字!)
response.end()
endif
parsenewstag=objclass.relateshow(getattribute(col,strtag),classid,newsid,keywords)
setobjclass=nothing
casepage
setobjclass=newncmspagetag
parsenewstag=objclass.pageshow(getattribute(show,strtag),classid,newsid)
setobjclass=nothing
caseelse
response.write(标签[news:xxxx]构造错误!)
response.end()
endselect
endfunction

functiongetcurclasscount(classid)
dimrs,curclasscount
setrs=conn.execute(selectcount(*)fromNCMS_newswhereclassidin(&classid&allchildclass(classid)&))
ifinstr(rs(0)/n_listnum,.)<>0then
curclasscount=fix(rs(0)/n_listnum)+1
else
curclasscount=rs(0)/n_listnum
endif
rs.close:setrs=nothing
getcurclasscount=curclasscount
endfunction

classncmsclasstag
publicty,len,order,lih
publicfunctionclassshow(stype,scolumn,classid,indexid,pagestr)
dimTempHTM,xsql,rs,sql,databox,l,obox
TempHTM=&chr(10)&<tablecellpadding=0cellspacing=0width=100%border=0>&chr(10)
TempHTM=TempHTM&<tr>&chr(10)
ifindexid=orindexid=0then
indexid=1
endif
selectcasestype
casetext
setrs=server.createobject(adodb.recordset)
iforder=descthen
sql=selectclassid,title,click,filename,addtimefromNCMS_newswhereclassidin(&classid&allchildclass(classid)&)andcreated=1andpagetype=0orderbyiddesc
elseiforder=ascthen
sql=selectclassid,title,click,filename,addtimefromNCMS_newswhereclassidin(&classid&allchildclass(classid)&)andcreated=1andpagetype=0orderbyidasc
else
response.write(标签[news:list]参数[order]错误!)
response.end()
endif
rs.cursorlocation=3
rs.opensql,conn,1,3
ifrs.eofthen
rs.close:setrs=nothing
TempHTM=<li><fontcolor=red>暂时没有新闻!</font></li>
classshow=TempHTM
exitfunction
endif
rs.pagesize=n_listnum
rs.absolutepage=indexid
forl=1tors.pagesize
ifrs.eofthenexitfor
TempHTM=TempHTM&<tdheight=&lih&align=leftvalign=middle>·<ahref=&site_root&/&site_html&/&getclasspath(rs(classid))&/&rs(filename)&site_extname&title=&rs(title)&>&gottopic(rs(title),len)&</a></td>&chr(10)
TempHTM=TempHTM&<tdheight=&lih&align=centervalign=middle>&rs(click)&</td>&chr(10)
TempHTM=TempHTM&<tdheight=&lih&align=centervalign=middle>&rs(addtime)&</td>&chr(10)
ifl=rs.pagesizethen
TempHTM=TempHTM&</tr>&chr(10)
else
ifcint(lmodscolumn)=0then
TempHTM=TempHTM&</tr>&chr(10)
TempHTM=TempHTM&<tr>&chr(10)
endif
endif
rs.movenext
next
rs.close:setrs=nothing
TempHTM=TempHTM&</table>&chr(10)
classshow=TempHTM&pagestr
caseimage
ifIsObjInstalled(persits.jpeg)=trueandjpeg_gate=0then
setrs=server.createobject(adodb.recordset)
iforder=descthen
sql=selectclassid,title,bimg,filename,addtimefromNCMS_newswhereclassidin(&classid&allchildclass(classid)&)andisimg=1andcreated=1andpagetype=0orderbyiddesc
elseiforder=ascthen
sql=selectclassid,title,bimg,filename,addtimefromNCMS_newswhereclassidin(&classid&allchildclass(classid)&)andisimg=1andcreated=1andpagetype=0orderbyidasc
else
response.write(标签[news:list]参数[order]错误!)
response.end()
endif
rs.cursorlocation=3
rs.opensql,conn,1,3
ifrs.eofthen
rs.close:setrs=nothing
TempHTM=<li><fontcolor=red>暂时没有新闻!</font></li>
classshow=TempHTM
exitfunction
endif
rs.pagesize=n_listnum
rs.absolutepage=indexid
forl=1tors.pagesize
ifrs.eofthenexitfor
TempHTM=TempHTM&<td><divid=simg><ahref=&site_root&/&site_html&/&getclasspath(rs(classid))&/&rs(filename)&site_extname&><imgheight=&jpeg_height&src=&site_root&/&site_upload&/&site_simg&/&rs(bimg)&width=&jpeg_width&alt=&rs(title)&/></a></div></td>&chr(10)
ifl=rs.pagesizethen
TempHTM=TempHTM&</tr>&chr(10)
else
ifcint(lmodscolumn)=0then
TempHTM=TempHTM&</tr>&chr(10)
TempHTM=TempHTM&<tr>&chr(10)
endif
endif
ifcheckfile(&site_root&/&site_upload&/&site_bimg&/&rs(bimg)&)=truethen
setobox=server.createobject(persits.jpeg)
obox.openserver.mappath(&site_root&/&site_upload&/&site_bimg&/&rs(bimg)&)
obox.width=jpeg_width
obox.height=jpeg_height
obox.saveserver.mappath(&site_root&/&site_upload&/&site_simg&/&rs(bimg)&)
setobox=nothing
endif
rs.movenext
next
rs.close:setrs=nothing
TempHTM=TempHTM&</table>&chr(10)
classshow=TempHTM&pagestr
else
setrs=server.createobject(adodb.recordset)
iforder=descthen
sql=selectclassid,title,bimg,filename,addtimefromNCMS_newswhereclassidin(&classid&allchildclass(classid)&)andisimg=1andcreated=1andpagetype=0orderbyiddesc
elseiforder=ascthen
sql=selectclassid,title,bimg,filename,addtimefromNCMS_newswhereclassidin(&classid&allchildclass(classid)&)andisimg=1andcreated=1andpagetype=0orderbyidasc
else
response.write(标签[news:list]参数[order]错误!)
response.end()
endif
rs.cursorlocation=3
rs.opensql,conn,1,3
ifrs.eofthen
rs.close:setrs=nothing
TempHTM=<li><fontcolor=red>暂时没有新闻!</font></li>
classshow=TempHTM
exitfunction
endif
rs.pagesize=n_listnum
rs.absolutepage=indexid
forl=1tors.pagesize
ifrs.eofthenexitfor
TempHTM=TempHTM&<td><divid=simg><ahref=&site_root&/&site_html&/&getclasspath(rs(classid))&/&rs(filename)&site_extname&><imgheight=&jpeg_height&src=&site_root&/&site_upload&/&site_bimg&/&rs(bimg)&width=&jpeg_width&alt=&rs(title)&/></a></div></td>&chr(10)
ifl=rs.pagesizethen
TempHTM=TempHTM&</tr>&chr(10)
else
ifcint(lmodscolumn)=0then
TempHTM=TempHTM&</tr>&chr(10)
TempHTM=TempHTM&<tr>&chr(10)
endif
endif
rs.movenext
next
rs.close:setrs=nothing
TempHTM=TempHTM&</table>&chr(10)
classshow=TempHTM&pagestr
endif
caseelse
response.write(标签[news:list]参数[ty]错误!)
response.end()
endselect
endfunction
endclass
1234下一页阅读全文


评论


亲,登录后才可以留言!