The method of deleting articles and attachments by dedecms
This article will explain in detail the method of deleting articles and attachments on dedecms. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
How does dedecms delete articles as well as attachments?
The modification method of deleting articles and attachments by dedecms
Dedecms delete articles also delete attachments to modify the method, the use of dedecms friends can refer to.
First add two functions
The code is as follows:
/ * get the body part of the document according to the document id * / function getArcBody ($arcid) {global $dsql; if (empty ($arcid)) return; $body =''; $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"; $row = $dsql- > GetOne ($query); if (empty ($row) return; $addtable = $row ['addtable']; $fieldset = $row [' fieldset'] Include_once (DEDEINC.'./dedetag.class.php'); $dtp = new DedeTagParse (); $dtp- > SetNameSpace ('field',''); $dtp- > LoadSource ($fieldset); if ($dtp- > CTags) {foreach ($dtp- > CTags as $tid= > $tag) {if ($tag- > GetAtt (' type') = = 'htmltext') {$body = $tag- > GetName (); break;} if (! empty ($body)) {$query = "select $body from `$addtable` where aid=$arcid"; $row = $row > dsql- ($dsql-) $body = $row [$body]; return $body;} return;} / * parse the local picture of the document content * / function get_img_from_body ($body) {$result = array (); if (empty ($body)) return $result; preg_match_all ('/\ ssrc= ([\ "|\']) ([^\ 1] *?)\. (gif | jpg | jpeg | png)\ 1 syntax. If (! empty ($res [2])) {foreach ($res [2] as $k = > $v) {$result [] = $v.'.'.$res [3] [$k];}} return $result;}
Post this code after include/common.func.php
Then open the background (assuming the default dede is used as the background) dede/inc/inc_batchup.php file
Add the code on line 22 as follows:
$body = getArcBody ($aid)
Then on line 139, that is,
Return true
Add the following code to the top line
The code is as follows:
If ($body) {$img_arr = get_img_from_body ($body); if (! empty ($img_arr)) {foreach ($img_arr as $v) {$img_file = GetTruePath (). Str_replace ($GLOBALS ['cfg_basehost'],'', $v); if (file_exists ($img_file) & &! is_dir ($img_file) @ unlink ($img_file);}
This makes it possible to delete local images with fields of type "htmltext" when you delete a document.
About dedecms delete articles and also delete attachments on the method to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.