[分享]信息列表批量添加TAG,批量复制到关键词

发布时间:2019-10-12 18:24:02

[分享]信息列表批量添加TAG,批量复制到关键词,7.5可用。e/clas/userfun.php添加函数加入TAG表 function eInsertTags2($tags,$clasid,$id,$newstime){ global $empire,$dbtbpre,$clas_r; if(!trim($tags)) { ...

您的位置:仿站网 > 问答 >
[分享]信息列表批量添加TAG,批量复制到关键词,7.5可用。

e/class/userfun.php添加函数

//加入TAG表   

function eInsertTags2($tags,$classid,$id,$newstime){   

        global $empire,$dbtbpre,$class_r;   

        if(!trim($tags))   

        {   

                printerror("TAGS信息不能为空", "", 1, 0, 1);   

        return '';   

        }

    $count = count($id); //统计ID数量   

    if (empty($count)){printerror("未选择信息ID", "", 1, 0, 1);}   

    $tags = RepPostVar($tags);   

    $tag = explode(",", $tags);   

    if (count($tag)>1) {  printerror("只能添加一个TAGS词", "", 1, 0, 1); }      

    $classid=(int)$classid;   

    $mid=(int)$class_r[$classid][modid]; //获取模型id

    $tbname=$class_r[$classid][tbname];//获取表名

        for($i=0;$i<$count;$i++)   

        {

        $id[$i] = (int)$id[$i];

        $fb = $empire->fetch1("select * from {$dbtbpre}ecms_".$tbname." where id='$id[$i]' limit 1");

        $classid=$fb['classid'];
               
        $newstime=$fb['newstime'];

        $ftbname=$dbtbpre."ecms_".$tbname."_data_".$fb['stb'];

        $r=$empire->fetch1("select tagid from {$dbtbpre}enewstags where tagname='$tags' limit 1");   

        $t = $empire->fetch1("select infotags from {$ftbname} where id='$id[$i]'");   

        $taga=$t['infotags'].",".$tags; //组合TAGS

        $taga=trim($t['infotags'].",".$tags,","); //组合TAGS

        $tagb[$i] = explode(",",$taga); //设置数组                 

        $tagc=array_values(array_unique($tagb[$i])); //数组排重

        $newtags[$i]=implode(",",$tagc);

        if($r[tagid])   

                {   

                        $datar=$empire->fetch1("select tagid,classid,newstime from

{$dbtbpre}enewstagsdata where tagid='$r[tagid]' and id='$id[$i]' and mid='$mid' limit 1");   

                        if($datar[tagid])   

                        {   

                                if($datar[classid]!=$classid||$datar[newstime]!=$newstime)   

                                {   

                                        $empire->query("update {$dbtbpre}enewstagsdata set classid=

'$classid',newstime='$newstime' where tagid='$r[tagid]' and id='$id[$i]' and mid='$mid' limit 1");   

                                }   

                        }   

                        else  

                        {   

                          $empire->query("update {$dbtbpre}enewstags set num=num+1 where tagid='$r[tagid]'");   

                          $empire->query("update {$ftbname} set infotags='$newtags[$i]' where id='$id[$i]'");   

                          $empire->query("insert into {$dbtbpre}enewstagsdata(tagid,classid,id,newstime,mid)

values('$r[tagid]','$classid','$id[$i]','$newstime','$mid');");   

                        }   

                }   

                else  

                {   

                        $empire->query("update {$ftbname} set infotags='$newtags[$i]' where id='$id[$i]'");   

            $empire->query("insert into {$dbtbpre}enewstags(tagname,num,isgood,cid) values('$tags',1,0,0);");   

                        $tagid=$empire->lastid();   

                        $empire->query("insert into {$dbtbpre}enewstagsdata(tagid,classid,id,newstime,mid) values

('$tagid','$classid','$id[$i]','$newstime','$mid');");   

                }   

        }   

    printerror("批量添加TAGS成功", "", 1, 0, 1);   

}


//批量复制TAGS到关键词
function eCopyTag2Key($classid,$id,$newstime){
    global $empire,$dbtbpre,$class_r;
    $count = count($id); //统计ID数量
    if (empty($count))
    {//如果id没选中
        printerror("未选择信息ID", "", 1, 0, 1);
    }
    $classid=(int)$classid;//这一步可省略
    $mid=(int)$class_r[$classid][modid];//取modid值,这一步可省略
    for($i=0;$i<$count;$i++)
    {
        $id[$i] = (int)$id[$i];
        $tbname=$class_r[$classid][tbname];//获取表名
        $r = $empire->fetch1("select * from {$dbtbpre}ecms_".$tbname." where id='$id[$i]' limit 1");
        $t = $empire->fetch1("select infotags from {$dbtbpre}ecms_".$tbname."_data_".$r['stb']." where id='$id[$i]'");//从信息表中取infotags和keyboard值
        $t=array_merge($r,$t);
        $taga=$t['infotags'].",".$t['keyboard']; //组合TAGS:在原有的infotags值上加上新keyboard
        $tagb[$i] = explode(",",$taga); //设置数组:用,分割tag
        $tagc=array_values(array_unique($tagb[$i])); //数组排重:排除重复?
        for($t=0;$t<count($tagb[$i]);$t++)
        {//二级子循环TAGS数组输出
            $newtags[$i].= ",".$tagc[$t];
        }
        $empire->query("update {$dbtbpre}ecms_".$tbname." set keyboard='".trim($newtags[$i],",")."' where id='$id[$i]'");//将新生成的keyboard写入到表中
    }
    printerror("已成功将TAGS批量复制到关键词字段", "", 1, 0, 1);
}


eadminecmsInfo.php  在任意2个elseif中间插入

elseif($enews=="CopyTag2Key")//列表批量复制Tags为关键词
{
                $classid=$_POST['classid'];
                $id=$_POST['id'];
        $newstime=time();   
        eCopyTag2Key($classid,$id,$newstime);
}
elseif($enews=="AddTags_all")//列表批量添加Tags
{
                $classid=$_POST['classid'];
                $id=$_POST['id'];
                $tags=$_POST['add_listtags'];
        $newstime=time();   
        eInsertTags2($tags,$classid,$id,$newstime);
}


e/data/html/list/   listinfo.php和alllistinfo.php

<font color="#666666">备注:多选框蓝色为未审核信息;发布者红色为会员投稿;信息ID粗体为未生成,点击ID可刷新页面.</font>前面加以下

<input type="text" name="add_listtags" id="add_listtags" size="50" value="" />
<input type="button" name="Submit" value="选择" onclick="window.open('tags/ChangeTags.php?form=listform&field=add_listtags<?=$ecms_hashur['ehref']?>','','width=700,height=550,scrollbars=yes');">
<input type="submit" name="Submit100" value="批量添加TAGS" onClick="document.listform.enews.value='AddTags_all';document.listform.action='ecmsinfo.php';">
<input type="submit" name="Submit99" value="批量复制TAGS到关键词" onClick="document.listform.enews.value='CopyTag2Key';document.listform.action='ecmsinfo.php';">
回复列表
1.
支持一下
2.
支持下
3.
支持一下
4.
支持
5.
支持一下
相关问题

仿站网专注于帝国CMS仿站及二次开发、模板定制等各种有关帝国CMS程序疑难杂症!
Copyright@2016-2023 汇鑫网络工作室 版权所有 仿站网 www.ecmsw.cn
鲁ICP备17005488号-1 鲁公网安备 37018102000481号