#How to delete document pictures in Dede?
Dede deletes the document and deletes the pictures in the article. This function is very important for friends who are doing picture websites, especially when deleting the collected articles, a lot of useless pictures will be generated. This The program does not guarantee that 100% of the images in the Body can be obtained, but during my personal use, I found no problems.
Recommended study: Dream Weaver cms
First, create the "extend.func.php" file in the "/include" directory. Then, save the following content in There are three functions in the "extend.func.php" file:
The code is as follows:
//解析body数据,获得所有图片的绝对地址 function GetPicsTruePath($body,$litpic) { $delfiles = array();//存储图片地址数据 if(!empty($litpic)) { $litpicpath = GetTruePath(); $litpicpath .= $litpic; $delfiles[] = $litpicpath;//缩略图地址 } preg_match_all("/src=[\"|'|\S|\s]([^ title="liehuo.net" |\/|>]*){0,}(([^>]*)\.(gif|jpg|png))/isU",$body,$tmpdata); $picspath = array_unique($tmpdata[2]);//body中所有图片的地址 foreach($picspath as $tmppath) { $path = GetTruePath();//获得绝对路径 $picpath = preg_replace("/[a-zA-z]+:\/\/[^ |\/|\s]*/",'',$tmppath);//去掉网址部分 $path .=$picpath; $delfiles[] = $path;//保存处理后的数据 } return $delfiles; } //获得文章Body数据 function GetArcBody($aid) { global $dsql; $query = "SELECT [url=mailto:dede_addonarticle.body]dede_addonarticle.body[/url] FROM [url=mailto:%60dede_addonarticle]`dede_addonarticle[/url]` WHERE [url=mailto:dede_addonarticle.aid]dede_addonarticle.aid[/url] = '$aid'"; $row = $dsql->GetOne($query); if(is_array($row)) return $row; else return false; } //写入日志文件 function WriteToDelFiles($msg)//删除文章的时候会通过此函数记录日志 { if(empty($msg)) $savemsg="未获得消息"; else $savemsg = $msg; $errorFile = dirname(__FILE__).'/../data/del_body_file.txt';//删除记录文件 $fp = @fopen($errorFile, 'a'); @fwrite($fp,"\r\n{$savemsg}"); @fclose($fp); }
Next open the "/dede/inc/inc_batchup.php" file.
1: Add below line 33, that is, below "$arcRow = $dsql->GetOne($arcQuery);":
$arcBodyRow = GetArcBody($aid);
2: Add below line 138, that is, above "return true;":
The code is as follows:
//解析Body中的资源,并删除 $willDelFiles = GetPicsTruePath($arcBodyRow['body'],$arcRow['litpic']); $nowtime = time(); $executetime = MyDate('Y-m-d H:i:s',$nowtime);//获得执行时间 $msg = "\r\n文章标题:$arcRow[title]"; WriteToDelFiles($msg); if(!empty($willDelFiles)) { foreach($willDelFiles as $file) { if(file_exists($file) && !is_dir($file)) { if(unlink($file)) $msg = "\r\n位置:$file\r\n结果:删除成功!\r\n时间:$executetime"; else $msg = "\r\n位置:$file\r\n结果:删除失败!\r\n时间:$executetime"; } else $msg = "\r\n位置:$file\r\n结果:文件不存!\r\n时间:$executetime"; WriteToDelFiles($msg); }//END foreach } else { $msg = "\r\n未在Body中解析到数据\r\nBody原始数据:$arcBodyRow[body]\r\n时间:$executetime"; WriteToDelFiles($msg); }
At this point, all modifications are completed. When deleting the article, the program will Analyze the image address in the Body, then delete it. And generate a log file: del_body_file.txt in the /data/ directory.
The above is the detailed content of How to delete document pictures in Dede. For more information, please follow other related articles on the PHP Chinese website!