帅与我无缘 發表於 2023-8-21 00:00:00

dedecms删除文章同时也删除附件的修改方法

<p>
        <span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>首先添加两个函数 </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <p class="right">
                <span><u>复制代码</u></span></p>
        <p>
                代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        /* <br>
        根据文档id获取文档的body部分 <br>
        */ <br>
        function getArcBody($arcid) <br>
        { <br>
        global $dsql; <br>
        if(empty($arcid)) return ; <br>
        $body = ''; <br>
        $query = "select arc.*,ch.addtable,ch.fieldset from `dede_arctiny` as arc left join `dede_channeltype` as ch on arc.channel=ch.id where arc.id=$arcid"; <br>
        $row = $dsql-&gt;GetOne($query); <br>
        if(empty($row)) return ; <br>
        $addtable = $row['addtable']; <br>
        $fieldset = $row['fieldset']; <br>
        include_once(DEDEINC.'./dedetag.class.php'); <br>
        $dtp = new DedeTagParse(); <br>
        $dtp-&gt;SetNameSpace('field','&lt;','&gt;'); <br>
        $dtp-&gt;LoadSource($fieldset); <br>
        if(is_array($dtp-&gt;CTags)) <br>
        { <br>
        foreach($dtp-&gt;CTags as $tid=&gt;$tag) <br>
        { <br>
        if($tag-&gt;GetAtt('type')=='htmltext') <br>
        { <br>
        $body = $tag-&gt;GetName(); <br>
        break; <br>
        } <br>
        } <br>
        } <br>
        if(!empty($body)) <br>
        { <br>
        $query = "select $body from `$addtable` where aid=$arcid"; <br>
        $row = $dsql-&gt;GetOne($query); <br>
        $body = $row[$body]; <br>
        return $body; <br>
        } <br>
        return ; <br>
        } <br>
        /* <br>
        解析文档内容的本地<u>图片</u>图片 <br>
        */ <br>
        function get_img_from_body($body) <br>
        { <br>
        $result = array(); <br>
        if(empty($body)) <br>
        return $result; <br>
        preg_match_all('/\ssrc=([\"|\'])([^\1]*?)\.(gif|jpg|jpeg|png)\1/',$body,$res); <br>
        if(!empty($res)) <br>
        { <br>
        foreach($res as $k=&gt;$v) <br>
        { <br>
        $result[] = $v.'.'.$res[$k]; <br>
        } <br>
        } <br>
        return $result; <br>
        } </p>
<p>
        <br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>把这段代码贴到include/common.func.php后面, </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>接着打开后台(假设使用默认的dede作为后台)dede/inc/inc_batchup.php文件, </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>在第22行添加代码如下: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>$body = getArcBody($aid); </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>接在在第139行,就是在 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>return true; </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>上面一行加上下面的代码 </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <p class="right">
                <span><u>复制代码</u></span></p>
        <p>
                代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        if($body) <br>
        { <br>
        $img_arr = get_img_from_body($body); <br>
        if(!empty($img_arr)) <br>
        { <br>
        foreach($img_arr as $v) <br>
        { <br>
        $img_file = GetTruePath().str_replace($GLOBALS['cfg_basehost'],'',$v); <br>
        if(file_exists($img_file) &amp;&amp; !is_dir($img_file)) <br>
        @unlink($img_file); <br>
        } <br>
        } <br>
        } </p>
<p>
        <br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>这样就可以实现删除文档的时候删除字段为“htmltext”类型的中的本地图片了。 </span></p>
頁: [1]
查看完整版本: dedecms删除文章同时也删除附件的修改方法