Blog 采用最新的MosquitoWeb 3.0d 创建,有空多联系啊!!
首页 上一页 下一页 末页 页次: 1 / 46 共 272 条记录 6 条/页
组件:Adodb.Stream的属性和方法
内容: 组件:"Adodb.Stream" 有下列方法: Cancel 方法 使用方法如下 Object.Cancel 说明:取消执行挂起的异步 Execute 或 Open 方法的调用。 Close 方法 使用方法如下 Object.Close :关闭对像 CopyTo 方法 使用方法如下 Object.CopyTo(destStream,[CharNumber]) 说明:将对像的数据复制,destStream指向要复制的对像,CharNumber为可选参数,指要复制的字节数,不选为全部复制。 Flush 方法 使用方法如下 Object.Flush 说明: LoadFromFile 方法 使用方法如下 Object.LoadFromFile(FileName) 说明:将FileName指定的文件装入对像中,参数FileName为指定的用户名。 Open 方法 使用方法如下 Object.Open(Source,[Mode],[Options],[UserName],[Password]) 说明:打开对像, 参数说明:Sourece 对像源,可不指定 Mode 指定打开模式,可不指定,可选参数如下: adModeRead =1 adModeReadWrite =3 adModeRecursive =4194304 adModeShareDenyNone =16 adModeShareDenyRead =4 adModeShareDenyWrite =8 adModeShareExclusive =12 adModeUnknown =0 adModeWrite =2 Options 指定打开的选项,可不指定,可选参数如下: adOpenStreamAsync =1 adOpenStreamFromRecord =4 adOpenStreamUnspecified=-1 UserName 指定用户名,可不指定。 Password 指定用户名的密码 Read 方法 使用方法如下: Object.Read(Numbytes) 说明:读取指定长度的二进制内容。 参数说明:Numbytes指定的要读取的找度,不指定则读取全部。
ReadText 方法 使用方法如下: Object.ReadText(NumChars) 说明:读取指定长度的文本 参数说明:NumChars指定的要读取的找度,不指定则读取全部。
SaveToFile 方法 使用方法如下: Object.SaveToFile(FileName,[Options]) 说明:将对像的内容写到FileName指定的文件中 参数说明:FileName指定的文件 Options 存取的选项,可不指定,可选参数如下: adSaveCreateNotExist =1 adSaveCreateOverWrite =2
SetEOS 方法 使用方法如下: Object.setEOS() 说明: SkipLine 方法 使用方法如下: Object.SkipLine() 说明: Write 方法 使用方法如下: Object.Write(Buffer) 说明:将指定的数据装入对像中。 参数说明:Buffer 为指定的要写入的内容。 WriteText 方法 使用方法如下: Object.Write(Data,[Options]) 说明:将指定的文本数据装入对像中。 参数说明:Data 为指定的要写入的内容。 Options 写入的选项,可不指定,可选参数如下: adWriteChar =0 adWriteLine =1
有下列属性: Charset EOS 返回对像内数据是否为空。
LineSeparator 指定换行格式,可选参数有 adCR =13 adCRLF =-1 adLF =10
Mode 指定或返加模式。
Position 指定或返加对像内数据的当前指针。
Size 返回对像内数据的大小。
State 返加对像状态是否打开。
Type 指定或返回的数据类型,可选参数为: adTypeBinary =1 adTypeText =2
内容: download.asp?file=相对路径的文件 就可以把这个文件下载下来
<%
call downloadFile(replace(replace(Request("file"),"\",""),"/",""))
Function downloadFile(strFile) ' make sure you are on the latest MDAC version for this to work ' -------------------------------------------------------------
' get full path of specified file strFilename = server.MapPath(strFile)
' clear the buffer Response.Buffer = True Response.Clear
'create stream Set s = Server.CreateObject("ADODB.Stream") s.Open
'Set as binary s.Type = 1
'load in the file on error resume next
' check the file exists Set fso = Server.CreateObject("Scripting.FileSystemObject") if not fso.FileExists(strFilename) then Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>") Response.End end if
' get length of file Set f = fso.GetFile(strFilename) intFilelength = f.size
s.LoadFromFile(strFilename) if err then Response.Write("<h1>Error: </h1>" & err.Description & "<p>") Response.End end if
' send the headers to the users browser Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name Response.AddHeader "Content-Length", intFilelength Response.CharSet = "UTF-8" Response.ContentType = "application/octet-stream"
' output the file to the browser Response.BinaryWrite s.Read Response.Flush
' tidy up s.Close Set s = Nothing
End Function
%>
内容: ASP中利用ADODB.Stream对象将字节流转换为字符流 '-------------------------------------------------------------------- ' 二进制转字符串 ' ' 入口参数:字节流 ' 函数返回:字符串 ' Code By:Madpolice 2002-12-20 ' 利用 ADODB.Stream 对象,速度比原来的字符替换法快了n倍,n≈30!!) '-------------------------------------------------------------------- '下面的常量是函数用到的,因为我在函数外面已经定义过了,因此不在这里重复定义 '---- StreamTypeEnum Values ---- 'Const adTypeBinary = 1 'Const adTypeText = 2
Function Bytes2bStr(vin) Dim BytesStream,StringReturn
Set BytesStream = Server.CreateObject("ADODB.Stream") '建立一个流对象 With BytesStream .Type = adTypeText '设置流对象的类型为字符流 .Open '打开流对象 .WriteText vin '把vin写入流对象中
.Position = 0 '设置流对象的起始位置是0,也就是开头 '这个操作必须做,为什么我也不知道,失败了n次得出的结论 '如果不进行这个操作,下面设置Charset属性就出错 .Charset = "GB2312" '设置流对象的编码方式为GB2312 .Position = 2 '设置流对象的起始位置是2(过滤掉开始的一个控制字符 '这个控制字符是WriteText方法按默认属性Charset="Unicode" '读入数据的时候自动加到数据开头的,字符的值是FF3F '这个控制字符占2字节,所以Position设置为2 '表示略过2个字节,下面的ReadText方法从Position开始读数据 StringReturn = .ReadText '把流对象的内容保存在StringReturn变量中 .close '关闭流对象 End With Set BytesStream = Nothing '销毁流对象
Bytes2bStr = StringReturn
End Function '--------------------------------------------------------------------
内容: 用Adodb.Stream将以二进制方式保存在数据库中的文件保存到硬盘
对于上传的数据库中的文件有的时候需要保存成硬盘上的文件,下面的代码以ACCESS数据库为例,演示怎样通过Adodb.Stream将文件保存到硬盘
表:Demo的结构 ======================================= id: 自动编号 filename:文本 data: OLE 对象
代码 ======================================= <% Dim Conn,ConnStr,Rs,Sql,MyStream
ConnStr="DBQ=" + Server.Mappath("Demo.mdb") + ";DRIVER={Microsoft Access Driver (*.mdb)};"
Set Conn = Server.CreateObject("Adodb.Connection")
Conn.Open ConnStr
Sql = "select * from demo where id=1"
Set Rs = Server.CreateObject("Adodb.RecordSet")
Rs.Open Sql,Conn,1,3
Set MyStream=Server.CreateObject("Adodb.Stream")
MyStream.Type = 1
MyStream.Open
MyStream.Write Rs("data").GetChunk(rs("data").ActualSize-78)
MyStream.SaveToFile "c:\" & Rs("fileName")
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing %>
作者:mosquito_520@163.com 日期:2008-11-21 19:42:11 查看:100次
1.文件夹的命名尽量为:你的标识_模板名称 2.模板文件夹内应包含模板缩略图 p.gif 100*100 3.模板文件夹内应包含模板缩略图 p.xml 表示模板的相关信息,具体说明如下:
<?xml version="1.0" encoding="utf-8"?> <dfcms> <name>模板名称</name> <author>模板的作者</author> <info>版权信息及相关说明</info> </dfcms>
4.所有文件统一采用UTF-8编码
5.文件功能: t.gif 模板缩略图 t.xml 模板配置相关信息 content.html 内容HTML页 footer.html 网上底部HTML代码 left.html 网站左侧HTMl代码 newsdetail.html 新闻明细页 newslist.html 新闻列表页 outherdetail.html 其它类明细页 outherlist.html 其它类列表页 productdetail.html 产品明细页 productlist.html 产品列表页 top.html 网站头部HTML代码
6.标签定义 ------页面类------ {{pageTop}} 头部页 {{pageLeft}} 左侧页 {{pageFooter}} 底部页 ------变量类------ {{tmpPath}} 模板路径 {{tmpComTitle}} 单位名称 {{tmpComAddress}} 单位地址 {{tmpComTel}} 单位电话 {{tmpComFax}} 单位传真 {{tmpWebTitle}} 网站名称 {{tmpWebUrl}} 网站地址 {{tmpWebICP}} 网站ICP备案 {{tmpWebHits}} 网站点击次数 {{tmpDescription}} 网站Mate信息 {{tmpKeywords}} 网站Mate信息 {{tmpLocation}} 我的当前位置 ------函数类------ {{funMenu}} 定义一个导航栏 {{funNewsClass}} 定义一个新闻分类 {{funProductClass}} 定义一个产品分类 {{funListPage}} 定义一个分页 {{funChannelTitle}} 定义一个栏目标题 {{funChannelContent}} 定义一个栏目内容 {{funListTitle}} 定义一个明细标题 {{funListPicBig}} 定义一个明细大图 {{funListContent}} 定义一个明细内容 {{funListFile}} 定义一个明细附件 {{funListHits}} 定义一个明细点击数 {{funListAddTime}} 定义一个明细添加时间 {{funListAddUser}} 定义一个明细添加人员 {{funListExt}} 定义一组附加属性
作者:mosquito_520@163.com 日期:2008-11-21 18:23:12 查看:110次
作者:mosquito_520@163.com 日期:2008-11-13 10:25:36 查看:112次
每个进行过较大型的ASP-Web应用程序设计的开发人员大概都有如下的经历:ASP代码与页面HTML混淆难分,业务逻辑与显示方式绞合,使得代码难以理解、难以修改;程序编写必须在美工之后,成为项目瓶颈;整合的程序代码和HTML静态页面时,花费大量的时间才能得到理想的效果,兼作了美工。的确,用脚本语言开发Web应用不容易将数据的处理和数据的显示分开,但在多人合作的情况下,如果无法将数据和显示分开,将大大影响开发的效率,专业分工的发挥。
其它的脚本语言,如JSP、PHP都有自己的解决方案,ASP的后一代产品ASP.NET也实现了代码与页面,似乎直接过渡到ASP是不错的选择。但是总有这样或那样的原因让我们不能或暂时不能放弃ASP直奔.NET大营。从公司角度来看,转换语言是一笔不少的投资,包括雇佣熟手.NET程序员、培训原有程序员、开发工具的转型、开发风格的转型、界面风格转变、接口风格、软件架构、文档、开发流程等等;这还意味着原有的代码必须在新语言环境里重写以实现最佳的效果和稳定性;同时将直接影响这段时间内项目的进度,更有可能导致个别程序员出走。由此看来在您决定转换语言之前,在原基础上寻求一种解决方案,才是最好的选择。
PHP通过模板实现代码与页面,可供选择的有FastTemplate、PHPLIB、Smarty等多种,其中PHPLIB的影响最大、使用最多。既然如此,我们直接把它搬到ASP来,对于同时使用PHP和ASP的公司还有很有好处:一、美工处理页面时,不管将要套用PHP还是ASP,处理方式是一样,无须经过培训;二、程序员编写代码时,两种语言间的思路接近或一致,相同功能在两种语言实现时,只需拷贝过来略作修改即可,保证了工作效率和项目进度。
1、模板类的设计
实现代码封装成为模板类,即是为了与PHPLIB兼容,也使得代码方便管理与扩展。 模板类要实现的目标为:从模板文件中读入显示的HTML代码,将这些显示代码中需要动态数据的地方替换为ASP程序运算所得出的数据,然后按照一定的顺序输出。其中,替换的部分可以自由的设定。因此它必须完成如下任务:
·从模板文件中读取显示用的HTML代码。 ·将模板文件和实际生成的数据结合,生成输出的结果。 ·允许同时处理多个模板。 ·允许模板的嵌套。 ·允许对模板中的某个单独的部分进行处理。
实现方法:
采用FSO读取模板文件 采用正则替换实现模板文件和数据的结合 处理多个模板用数组存储来实现。
模板的嵌套的实现主要的想法是:将模板和输出(任何中间的分析结果)一视同仁,都可拿来做替换,即可实现。
单独部分的处理的通过在模板文件中设定标注,然后在正则替换中结合标注来控制,实现部分替换。
作者:mosquito_520@163.com 日期:2008-11-2 17:00:19 查看:123次
<%
Class Cls_Template
Dim Reg Dim Page Dim CID Dim SID Dim Rule Dim Content Dim Template Dim Cachetimei
Private Sub Class_Initialize() Set Reg = New RegExp Reg.Ignorecase = True Reg.Global = True Page = 0 CID = 0 SID = 0 Rule = "" Content = "" Template = "" ' 模板路径 Cachetimei = -1 ' 标签缓存时间 End Sub
Private Sub Class_Terminate() 'Set Reg = Nothing End Sub
' 载入模板 Public Function Load(ByVal Templatefile) Template = Templatefile If Templatecache = 1 Then If ChkCache("LoadTemplate_" & Server.Mappath(Template)) Then Content = GetCache("LoadTemplate_" & Server.Mappath(Template)) Else Call Loadfile Call SetCache("LoadTemplate_" & Server.Mappath(Template), Content) End If Else Call Loadfile End If End Function
' 检测SQL缓存 Function ChkCacheSQL(ByVal CacheName) If Cachetimei <= 0 Then ChkCacheSQL = False: Exit Function Dim CacheData ChkCacheSQL = False CacheName = LCase(Filterstr(CacheName)) CacheData = Application(Cacheflag & CacheName) If Not IsArray(CacheData) Then Exit Function If Not IsDate(CacheData(1)) Then Exit Function If DateDiff("s", CDate(CacheData(1)), Now()) < 60 * Cachetime Then ChkCacheSQL = True End Function
' 标签分析,有缓存有效期判断 Public Function Parser() If Not IsNumeric(Page) Then Page = 0 Else Page = Int(Page) Parser_My ' 自定义标签 Parser_Sys ' 系统标签 Parser_Com ' 列表标签 Parser_IF ' IF ELSE END End Function
' 自定义标签 Public Function Parser_My() On Error Resume Next If GetCache("MyLableState") = "No" Then Content = RegReplace(Content, "{My:([\s\S]*?)}", ""): Exit Function If Not ChkCache("MyLable") Then Dim Rs Set Rs = DB("Select [Name],[Code] From [{pre}Label]", 1) If Not Rs.Eof Then Call SetCache("MyLable", Rs.Getrows()) Call SetCache("MyLableState", "Yes") Rs.Close: Set Rs = Nothing Else Rs.Close: Set Rs = Nothing Call SetCache("MyLableState", "No") Content = RegReplace(Content, "{My:([\s\S]*?)}", ""): Exit Function End If End If Dim Ns, i, j Ns = GetCache("MyLable") Dim Matches, Match, MyValue Reg.Pattern = "{My:([\s\S]*?)}" Set Matches = Reg.Execute(Content) For Each Match In Matches If Len(Replace(Match.SubMatches(0), " ", "")) > 0 Then MyValue = Lang_Parser_My_1 & " <font color=red>" & Replace(Match.SubMatches(0), " ", "") & "</font> " & Lang_Parser_My_2 For i = 0 To UBound(Ns, 2) If LCase(Ns(0, i)) = LCase(Replace(Match.SubMatches(0), " ", "")) Then MyValue = Ns(1, i) If InStr(MyValue, "$$$") > 0 Then Randomize j = Round(UBound(Split(MyValue, "$$$")) * Rnd) '随机值第一个到最后一个 MyValue = Split(MyValue, "$$$")(j) End If Exit For End If Next End If Content = Replace(Content, Match.Value, MyValue) ' 替换 If Err Then Err.Clear: Response.Write "<font color=red>" & Lang_Parser_My_Error & "[" & AspArr(i) & "]</font>": Response.End Next End Function
' 分析系统标签 Public Function Parser_Sys() On Error Resume Next Dim Matches, Match, SysValue Reg.Pattern = "{Sys:([\s\S]*?)}" Set Matches = Reg.Execute(Content) For Each Match In Matches If InStr(LCase(Match.SubMatches(0)), "database") = 0 Then If Len(Replace(Match.SubMatches(0), " ", "")) > 0 Then Execute ("SysValue = " & Replace(Match.SubMatches(0), " ", "")) Else SysValue = "" Else SysValue = "" End If Content = Replace(Content, Match.Value, SysValue) ' 替换 If Err Then Err.Clear: Response.Write "<font color=red>" & Lang_Parser_Sys_Error & "[" & AspArr(i) & "]</font>": Response.End Next reg.pattern = "<(.*?)(src=|href=|value=)""(images/|css/|js/)(.*?)""(.*?)>" content = reg.replace(content, "<$1$2""" & httpurl & installdir & templatedir & "/$3$4""$5>") reg.pattern = "{tag:goto}" content = reg.replace(content, httpurl & installdir & "redirect.asp?") End Function
' 列表标签 '<!--commend:{ $row=10 $cid={field:cid} $mode=commend }-->..............................<!--commend--> Public Function Parser_Com() On Error Resume Next Dim Matches, Match Dim Rs, i, j Dim Matche, BackValue Dim TagLabs, Tagsstr, Loopstr Dim Tag_Cache, Tag_Row, Tag_Col, Tag_Width, Tag_Class Dim Tag_Aid, Tag_Cid, Tag_Type, Tag_Mode, Tag_Keys, Tag_Order Dim Tag_SQL, Tag_Table, Tag_Where, Tag_Field Reg.Pattern = "<!--(.+?):\{(.+?)\}-->([\s\S]*?)<!--\1-->" Set Matches = Reg.Execute(Content) For Each Match In Matches TagLabs = Match.SubMatches(0) ' 标签 Tagsstr = Match.SubMatches(1) ' 属性 Loopstr = Match.SubMatches(2) ' innerText If LCase(TagLabs) <> "page" Then ' 分页标签 ' 共用属性 Tag_Cache = GetAttr(Tagsstr, "cache", True) ' 缓存时间 def:defcachetime Tag_Row = GetAttr(Tagsstr, "row", True) ' 列数量 def:10 Tag_Col = GetAttr(Tagsstr, "col", True) ' 行数量 def:1 Tag_Width = GetAttr(Tagsstr, "width", True) '#表格宽度 Tag_Class = GetAttr(Tagsstr, "class", False) '#表格样式 Tag_Field = GetAttr(Tagsstr, "field", True) ' 所有字段 If Len(Tag_Cache) = 0 Or Not IsNumeric(Tag_Cache) Then Tag_Cache = -1 ' 标签不用缓存 If Len(Tag_Row) = 0 Or Not IsNumeric(Tag_Row) Then Tag_Row = 10 If Int(Tag_Row) < 1 Then Tag_Row = 1 If Len(Tag_Col) = 0 Or Not IsNumeric(Tag_Col) Then Tag_Col = 1 If Int(Tag_Col) < 1 Then Tag_Col = 1 If Len(Tag_Width) = 0 Then Tag_Width = "100%" If Len(Tag_Class) > 0 Then Tag_Class = " Class=""" & Tag_Class & """ " If Len(Tag_Field) = 0 Then Tag_Field = "*" Tag_Cache = Int(Tag_Cache): Tag_Row = Int(Tag_Row): Tag_Col = Int(Tag_Col) ' 内容Content专用属性 Tag_Aid = GetAttr(Tagsstr, "aid", True) ' 这个文章不显示出来 Tag_Cid = GetAttr(Tagsstr, "cid", True) ' 栏目ID,多用个,号分隔 Tag_Type = GetAttr(Tagsstr, "type", True) ' 类型: text/images def:text Tag_Mode = GetAttr(Tagsstr, "mode", True) ' 类型(推荐,热门,相关) Tag_Keys = GetAttr(Tagsstr, "keys", True) ' 关键字 Tag_Order = GetAttr(Tagsstr, "order", False) ' 排序 def:[id] desc[组合查询可用] Tag_SQL = GetAttr(Tagsstr, "sql", False) ' 单独SQL查询 Tag_Table = GetAttr(Tagsstr, "table", True) ' 组合查询,表 Tag_Where = GetAttr(Tagsstr, "where", False) ' 组合查询,条件 ' 默认设置 If LCase(Tag_Table) = "channel" And Len(Tag_Where) = 0 Then Tag_Where = "[FatherID]=0 And [OutSideLink]=0 And [Order]>=0" If LCase(Tag_Table) = "channel" And Len(Tag_Order) = 0 Then Tag_Order = "[Order] Desc,[ID] Desc" ' SQL查询组合 If Len(Tag_SQL) = 0 Then If Len(Tag_Table) > 0 Then If Len(Tag_Where) > 0 Then Tag_Where = " Where " & Tag_Where & " " If Len(Tag_Order) = 0 Then If LCase(Tag_Table) = "channel" Then Tag_Order = "[Order] Desc,[ID] Desc" Else Tag_Order = "[ID] Desc" End If End If Tag_SQL = "Select Top " & Tag_Row * Tag_Col & " " & Tag_Field & " From [{pre}" & Tag_Table & "] " & Tag_Where & " Order By " & Tag_Order ' 最终查询语句 Else Tag_Where = "" If Len(Tag_Aid) > 0 Then If InStr(Tag_Aid, ",") > 0 Then Tag_Where = " [ID] In (" & Tag_Aid & ") " Else Tag_Where = " [ID]<>" & Tag_Aid & " " End If End If If Len(Tag_Cid) > 0 Then If Len(Tag_Where) > 0 Then Tag_Where = Tag_Where & " And [Cid] In (" & Tag_Cid & ") " Else Tag_Where = " [Cid] In (" & Tag_Cid & ") " 'If Len(Tag_Where) > 0 Then Tag_Where = Tag_Where & " And ([Cid] In (" & Tag_Cid & ") or [Sid] in (" & tag_cid & ")) " Else Tag_Where = " ([Cid] In (" & Tag_Cid & ") or [Sid] in (" & tag_cid & ")) " End If If LCase(Tag_Type) = "images" Then If Len(Tag_Where) > 0 Then Tag_Where = Tag_Where & " And [Indexpic]<>'' " Else Tag_Where = Tag_Where & " [Indexpic]<>'' " End If If LCase(Tag_Type) = "noimages" Then If Len(Tag_Where) > 0 Then Tag_Where = Tag_Where & " And [Indexpic]='' " Else Tag_Where = Tag_Where & " [Indexpic]='' " End If Select Case LCase(Tag_Mode) Case "commend" If Len(Tag_Where) > 0 Then Tag_Where = Tag_Where & " And [Commend]=1 " Else Tag_Where = Tag_Where & " [Commend]=1 " Case "uncommend" If Len(Tag_Where) > 0 Then Tag_Where = Tag_Where & " And [Commend]=0 " Else Tag_Where = Tag_Where & " [Commend]=0 " Case "about" If Len(Tag_Keys) > 0 Then Tag_Cache = -1 ' 不缓存 Dim Tag_KeysLink Tag_Keys = Split(Replace(Tag_Keys, "'", ""), ",") j = UBound(Tag_Keys): If j > 5 Then j = 5 For i = 0 To j If Len(Tag_Keys(i)) > 0 Then If Len(Tag_KeysLink) = 0 Then Tag_KeysLink = " [Keywords] Like '%" & Tag_Keys(i) & "%'" Else Tag_KeysLink = Tag_KeysLink & " Or [Keywords] Like '%" & Tag_Keys(i) & "%'" End If End If Next If Len(Tag_KeysLink) > 0 Then If Len(Tag_Where) > 0 Then Tag_Where = Tag_Where & " And (" & Tag_KeysLink & ") " Else Tag_Where = Tag_Where & " (" & Tag_KeysLink & ") " End If End If End Select If LCase(Tag_Mode) = "hot" Then Tag_Order = "[Views] Desc" Else If Len(Tag_Order) = 0 Then Tag_Order = "[ID] Desc" End If If Len(Tag_Where) > 0 Then Tag_Where = Tag_Where & " And [Display]=1 " Else Tag_Where = " [Display]=1" Tag_SQL = "Select Top " & Tag_Row * Tag_Col & " " & Tag_Field & " From [{pre}Content] Where " & Tag_Where & " Order By " & Tag_Order ' 最终查询语句 End If End If Cachetimei = Tag_Cache ' 标签缓存 If ChkCacheSQL(Template & Tag_SQL) Then BackValue = GetCache(Template & Tag_SQL) Else BackValue = "" Err.Clear Set Rs = DB(Tag_SQL, 3) If Err Then Response.Write "<font color=red>" & Lang_Parser_Com_Error & "[" & Tag_SQL & " => & " & Err.Description & "]</font>": Response.End If Tag_Col > 1 Then BackValue = BackValue & "<table width=""" & Tag_Width & """ " & Tag_Class & " border=""0"" cellpadding=""0"" cellspacing=""0"">" & vbCrLf: j = 0 ' 表 Session(Cacheflag & "_Parser_i") = 0 For i = 1 To Tag_Row * Tag_Col If Rs.Eof Then Exit For ' 不存在记录就退出 j = j + 1 If Tag_Col > 1 Then ' 表 If j = 1 Then BackValue = BackValue & " <tr>" & vbCrLf BackValue = BackValue & " <td valign=""top"" width=""" & Round(100 / Tag_Col) & "%"">" End If If Len(TagLabs) = 0 Then TagLabs = "field" Session(Cacheflag & "_Parser_i") = Session(Cacheflag & "_Parser_i") + 1 ' 记数 BackValue = BackValue & Parser_Tags("\[" & TagLabs & ":(.+?)\]", Loopstr, Rs) ' 替换 If Tag_Col > 1 Then ' 表 BackValue = BackValue & " </td>" & vbCrLf If j = Tag_Col Then BackValue = BackValue & " </tr>" & vbCrLf: j = 0 End If Rs.MoveNext Next If Tag_Col > 1 Then If j < Tag_Col And j > 0 Then For i = 1 To Tag_Col - j BackValue = BackValue & " <td></td>" & vbCrLf Next BackValue = BackValue & " </tr>" & vbCrLf End If BackValue = BackValue & "</table>" & vbCrLf End If Rs.Close Call SetCache(Template & Tag_SQL, BackValue) End If Content = Replace(Content, Match.Value, BackValue) End If Next If RegExists("<!--(.+?):\{(.+?)\}-->([\s\S]*?)<!--\1-->", Content) Then Call Parser_Com ' 多次调用 End Function
' 分页标签 Public Function Parser_Page() 'On Error Resume Next Dim Matches, Match Dim Rs, i, j Dim Matche, BackValue Dim Tagsstr, Loopstr Dim Tag_Size, Tag_Order, Tag_Field, Tag_Table, Tag_Style, Tag_SQL, Tag_Where Dim Tag_RecordCount, Tag_PageCount Reg.Pattern = "<!--Page:\{(.+?)\}-->([\s\S]*?)<!--Page-->" Set Matches = Reg.Execute(Content) For Each Match In Matches BackValue = "" Tagsstr = Match.SubMatches(0) ' 属性 Loopstr = Match.SubMatches(1) ' innerText Tag_Size = GetAttr(Tagsstr, "size", True) Tag_Order = GetAttr(Tagsstr, "order", False) Tag_Table = GetAttr(Tagsstr, "table", True) Tag_Style = GetAttr(Tagsstr, "style", True) Tag_Field = GetAttr(Tagsstr, "field", True) ' 所有字段 If Len(Tag_Size) = 0 Or Not IsNumeric(Tag_Size) Then Tag_Size = 10 If Len(Tag_Order) = 0 Then Tag_Order = "[ID] Desc" If Len(Tag_Table) = 0 Then Tag_Table = "Content" If Len(Tag_Style) = 0 Or Not IsNumeric(Tag_Style) Then Tag_Style = 1 If Len(Tag_Field) = 0 Then Tag_Field = "*" Tag_Size = Int(Tag_Size): Tag_Table = " [{pre}" & Tag_Table & "] ": Tag_Style = Int(Tag_Style): Tag_Where = " [Display]=1 "
If Len(CID) > 0 And isnumeric(CID) Then Tag_Where = Tag_Where & " And [CID]=" & CID ' 存在CID则调用指定CID/SID的内容 'If Len(CID) > 0 And isnumeric(CID) Then Tag_Where = Tag_Where & " And ([CID]=" & CID & " Or [SID]=" & CID & ")" ' 存在CID则调用指定CID/SID的内容 If Len(CID) = 0 And Len(SID)>0 And isnumeric(SID) Then Tag_Where = Tag_Where & " And [SID]=" & SID ' 不存在CID,而存在SID则调用SID的内容
Set Rs = New DataList Rs.Result = 1 Rs.Field = Tag_Field Rs.Table = Tag_Table Rs.Where = Tag_Where Rs.Order = Tag_Order Rs.PageSize = Tag_Size Rs.AbsolutePage = Page Rs.List() Session(Cacheflag & "_Parser_i") = 0 For i = 1 To Tag_Size If Rs.Data.Eof Then Exit For Session(Cacheflag & "_Parser_i") = Session(Cacheflag & "_Parser_i") + 1 ' 记数 BackValue = BackValue & Parser_Tags("\[Page:(.+?)\]", Loopstr, Rs.Data) ' 替换 Rs.Data.MoveNext Next Content = RegReplace(Content, "{tag:page}", "{{tag:page_www.5u.hk}}") Content = Replace(Content, Match.Value, BackValue) Tag_RecordCount = Rs.RecordCount: Tag_PageCount = Rs.PageCount: Rs.Data.Close If Tag_PageCount = 0 Then Tag_PageCount = 1 Next Dim GetPageList if matches.count >0 then GetPageList = PageListX(Tag_PageCount, Tag_RecordCount, Page, Tag_Size, CID) end if Content = RegReplace(Content, "{{tag:page_www.5u.hk}}", GetPageList) Set Rs = Nothing End Function
' 字符替换 Public Function Parser_Tags(ByVal Pattern, ByVal Temp, ByVal Dat) On Error Resume Next Dim Matches, Match Dim Tagsstr, Tagsval, Tagsvalt, TagTitle: TagTitle = False Dim Tag_Len, Tag_Lenext, Tag_Format, Tag_Replace, Tag_Function,Tag_width,Tag_Height Dim Re, Re1, Re2 Dim i, c, l, t Reg.Pattern = Pattern Set Matches = Reg.Execute(Temp) For Each Match In Matches Tagsstr = Match.SubMatches(0) Tag_Len = GetAttr(Tagsstr, "len", True) Tag_Lenext = GetAttr(Tagsstr, "lenext", True) Tag_Format = GetAttr(Tagsstr, "format", False) Tag_Replace = GetAttr(Tagsstr, "replace", False) Tag_Function = GetAttr(Tagsstr, "function", True) Tag_Width=GetAttr(Tagsstr, "width", True) Tag_Height=GetAttr(Tagsstr, "height", True) Tagsval = Split(Tagsstr, " ")(0) Select Case LCase(Tagsval) Case "aid" Tagsval = Dat("AID") If Err Then Err.Clear: Tagsval = Dat("ID") ' Content Case "aurl" Tagsval = Dat("ID") ' Content Tagsval = BuildViewPath(Dat("ID"), Dat("Cid"), Dat("Diyname"), Dat("Createtime"), Dat("ViewPath")) Case "curl" Tagsval = Dat("Cid") ' Content If Err Then Err.Clear: Tagsval = Dat("ID") ' Channel If Createhtml = 1 Then ' 栏目只在1时才会生成,其他均不生成 If Len(GetChannel(Tagsval, "Domain")) > 0 Then Tagsval = GetChannel(Tagsval, "Domain") Else Tagsval = Httpurl & GetChannel(Tagsval, "Ruleindex") Else ' ASP If Len(GetChannel(Tagsval, "Domain")) > 0 Then Tagsval = GetChannel(Tagsval, "Domain") Else Tagsval = Httpurl & Installdir & "channel.asp?id=" & Tagsval End If Case "surl" ' sid -> name Tagsval = "" Case "cname" Tagsval = GetChannel(Dat("cid"), "name") Case "sname" ' sid -> name Tagsval = "" Case "ctable" Tagsval = GetChannel(Dat("cid"), "table") Case "titlex" Tagsval = Dat("Title") ' Content TagTitle = True Case "modeindex" Tagsval = "" Case "i" Tagsval = Session(Cacheflag & "_Parser_i") Case Else If LCase(Left(Tagsval, 5)) = "mode_" Then Dim Modetag: Modetag = Right(Tagsval, Len(Tagsval) - 5) Tagsval = Dat("ModeIndex") If Len(Tagsval) > 0 And InStr(Tagsval, "<" & Modetag & ">") > 0 And InStr(Tagsval, "</" & Modetag & ">") > 0 Then ' Get Mode Tag Value Else Tagsval = "" End If Else Tagsval = Dat(Tagsval) End If End Select Tagsval = Replace(Replace(Replace(Replace(Tagsval, " ", " "), """, Chr(34)), ">", ">"), "<", "<") If Len(Replace(Tag_Replace, " ", "")) > 0 Then Re = Split(Tag_Replace, "##") If UBound(Re) >= 0 Then Re1 = Re(0): Re2 = Re(1) Else Re1 = Re(0): Re2 = Re(0) Tagsval = Replace(Tagsval, Re1, Re2) End If If Len(Replace(Tag_Format, " ", "")) > 0 Then ' 格式化时间 If IsDate(Tagsval) Then Tagsvalt = Tagsval: Tagsvalt = LCase(Tag_Format): Tagsvalt = Replace(Tagsvalt, "weeka", "WEEKA"): Tagsvalt = Replace(Tagsvalt, "montha", "MONTHA"): Tagsvalt = Replace(Tagsvalt, "week", "WEEK"): Tagsvalt = Replace(Tagsvalt, "month", "MONTH") If InStr(Tagsvalt, "WEEKA") Then Tagsvalt = Replace(Tagsvalt, "WEEKA", Lang_Week_Abbr(Weekday(Tagsval))) If InStr(Tagsvalt, "WEEK") Then Tagsvalt = Replace(Tagsvalt, "WEEK", Lang_Week(Weekday(Tagsval))) If InStr(Tagsvalt, "MONTHA") Then Tagsvalt = Replace(Tagsvalt, "MONTHA", Lang_Month_Abbr(Month(Tagsval))) If InStr(Tagsvalt, "MONTH") Then Tagsvalt = Replace(Tagsvalt, "MONTH", Lang_Month(Month(Tagsval))) If InStr(Tagsvalt, "yyyy") > 0 Then Tagsvalt = Replace(Tagsvalt, "yyyy", Year(Tagsval)) If InStr(Tagsvalt, "yy") > 0 Then Tagsvalt = Replace(Tagsvalt, "yy", Right(Year(Tagsval), 2)) If InStr(Tagsvalt, "mm") > 0 Then Tagsvalt = Replace(Tagsvalt, "mm", Right("0" & Month(Tagsval), 2)) If InStr(Tagsvalt, "m") > 0 Then Tagsvalt = Replace(Tagsvalt, "m", Month(Tagsval)) If InStr(Tagsvalt, "dd") > 0 Then Tagsvalt = Replace(Tagsvalt, "dd", Right("0" & Day(Tagsval), 2)) If InStr(Tagsvalt, "d") > 0 Then Tagsvalt = Replace(Tagsvalt, "d", Day(Tagsval)) If InStr(Tagsvalt, "hh") > 0 Then Tagsvalt = Replace(Tagsvalt, "hh", Right("0" & Hour(Tagsval), 2)) If InStr(Tagsvalt, "h") > 0 Then Tagsvalt = Replace(Tagsvalt, "h", Hour(Tagsval)) If InStr(Tagsvalt, "nn") > 0 Then Tagsvalt = Replace(Tagsvalt, "nn", Right("0" & Minute(Tagsval), 2)) If InStr(Tagsvalt, "n") > 0 Then Tagsvalt = Replace(Tagsvalt, "n", Minute(Tagsval)) If InStr(Tagsvalt, "ss") > 0 Then Tagsvalt = Replace(Tagsvalt, "ss", Right("0" & Second(Tagsval), 2)) If InStr(Tagsvalt, "s") > 0 Then Tagsvalt = Replace(Tagsvalt, "s", Second(Tagsval)) Tagsval = Tagsvalt End If End If If Len(Tag_Len) > 0 Then If IsNumeric(Tag_Len) Then Tag_Len = Int(Tag_Len) For i = 1 To Len(Tagsval) c = Abs(Asc(Mid(Tagsval, i, 1))) If c > 255 Or c < 2 Then t = t + 2 Else t = t + 1 If t >= Tag_Len Then Tagsval = Left(Tagsval, i) & Tag_Lenext: Exit For Next End If End If If Len(Tag_Function) > 0 Then Tag_Function = Split(Tag_Function, ",") For i = 0 To UBound(Tag_Function) Select Case LCase(Tag_Function(i)) Case "urlencode": Tagsval = Server.UrlEnCode(Tagsval) Case "htmlencode": Tagsval = Server.HtmlEnCode(Tagsval) Case "abs": Tagsval = Abs(Tagsval) Case "trim": Tagsval = Trim(Tagsval) Case "ucase": Tagsval = UCase(Tagsval) Case "lcase": Tagsval = LCase(Tagsval) Case "clearhtml": Tagsval = RegReplace(Tagsval, "(\<.+?\>)", ""): Tagsval = Replace(Trim(Tagsval), vbCrLf, " ") Case "tags" t = Split(Tagsval, ","): Tagsval = "" For c = 0 To UBound(t) If Len(Tagsval) > 0 Then Tagsval = Tagsval & "," Tagsval = Tagsval & " <a href='" & Httpurl & Installdir & "plus/search/index.asp?keyword=" & Server.UrlEnCode(t(c)) & "'>" & t(c) & "</a>" Next End Select Next End If If len(Tag_Width) > 0 or len(Tag_Height) > 0 then If instr(tag_width,",") > 0 or len(tag_width)=0 then tag_width = 100 else tag_width = int(tag_width) If instr(tag_height,",") > 0 or len(tag_height)=0 then tag_height = 100 else tag_height = int(tag_height) Tagsval = Cutjpeg(Tagsval,Tag_Width , tag_height) end if If IsNull(Tagsval) Then Tagsval = "" If TagTitle Then TagTitle = False Dim TitleStyle: TitleStyle = Split(Dat("Style") & ",", ",") If Len(TitleStyle(0)) > 0 Then Tagsval = "<" & TitleStyle(0) & ">" & Tagsval & "</" & TitleStyle(0) & ">" If Len(TitleStyle(1)) > 0 Then Tagsval = "<font color=""" & TitleStyle(1) & """>" & Tagsval & "</font>" End If Temp = Replace(Temp, Match.Value, Tagsval) Next Parser_Tags = Temp End Function
' 判断标签 Public Function Parser_IF() On Error Resume Next Dim Matches, Match Dim TestIF Reg.Pattern = "{If:(.+?)}([\s\S]*?){Else}([\s\S]*?){End If}" Set Matches = Reg.Execute(Content) For Each Match In Matches Execute ("If " & Match.SubMatches(0) & " Then TestIf = True Else TestIf = False") If TestIF Then Content = Replace(Content, Match.Value, Match.SubMatches(1)) Else Content = Replace(Content, Match.Value, Match.SubMatches(2)) ' 替换 If Err Then Response.Write "<font color=red>" & Lang_Parser_IF_Error & "[" & Match.SubMatches(0) & "]" & Err.Description & "</font>": Err.Clear: Response.End Next Reg.Pattern = "{If:(.+?)}([\s\S]*?){End If}" Set Matches = Reg.Execute(Content) For Each Match In Matches Execute ("If " & Match.SubMatches(0) & " Then TestIf = True Else TestIf = False") If TestIF Then Content = Replace(Content, Match.Value, Match.SubMatches(1)) Else Content = Replace(Content, Match.Value, "") ' 替换 If Err Then Response.Write "<font color=red>" & Lang_Parser_IF_Error & "[" & Match.SubMatches(0) & "]" & Err.Description & "</font>": Err.Clear: Response.End Next End Function
' 正表达式替换 Public Function RegReplace(ByVal ReplaceContent, ByVal Pattern, ByVal ReplaceVal) Reg.Pattern = Pattern RegReplace = Reg.Replace(ReplaceContent, ReplaceVal) End Function
' 是否存在此类标签 Public Function RegExists(ByVal Pattern, ByVal TestContent) Reg.Pattern = Pattern RegExists = Reg.Test(TestContent) End Function
' 获取指定标签属性的值 'Tag_Cache = GetAttr(" $row=10 $cid={field:cid} $mode=commend ", "cache", True) Public Function GetAttr(ByVal Tagsstr, ByVal AttrName, ByVal ReplaceSpace) If Len(Tagsstr) <= 3 Or InStr(LCase(Tagsstr), "$" & LCase(AttrName) & "=") = 0 Then GetAttr = "": Exit Function Dim Matches, Match Reg.Pattern = "\$" & AttrName & "=(.+?) \$" Set Matches = Reg.Execute(Tagsstr & " $") For Each Match In Matches GetAttr = Match.SubMatches(0) Next If ReplaceSpace Then GetAttr = Replace(GetAttr, " ", "") If Len(GetAttr) > 0 And IsNumeric(GetAttr) And InStr(GetAttr, ",") = 0 Then GetAttr = Int(GetAttr) End If End Function
' 载入模板 Public Function Loadfile() Dim Obj On Error Resume Next Set Obj = Server.CreateObject("adodb.stream") With Obj .Type = 2: .Mode = 3: .Open: .Charset = Response.charset : .Position = Obj.Size: .Loadfromfile Server.Mappath(Template): Content = .ReadText: .Close End With Set Obj = Nothing If Err Then Response.Write "<font color=red>" & Lang_Parser_LoadFile_Error & "[" & Template & "]</font>": Response.End End Function
public function rep(s,d) content = replace(content,s,d) end function
End Class
作者:mosquito_520@163.com 日期:2008-11-2 16:50:01 查看:118次
text = "<div id=""id"">{{id}}</div> <div id=""title"">{{title}}</div>" a = "<tag:Article id=""300"" content=""1500"" /> <tag:loop channelid=""17"" pagesize=""10"" title=""10"" elite=""fales"" column=""2"" />" response.write ProcessCustomTags(a)
Function ProcessCustomTags(ByVal sContent) Dim objRegEx, Match, Matches Set objRegEx = New RegExp objRegEx.Pattern = "<tag:[^<>]+?\/>" objRegEx.IgnoreCase = True objRegEx.Global = True Set Matches = objRegEx.Execute(sContent) For Each Match in Matches sContent = Replace(sContent, Match.Value, ParseTag(Match.Value)) Next set Matches = nothing set objRegEx = nothing ProcessCustomTags = sContent End Function
function ParseTag(ByVal strTag) dim arrResult, ClassName, arrAttributes, sTemp, i, objClass if len(strTag) = 0 then exit function arrResult = Split(strTag, ":") ClassName = Split(arrResult(1), " ")(0) select case uCase(ClassName) case "LOOP" 'response.write GetAttribute("channelid", strTag) & "<br>" 'response.write GetAttribute("pagesize", strTag) & "<br>" 'response.write GetAttribute("title", strTag) & "<br>" 'response.write GetAttribute("elite", strTag) & "<br>" 'response.write GetAttribute("column", strTag) & "<br>" for i = 1 to GetAttribute("pagesize", strTag) t = replace(text,"{{id}}",i) t = replace(t,"{{title}}", i & "title") ParseTag = ParseTag & t & Vbcrlf next
case "ARTICLE" 'response.write GetAttribute("id", strTag) & "<br>" 'response.write GetAttribute("content", strTag) & "<br>" end select end function
function GetAttribute(ByVal strAttribute, ByVal strTag) Dim objRegEx, Matches Set objRegEx = New RegExp objRegEx.Pattern = lCase(strAttribute) & "=""[0-9a-zA-Z]*""" objRegEx.IgnoreCase = True objRegEx.Global = True Set Matches = objRegEx.Execute(strTag) if Matches.Count > 0 then GetAttribute = Split(Matches(0).Value,"""")(1) else GetAttribute = "" end if set Matches = nothing set objRegEx = nothing end function
作者:mosquito_520@163.com 日期:2008-11-2 16:48:28 查看:131次
首页 上一页 下一页 末页 页次: 1 / 46 共 272 条记录 6 条/页
|
|