說(shuō)明:
因?yàn)榫W(wǎng)站多地區(qū)所需,需要用到文檔復(fù)制功能钾菊,就在網(wǎng)上搜尋了一些大神寫的復(fù)制欄目文檔的功能帅矗,但是Copy下來(lái)以后,發(fā)現(xiàn)功能以及代碼不是很完善煞烫,所以就完善了一番浑此,完善了起始ID、重復(fù)文檔跳過(guò)滞详,生成文章的顯示問(wèn)題等問(wèn)題凛俱,為了以后能用到此功能的童鞋,可以使用的更順暢料饥,本人只是初入PHP的一個(gè)小白蒲犬,代碼中還有不足的地方,請(qǐng)各位大神指教岸啡,我一定竭盡全力去更加完善原叮。
第一步:修改模板文件
修改文件dede/templets/content_batch_up.htm? ?其中dede是項(xiàng)目的后臺(tái)路徑,已修改的替換新路徑
1巡蘸、修改頭部腳本函數(shù)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奋隶、添加復(fù)制欄目按鈕
在模板文件中查找
<input name="action" type="radio" class="np" value="move" id="moveradio" onClick="ShowHideMove()" />移動(dòng)文檔
在上邊代碼后面添加
<input name="action" type="radio" class="np tarrow-fool" value="copy" id="copyradio" onClick="ShowHideMove()" />復(fù)制欄目文檔
第二步:修改操作文件
修改文件dede/content_batchup_action.php? ?其中dede是項(xiàng)目的后臺(tái)路徑,已修改的替換新路徑
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文件中查找下邊代碼搬味,細(xì)心的童鞋可以發(fā)現(xiàn)“//修正縮略圖錯(cuò)誤”這個(gè)操作出現(xiàn)了兩次境氢,應(yīng)該是開(kāi)發(fā)人員的惡搞吧,可以刪除掉該操作
//刪除空標(biāo)題內(nèi)容
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();
}
//修正縮略圖錯(cuò)誤
else if($action=='modddpic')
{
? ? $dsql->ExecuteNoneQuery("UPDATE #@__archives SET litpic='' WHERE trim(litpic)='litpic' ");
? ? ShowMsg("成功修正縮略圖錯(cuò)誤产还!","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("無(wú)法檢測(cè)復(fù)制到的新欄目的信息嘀趟,不能完成操作脐区!","javascript:;");
? ? ? ? exit();
? ? }
? ? if($typenew['ispart']!=0)
? ? {
? ? ? ? $dsql->Close();
? ? ? ? ShowMsg("你不能把數(shù)據(jù)復(fù)制到非最終列表的欄目!","javascript:;");
? ? ? ? exit();
? ? }
? ? if($typenew['channeltype']!=$typeold['channeltype'])
? ? {
? ? ? ? $dsql->Close();
? ? ? ? ShowMsg("不能把數(shù)據(jù)復(fù)制到內(nèi)容類型不同的欄目她按!","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);//第二個(gè)參數(shù)是排序值牛隅,參考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()轉(zhuǎn)換; 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()轉(zhuǎn)換酌泰; adan;090508
? ? ? ? $keywords = $row->keywords;
? ? ? ? require_once(DEDEADMIN."/inc/inc_archives_functions.php");
? ? ? ? //重復(fù)文檔跳過(guò)
? ? ? ? $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("無(wú)法獲得主鍵媒佣,因此無(wú)法進(jìn)行后續(xù)操作!","-1");
? ? ? ? ? ? exit();
? ? ? ? }
? ? ? ? //加入數(shù)據(jù)表#@__archives的SQL語(yǔ)句
? ? ? ? //----------------------------------
? ? ? ? $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("把數(shù)據(jù)保存到數(shù)據(jù)庫(kù)主表 `#@__archives` 時(shí)出錯(cuò)陵刹,請(qǐng)把相關(guān)信息提交給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("沒(méi)找到當(dāng)前模型[{$channelid}]的主表信息,無(wú)法完成操作!也糊。","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("把數(shù)據(jù)保存到數(shù)據(jù)庫(kù)附加表 `{$addtable}` 時(shí)出錯(cuò)炼蹦,請(qǐng)把相關(guān)信息提交給DedeCms官方。".str_replace('"','',$gerr),"javascript:;");
? ? ? ? ? ? exit();
? ? ? ? }
? ? ? ? else $tdd++;
? ? }
? ? if($tdd>0)
? ? {
? ? ? ? $jumpurl = "makehtml_archives_action.php?typeid=$newtypeid&pagesize=20";
? ? ? ? ShowMsg("成功復(fù)制了 $tdd 條記錄狸剃,準(zhǔn)備重新生成HTML...",$jumpurl);
? ? }
? ? else ShowMsg("完成操作掐隐,沒(méi)復(fù)制任何數(shù)據(jù)...","javascript:;");
? ? exit();
}
這就是此次的完善,感覺(jué)還可以的點(diǎn)個(gè)贊再走吧钞馁,分享也不是不可以哦虑省,收藏就更好了!