说明:
因为网站多地区所需,需要用到文档复制功能,就在网上搜寻了一些大神写的复制栏目文档的功能,但是Copy下来以后,发现功能以及代码不是很完善,所以就完善了一番,完善了起始ID、重复文档跳过,生成文章的显示问题等问题,为了以后能用到此功能的童鞋,可以使用的更顺畅,本人只是初入PHP的一个小白,代码中还有不足的地方,请各位大神指教,我一定竭尽全力去更加完善。
第一步:修改模板文件
修改文件dede/templets/content_batch_up.htm 其中dede是项目的后台路径,已修改的替换新路径
1、修改头部脚本函数ShowHideMove()
function ShowHideMove() {
var selBox = document.getElementByIdx_x('moveradio');
var selBox2 = document.getElementByIdx_x('copyradio');//edited by adan;090508
var obj = document.getElementByIdx_x('moveField');
if(selBox.checked||selBox2.checked) obj.style.display = "block";//edited by adan;090508
else obj.style.display = "none";
}
2、添加复制栏目按钮
在模板文件中查找
<input name="action" type="radio" class="np" value="move" id="moveradio" onClick="ShowHideMove()" />移动文档
在上边代码后面添加
<input name="action" type="radio" class="np tarrow-fool" value="copy" id="copyradio" onClick="ShowHideMove()" />复制栏目文档
第二步:修改操作文件
修改文件dede/content_batchup_action.php 其中dede是项目的后台路径,已修改的替换新路径
1、在php文件中查找下边代码,然后替换成新的代码
旧:
if($typeid!=0)
{
$ids = GetSonIds($typeid);
$gwhere .= " AND typeid IN($ids) ";
}
新:
if($typeid!=0 && $action!='copy')
{
$ids = GetSonIds($typeid);
$gwhere .= " AND typeid IN($ids) ";
}else if($typeid!=0 && $action=='copy')
{
$gwhere .= " AND typeid = '$typeid' ";
}
2、在php文件中查找下边代码,细心的童鞋可以发现“//修正缩略图错误”这个操作出现了两次,应该是开发人员的恶搞吧,可以删除掉该操作
//删除空标题内容
else if($action=='delnulltitle')
{
$dsql->SetQuery("SELECT id FROM #@__archives WHERE trim(title)='' ");
$dsql->Execute('x');
$tdd = 0;
while($row = $dsql->GetObject('x'))
{
if(DelArc($row->id)) $tdd++;
}
ShowMsg("成功删除 $tdd 条记录!","javascript:;");
exit();
}
//修正缩略图错误
else if($action=='modddpic')
{
$dsql->ExecuteNoneQuery("UPDATE #@__archives SET litpic='' WHERE trim(litpic)='litpic' ");
ShowMsg("成功修正缩略图错误!","javascript:;");
exit();
}
查找到以后在此代码之后加入下列代码:
else if($action=='copy')
{
if(empty($typeid))
{
ShowMsg('该操作必须指定栏目!','javascript:;');
exit();
}
$typeold = $dsql->GetOne("Select * From `#@__arctype` where id='$typeid'; ");
$typenew = $dsql->GetOne("Select * From `#@__arctype` where id='$newtypeid'; ");
if(!is_array($typenew))
{
$dsql->Close();
ShowMsg("无法检测复制到的新栏目的信息,不能完成操作!","javascript:;");
exit();
}
if($typenew['ispart']!=0)
{
$dsql->Close();
ShowMsg("你不能把数据复制到非最终列表的栏目!","javascript:;");
exit();
}
if($typenew['channeltype']!=$typeold['channeltype'])
{
$dsql->Close();
ShowMsg("不能把数据复制到内容类型不同的栏目!","javascript:;");
exit();
}
$gwhere .= " And channel='".$typenew['channeltype']."' And title like '%$keyword%'";
$ch = $dsql->GetOne("Select addtable From `#@__channeltype` where id={$typenew['channeltype']} ");
$addtable = $ch['addtable'];
// 2020-4-8 update
$dsql->SetQuery("Select * From `#@__archives` $gwhere");
// 2020-4-8 update
// $dsql->SetQuery("Select * From `#@__archives` where typeid='$typeid'");
$dsql->Execute('c');
$tdd = 0;
while($row = $dsql->GetObject('c'))
{
$senddate = time();
$sortrank = AddDay($senddate,0);//第二个参数是排序值,参考article_add.php
$ID = $row->id;
$typeid = $newtypeid;//$newtypeid
$sortrank = $row->sortrank;
$flag = $row->flag;
$ismake = $row->ismake;
$channelid = $row->channel;
$arcrank = $row->arcrank;
$click = $row->click;
$money = $row->money;
$title = addslashes($row->title);//需要添加addslashes()转换; adan;090508
$shorttitle = $row->shorttitle;
$color = $row->color;
$writer = $row->writer;
$source = $row->source;
$litpic = $row->litpic;
$pubdate = $row->pubdate;
$adminid = $cuserLogin->getUserID();
$notpost = $row->notpost;
$description = addslashes($row->description);//需要添加addslashes()转换; adan;090508
$keywords = $row->keywords;
require_once(DEDEADMIN."/inc/inc_archives_functions.php");
//重复文档跳过
$repetition = $dsql->GetOne("Select id From `#@__archives` where title='$title' and typeid = '$typeid' ");
if($repetition && $repetition['id'] > 0){
continue;
}
//生成文档ID
$arcID = GetIndexKey($arcrank,$typeid,$sortrank,$channelid,$senddate,$adminid);
if(empty($arcID))
{
ShowMsg("无法获得主键,因此无法进行后续操作!","-1");
exit();
}
//加入数据表#@__archives的SQL语句
//----------------------------------
$inQuery = "INSERT INTO `#@__archives`(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,
color,writer,source,litpic,pubdate,senddate,mid,lastpost,scores,goodpost,badpost,notpost,description,keywords,filename)
VALUES ('$arcID','$typeid','','$sortrank','$flag','$ismake','$channelid','$arcrank','0','$money',
'$title','$shorttitle','$color','$writer','$source','$litpic','$pubdate','$senddate',
'$adminid','0','0','0','0','0','$description','$keywords','');";
if(!$dsql->ExecuteNoneQuery($inQuery))
{
$gerr = $dsql->GetError();
$dsql->ExecuteNoneQuery("Delete From `#@__arctiny` where id='$arcID'");
ShowMsg("把数据保存到数据库主表 `#@__archives` 时出错,请把相关信息提交给DedeCms官方。".str_replace('"','',$gerr),"javascript:;");
exit();
}
//保存到附加表
$cts = $dsql->GetOne("Select addtable From `#@__channeltype` where id='$channelid' ");
$addtable = trim($cts['addtable']);
if(empty($addtable))
{
$dsql->ExecuteNoneQuery("Delete From `#@__archives` where id='$arcID'");
$dsql->ExecuteNoneQuery("Delete From `#@__arctiny` where id='$arcID'");
ShowMsg("没找到当前模型[{$channelid}]的主表信息,无法完成操作!。","javascript:;");
exit();
}
$useip = GetIP();
$redirecturl = $addRow['redirecturl'];
$templet = $addRow['templet'];
$addRow = $dsql->GetOne("Select * from `{$addtable}` where aid='$ID'");
$body = addslashes($addRow["body"]);
$query = "INSERT INTO `{$addtable}`(aid,typeid,redirecturl,templet,userip,body) Values('$arcID','$typeid','$redirecturl','$templet','$useip','$body')";
if(!$dsql->ExecuteNoneQuery($query))
{
$gerr = $dsql->GetError();
$dsql->ExecuteNoneQuery("Delete From `#@__archives` where id='$arcID'");
$dsql->ExecuteNoneQuery("Delete From `#@__arctiny` where id='$arcID'");
ShowMsg("把数据保存到数据库附加表 `{$addtable}` 时出错,请把相关信息提交给DedeCms官方。".str_replace('"','',$gerr),"javascript:;");
exit();
}
else $tdd++;
}
if($tdd>0)
{
$jumpurl = "makehtml_archives_action.php?typeid=$newtypeid&pagesize=20";
ShowMsg("成功复制了 $tdd 条记录,准备重新生成HTML...",$jumpurl);
}
else ShowMsg("完成操作,没复制任何数据...","javascript:;");
exit();
}
这就是此次的完善,感觉还可以的点个赞再走吧,分享也不是不可以哦,收藏就更好了!

网友评论