当前位置:首页 > CMS教程 > DeDecms > 列表

DEDE删除文章同时删除附件解决代码

发布:smiling 来源: PHP粉丝网  添加日期:2015-03-24 16:38:05 浏览: 评论:0 

DEDE删除文章同时删除附件解决代码:

  1. /* 
  2. 根据文档id获取文档的body部分 
  3. */ 
  4. function getArcBody($arcid) 
  5. { 
  6. global $dsql; 
  7. if(emptyempty($arcid)) return ; 
  8. $body = ''; 
  9. $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"; 
  10. $row = $dsql->GetOne($query); 
  11. if(emptyempty($row)) return ; 
  12. $addtable = $row['addtable']; 
  13. $fieldset = $row['fieldset']; 
  14. include_once(DEDEINC.'./dedetag.class.php教程'); 
  15. $dtp = new DedeTagParse(); 
  16. $dtp->SetNameSpace('field','<','>'); 
  17. $dtp->LoadSource($fieldset); 
  18. if(is_array($dtp->CTags)) 
  19. { 
  20. foreach($dtp->CTags as $tid=>$tag) 
  21. { 
  22. if($tag->GetAtt('type')=='htmltext') 
  23. { 
  24. $body = $tag->GetName(); 
  25. break; 
  26. } 
  27. } 
  28. } 
  29. if(!emptyempty($body)) 
  30. { 
  31. $query = "select $body from `$addtable` where aid=$arcid"; 
  32. $row = $dsql->GetOne($query); 
  33. $body = $row[$body]; 
  34. return $body; 
  35. } 
  36. return ; 
  37. } 
  38. /* 
  39. 解析文档内容的本地图片图片 
  40. */ 
  41. function get_img_from_body($body) 
  42. { 
  43. $result = array(); 
  44. if(emptyempty($body)) 
  45. return $result; 
  46. preg_match_all('/ssrc=(["|'])([^1]*?).(gif|jpg|jpeg|png)1/',$body,$res); 
  47. if(!emptyempty($res[2]))//开源软件:phpfensi.com 
  48. { 
  49. foreach($res[2] as $k=>$v) 
  50. { 
  51. $result[] = $v.'.'.$res[3][$k]; 
  52. } 
  53. } 
  54. return $result; 
  55. } 

把这段代码贴到include/common.func.php后面,接着打开后台,假设使用默认的dede作为后台,dede/inc/inc_batchup.php文件,在第22行添加代码如下:

$body = getArcBody($aid);

接在在第139行,就是在 return true;上面一行加上下面的代码:

  1. if($body) 
  2. { 
  3. $img_arr = get_img_from_body($body); 
  4. if(!emptyempty($img_arr)) 
  5. { 
  6. foreach($img_arr as $v) 
  7. { 
  8. $img_file = GetTruePath().str_replace($GLOBALS['cfg_basehost'],'',$v); 
  9. if(file_exists($img_file) && !is_dir($img_file)) 
  10. @unlink($img_file); 
  11. } 
  12. } 
  13. } 

这样就可以实现删除文档的时候删除字段为“htmltext”类型的中的本地图片了.

Tags: DEDE删除文章 DEDE删除附件

分享到: