分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

【discuzX2】/source/function/function_delete.php数据清理函数集合分析

发布时间:2023-09-06 01:09责任编辑:苏小强关键词:暂无标签
  1. <?php
  2. /**
  3. *[Discuz!](C)2001-2099ComsenzInc.
  4. *ThisisNOTafreeware,useissubjecttolicenseterms
  5. *
  6. *$Id:function_delete.php270602012-01-0401:32:05Zsonglixin$
  7. */
  8. if(!defined(‘IN_DISCUZ‘)){
  9. exit(‘AccessDenied‘);
  10. }
  11. require_oncelibfile(‘function/home‘);
  12. /**
  13. *删除用户
  14. *@paramstring$uids待删的ID数组
  15. *@paramboolean$delpost是否包含帖子信息
  16. */
  17. functiondeletemember($uids,$delpost=true){
  18. if(!$uids){
  19. return;
  20. }
  21. //腾讯安全
  22. require_oncelibfile(‘function/sec‘);
  23. updateMemberOperate($uids,2);
  24. if($delpost){
  25. deleteattach($uids,‘uid‘);
  26. deletepost($uids,‘authorid‘);
  27. }
  28. require_oncelibfile(‘function/forum‘);
  29. foreach($uidsas$uid){
  30. my_thread_log(‘deluser‘,array(‘uid‘=>$uid));
  31. }
  32. $uids=dimplode($uids);
  33. $numdeleted=DB::result_first("SELECTCOUNT(*)FROM".DB::table(‘common_member‘)."WHEREuidIN($uids)");
  34. foreach(array(‘common_member_field_forum‘,‘common_member_field_home‘,‘common_member_count‘,‘common_member_log‘,‘common_member_profile‘,
  35. ‘common_member_verify‘,‘common_member_verify_info‘,‘common_member_status‘,‘common_member_validate‘,‘common_member_magic‘,
  36. ‘forum_access‘,‘forum_moderator‘,‘common_member_action_log‘)as$table){
  37. DB::delete($table,"uidIN($uids)");
  38. }
  39. $doids=array();
  40. $query=DB::query("SELECT*FROM".DB::table(‘home_doing‘)."WHEREuidIN($uids)");
  41. while($value=DB::fetch($query)){
  42. $doids[$value[‘doid‘]]=$value[‘doid‘];
  43. }
  44. $delsql=!empty($doids)?"doidIN(".dimplode($doids).")OR":"";
  45. DB::delete(‘home_docomment‘,"$delsqluidIN($uids)");
  46. DB::delete(‘common_domain‘,"idIN($uids)ANDidtype=‘home‘");
  47. DB::delete(‘home_feed‘,"uidIN($uids)OR(idIN($uids)ANDidtype=‘uid‘)");
  48. DB::delete(‘home_notification‘,"uidIN($uids)ORauthoridIN($uids)");
  49. DB::delete(‘home_poke‘,"uidIN($uids)ORfromuidIN($uids)");
  50. DB::delete(‘home_comment‘,"(uidIN($uids)ORauthoridIN($uids)OR(idIN($uids)ANDidtype=‘uid‘))");
  51. DB::delete(‘home_visitor‘,"uidIN($uids)ORvuidIN($uids)");
  52. DB::delete(‘home_friend‘,"uidIN($uids)ORfuidIN($uids)");
  53. DB::delete(‘home_friend_request‘,"uidIN($uids)ORfuidIN($uids)");
  54. DB::delete(‘common_invite‘,"uidIN($uids)ORfuidIN($uids)");
  55. DB::delete(‘common_myinvite‘,"touidIN($uids)ORfromuidIN($uids)");
  56. DB::delete(‘common_moderate‘,"idIN(".$uids.")ANDidtype=‘uid_cid‘");
  57. //note删除相册图片
  58. $query=DB::query("SELECTfilepath,thumb,remoteFROM".DB::table(‘home_pic‘)."WHEREuidIN($uids)");
  59. while($value=DB::fetch($query)){
  60. $pics[]=$value;
  61. }
  62. deletepicfiles($pics);
  63. //note删除相册封面图片
  64. include_oncelibfile(‘function/home‘);
  65. $query=DB::query("SELECT*FROM".DB::table(‘home_album‘)."WHEREuidIN($uids)");
  66. while($value=DB::fetch($query)){
  67. pic_delete($value[‘pic‘],‘album‘,0,($value[‘picflag‘]==2?1:0));
  68. }
  69. DB::query("DELETEFROM".DB::table(‘common_mailcron‘).",".DB::table(‘common_mailqueue‘)."USING".DB::table(‘common_mailcron‘).",".DB::table(‘common_mailqueue‘)."WHERE".DB::table(‘common_mailcron‘).".touidIN($uids)AND".DB::table(‘common_mailcron‘).".c.cid",‘UNBUFFERED‘);
  70. foreach(array(‘home_doing‘,‘home_share‘,‘home_album‘,‘common_credit_rule_log‘,‘common_credit_rule_log_field‘,
  71. ‘home_pic‘,‘home_blog‘,‘home_blogfield‘,‘home_class‘,‘home_clickuser‘,
  72. ‘home_userapp‘,‘home_userappfield‘,‘home_show‘,‘common_member‘)as$table){
  73. DB::delete($table,"uidIN($uids)");
  74. }
  75. manyoulog(‘user‘,$uids,‘delete‘);
  76. return$numdeleted;
  77. }
  78. /**
  79. *删除帖子
  80. *@paramarray$ids待删的ID数组
  81. *@paramstring$idtypeauthorid/tid/pid
  82. *@paramboolean$credit是否处理积分
  83. *@paramint$posttableidpost分表ID
  84. */
  85. functiondeletepost($ids,$idtype=‘pid‘,$credit=false,$posttableid=false,$recycle=false){
  86. global$_G;
  87. $recycle=$recycle&&$idtype==‘pid‘?true:false;
  88. if($_G[‘setting‘][‘plugins‘][HOOKTYPE.‘_deletepost‘]){
  89. $_G[‘deletepostids‘]=&$ids;
  90. $hookparam=func_get_args();
  91. hookscript(‘deletepost‘,‘global‘,‘funcs‘,array(‘param‘=>$hookparam,‘step‘=>‘check‘),‘deletepost‘);
  92. }
  93. if(!$ids||!in_array($idtype,array(‘authorid‘,‘tid‘,‘pid‘))){
  94. return0;
  95. }
  96. //notepost分表缓存
  97. loadcache(‘posttableids‘);
  98. $posttableids=!empty($_G[‘cache‘][‘posttableids‘])?($posttableid!==false&&in_array($posttableid,$_G[‘cache‘][‘posttableids‘])?array($posttableid):$_G[‘cache‘][‘posttableids‘]):array(‘0‘);
  99. if($idtype==‘pid‘){
  100. require_oncelibfile(‘function/forum‘);
  101. foreach($idsas$pid){
  102. my_post_log(‘delete‘,array(‘pid‘=>$pid));
  103. }
  104. }
  105. $count=count($ids);
  106. $idsstr=dimplode($ids);
  107. //处理积分
  108. if($credit){
  109. $tuidarray=$ruidarray=array();
  110. foreach($posttableidsas$id){
  111. $query=DB::query(‘SELECTtid,pid,first,authorid,replycredit,invisibleFROM‘.DB::table(getposttable($id))."WHERE$idtypeIN($idsstr)");
  112. while($post=DB::fetch($query)){
  113. if($post[‘invisible‘]!=-1&&$post[‘invisible‘]!=-5){
  114. if($post[‘first‘]){
  115. $tuidarray[$post[‘fid‘]][]=$post[‘authorid‘];
  116. }else{
  117. $ruidarray[$post[‘fid‘]][]=$post[‘authorid‘];
  118. if($post[‘authorid‘]>0&&$post[‘replycredit‘]>0){
  119. $replycredit_list[$post[‘authorid‘]][$post[‘tid‘]]+=$post[‘replycredit‘];
  120. }
  121. }
  122. $tids[]=$post[‘tid‘];
  123. }
  124. }
  125. }
  126. if($tuidarray||$ruidarray){
  127. require_oncelibfile(‘function/post‘);
  128. }
  129. //处理发贴的积分
  130. if($tuidarray){
  131. foreach($tuidarrayas$fid=>$tuids){
  132. updatepostcredits(‘-‘,$tuids,‘post‘,$fid);
  133. }
  134. }
  135. //处理回帖的积分
  136. if($ruidarray){
  137. foreach($ruidarrayas$fid=>$ruids){
  138. updatepostcredits(‘-‘,$ruids,‘reply‘,$fid);
  139. }
  140. }
  141. }
  142. foreach($posttableidsas$id){
  143. if($recycle){
  144. DB::query("UPDATE".DB::table(getposttable($id))."SETinvisible=‘-5‘WHEREpidIN($idsstr)");
  145. }else{
  146. foreach(array(getposttable($id),‘forum_postcomment‘)as$table){
  147. DB::delete($table,"$idtypeIN($idsstr)");
  148. }
  149. DB::delete(‘forum_trade‘,($idtype==‘authorid‘?‘sellerid‘:$idtype)."IN($idsstr)");
  150. DB::delete(‘home_feed‘,"idIN($idsstr)ANDidtype=‘".($idtype==‘authorid‘?‘uid‘:$idtype)."‘");
  151. }
  152. }
  153. if(!$recycle&&$idtype!=‘authorid‘){
  154. foreach(array(‘forum_postposition‘,‘forum_poststick‘)as$table){
  155. DB::delete($table,"$idtypeIN($idsstr)");
  156. }
  157. }
  158. if($idtype==‘pid‘){
  159. DB::delete(‘forum_postcomment‘,"rpidIN($idsstr)");
  160. DB::delete(‘common_moderate‘,"idIN($idsstr)ANDidtype=‘pid‘");
  161. }
  162. if($replycredit_list){
  163. $query=DB::query("SELECTtid,extcreditstypeFROM".DB::table(‘forum_replycredit‘)."WHEREtidIN(".dimplode($tids).")");
  164. while($rule=DB::fetch($query)){
  165. $rule[‘extcreditstype‘]=$rule[‘extcreditstype‘]?$rule[‘extcreditstype‘]:$_G[‘setting‘][‘creditstransextra‘][10];
  166. $replycredity_rule[$rule[‘tid‘]]=$rule;
  167. }
  168. foreach($replycredit_listAS$uid=>$tid_credit){
  169. foreach($tid_creditAS$tid=>$credit){
  170. $uid_credit[$replycredity_rule[$tid][‘extcreditstype‘]]-=$credit;
  171. }
  172. updatemembercount($uid,$uid_credit,true);
  173. }
  174. }
  175. if(!$recycle){
  176. deleteattach($ids,$idtype);
  177. }
  178. if($_G[‘setting‘][‘plugins‘][HOOKTYPE.‘_deletepost‘]){
  179. hookscript(‘deletepost‘,‘global‘,‘funcs‘,array(‘param‘=>$hookparam,‘step‘=>‘delete‘),‘deletepost‘);
  180. }
  181. return$count;
  182. }
  183. functiondeletethreadcover($tids){
  184. global$_G;
  185. loadcache(array(‘threadtableids‘,‘posttableids‘));
  186. $threadtableids=!empty($_G[‘cache‘][‘threadtableids‘])?$_G[‘cache‘][‘threadtableids‘]:array(0);
  187. $deletecover=array();
  188. foreach($threadtableidsas$tableid){
  189. if(!$tableid){
  190. $threadtable="forum_thread";
  191. }else{
  192. $threadtable="forum_thread_$tableid";
  193. }
  194. $query=DB::query("SELECTcover,tidFROM".DB::table($threadtable)."WHEREtidIN($tids)");
  195. while($row=DB::fetch($query)){
  196. if($row[‘cover‘]){
  197. $deletecover[$row[‘tid‘]]=$row[‘cover‘];
  198. }
  199. }
  200. }
  201. if($deletecover){
  202. foreach($deletecoveras$tid=>$cover){
  203. $filename=getthreadcover($tid,0,1);
  204. $remote=$cover<0?1:0;
  205. dunlink(array(‘attachment‘=>$filename,‘remote‘=>$remote,‘thumb‘=>0));
  206. }
  207. }
  208. }
  209. /**
  210. *删除主题
  211. *@paramarray$ids待删的ID数组
  212. *@paramboolean$membercount是否更新用户帖数统计
  213. *@paramboolean$credit是否处理积分
  214. *@paramboolean$ponly是否只处理分表、入回收站时使用
  215. */
  216. functiondeletethread($tids,$membercount=false,$credit=false,$ponly=false){
  217. global$_G;
  218. if($_G[‘setting‘][‘plugins‘][HOOKTYPE.‘_deletethread‘]){
  219. $_G[‘deletethreadtids‘]=&$tids;
  220. $hookparam=func_get_args();
  221. hookscript(‘deletethread‘,‘global‘,‘funcs‘,array(‘param‘=>$hookparam,‘step‘=>‘check‘),‘deletethread‘);
  222. }
  223. if(!$tids){
  224. return0;
  225. }
  226. require_oncelibfile(‘function/forum‘);
  227. foreach($tidsas$tid){
  228. my_post_log(‘delete‘,array(‘tid‘=>$tid));
  229. }
  230. $count=count($tids);
  231. $tids=dimplode($tids);
  232. //note主题分表缓存
  233. loadcache(array(‘threadtableids‘,‘posttableids‘));
  234. $threadtableids=!empty($_G[‘cache‘][‘threadtableids‘])?$_G[‘cache‘][‘threadtableids‘]:array();
  235. $posttableids=!empty($_G[‘cache‘][‘posttableids‘])?$_G[‘cache‘][‘posttableids‘]:array(‘0‘);
  236. //补充主题主表
  237. if(!in_array(0,$threadtableids)){
  238. $threadtableids=array_merge(array(0),$threadtableids);
  239. }
  240. DB::delete(‘common_moderate‘,"idIN($tids)ANDidtype=‘tid‘");
  241. //note收集待删的tid、fid、posttableid、threadtables
  242. $atids=$fids=$postids=$threadtables=array();
  243. foreach($threadtableidsas$tableid){
  244. $threadtable=!$tableid?"forum_thread":"forum_thread_$tableid";
  245. //note收集待删的tid、fid、posttableid
  246. $query=DB::query("SELECTcover,tid,fid,posttableidFROM".DB::table($threadtable)."WHEREtidIN($tids)");
  247. while($row=DB::fetch($query)){
  248. $atids[]=$row[‘tid‘];
  249. //note整理出回帖分表
  250. $row[‘posttableid‘]=!empty($row[‘posttableid‘])&&in_array($row[‘posttableid‘],$posttableids)?$row[‘posttableid‘]:‘0‘;
  251. $postids[$row[‘posttableid‘]][$row[‘tid‘]]=$row[‘tid‘];
  252. if($tableid){
  253. $fids[$row[‘fid‘]][]=$tableid;
  254. }
  255. }
  256. if(!$tableid&&!$ponly){
  257. $threadtables[]=$threadtable;
  258. }
  259. }
  260. //更新主题、帖子的积分或用户统计
  261. if($credit||$membercount){
  262. $losslessdel=$_G[‘setting‘][‘losslessdel‘]>0?TIMESTAMP-$_G[‘setting‘][‘losslessdel‘]*86400:0;
  263. //note从分表中得到所有的post列表
  264. $postlist=$uidarray=$tuidarray=$ruidarray=array();
  265. foreach($postidsas$posttableid=>$posttabletids){
  266. $query=DB::query(‘SELECTtid,first,authorid,dateline,replycredit,invisibleFROM‘.DB::table(getposttable($posttableid)).‘WHEREtidIN(‘.dimplode($posttabletids).‘)‘);
  267. while($post=DB::fetch($query)){
  268. if($post[‘invisible‘]!=-1&&$post[‘invisible‘]!=-5){
  269.  

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved