需求背景: 之前發布了不少文章,后來發現之前的這些文章當時發布時都沒有添加tag標簽,然而現在需要都添加上tag標簽,然而這個在默認的織夢后臺是沒辦法批量實現的,只能一篇篇文章去修改。

思考: 織夢原本的文章批量管理中有這么幾項,看圖:

根據這個自動關鍵詞、批量增加屬性、批量刪除屬性這個思路來進行批量tag標簽操作。


修改后的具體效果如下: 


具體實現步驟:三步

1、打開dede/templets/content_list.htm,找到:

<a href="javascript:;" onClick="cAtts('attsDel',event,this)" class="coolbg">&nbsp;刪除屬性&nbsp;</a> 
在他后邊添加:

<a class="coolbg" onclick="EditArcs('tagsEdit',event,this)" href="javascript:;"> 修改tags標簽 </a> 

2、打開dede/js/list.js,在文件最后邊添加:

/*批量修改文檔*/ 
function EditArcs(jname,e,obj){ 
var qstr=getCheckboxItem(); 
if(qstr=='') 
{ 
alert('必需選擇一個或多個文檔!'); 
return; 
} 
LoadQuickDiv(e, 'archives_do.php?dopost=batchEditArchives&qstr='+qstr+'&dojob='+jname+'&rnd='+Math.random(), 'tagsEditDlg', '450px', '160px'); 
ChangeFullDiv('show'); 
} 

3.打開dede/archives_do.php,這個文件的最后四行是:

<?php 
//AJAX窗體結束 
} 
?> 

替換成:


<?php 
//AJAX 窗體結束 
} 
/* 
 * -------------------------------------------- 
 * function batchEditArchives(){} 
 * 批量修改文檔 
 * -------------------------------------------- 
 * */ 
else if ($dopost == 'batchEditArchives') 
{ 
    if( !empty($aid) && empty($qstr) ) 
    { 
        $qstr = $aid; 
    } 
    $dojobname = '修改TAG標簽'; 
    AjaxHead(); 
    //輸出AJAX可移動窗體 
    $divname = 'tagsEditDlg'; 
    echo "<div class='title' onmousemove=\"DropMoveHand('{$divname}', 225);\" onmousedown=\"DropStartHand();\" onmouseup=\"DropStopHand();\">\r\n"; 
    echo "  <div class='titLeft'>{$dojobname}</div>\r\n"; 
    echo "  <div class='titRight'><img src='images/ico-close.gif' style='cursor:pointer;' onclick='HideObj(\"{$divname}\");ChangeFullDiv(\"hide\");' alt='封鎖' title='封鎖' /></div>\r\n"; 
    echo "</div>\r\n"; 
    echo "<form name='tagsEditDlgform' action='archives_do.php' method='post'>\r\n"; 
    echo "<input type='hidden' name='dopost' value='{$dojob}' />\r\n"; 
    echo "<input type='hidden' name='qstr' value='{$qstr}' />\r\n"; 
    echo "<table width='100%' style='margin-top:6px;z-index:9000;'>\r\n"; 
?> 
<tr height='28'> 
    <td width="80" class='bline'>&nbsp;標 簽:</td> 
    <td class='bline'> 
    <input type='text' name='tags' id="tags" value='' />(','號分隔,單個標簽小于12字節) 
    </td> 
</tr> 
<tr height='32'> 
    <td width="80" class='bline'>&nbsp;文檔ID:</td> 
    <td class='bline'> 
        <input type='text' name='tmpids' value="<?php echo $qstr; ?>" style='width:310px;overflow:hidden;' /> 
    </td> 
</tr> 
<tr height='32'> 
    <td colspan='2' align='center' style='padding-top:12px'> 
        <input name="imageField" type="image" src="images/button_ok.gif" width="60" height="22" class="np" border="0" style="cursor:pointer" /> 
        &nbsp;&nbsp; 
        <img src="images/button_back.gif" width="60" height="22" border="0" onclick='HideObj("<?php echo $divname; ?>");ChangeFullDiv("hide");' style="cursor:pointer" /> 
    </td> 
</td> 
</tr> 
</table> 
</form> 
<?php 
//AJAX 窗體結束 
} 
//修改標簽結束 
/* 
 * ------------------------------ 
 * 修改標簽詳細操作 
 * function tagsEdit(){} 
 * ------------------------------ 
 * 
 * */ 
elseif ($dopost == 'tagsEdit'){ 
    //CheckPurview('a_Commend,sys_ArcBatch'); 
    if( !empty($aid) && empty($qstr) ) 
    { 
        $qstr = $aid; 
    } 
    if($qstr=='') 
    { 
        ShowMsg("參數無效!", $ENV_GOBACK_URL); 
        exit(); 
    } 
  
    if(empty($tags)) 
    { 
        ShowMsg("必需輸入tags標簽!", $ENV_GOBACK_URL); 
        exit(); 
    } 
    $tags = str_replace(',', ',', $tags); 
    $tagss = explode(',',$tags); 
    if(empty($tagss)){ 
        ShowMsg("必需輸入tags標簽!", $ENV_GOBACK_URL); 
        exit(); 
    } 
  
    $arcids = ereg_replace('[^0-9,]','',ereg_replace('`', ',', $qstr)); 
    $arcids_arr = explode(',', $arcids); 
    if (empty($arcids_arr)) { 
        ShowMsg("參數無效!", $ENV_GOBACK_URL); 
        exit(); 
    } 
  
    foreach($arcids_arr as $id){ 
        /* 
        * 處理修改后的Tag 
        */ 
        $oldtag = GetTags($id); 
        $oldtags = explode(',',$oldtag); 
        foreach($tagss as $tag) 
        { 
            $tag = trim($tag); 
            if(isset($tag[255]) || $tag!=stripslashes($tag)) 
            { 
                continue; 
            } 
            if(!in_array($tag,$oldtags)) 
            { 
                InsertOneTag($tag,$id); 
            } 
        } 
        foreach($oldtags as $tag) 
        { 
            if(!in_array($tag,$tagss)) 
            { 
                $dsql->ExecuteNoneQuery("Delete From `js_taglist` where aid='$id' And tag like '$tag' "); 
                $dsql->ExecuteNoneQuery("Update `js_tagindex` set total=total-1 where tag like '$tag' "); 
            } 
            else 
            { 
                $dsql->ExecuteNoneQuery("Update `js_taglist` set `arcrank` = '$arcrank', `typeid` = '$typeid' where tag like '$tag' "); 
            } 
        } 
    } 
    ShowMsg("成功修改選中文檔的tags標簽!", $ENV_GOBACK_URL); 
    exit(); 
  
}