欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp下tag的实现,简单介绍与部分代码

程序员文章站 2023-01-03 21:51:06
标签(tag)是什么? 标签是一种更为*、灵活,完全由用户决定的分类方式,而非传统的由网站定义的分类。您可以根据自己的理解,对发表的文章、上传的图片、音乐、视频等各种文件...
标签(tag)是什么?
标签是一种更为*、灵活,完全由用户决定的分类方式,而非传统的由网站定义的分类。您可以根据自己的理解,对发表的文章、上传的图片、音乐、视频等各种文件添加一个或多个标签,进行灵活的描述。 
添加标签(tag)有什么作用?
标签体现了群体的力量,使得用户之间可以通过相近的内容产生更多的关联和互动。您在发表日志或上传文件时添加了tag ,就可以看到woku.com所有和您使用了相同tag 的日志和文件。 
标签频道中不同大小、粗细的文字代表什么?
使用不同大小、粗细字体的标签,代表着标签不同的使用频率。字体越大、越粗,说明这些标签的使用频率越高。 
  添加标签时需要注意些什么?
① 多个标签之间请用空格分隔。 
② 每个标签的最大长度为 10 个汉字。 
③ 每篇日志或每个文件最多只能添加10个标签,这包括您自己以及其他用户添加的标签。 
我可以在别人发表的日志和文件中添加标签吗?
您可以根据浏览对象的阅读权限来判断是否可以添加标签。公开的日志或文件,所有用户都可以添加标签;仅供好友浏览的日志,只有好友和作者能添加标签;仅作者可以浏览的日志或文件,只有作者能够添加标签。当然,无论是谁添加的标签,都只有该日志或文件的作者可以修改或删除这些标签。 
所以呢我找了些实现tag功能的asp代码,仅供参考
复制代码 代码如下:

'*********************************************************
' 目的:    定义ttag类
' 输入:    无
' 返回:    无
'*********************************************************
class ttag

    public id
    public name
    public intro
    public order
    public count


    public property get encodename
        encodename = server.urlencode(name)
    end property

    public property get url
        url = zc_blog_host & "catalog.asp?"& "tags=" & server.urlencode(name)
    end property

    public property get htmlurl
        htmlurl=transferhtml(url,"[html-format]")
    end property

    public property get htmlintro
        htmlintro=transferhtml(intro,"[html-format]")
    end property

    public property get htmlname
        htmlname=transferhtml(name,"[html-format]")
    end property

    public property get rssurl
        rssurl = zc_blog_host & "sydication.asp?tags=" & id
    end property

    public function post()

        call checkparameter(id,"int",0)
        call checkparameter(order,"int",0)

        name=filtersql(name)
        name=transferhtml(name,"[normalname]")
        if len(name)=0 then post=false:exit function

        intro=filtersql(intro)
        intro=transferhtml(intro,"[html-format]")


        if id=0 then
            objconn.execute("insert into [blog_tag]([tag_name],[tag_order],[tag_intro]) values ('"&name&"',"&order&",'"&intro&"')")
        else
            objconn.execute("update [blog_tag] set [tag_name]='"&name&"',[tag_order]="&order&",[tag_intro]='"&intro&"' where [tag_id] =" & id)
        end if

        post=true

    end function


    public function loadinfobyid(tag_id)

        call checkparameter(tag_id,"int",0)

        dim objrs
        set objrs=objconn.execute("select [tag_id],[tag_name],[tag_intro],[tag_order],[tag_count] from [blog_tag] where [tag_id]=" & tag_id)

        if (not objrs.bof) and (not objrs.eof) then

            id=objrs("tag_id")
            name=objrs("tag_name")
            intro=objrs("tag_intro")
            order=objrs("tag_order")
            count=objrs("tag_count")

            loadinfobyid=true

        end if

        objrs.close
        set objrs=nothing

        if isnull(intro) then intro=""

    end function

    public function loadinfobyarray(arytaginfo)

        if isarray(arytaginfo)=true then
            id=arytaginfo(0)
            name=arytaginfo(1)
            intro=arytaginfo(2)
            order=arytaginfo(3)
            count=arytaginfo(4)
        end if

        if isnull(intro) then intro=""

        loadinfobyarray=true

    end function


    public function del()

        call checkparameter(id,"int",0)
        if (id=0) then del=false:exit function

        dim s
        dim i
        dim objrs

        set objrs=server.createobject("adodb.recordset")
        objrs.cursortype = adopenkeyset
        objrs.locktype = adlockreadonly
        objrs.activeconnection=objconn
        objrs.source=""

        objrs.open("select [log_id],[log_tag] from [blog_article] where [log_tag] like '%{" & id & "}%'")

        if (not objrs.bof) and (not objrs.eof) then
            do while not objrs.eof
                i=objrs("log_id")
                s=objrs("log_tag")
                s=replace(s,"{"& id &"}","")
                objconn.execute("update [blog_article] set [log_tag]='"& s &"' where [log_id] =" & i)
                objrs.movenext
            loop
        end if
        objrs.close

        objconn.execute("delete from [blog_tag] where [tag_id] =" & id)
        del=true
    end function


    public function maketemplate(s)

        s=replace(s,"<#article/tag/id#>",id)
        s=replace(s,"<#article/tag/name#>",htmlname)
        s=replace(s,"<#article/tag/intro#>",htmlintro)
        s=replace(s,"<#article/tag/count#>",count)
        s=replace(s,"<#article/tag/url#>",htmlurl)
        s=replace(s,"<#article/tag/encodename#>",encodename)

        maketemplate=s

    end function


end class
'*********************************************************


'*********************************************************
' 目的:    tags读取
'*********************************************************
function gettags()

    dim i,j,k,l

    dim aryalldata
    dim arysingledata()

    erase tags

    dim objrs

    set objrs=objconn.execute("select top 1 [tag_id] from [blog_tag] order by [tag_id] desc")
    if (not objrs.bof) and (not objrs.eof) then
        i=objrs("tag_id")
        redim tags(i)
    end if

    set objrs=objconn.execute("select [tag_id],[tag_name],[tag_intro],[tag_order],[tag_count] from [blog_tag] order by [tag_id] asc")
    if (not objrs.bof) and (not objrs.eof) then

        aryalldata=objrs.getrows(objrs.recordcount)
        objrs.close
        set objrs=nothing

        k=ubound(aryalldata,1)
        l=ubound(aryalldata,2)
        for i=0 to l
            set tags(aryalldata(0,i))=new ttag
            tags(aryalldata(0,i)).loadinfobyarray(array(aryalldata(0,i),aryalldata(1,i),aryalldata(2,i),aryalldata(3,i),aryalldata(4,i)))
        next

    end if

    gettags=true

end function