网络建站知识发布于分享网站

当前位置:首页>>新闻中心>>CMS教程>>dedecms教程

实现Dedecms文档复制功能的添加方法

时间:2025-03-30 13:13:20    来源:    人气:1

在Dedecms中添加复制文档功能是一项非常实用的改进,能够帮助用户更高效地管理内容。以下是具体步骤,按照这些步骤操作可以轻松实现该功能。

一、打开模板文件
打开目录下的文件。
找到以下代码行:

复制代码

<a href="javascript:;">

在其下方添加以下代码:

复制代码

<a href="javascript:;">

二、修改JavaScript文件
打开文件。
找到函数:

复制代码

function moveArc(e, obj, cid){
    var qstr=getCheckboxItem();
    if(qstr==''){
        alert('必须选择一个或多个文档!');
        return;
    }
    LoadQuickDiv(e, 'archives_do.php?dopost=moveArchives&qstr='+qstr+'&channelid='+cid+'&rnd='+Math.random(), 'moveArchives', '450px', '180px');
    ChangeFullDiv('show');
}
    

在该函数下方添加函数:

复制代码

function copyArc(e, obj, cid){
    var qstr=getCheckboxItem();
    if(qstr==''){
        alert('必须选择一个或多个文档!');
        return;
    }
    LoadQuickDiv(e, 'archives_do.php?dopost=copyArchives&qstr='+qstr+'&channelid='+cid+'&rnd='+Math.random(), 'copyArchives', '450px', '180px');
    ChangeFullDiv('show');
}
    

三、修改PHP处理文件
打开文件。
找到以下代码:

复制代码

else if($dopost=='moveArchives')
{
    

在此代码块结束处(大约在第433行左右),添加以下代码:

复制代码

/*-------------------------
function copyArchives(){ }
-------------------------*/
else if($dopost=='copyArchives')
{
    CheckPurview('sys_ArcBatch');
    if(empty($totype))
    {
        require_once(DEDEINC.'/typelink.class.php');
        if( !empty($aid) && empty($qstr) ) $qstr = $aid;
        AjaxHead();
        $channelid = empty($channelid) ? 0 : $channelid;
        $tl = new TypeLink($aid);
        $typeOptions = $tl->GetOptionArray(0, $admin_catalogs, $channelid);
        $typeOptions = "<select name='totype' style='width:90%'>";
        $typeOptions .= "\r\n";
        $typeOptions .= $typeOptions."</select>";
        
        // 输出AJAX可移动窗体
        $divname = 'copyArchives';
        echo "<div class='title'"DropMoveHand('$divname', 225);\\""DropStartHand();\\""DropStopHand();\\"><br>\n";
        echo "  <div class='titLeft'>复制文档</div>\r\n";
        echo "  <div class='titRight'><img src='images/ico-close.gif' style='cursor:pointer''HideObj(\\"$divname\\");ChangeFullDiv(\\"hide\\");' alt='关闭' title='关闭' /></div>\r\n";
        echo "</div>\r\n";
        echo "<form name='quickeditform' action='archives_do.php' method='post'>\r\n";
        echo "<input type='hidden' name='dopost' value='{$dopost}' />\r\n";
        echo "<input type='hidden' name='qstr' value='{$qstr}' />\r\n";
        echo "<table width='px' style='margin-top:6px;z-index:9000'>\r\n";
        echo "";
        echo "";
        echo "  ";
        echo "";
        echo "  ";
        echo "";
        echo "  ";
        echo "";
        echo "";
        echo "";
        echo "";
        // AJAX窗体结束
    }
    else
    {
        $totype = preg_replace("#[^0-9]#", '', $totype);
        $typeInfos = $dsql->GetOne("SELECT tp.channeltype,tp.ispart,tp.channeltype,ch.maintable,ch.addtable,ch.issystem FROM `me_arctype` tp LEFT JOIN `me_channeltype` ch on ch.id=tp.channeltype WHERE tp.id='$totype' ");
        $idtype = "id";
        if(!is_array($typeInfos))
        {
            ShowMsg('参数错误!','-1');
            exit();
        }
        if($typeInfos['ispart']!=0)
        {
            ShowMsg('文档保存的栏目必须为最终列表栏目!','-1');
            exit();
        }
        if(empty($typeInfos['addtable']))
        {
            $typeInfos['maintable'] = 'me_archives';
        }
        // 增加单表模型判断
        if($typeInfos['issystem'] == -1)
        {
            $typeInfos['maintable'] = $typeInfos['addtable'];
            $idtype = "aid";
        }
        $arcids = preg_replace("#[^0-9,]#", '', preg_replace("#`#", ',', $qstr));
        $arc = '';
        $j = 0;
        $okids = array();
        $dsql->SetQuery("SELECT {$idtype},typeid FROM `{$typeInfos['maintable']}` WHERE {$idtype} in($arcids) AND channel='{$typeInfos['channeltype']}' ");
        $dsql->Execute();
        while($row = $dsql->GetArray())
        {
            if($row['typeid']!=$totype)
            {
                $dsql->ExecuteNoneQuery("insert into me_arctiny (typeid,typeid2,arcrank,channel,senddate,sortrank,mid) select typeid,typeid2,arcrank,channel,senddate,sortrank,mid from me_arctiny where id='{$row[$idtype]}'");
                $xid = $dsql->GetLastID();  
                $dsql->ExecuteNoneQuery("insert into `{$typeInfos['maintable']}`(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,color,writer,source,litpic,pubdate,senddate,mid,keywords,lastpost,scores,goodpost,badpost,voteid,notpost,description,filename,dutyadmin,tackid,mtype,weight) select case when id>'0' then '$xid'  else '' end, case when typeid>'0' then '$totype'  else '' end,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,color,writer,source,litpic,pubdate,senddate,mid,keywords ,lastpost,scores,goodpost,badpost,voteid,notpost,description,filename,dutyadmin,tackid,mtype,weight from `{$typeInfos['maintable']}` WHERE id='{$row[$idtype]}' ");
                $dsql->ExecuteNoneQuery("insert into `{$typeInfos['addtable']}`(aid,typeid,body,redirecturl,templet,userip,bigpic) select case when aid>'0' then '$xid'  else '' end,$totype,body,redirecturl,templet,userip,bigpic from `{$typeInfos['addtable']}` WHERE aid='{$row[$idtype]}' ");
                $okids[] = $row[$idtype];
                $j++;
            }
        }
        // 更新HTML
        foreach($okids as $aid)
        {
            $arc = new Archives($aid);
            $arc->MakeHtml();
        }
        ShowMsg("成功复制 $j 个文档!", $ENV_GOBACK_URL);
        exit();
    }
}
    

以上步骤完成后,您就可以在Dedecms后台使用复制文档的功能了。

相关文章

  • Dedecms 删除文档时同时清除文章中图片的方法

    Dedecms 删除文档时同时清除文章中图片的方法

    在网站建设与维护的过程中,优化代码结构和功能是提升网站性能的重要步骤。本文将介绍如何通过自定义函数实现文章删除时自动清理相关资源的功能,从而提高系统的整洁性和存储效率。以下是具体的操作步骤及代码实现。首先, 在 `/include` 目录下创建一个名为 `extend.func.php` 的文件...
    2025-03-31
  • Dedecms上传图片提示302错误ERROR的解决方法

    Dedecms上传图片提示302错误ERROR的解决方法

    在进行图片上传操作时,用户可能会遇到302错误以及带有ERROR提示的图片上传失败问题。这些问题可能由多种原因引发,因此本文将对这些情况进行整理,以帮助大家更有效地定位并解决问题。 第一种情况:图片文件本身损坏。 这种情况会导致系统返回ERROR错误提示,不过发生概率较低。如果怀疑是图片损坏导致的...
    2025-03-31
  • DEDECMS模板使用教程

    DEDECMS模板使用教程

    如果您正在寻找一种高效的方法来使用Dedecms模板搭建网站或论坛,那么本文将为您提供详尽的指导。从模板解压到最终完成配置,每一步都将清晰呈现,帮助您快速掌握整个流程。 第一步:解压Dedecms模板 将下载的Dedecms模板文件解压出来,确保所有文件完整无误。如下图所示: 第二步:获取D...
    2025-03-31
  • Dedecms Dede 附加表自定义字段与主表文章关联方法

    Dedecms Dede 附加表自定义字段与主表文章关联方法

    在使用DedeCMS开发装修网站时,设计师和设计作品之间的关联是一个重要的功能需求。通常情况下,文章(作品)的内容部分存储在主表dede_addonarticle中,而自定义字段则存储在附加表dede_archives中。为了实现这一功能,可以采用以下两种方法。 ① 根据发布人调用相关文章; ...
    2025-03-31

公众号