当前位置:首页 > CMS教程 > 帝国cms > 列表

帝国cms后台批量添加tags和前台录入tags的方法

发布:smiling 来源: PHP粉丝网  添加日期:2014-03-30 16:03:39 浏览: 评论:0 

修改步骤:

1、以下代码加入到admin/ecmsinfo.php 在任意2个elseif中间插入就行:

  1. elseif($enews=="AddTags_all")//列表批量添加Tags{$classid=$_POST['classid'];$id=$_POST['id'];$tags=$_POST['add_listtags'];$newstime=time();eInsertTags2($tags,$classid,$id,$newstime);} 

2、将以下代码加入到class/uesrfun.php

  1. //加入TAG表 
  2. function eInsertTags2($tags,$classid,$id,$newstime){ 
  3.         global $empire,$dbtbpre,$class_r
  4.         if(!trim($tags)) 
  5.         { 
  6.                 printerror("TAGS信息不能为空""", 1, 0, 1); 
  7.         return ''
  8.         }            
  9.     $count = count($id); //统计ID数量 
  10.     $tags = RepPostVar($tags); 
  11.     $tag = explode(","$tags); 
  12.     if (emptyempty($count)) 
  13.     { 
  14.         printerror("未选择信息ID""", 1, 0, 1); 
  15.     } 
  16.     if (count($tag)>1) 
  17.     { 
  18.         printerror("只能添加一个TAGS词""", 1, 0, 1); 
  19.     } 
  20.      
  21.     $classid=(int)$classid
  22.     $id[$i] = (int)$id[$i]; 
  23.     $mid=(int)$class_r[$classid][modid]; 
  24.         for($i=0;$i<$count;$i++) 
  25.         { 
  26.                 $tbname=$class_r[$classid][tbname];//获取表名 
  27.         $r=$empire->fetch1("select tagid from {$dbtbpre}enewstags where tagname='$tags' limit 1"); 
  28.         $t = $empire->fetch1("select infotags from {$dbtbpre}ecms_".$tbname." where id='$id[$i]'"); 
  29.         $taga=$t['infotags'].",".$tags//组合TAGS                                                  
  30.         $tagb[$i] = explode(",",$taga); //设置数组               
  31.         $tagc=array_values(array_unique($tagb[$i])); //数组排重              
  32.         for($t=0;$t<count($tagc);$t++)  
  33.         {//二级子循环TAGS数组输出 
  34.             $newtags[$i].= ",".$tagc[$t]; 
  35.         } 
  36.                 if($r[tagid]) 
  37.                 { 
  38.                         $datar=$empire->fetch1("select tagid,classid,newstime from {$dbtbpre}enewstagsdata where tagid='$r[tagid]' and id='$id[$i]' and mid='$mid' limit 1"); 
  39.                         if($datar[tagid]) 
  40.                         { 
  41.                                 if($datar[classid]!=$classid||$datar[newstime]!=$newstime
  42.                                 { 
  43.                                         $empire->query("update {$dbtbpre}enewstagsdata set classid='$classid',newstime='$newstime' where tagid='$r[tagid]' and id='$id[$i]' and mid='$mid' limit 1"); 
  44.                                 } 
  45.                         } 
  46.                         else 
  47.                         { 
  48.                                 $empire->query("update {$dbtbpre}enewstags set num=num+1 where tagid='$r[tagid]'"); 
  49.                 $empire->query("update {$dbtbpre}ecms_".$tbname." set infotags='".trim($newtags[$i],",")."' where id='$id[$i]'"); 
  50.                                 $empire->query("insert into {$dbtbpre}enewstagsdata(tagid,classid,id,newstime,mid) values('$r[tagid]','$classid','$id[$i]','$newstime','$mid');"); 
  51.                         } 
  52.                 } 
  53.                 else 
  54.                 { 
  55.                         $empire->query("update {$dbtbpre}ecms_".$tbname." set infotags='".trim($newtags[$i],",")."' where id='$id[$i]'"); 
  56.             $empire->query("insert into {$dbtbpre}enewstags(tagname,num,isgood,cid) values('$tags',1,0,0);"); 
  57.                         $tagid=$empire->lastid(); 
  58.                         $empire->query("insert into {$dbtbpre}enewstagsdata(tagid,classid,id,newstime,mid) values('$tagid','$classid','$id[$i]','$newstime','$mid');"); 
  59.                 } 
  60.         } 
  61.     printerror("批量添加TAGS成功""", 1, 0, 1); 

3、信息管理列表模板最后一列修改成以下代码 e/data/html/list/文件夹内的listinfo.php文件.

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

修改为:

  1. <td height="25" colspan="8"
  2.       <table width="100%" border="0" cellpadding="0" cellspacing="0"
  3.           <tr>  
  4.             <td width="68%" height="25">  
  5.               <font color="#666666">备注:多选框蓝色为未审核信息;发布者红色为会员投稿;信息ID粗体为未生成,点击ID可刷新页面.</font> 
  6.             </td> 
  7.             <td width="32%"> <input type="text" name="add_listtags" id="add_listtags" size="50" value="" /> 
  8.       <input type="submit" name="Submit100" value="添加TAGS" onClick="document.listform.enews.value='AddTags_all';document.listform.action='ecmsinfo.php';"
  9.       </td> 
  10.           </tr> 
  11.         </table>    
  12.       </td> 

增加前台投稿录入tags功能,备份 /e/class/qinfofun.php 文件后,打开编辑:

$sql=$empire->query("insert into {$dbtbpre}ecms_".$tbname.

将这段代码:

  1. $sql=$empire->query("insert into {$dbtbpre}ecms_".$tbname."(classid,onclick,newspath,keyboard,keyid,userid,username,ztid,checked,istop,truetime,ismember,dokey,isgood,titlefont,titleurl,filename,groupid,newstempid,plnum,firsttitle,isqf,userfen,totaldown,closepl,havehtml,lastdotime,haveaddfen,infopfen,infopfennum,votenum,stb,ttid".$ret_r[0].") values('$classid',0,'$newspath','$keyboard','$keyid','".$muserid."','".addslashes($musername)."','$ztid','$checked',0,'$truetime',1,1,0,'$titlefont','','',0,'$newstempid',0,0,'$isqf',0,0,0,'$havehtml','$truetime','$haveaddfen',0,0,0,'$ret_r[4]','$ttid'".$ret_r[1].");"); 

替换为:

  1. $sql=$empire->query("insert into {$dbtbpre}ecms_".$tbname."(classid,onclick,newspath,keyboard,keyid,userid,username,ztid,checked,istop,truetime,ismember,dokey,isgood,titlefont,titleurl,filename,groupid,newstempid,plnum,firsttitle,isqf,userfen,totaldown,closepl,infotags,havehtml,lastdotime,haveaddfen,infopfen,infopfennum,votenum,stb,ttid".$ret_r[0].") values('$classid',0,'$newspath','$keyboard','$keyid','".$muserid."','".addslashes($musername)."','$ztid','$checked',0,'$truetime',1,1,0,'$titlefont','','',0,'$newstempid',0,0,'$isqf',0,0,0,'".addslashes($add[infotags])."','$havehtml','$truetime','$haveaddfen',0,0,0,'$ret_r[4]','$ttid'".$ret_r[1].");"); 

其实就是新增了两个部分,自己仔细看,然后找到,扣点记录,在这行上面新增:

  1. //TAGS 
  2.                 $oldinfotags=''
  3.                 if($add['infotags']&&$add['infotags']<>$oldinfotags
  4.                      { 
  5.                 $tagtime=emptyempty($newstime)?time():to_time($newstime); 
  6.                 eInsertTags($add['infotags'],$classid,$id,$tagtime); 

保存文件,在投稿表单里新增tags的投稿框即可,如:

<input name="infotags" type="text" id="infotags" value="" size="">

Tags: 前台 后台 方法 tags

分享到: