www.gusucode.com > 要听音乐网完美修正版 1.0源码程序 > inc/function.asp
<% '--------------------------------------------------------------- ' NB联盟防注入函数 ReqNum / ReqStr '--------------------------------------------------------------- Function ReqNum ( StrName ) ReqNum = Request ( StrName ) if Not isNumeric ( ReqNum ) then Response.Write "参数必须为数字型!" Response.End End if End Function Function ReqStr ( StrName ) ReqStr = Replace ( Request(StrName), "'", "''" ) End Function '************************************************** '函数名:gotTopic '作 用:截字符串,汉字一个算两个字符,英文算一个字符 '参 数:str ----原字符串 ' strlen ----截取长度 '返回值:截取后的字符串 '************************************************** function gotTopic(str,strlen) if str="" then gotTopic="" exit function end if dim l,t,c, i str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<") l=len(str) t=0 for i=1 to l c=Abs(Asc(Mid(str,i,1))) if c>255 then t=t+2 else t=t+1 end if if t>=strlen then gotTopic=left(str,i) & "…" exit for else gotTopic=str end if next gotTopic=replace(replace(replace(replace(gotTopic," "," "),chr(34),"""),">",">"),"<","<") end function Rem ==================函数部分======================================================================== '------------------------------------------------ '用途:检查是否为数字,以及数字是否超出范围 '输入:检查字符,传值方式(0直接传,1取Form,2取QueryString,3取cookies,4直接Reqeust),开始数字(默认数字),结束数字(为-1则不检查大小) Function CheckNum(str_str,int_quest,int_startnum,int_endnum) mystr=Trim(str_str) Select Case int_quest Case 1 istr=Request.Form(mystr) Case 2 istr=Request.QueryString(mystr) Case 3 istr=Request.Cookies(mystr) Case 4 istr=Request(mystr) Case Else istr=mystr End Select istr=Left(istr,32) If IsNumeric(istr) Then iNum=CDbl(istr) Else iNum=int_startnum End If If int_endnum>-1Then If iNum<int_startnum Then iNum=int_startnum If iNum>int_endnum Then iNum=int_endnum End If CheckNum=iNum End Function '------------------------------------------------ '用途:检查过滤字符串 '输入:字符串,传值方式(0直接传,1取Form,2取QueryString,3取cookies,4直接Reqeust),检查方式(1不过滤html,2纯html,3标题过滤,4其他html过滤,),字符段截取长度 Function CheckStr(str_str,int_quest,int_type,int_strlen) mystr=str_str Select Case int_quest Case 1 istr=Request.Form(mystr) Case 2 istr=Request.QueryString(mystr) Case 3 istr=Request.Cookies(mystr) Case 4 istr=Request(mystr) Case Else istr=mystr End Select istr=""&Trim(istr) istr=Replace(istr,"'","''") Select Case int_type Case 1 istr=Replace(istr,CHR(32)," ") istr=Replace(istr,CHR(9)," ") istr=Replace(istr,CHR(10) & CHR(10),"</P><P> ") istr=Replace(istr,CHR(10),"<BR> ") istr=Replace(istr,CHR(13),"") Case 2 istr=istr Case 3 istr=Replace(istr,CHR(32)," ") istr=Replace(istr,CHR(9)," ") istr=Replace(istr,CHR(13), "") istr=Replace(istr,"<","<") istr=Replace(istr,">",">") istr=Replace(istr,CHR(34),""") istr=Replace(istr," "," ") istr=Replace(istr,CHR(39), "'") Case Else istr=Replace(istr,CHR(32)," ") istr=Replace(istr,CHR(9)," ") istr=Replace(istr,CHR(10) & CHR(10), "</P><P> ") istr=Replace(istr,CHR(10), "<BR> ") istr=Replace(istr,CHR(13), "") istr=Replace(istr,"<","<") istr=Replace(istr,">",">") istr=Replace(istr,CHR(34),""") istr=Replace(istr," "," ") istr=Replace(istr,CHR(39), "'") End select istr=CutStr(istr,int_strlen,"") CheckStr=istr End Function '------------------------------------------------ function isint(para) on error resume next dim str dim l,i if isNUll(para) then isint=false exit function end if str=cstr(para) if trim(str)="" then isint=false exit function end if l=len(str) for i=1 to l if mid(str,i,1)>"9" or mid(str,i,1)<"0" then isint=false exit function end if next isint=true if err.number<>0 then err.clear end function function checkid(str) if not isint(str) then Response.write "ID序号只能是0-9的数字组合" Response.end end if end function '================================================= '过程名:Shownewspecial '作 用:显示最近更新的专集 '参 数:specialNum ----最多显示多少个专辑 ' ShowTitle ----是否显示专辑名称,True为显示,False为不显示 ' TitleLen ----标题最多字符数,一个汉字=两个英文字符 '================================================= sub Shownewspecial(specialNum,ShowTitle,TitleLen) dim sqlnewspecial,rsnewspecial,i if specialNum>0 and specialNum<=10 then sqlnewspecial="select top " & specialNum else sqlnewspecial="select top 10 " end if sqlnewspecial=sqlnewspecial & " s.SpecialID,s.NClassID,s.NClass,s.name,s.pic,s.Times from special s" sqlnewspecial=sqlnewspecial & " order by s.SpecialID desc" Set rsnewspecial= Server.CreateObject("ADODB.Recordset") rsnewspecial.open sqlnewspecial,conn,1,1 if TitleLen<0 or TitleLen>255 then TitleLen=16 if rsnewspecial.bof and rsnewspecial.eof then response.write "<td width='135' align='center'>没有专辑</td>" else i=0 do while not rsnewspecial.eof i=i+1 if i>specialNum then exit do response.Write "<td height='140' valign='top'><table width='100' border='0' align='center' cellpadding='0' cellspacing='0'>" response.Write "<tr><td width='100' height='104'><div align='center'><a href='../musiclist/" & rsnewspecial("SpecialID") & ".htm' target='_blank'><img src='../" & rsnewspecial("pic") & "' alt='专辑《" & rsnewspecial("name") & "》' width='80' height='100' border='0' class='pic_c'></a></div></td></tr>" if ShowTitle=True then response.Write "<tr><td height='18'><a href='../musiclist/" & rsnewspecial("SpecialID") & ".htm'>" & gotTopic(rsnewspecial("name"),TitleLen) & "</a></td></tr>" end if response.Write "<tr><td height='18'><a href='../Albumlist/" & rsnewspecial("NClassID") & ".htm' target='_blank'>" & rsnewspecial("NClass") & "</a></td></tr>" response.Write "<tr><td height='18'>" & rsnewspecial("Times") & "</td></tr>" response.Write "</table></td>" rsnewspecial.movenext loop end if rsnewspecial.close set rsnewspecial=nothing end sub '================================================= '过程名:Showtjmusic '作 用:显示推荐的歌曲,但不是按最新,仿1ting的功能 '参 数:musicNum ----最多显示多少个专辑 ' TitleLen ----标题最多字符数,一个汉字=两个英文字符 '================================================= sub Showtjmusic(musicNum) dim sqltjmusic,rstjmusic,i if musicNum>0 and musicNum<=50 then sqltjmusic="select top " & musicNum else sqltjmusic="select top 28 " end if sqltjmusic=sqltjmusic & " M.ID,M.MusicName,M.Tj from MusicList M where M.Tj=1" sqltjmusic=sqltjmusic & " order by M.ID desc" Set rstjmusic= Server.CreateObject("ADODB.Recordset") rstjmusic.open sqltjmusic,conn,1,1 if rstjmusic.bof and rstjmusic.eof then response.write "<td width='185' align='center'>没有需要推荐的歌曲</td>" end if i=0 do while not rstjmusic.eof i=i+1 if i=1 then response.Write "<tr>" end if response.Write "<td width=*><div align='center'><a href=javascript:playit('" & rstjmusic("ID") & "')>" & rstjmusic("MusicName") & "</a></div></td>" if (i mod 2)=0 and i>=2 then response.Write "</tr><tr><td height='1' valign='top' bgcolor='#CCCCFF'></td><td height='1' valign='top' bgcolor='#CCCCFF'></td></tr><tr>" end if rstjmusic.movenext loop rstjmusic.close set rstjmusic=nothing end sub '================================================= '过程名:Shownewtjmusic '作 用:显示最新推荐的歌曲 '================================================= sub shownewtjMusic() dim MM_strSQL dim rs MM_strSQL="SELECT top 10 * FROM MusicList where IsGood=1 order by id desc" set rs=conn.execute(MM_strSQL) i=0 do while not rs.eof i=i+1 if i="11" then exit do %> <tr> <td width="7%" height="27" align=middle class="tab_lb"><input type="checkbox" name="checked" value="<%=rs("id")%>"> </td> <td class="tab_lb" width="50%" align=left><%=i%>.<a href=javascript:playit('<%=rs("id")%>')><%=gotTopic(rs("MusicName"),20)%></a></td> <td class="tab_lb" width="15%" align=middle><a href=javascript:playit('<%=rs("id")%>')><img src='../images/wma.gif' border='0'></a></td> <td class="tab_lb" width="9%" align=middle><div align="center"><a href="http://mp3.baidu.com/m?tn=baidump3lyric&word=<%=rs("MusicName")%>&ct=150994944&lm=-1" target="_blank">歌词</a></div></td> <td class="tab_lb" width="19%" align=middle><div align="center"><%=rs("hits")%></div></td> </tr> <% rs.movenext loop set rs=nothing end sub '================================================= '过程名:ShowSpecialtop '作 用:显示5种专辑排行,仿1ting的功能 '参 数:TopType '================================================= sub showSpecialtop(byval TopType) dim sql,rs,m if TopType="专辑总榜" then sql="SELECT top 18 * FROM special order by hits desc" elseif TopType="最新专辑" then sql="SELECT top 18 * FROM special order by SpecialID desc" elseif TopType="华人专辑" then sql="SELECT top 18 * FROM special where SClassID=1 or SClassID=2 or SClassID=3 order by hits desc" elseif TopType="日韩欧美" then sql="SELECT top 18 * FROM special where SClassID=5 or SClassID=6 or SClassID=7 or SClassID=9 order by hits desc" end if set rs=conn.execute(sql) m=0 do while not rs.eof m=m+1 if m=19 then exit do %> <tr> <td width="81%" height="25" class="tab_ly"> <%=m%>.<a href="../MusicList/<%=rs("SpecialID")%>.htm" title="<%=rs("name")%>"> <%=gotTopic(rs("name"),16)%></a>— <a href="../Albumlist/<%=rs("NClassID")%>.htm" target="_blank"><%=gotTopic(rs("NClass"),10)%></a></td> </tr> <% rs.movenext loop rs.close set rs=nothing end sub %> <% '================================================= '过程名:Showmusic '作 用:显示5种歌曲排行,最新,排行,总排行 '参 数:musicType '================================================= sub showmusic(byval musicType) dim sqlgequ,rsgequ,s if musicType="歌曲总榜" then sqlgequ="SELECT top 15 id,MusicName,hits FROM MusicList order by hits desc" elseif musicType="华人歌曲排行" then sqlgequ="SELECT top 15 id,MusicName,SClassID,hits FROM MusicList where SClassID=1 or SClassID=2 or SClassID=3 order by hits desc" elseif musicType="华人最新歌曲" then sqlgequ="SELECT top 15 id,MusicName,SClassID FROM MusicList where SClassID=1 or SClassID=2 or SClassID=3 order by id desc" elseif musicType="日韩欧美排行" then sqlgequ="SELECT top 15 id,MusicName,SClassID,hits FROM MusicList where SClassID=5 or SClassID=6 or SClassID=7 or SClassID=9 order by hits desc" elseif musicType="日韩欧美最新" then sqlgequ="SELECT top 15 id,MusicName,SClassID FROM MusicList where SClassID=5 or SClassID=6 or SClassID=7 or SClassID=9 order by id desc" end if set rsgequ=conn.execute(sqlgequ) s=0 do while not rsgequ.eof s=s+1 if s=16 then exit do %> <tr> <td width="37" height="27" align=middle class="tab_ly2"><input type="checkbox" name="checked" value="<%=rsgequ("id")%>"> </td> <td width="156" align=left class="tab_ly2"><%=s%>.<a href=javascript:playit('<%=rsgequ("id")%>')><%=gotTopic(rsgequ("MusicName"),20)%></a></td> <td width="69" align=center class="tab_ly2"><span class="tab_lb"><a href=javascript:playit('<%=rsgequ("id")%>')><img src='../images/wma.gif' border='0'></a></span></td> </tr> <% rsgequ.movenext loop rsgequ.close set rsgequ=nothing end sub sub error() %> <p align='center'><br><br><%=errmsg%><br><br><br><br></p> <% end sub %>