function_delete.php 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: function_delete.php 36334 2017-01-03 01:32:35Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. require_once libfile('function/home');
  12. function deletemember($uids, $delpost = true) {
  13. global $_G;
  14. if(!$uids) {
  15. return;
  16. }
  17. if($_G['setting']['plugins']['func'][HOOKTYPE]['deletemember']) {
  18. $_G['deleteposuids'] = & $uids;
  19. $hookparam = func_get_args();
  20. hookscript('deletemember', 'global', 'funcs', array('param' => $hookparam, 'step' => 'check'), 'deletemember');
  21. }
  22. if($delpost) {
  23. deleteattach($uids, 'uid');
  24. deletepost($uids, 'authorid');
  25. }
  26. $arruids = $uids;
  27. $uids = dimplode($uids);
  28. $numdeleted = count($arruids);
  29. foreach(array('common_member_field_forum', 'common_member_field_home', 'common_member_count',
  30. 'common_member_profile', 'common_member_status',) as $table) {
  31. C::t($table)->delete($arruids, true, 1);
  32. }
  33. foreach(array( 'common_member_log', 'common_member_verify', 'common_member_validate', 'common_member_magic') as $table) {
  34. C::t($table)->delete($arruids, true);
  35. }
  36. C::t('forum_access')->delete_by_uid($arruids);
  37. C::t('common_member_verify_info')->delete_by_uid($arruids);
  38. C::t('common_member_action_log')->delete_by_uid($arruids);
  39. C::t('forum_moderator')->delete_by_uid($arruids);
  40. C::t('forum_post_location')->delete_by_uid($arruids);
  41. $doids = array();
  42. $query = C::t('home_doing')->fetch_all_by_uid_doid($arruids);
  43. foreach($query as $value) {
  44. $doids[$value['doid']] = $value['doid'];
  45. }
  46. C::t('home_docomment')->delete_by_doid_uid($doids, $arruids);
  47. C::t('common_domain')->delete_by_id_idtype($arruids, 'home');
  48. C::t('home_feed')->delete_by_uid($arruids);
  49. C::t('home_notification')->delete_by_uid($arruids);
  50. C::t('home_poke')->delete_by_uid_or_fromuid($uids);
  51. C::t('home_comment')->delete_by_uid($arruids);
  52. C::t('home_visitor')->delete_by_uid_or_vuid($uids);
  53. C::t('home_friend')->delete_by_uid_fuid($arruids);
  54. C::t('home_friend_request')->delete_by_uid_or_fuid($arruids);
  55. C::t('common_invite')->delete_by_uid_or_fuid($arruids);
  56. C::t('common_myinvite')->delete_by_touid_or_fromuid($uids);
  57. C::t('common_moderate')->delete($arruids, 'uid_cid');
  58. C::t('common_member_forum_buylog')->delete_by_uid($arruids);
  59. C::t('forum_threadhidelog')->delete_by_uid($arruids);
  60. C::t('common_member_crime')->delete_by_uid($arruids);
  61. foreach(C::t('forum_collectionfollow')->fetch_all_by_uid($arruids) as $follow) {
  62. C::t('forum_collection')->update_by_ctid($follow['ctid'], 0, -1);
  63. }
  64. foreach(C::t('forum_collectioncomment')->fetch_all_by_uid($arruids) as $comment) {
  65. C::t('forum_collection')->update_by_ctid($comment['ctid'], 0, 0, -1);
  66. }
  67. $query = C::t('home_pic')->fetch_all_by_uid($uids);
  68. foreach($query as $value) {
  69. $pics[] = $value;
  70. }
  71. deletepicfiles($pics);
  72. include_once libfile('function/home');
  73. $query = C::t('home_album')->fetch_all_by_uid($arruids);
  74. foreach($query as $value) {
  75. pic_delete($value['pic'], 'album', 0, ($value['picflag'] == 2 ? 1 : 0));
  76. }
  77. C::t('common_mailcron')->delete_by_touid($arruids);
  78. foreach(array('home_doing', 'home_share', 'home_album', 'common_credit_rule_log', 'common_credit_rule_log_field',
  79. 'home_pic', 'home_blog', 'home_blogfield', 'home_class', 'home_clickuser',
  80. 'home_userapp', 'home_userappfield', 'home_show', 'forum_collectioncomment', 'forum_collectionfollow', 'forum_collectionteamworker') as $table) {
  81. C::t($table)->delete_by_uid($arruids);
  82. }
  83. C::t('common_member')->delete($arruids, 1, 1);
  84. manyoulog('user', $uids, 'delete');
  85. if($_G['setting']['plugins']['func'][HOOKTYPE]['deletemember']) {
  86. hookscript('deletemember', 'global', 'funcs', array('param' => $hookparam, 'step' => 'delete'), 'deletemember');
  87. }
  88. return $numdeleted;
  89. }
  90. function deletepost($ids, $idtype = 'pid', $credit = false, $posttableid = false, $recycle = false) {
  91. global $_G;
  92. $recycle = $recycle && $idtype == 'pid' ? true : false;
  93. if($_G['setting']['plugins']['func'][HOOKTYPE]['deletepost']) {
  94. $_G['deletepostids'] = & $ids;
  95. $hookparam = func_get_args();
  96. hookscript('deletepost', 'global', 'funcs', array('param' => $hookparam, 'step' => 'check'), 'deletepost');
  97. }
  98. if(!$ids || !in_array($idtype, array('authorid', 'tid', 'pid'))) {
  99. return 0;
  100. }
  101. loadcache('posttableids');
  102. $posttableids = !empty($_G['cache']['posttableids']) ? ($posttableid !== false && in_array($posttableid, $_G['cache']['posttableids']) ? array($posttableid) : $_G['cache']['posttableids']): array('0');
  103. $count = count($ids);
  104. $idsstr = dimplode($ids);
  105. if($credit) {
  106. $tuidarray = $ruidarray = $_G['deleteauthorids'] = array();
  107. foreach($posttableids as $id) {
  108. $postlist = array();
  109. if($idtype == 'pid') {
  110. $postlist = C::t('forum_post')->fetch_all($id, $ids, false);
  111. } elseif($idtype == 'tid') {
  112. $postlist = C::t('forum_post')->fetch_all_by_tid($id, $ids, false);
  113. } elseif($idtype == 'authorid') {
  114. $postlist = C::t('forum_post')->fetch_all_by_authorid($id, $ids, false);
  115. }
  116. foreach($postlist as $post) {
  117. if($post['invisible'] != -1 && $post['invisible'] != -5) {
  118. if($post['first']) {
  119. $tuidarray[$post['fid']][] = $post['authorid'];
  120. } else {
  121. $ruidarray[$post['fid']][] = $post['authorid'];
  122. if($post['authorid'] > 0 && $post['replycredit'] > 0) {
  123. $replycredit_list[$post['authorid']][$post['tid']] += $post['replycredit'];
  124. }
  125. }
  126. $tids[$post['tid']] = $post['tid'];
  127. $_G['deleteauthorids'][$post['authorid']] = $post['authorid'];
  128. }
  129. }
  130. unset($postlist);
  131. }
  132. if($tuidarray || $ruidarray) {
  133. require_once libfile('function/post');
  134. }
  135. if($tuidarray) {
  136. foreach($tuidarray as $fid => $tuids) {
  137. updatepostcredits('-', $tuids, 'post', $fid);
  138. }
  139. }
  140. if($ruidarray) {
  141. foreach($ruidarray as $fid => $ruids) {
  142. updatepostcredits('-', $ruids, 'reply', $fid);
  143. }
  144. }
  145. }
  146. foreach($posttableids as $id) {
  147. if($recycle) {
  148. C::t('forum_post')->update($id, $ids, array('invisible' => -5));
  149. } else {
  150. if($idtype == 'pid') {
  151. C::t('forum_post')->delete($id, $ids);
  152. C::t('forum_postcomment')->delete_by_pid($ids);
  153. C::t('forum_postcomment')->delete_by_rpid($ids);
  154. } elseif($idtype == 'tid') {
  155. C::t('forum_post')->delete_by_tid($id, $ids);
  156. C::t('forum_postcomment')->delete_by_tid($ids);
  157. } elseif($idtype == 'authorid') {
  158. C::t('forum_post')->delete_by_authorid($id, $ids);
  159. C::t('forum_postcomment')->delete_by_authorid($ids);
  160. }
  161. C::t('forum_trade')->delete_by_id_idtype($ids, ($idtype == 'authorid' ? 'sellerid' : $idtype));
  162. C::t('home_feed')->delete_by_id_idtype($ids, ($idtype == 'authorid' ? 'uid' : $idtype));
  163. }
  164. }
  165. if(!$recycle && $idtype != 'authorid') {
  166. if($idtype == 'pid') {
  167. C::t('forum_poststick')->delete_by_pid($ids);
  168. } elseif($idtype == 'tid') {
  169. C::t('forum_poststick')->delete_by_tid($ids);
  170. }
  171. }
  172. if($idtype == 'pid') {
  173. C::t('forum_postcomment')->delete_by_rpid($ids);
  174. C::t('common_moderate')->delete($ids, 'pid');
  175. C::t('forum_post_location')->delete($ids);
  176. C::t('forum_filter_post')->delete_by_pid($ids);
  177. C::t('forum_hotreply_number')->delete_by_pid($ids);
  178. C::t('forum_hotreply_member')->delete_by_pid($ids);
  179. } elseif($idtype == 'tid') {
  180. C::t('forum_post_location')->delete_by_tid($ids);
  181. C::t('forum_filter_post')->delete_by_tid($ids);
  182. C::t('forum_hotreply_number')->delete_by_tid($ids);
  183. C::t('forum_hotreply_member')->delete_by_tid($ids);
  184. C::t('forum_sofa')->delete($ids);
  185. } elseif($idtype == 'authorid') {
  186. C::t('forum_post_location')->delete_by_uid($ids);
  187. }
  188. if($replycredit_list) {
  189. foreach(C::t('forum_replycredit')->fetch_all($tids) as $rule) {
  190. $rule['extcreditstype'] = $rule['extcreditstype'] ? $rule['extcreditstype'] : $_G['setting']['creditstransextra'][10] ;
  191. $replycredity_rule[$rule['tid']] = $rule;
  192. }
  193. foreach($replycredit_list AS $uid => $tid_credit) {
  194. foreach($tid_credit AS $tid => $credit) {
  195. $uid_credit[$replycredity_rule[$tid]['extcreditstype']] -= $credit;
  196. }
  197. updatemembercount($uid, $uid_credit, true);
  198. }
  199. }
  200. if(!$recycle) {
  201. deleteattach($ids, $idtype);
  202. }
  203. if($tids) {
  204. foreach($tids as $tid) {
  205. updatethreadcount($tid, 1);
  206. }
  207. }
  208. if($_G['setting']['plugins']['func'][HOOKTYPE]['deletepost']) {
  209. hookscript('deletepost', 'global', 'funcs', array('param' => $hookparam, 'step' => 'delete'), 'deletepost');
  210. }
  211. return $count;
  212. }
  213. function deletethreadcover($tids) {
  214. global $_G;
  215. loadcache(array('threadtableids', 'posttableids'));
  216. $threadtableids = !empty($_G['cache']['threadtableids']) ? $_G['cache']['threadtableids'] : array(0);
  217. $deletecover = array();
  218. foreach($threadtableids as $tableid) {
  219. foreach(C::t('forum_thread')->fetch_all_by_tid($tids, 0, 0, $tableid) as $row) {
  220. if($row['cover']) {
  221. $deletecover[$row['tid']] = $row['cover'];
  222. }
  223. }
  224. }
  225. if($deletecover) {
  226. foreach($deletecover as $tid => $cover) {
  227. $filename = getthreadcover($tid, 0, 1);
  228. $remote = $cover < 0 ? 1 : 0;
  229. dunlink(array('attachment' => $filename, 'remote' => $remote, 'thumb' => 0));
  230. }
  231. }
  232. }
  233. function deletethread($tids, $membercount = false, $credit = false, $ponly = false) {
  234. global $_G;
  235. if($_G['setting']['plugins']['func'][HOOKTYPE]['deletethread']) {
  236. $_G['deletethreadtids'] = & $tids;
  237. $hookparam = func_get_args();
  238. hookscript('deletethread', 'global', 'funcs', array('param' => $hookparam, 'step' => 'check'), 'deletethread');
  239. }
  240. if(!$tids) {
  241. return 0;
  242. }
  243. $count = count($tids);
  244. $arrtids = $tids;
  245. $tids = dimplode($tids);
  246. loadcache(array('threadtableids', 'posttableids'));
  247. $threadtableids = !empty($_G['cache']['threadtableids']) ? $_G['cache']['threadtableids'] : array();
  248. $posttableids = !empty($_G['cache']['posttableids']) ? $_G['cache']['posttableids'] : array('0');
  249. if(!in_array(0, $threadtableids)) {
  250. $threadtableids = array_merge(array(0), $threadtableids);
  251. }
  252. C::t('common_moderate')->delete($arrtids, 'tid');
  253. C::t('forum_threadclosed')->delete($arrtids);
  254. C::t('forum_newthread')->delete_by_tids($arrtids);
  255. $cachefids = $atids = $fids = $postids = $threadtables = $_G['deleteauthorids'] = array();
  256. foreach($threadtableids as $tableid) {
  257. foreach(C::t('forum_thread')->fetch_all_by_tid($arrtids, 0, 0, $tableid) as $row) {
  258. $atids[] = $row['tid'];
  259. $row['posttableid'] = !empty($row['posttableid']) && in_array($row['posttableid'], $posttableids) ? $row['posttableid'] : '0';
  260. $postids[$row['posttableid']][$row['tid']] = $row['tid'];
  261. if($tableid) {
  262. $fids[$row['fid']][] = $tableid;
  263. }
  264. $cachefids[$row['fid']] = $row['fid'];
  265. $_G['deleteauthorids'][$row['authorid']] = $row['authorid'];
  266. }
  267. if(!$tableid && !$ponly) {
  268. $threadtables[] = $tableid;
  269. }
  270. }
  271. if($credit || $membercount) {
  272. $losslessdel = $_G['setting']['losslessdel'] > 0 ? TIMESTAMP - $_G['setting']['losslessdel'] * 86400 : 0;
  273. $postlist = $uidarray = $tuidarray = $ruidarray = array();
  274. foreach($postids as $posttableid => $posttabletids) {
  275. foreach(C::t('forum_post')->fetch_all_by_tid($posttableid, $posttabletids, false) as $post) {
  276. if($post['invisible'] != -1 && $post['invisible'] != -5) {
  277. $postlist[] = $post;
  278. }
  279. }
  280. }
  281. foreach(C::t('forum_replycredit')->fetch_all($arrtids) as $rule) {
  282. $rule['extcreditstype'] = $rule['extcreditstype'] ? $rule['extcreditstype'] : $_G['setting']['creditstransextra'][10] ;
  283. $replycredit_rule[$rule['tid']] = $rule;
  284. }
  285. foreach($postlist as $post) {
  286. if($post['dateline'] < $losslessdel) {
  287. if($membercount) {
  288. if($post['first']) {
  289. updatemembercount($post['authorid'], array('threads' => -1, 'post' => -1), false);
  290. } else {
  291. updatemembercount($post['authorid'], array('posts' => -1), false);
  292. }
  293. }
  294. } else {
  295. if($credit) {
  296. if($post['first']) {
  297. $tuidarray[$post['fid']][] = $post['authorid'];
  298. } else {
  299. $ruidarray[$post['fid']][] = $post['authorid'];
  300. }
  301. }
  302. }
  303. if($credit || $membercount) {
  304. if($post['authorid'] > 0 && $post['replycredit'] > 0) {
  305. if($replycredit_rule[$post['tid']]['extcreditstype']) {
  306. updatemembercount($post['authorid'], array($replycredit_rule[$post['tid']]['extcreditstype'] => (int)('-'.$post['replycredit'])));
  307. }
  308. }
  309. }
  310. }
  311. if($credit) {
  312. if($tuidarray || $ruidarray) {
  313. require_once libfile('function/post');
  314. }
  315. if($tuidarray) {
  316. foreach($tuidarray as $fid => $tuids) {
  317. updatepostcredits('-', $tuids, 'post', $fid);
  318. }
  319. }
  320. if($ruidarray) {
  321. foreach($ruidarray as $fid => $ruids) {
  322. updatepostcredits('-', $ruids, 'reply', $fid);
  323. }
  324. }
  325. $auidarray = $attachtables = array();
  326. foreach($atids as $tid) {
  327. $attachtables[getattachtableid($tid)][] = $tid;
  328. }
  329. foreach($attachtables as $attachtable => $attachtids) {
  330. foreach(C::t('forum_attachment_n')->fetch_all_by_id($attachtable, 'tid', $attachtids) as $attach) {
  331. if($attach['dateline'] > $losslessdel) {
  332. $auidarray[$attach['uid']] = !empty($auidarray[$attach['uid']]) ? $auidarray[$attach['uid']] + 1 : 1;
  333. }
  334. }
  335. }
  336. if($auidarray) {
  337. $postattachcredits = !empty($_G['forum']['postattachcredits']) ? $_G['forum']['postattachcredits'] : $_G['setting']['creditspolicy']['postattach'];
  338. updateattachcredits('-', $auidarray, $postattachcredits);
  339. }
  340. }
  341. }
  342. $relatecollection = C::t('forum_collectionthread')->fetch_all_by_tids($arrtids);
  343. if(count($relatecollection) > 0) {
  344. $collectionids = array();
  345. foreach($relatecollection as $collection) {
  346. $collectionids[] = $collection['ctid'];
  347. }
  348. $collectioninfo = C::t('forum_collection')->fetch_all($collectionids);
  349. foreach($relatecollection as $collection) {
  350. $decthread = C::t('forum_collectionthread')->delete_by_ctid_tid($collection['ctid'], $arrtids);
  351. $lastpost = null;
  352. if(in_array($collectioninfo[$collection['ctid']]['lastpost'], $arrtids) && ($collectioninfo[$collection['ctid']]['threadnum'] - $decthread) > 0) {
  353. $collection_thread = C::t('forum_collectionthread')->fetch_by_ctid_dateline($collection['ctid']);
  354. if($collection_thread) {
  355. $thread = C::t('forum_thread')->fetch($collection_thread['tid']);
  356. $lastpost = array(
  357. 'lastpost' => $thread['tid'],
  358. 'lastsubject' => $thread['subject'],
  359. 'lastposttime' => $thread['dateline'],
  360. 'lastposter' => $thread['authorid']
  361. );
  362. }
  363. }
  364. C::t('forum_collection')->update_by_ctid($collection['ctid'], -$decthread, 0, 0, 0, 0, 0, $lastpost);
  365. }
  366. C::t('forum_collectionrelated')->delete($arrtids);
  367. }
  368. if($cachefids) {
  369. C::t('forum_thread')->clear_cache($cachefids, 'forumdisplay_');
  370. }
  371. if($ponly) {
  372. if($_G['setting']['plugins']['func'][HOOKTYPE]['deletethread']) {
  373. hookscript('deletethread', 'global', 'funcs', array('param' => $hookparam, 'step' => 'delete'), 'deletethread');
  374. }
  375. C::t('forum_thread')->update($arrtids, array('displayorder'=>-1, 'digest'=>0, 'moderated'=>1));
  376. foreach($postids as $posttableid=>$oneposttids) {
  377. C::t('forum_post')->update_by_tid($posttableid, $oneposttids, array('invisible' => '-1'));
  378. }
  379. return $count;
  380. }
  381. C::t('forum_replycredit')->delete($arrtids);
  382. C::t('forum_post_location')->delete_by_tid($arrtids);
  383. C::t('common_credit_log')->delete_by_operation_relatedid(array('RCT', 'RCA', 'RCB'), $arrtids);
  384. C::t('forum_threadhidelog')->delete_by_tid($arrtids);
  385. deletethreadcover($arrtids);
  386. foreach($threadtables as $tableid) {
  387. C::t('forum_thread')->delete_by_tid($arrtids, false, $tableid);
  388. }
  389. if($atids) {
  390. foreach($postids as $posttableid=>$oneposttids) {
  391. deletepost($oneposttids, 'tid', false, $posttableid);
  392. }
  393. deleteattach($atids, 'tid');
  394. }
  395. if($fids) {
  396. loadcache('forums');
  397. foreach($fids as $fid => $tableids) {
  398. if(empty($_G['cache']['forums'][$fid]['archive'])) {
  399. continue;
  400. }
  401. foreach(C::t('forum_thread')->count_posts_by_fid($fid) as $row) {
  402. C::t('forum_forum_threadtable')->insert(array(
  403. 'fid' => $fid,
  404. 'threadtableid' => $tableid,
  405. 'threads' => $row['threads'],
  406. 'posts' => $row['posts']
  407. ), false, true);
  408. }
  409. }
  410. }
  411. foreach(array('forum_forumrecommend', 'forum_polloption', 'forum_poll', 'forum_polloption_image', 'forum_activity', 'forum_activityapply', 'forum_debate',
  412. 'forum_debatepost', 'forum_threadmod', 'forum_relatedthread',
  413. 'forum_pollvoter', 'forum_threadimage', 'forum_threadpreview') as $table) {
  414. C::t($table)->delete_by_tid($arrtids);
  415. }
  416. C::t('forum_typeoptionvar')->delete_by_tid($arrtids);
  417. C::t('forum_poststick')->delete_by_tid($arrtids);
  418. C::t('forum_filter_post')->delete_by_tid($arrtids);
  419. C::t('forum_hotreply_member')->delete_by_tid($arrtids);
  420. C::t('forum_hotreply_number')->delete_by_tid($arrtids);
  421. C::t('home_feed')->delete_by_id_idtype($arrtids, 'tid');
  422. C::t('common_tagitem')->delete(0, $arrtids, 'tid');
  423. C::t('forum_threadrush')->delete($arrtids);
  424. if($_G['setting']['plugins']['func'][HOOKTYPE]['deletethread']) {
  425. hookscript('deletethread', 'global', 'funcs', array('param' => $hookparam, 'step' => 'delete'), 'deletethread');
  426. }
  427. return $count;
  428. }
  429. function deleteattach($ids, $idtype = 'aid') {
  430. global $_G;
  431. if(!$ids || !in_array($idtype, array('authorid', 'uid', 'tid', 'pid'))) {
  432. return;
  433. }
  434. $idtype = $idtype == 'authorid' ? 'uid' : $idtype;
  435. $pics = $attachtables = array();
  436. if($idtype == 'tid') {
  437. $pollImags = C::t('forum_polloption_image')->fetch_all_by_tid($ids);
  438. foreach($pollImags as $image) {
  439. dunlink($image);
  440. }
  441. }
  442. foreach(C::t('forum_attachment')->fetch_all_by_id($idtype, $ids) as $attach) {
  443. $attachtables[$attach['tableid']][] = $attach['aid'];
  444. }
  445. foreach($attachtables as $attachtable => $aids) {
  446. if($attachtable == 127) {
  447. continue;
  448. }
  449. $attachs = C::t('forum_attachment_n')->fetch_all($attachtable, $aids);
  450. foreach($attachs as $attach) {
  451. if($attach['picid']) {
  452. $pics[] = $attach['picid'];
  453. }
  454. dunlink($attach);
  455. }
  456. C::t('forum_attachment_exif')->delete($aids);
  457. C::t('forum_attachment_n')->delete($attachtable, $aids);
  458. }
  459. C::t('forum_attachment')->delete_by_id($idtype, $ids);
  460. if($pics) {
  461. $albumids = array();
  462. C::t('home_pic')->delete($pics);
  463. $query = C::t('home_pic')->fetch_all($pics);
  464. foreach($query as $album) {
  465. if(!in_array($album['albumid'], $albumids)) {
  466. C::t('home_album')->update($album['albumid'], array('picnum' => C::t('home_pic')->check_albumpic($album['albumid'])));
  467. $albumids[] = $album['albumid'];
  468. }
  469. }
  470. }
  471. }
  472. function deletecomments($cids) {
  473. global $_G;
  474. $blognums = $newcids = $dels = $counts = array();
  475. $allowmanage = checkperm('managecomment');
  476. $query = C::t('home_comment')->fetch_all($cids);
  477. $deltypes = array();
  478. foreach($query as $value) {
  479. if($allowmanage || $value['authorid'] == $_G['uid'] || $value['uid'] == $_G['uid']) {
  480. $dels[] = $value;
  481. $newcids[] = $value['cid'];
  482. $deltypes[] = $value['idtype'].'_cid';
  483. if($value['authorid'] != $_G['uid'] && $value['uid'] != $_G['uid']) {
  484. $counts[$value['authorid']]['coef'] -= 1;
  485. }
  486. if($value['idtype'] == 'blogid') {
  487. $blognums[$value['id']]++;
  488. }
  489. }
  490. }
  491. if(empty($dels)) return array();
  492. C::t('home_comment')->delete($newcids);
  493. for($i = 0; $i < count($newcids); $i++) {
  494. C::t('common_moderate')->delete($newcids[$i], $deltypes[$i]);
  495. }
  496. if($counts) {
  497. foreach ($counts as $uid => $setarr) {
  498. batchupdatecredit('comment', $uid, array(), $setarr['coef']);
  499. }
  500. }
  501. if($blognums) {
  502. $nums = renum($blognums);
  503. foreach ($nums[0] as $num) {
  504. C::t('home_blog')->increase($nums[1][$num], 0, array('replynum' => -$num));
  505. }
  506. }
  507. return $dels;
  508. }
  509. function deleteblogs($blogids, $force = false) {
  510. global $_G;
  511. $blogs = $newblogids = $counts = array();
  512. $allowmanage = checkperm('manageblog');
  513. $query = C::t('home_blog')->fetch_all($blogids);
  514. foreach($query as $value) {
  515. if($allowmanage || $value['uid'] == $_G['uid']) {
  516. $blogs[] = $value;
  517. $newblogids[] = $value['blogid'];
  518. if($value['status'] == 0) {
  519. if($value['uid'] != $_G['uid']) {
  520. $counts[$value['uid']]['coef'] -= 1;
  521. }
  522. $counts[$value['uid']]['blogs'] -= 1;
  523. }
  524. }
  525. }
  526. if(empty($blogs)) return array();
  527. C::t('common_moderate')->delete($newblogids, 'blogid');
  528. C::t('common_moderate')->delete($newblogids, 'blogid_cid');
  529. if(getglobal('setting/blogrecyclebin') && !$force) {
  530. C::t('home_blog')->update($newblogids, array('status' => -1));
  531. return $blogs;
  532. }
  533. C::t('home_blog')->delete($newblogids);
  534. C::t('home_blogfield')->delete($newblogids);
  535. C::t('home_comment')->delete('', $newblogids, 'blogid');
  536. C::t('home_feed')->delete_by_id_idtype($newblogids, 'blogid');
  537. C::t('home_clickuser')->delete_by_id_idtype($newblogids, 'blogid');
  538. if($counts) {
  539. foreach ($counts as $uid => $setarr) {
  540. batchupdatecredit('publishblog', $uid, array('blogs' => $setarr['blogs']), $setarr['coef']);
  541. }
  542. }
  543. C::t('common_tagitem')->delete(0, $newblogids, 'blogid');
  544. return $blogs;
  545. }
  546. function deletefeeds($feedids) {
  547. global $_G;
  548. $allowmanage = checkperm('managefeed');
  549. $feeds = $newfeedids = array();
  550. $query = C::t('home_feed')->fetch_all($feedids);
  551. foreach($query as $value) {
  552. if($allowmanage || $value['uid'] == $_G['uid']) {
  553. $newfeedids[] = $value['feedid'];
  554. $feeds[] = $value;
  555. }
  556. }
  557. if(empty($newfeedids)) return array();
  558. C::t('home_feed')->delete($newfeedids);
  559. return $feeds;
  560. }
  561. function deleteshares($sids) {
  562. global $_G;
  563. $allowmanage = checkperm('manageshare');
  564. $shares = $newsids = $counts = array();
  565. foreach(C::t('home_share')->fetch_all($sids) as $value) {
  566. if($allowmanage || $value['uid'] == $_G['uid']) {
  567. $shares[] = $value;
  568. $newsids[] = $value['sid'];
  569. if($value['uid'] != $_G['uid']) {
  570. $counts[$value['uid']]['coef'] -= 1;
  571. }
  572. $counts[$value['uid']]['sharings'] -= 1;
  573. }
  574. }
  575. if(empty($shares)) return array();
  576. C::t('home_share')->delete($newsids);
  577. C::t('home_comment')->delete('', $newsids, 'sid');
  578. C::t('home_feed')->delete_by_id_idtype($newsids, 'sid');
  579. C::t('common_moderate')->delete($newsids, 'sid');
  580. C::t('common_moderate')->delete($newsids, 'sid_cid');
  581. if($counts) {
  582. foreach ($counts as $uid => $setarr) {
  583. batchupdatecredit('createshare', $uid, array('sharings' => $setarr['sharings']), $setarr['coef']);
  584. }
  585. }
  586. return $shares;
  587. }
  588. function deletedoings($ids) {
  589. global $_G;
  590. $allowmanage = checkperm('managedoing');
  591. $doings = $newdoids = $counts = array();
  592. $query = C::t('home_doing')->fetch_all($ids);
  593. foreach($query as $value) {
  594. if($allowmanage || $value['uid'] == $_G['uid']) {
  595. $doings[] = $value;
  596. $newdoids[] = $value['doid'];
  597. if($value['uid'] != $_G['uid']) {
  598. $counts[$value['uid']]['coef'] -= 1;
  599. }
  600. $counts[$value['uid']]['doings'] -= 1;
  601. }
  602. }
  603. if(empty($doings)) return array();
  604. C::t('home_doing')->delete($newdoids);
  605. C::t('home_docomment')->delete_by_doid_uid($newdoids);
  606. C::t('home_feed')->delete_by_id_idtype($newdoids, 'doid');
  607. C::t('common_moderate')->delete($newdoids, 'doid');
  608. if($counts) {
  609. foreach ($counts as $uid => $setarr) {
  610. if ($uid) {
  611. batchupdatecredit('doing', $uid, array('doings' => $setarr['doings']), $setarr['coef']);
  612. $lastdoing = C::t('home_doing')->fetch_all_by_uid_doid($uid, '', 'dateline', 0, 1, true, true);
  613. $setarr = array('recentnote'=>$lastdoing[0]['message'], 'spacenote'=>$lastdoing[0]['message']);
  614. C::t('common_member_field_home')->update($_G['uid'], $setarr);
  615. }
  616. }
  617. }
  618. return $doings;
  619. }
  620. function deletespace($uid) {
  621. global $_G;
  622. $allowmanage = checkperm('managedelspace');
  623. if($allowmanage) {
  624. C::t('common_member')->update($uid, array('status' => 1));
  625. manyoulog('user', $uid, 'delete');
  626. return true;
  627. } else {
  628. return false;
  629. }
  630. }
  631. function deletepics($picids) {
  632. global $_G;
  633. $albumids = $sizes = $pics = $newids = array();
  634. $allowmanage = checkperm('managealbum');
  635. $haveforumpic = false;
  636. $query = C::t('home_pic')->fetch_all($picids);
  637. foreach($query as $value) {
  638. if($allowmanage || $value['uid'] == $_G['uid']) {
  639. $pics[] = $value;
  640. $newids[] = $value['picid'];
  641. $sizes[$value['uid']] = $sizes[$value['uid']] + $value['size'];
  642. $albumids[$value['albumid']] = $value['albumid'];
  643. if(!$haveforumpic && $value['remote'] > 1) {
  644. $haveforumpic = true;
  645. }
  646. }
  647. }
  648. if(empty($pics)) return array();
  649. C::t('home_pic')->delete($newids);
  650. if($haveforumpic) {
  651. for($i = 0;$i < 10;$i++) {
  652. C::t('forum_attachment_n')->reset_picid($i, $newids);
  653. }
  654. }
  655. C::t('home_comment')->delete('', $newids, 'picid');
  656. C::t('home_feed')->delete_by_id_idtype($newids, 'picid');
  657. C::t('home_clickuser')->delete_by_id_idtype($newids, 'picid');
  658. C::t('common_moderate')->delete($newids, 'picid');
  659. C::t('common_moderate')->delete($newids, 'picid_cid');
  660. if($sizes) {
  661. foreach ($sizes as $uid => $setarr) {
  662. $attachsize = intval($sizes[$uid]);
  663. updatemembercount($uid, array('attachsize' => -$attachsize), false);
  664. }
  665. }
  666. require_once libfile('function/spacecp');
  667. foreach ($albumids as $albumid) {
  668. if($albumid) {
  669. album_update_pic($albumid);
  670. }
  671. }
  672. deletepicfiles($pics);
  673. return $pics;
  674. }
  675. function deletepicfiles($pics) {
  676. global $_G;
  677. $remotes = array();
  678. include_once libfile('function/home');
  679. foreach ($pics as $pic) {
  680. pic_delete($pic['filepath'], 'album', $pic['thumb'], $pic['remote']);
  681. }
  682. }
  683. function deletealbums($albumids) {
  684. global $_G;
  685. $sizes = $dels = $newids = $counts = array();
  686. $allowmanage = checkperm('managealbum');
  687. $albums = C::t('home_album')->fetch_all($albumids);
  688. foreach($albums as $value) {
  689. if($value['albumid']) {
  690. if($allowmanage || $value['uid'] == $_G['uid']) {
  691. $dels[] = $value;
  692. $newids[] = $value['albumid'];
  693. if(!empty($value['pic'])) {
  694. include_once libfile('function/home');
  695. pic_delete($value['pic'], 'album', 0, ($value['picflag'] == 2 ? 1 : 0));
  696. }
  697. }
  698. $counts[$value['uid']]['albums'] -= 1;
  699. }
  700. }
  701. if(empty($dels)) return array();
  702. $pics = $picids = array();
  703. $query = C::t('home_pic')->fetch_all_by_albumid($newids);
  704. foreach($query as $value) {
  705. $pics[] = $value;
  706. $picids[] = $value['picid'];
  707. $sizes[$value['uid']] = $sizes[$value['uid']] + $value['size'];
  708. }
  709. if($picids) {
  710. deletepics($picids);
  711. }
  712. C::t('home_album')->delete($newids);
  713. C::t('home_feed')->delete_by_id_idtype($newids, 'albumid');
  714. if($picids) {
  715. C::t('home_clickuser')->delete_by_id_idtype($picids, 'picid');
  716. }
  717. if($sizes) {
  718. foreach ($sizes as $uid => $value) {
  719. $attachsize = intval($sizes[$uid]);
  720. $albumnum = $counts[$uid]['albums'] ? $counts[$uid]['albums'] : 0;
  721. updatemembercount($uid, array('albums' => $albumnum, 'attachsize' => -$attachsize), false);
  722. }
  723. }
  724. return $dels;
  725. }
  726. function deletetrasharticle($aids) {
  727. global $_G;
  728. require_once libfile('function/home');
  729. $articles = $trashid = $pushs = $dels = array();
  730. foreach(C::t('portal_article_trash')->fetch_all($aids) as $value) {
  731. $dels[$value['aid']] = $value['aid'];
  732. $article = dunserialize($value['content']);
  733. $articles[$article['aid']] = $article;
  734. if(!empty($article['idtype'])) $pushs[$article['idtype']][] = $article['id'];
  735. if($article['pic']) {
  736. pic_delete($article['pic'], 'portal', $article['thumb'], $article['remote']);
  737. }
  738. if($article['htmlmade'] && $article['htmldir'] && $article['htmlname']) {
  739. deletehtml(DISCUZ_ROOT.'/'.$article['htmldir'].$article['htmlname'], $article['contents']);
  740. }
  741. }
  742. if($dels) {
  743. C::t('portal_article_trash')->delete($dels, 'UNBUFFERED');
  744. deletearticlepush($pushs);
  745. deletearticlerelated($dels);
  746. }
  747. return $articles;
  748. }
  749. function deletearticle($aids, $istrash = true) {
  750. global $_G;
  751. if(empty($aids)) return false;
  752. $trasharr = $article = $bids = $dels = $attachment = $attachaid = $catids = $pushs = array();
  753. $query = C::t('portal_article_title')->fetch_all($aids);
  754. foreach($query as $value) {
  755. $catids[] = intval($value['catid']);
  756. $dels[$value['aid']] = $value['aid'];
  757. $article[] = $value;
  758. if(!empty($value['idtype'])) $pushs[$value['idtype']][] = $value['id'];
  759. }
  760. if($dels) {
  761. foreach($article as $key => $value) {
  762. if($istrash) {
  763. $trasharr[] = array('aid' => $value['aid'], 'content'=>serialize($value));
  764. } elseif($value['pic']) {
  765. pic_delete($value['pic'], 'portal', $value['thumb'], $value['remote']);
  766. $attachaid[] = $value['aid'];
  767. if($value['madehtml'] && $value['htmldir'] && $value['htmlname']) {
  768. deletehtml(DISCUZ_ROOT.'/'.$value['htmldir'].$value['htmlname'], $value['contents']);
  769. }
  770. }
  771. }
  772. if($istrash && $trasharr) {
  773. C::t('portal_article_trash')->insert_batch($trasharr);
  774. } else {
  775. deletearticlepush($pushs);
  776. deletearticlerelated($dels);
  777. }
  778. C::t('portal_article_title')->delete($dels);
  779. C::t('common_moderate')->delete($dels, 'aid');
  780. $catids = array_unique($catids);
  781. if($catids) {
  782. foreach($catids as $catid) {
  783. $cnt = C::t('portal_article_title')->fetch_count_for_cat($catid);
  784. C::t('portal_category')->update($catid, array('articles'=>dintval($cnt)));
  785. }
  786. }
  787. }
  788. return $article;
  789. }
  790. function deletearticlepush($pushs) {
  791. if(!empty($pushs) && is_array($pushs)) {
  792. foreach($pushs as $idtype=> $fromids) {
  793. switch ($idtype) {
  794. case 'blogid':
  795. if(!empty($fromids)) C::t('home_blogfield')->update($fromids, array('pushedaid'=>'0'));
  796. break;
  797. case 'tid':
  798. if(!empty($fromids)) C::t('forum_thread')->update($fromids, array('pushedaid'=>'0'));
  799. break;
  800. }
  801. }
  802. }
  803. }
  804. function deletearticlerelated($dels) {
  805. C::t('portal_article_count')->delete($dels);
  806. C::t('portal_article_content')->delete_by_aid($dels);
  807. if($attachment = C::t('portal_attachment')->fetch_all_by_aid($dels)) {
  808. require_once libfile('function/home');
  809. foreach ($attachment as $value) {
  810. pic_delete($value['attachment'], 'portal', $value['thumb'], $value['remote']);
  811. }
  812. C::t('portal_attachment')->delete(array_keys($attachment));
  813. }
  814. C::t('portal_comment')->delete_by_id_idtype($dels, 'aid');
  815. C::t('common_moderate')->delete($dels, 'aid_cid');
  816. C::t('portal_article_related')->delete_by_aid_raid($dels);
  817. }
  818. function deleteportaltopic($dels) {
  819. if(empty($dels)) return false;
  820. $targettplname = array();
  821. foreach ((array)$dels as $key => $value) {
  822. $targettplname[] = 'portal/portal_topic_content_'.$value;
  823. }
  824. C::t('common_diy_data')->delete($targettplname, null);
  825. require_once libfile('class/blockpermission');
  826. $tplpermission = & template_permission::instance();
  827. $templates = array();
  828. $tplpermission->delete_allperm_by_tplname($targettplname);
  829. deletedomain($dels, 'topic');
  830. C::t('common_template_block')->delete_by_targettplname($targettplname);
  831. require_once libfile('function/home');
  832. $picids = array();
  833. foreach(C::t('portal_topic')->fetch_all($dels) as $value) {
  834. if($value['picflag'] != '0') pic_delete(str_replace('portal/', '', $value['cover']), 'portal', 0, $value['picflag'] == '2' ? '1' : '0');
  835. }
  836. $picids = array();
  837. foreach(C::t('portal_topic_pic')->fetch_all($dels) as $value) {
  838. $picids[] = $value['picid'];
  839. pic_delete($value['filepath'], 'portal', $value['thumb'], $value['remote']);
  840. }
  841. if (!empty($picids)) {
  842. C::t('portal_topic_pic')->delete($picids, true);
  843. }
  844. C::t('portal_topic')->delete($dels);
  845. C::t('portal_comment')->delete_by_id_idtype($dels, 'topicid');
  846. C::t('common_moderate')->delete($dels, 'topicid_cid');
  847. include_once libfile('function/block');
  848. block_clear();
  849. include_once libfile('function/cache');
  850. updatecache('diytemplatename');
  851. }
  852. function deletedomain($ids, $idtype) {
  853. if($ids && $idtype) {
  854. C::t('common_domain')->delete_by_id_idtype($ids, $idtype);
  855. }
  856. }
  857. function deletecollection($ctid) {
  858. $tids = array();
  859. $threadlist = C::t('forum_collectionthread')->fetch_all_by_ctid($ctid);
  860. $tids = array_keys($threadlist);
  861. deleterelatedtid($tids, $ctid);
  862. $collectionteamworker = C::t('forum_collectionteamworker')->fetch_all_by_ctid($ctid);
  863. foreach ($collectionteamworker as $worker) {
  864. notification_add($worker['uid'], "system", 'collection_removed', array('ctid'=>$collectiondata['ctid'], 'collectionname'=>$collectiondata['name']), 1);
  865. }
  866. C::t('forum_collectionthread')->delete_by_ctid($ctid);
  867. C::t('forum_collectionfollow')->delete_by_ctid($ctid);
  868. C::t('forum_collectioncomment')->delete_by_ctid($ctid);
  869. C::t('forum_collectionteamworker')->delete_by_ctid($ctid);
  870. C::t('forum_collectioninvite')->delete_by_ctid($ctid);
  871. C::t('forum_collection')->delete($ctid, true);
  872. }
  873. function deleterelatedtid($tids, $ctid) {
  874. $loadreleated = C::t('forum_collectionrelated')->fetch_all($tids, true);
  875. foreach($loadreleated as $loadexist) {
  876. if($loadexist['tid']) {
  877. $collectionlist = explode("\t", $loadexist['collection']);
  878. if(count($collectionlist)>0) {
  879. foreach ($collectionlist as $collectionkey=>$collectionvalue) {
  880. if ($collectionvalue == $ctid) {
  881. unset($collectionlist[$collectionkey]);
  882. break;
  883. }
  884. }
  885. }
  886. $newcollection = implode("\t", $collectionlist);
  887. if (trim($newcollection) == '') {
  888. C::t('forum_collectionrelated')->delete($loadexist['tid']);
  889. C::t('forum_thread')->update_status_by_tid($loadexist['tid'], '1111111011111111', '&');
  890. } else {
  891. C::t('forum_collectionrelated')->update_collection_by_ctid_tid($newcollection, $loadexist['tid'], true);
  892. }
  893. }
  894. }
  895. }
  896. function deletehtml($htmlname, $count = 1) {
  897. global $_G;
  898. @unlink($htmlname.'.'.$_G['setting']['makehtml']['extendname']);
  899. if($count > 1) {
  900. for($i = 2; $i <= $count; $i++) {
  901. @unlink($htmlname.$i.'.'.$_G['setting']['makehtml']['extendname']);
  902. }
  903. }
  904. }
  905. function deletememberpost($uids) {
  906. global $_G;
  907. require_once libfile('function/post');
  908. loadcache('posttableids');
  909. foreach($uids as $uid) {
  910. $tidsdelete = array();
  911. $posttables = empty($_G['cache']['posttableids']) ? array(0) : $_G['cache']['posttableids'];
  912. foreach($posttables as $posttableid) {
  913. $pidsthread = $pidsdelete = array();
  914. $postlist = C::t('forum_post')->fetch_all_by_authorid($posttableid, $uid, false);
  915. if($postlist) {
  916. foreach($postlist as $post) {
  917. if($post['first']) {
  918. $tidsdelete[] = $post['tid'];
  919. }
  920. $pidsdelete[] = $post['pid'];
  921. $pidsthread[$post['pid']] = $post['tid'];
  922. }
  923. }
  924. deletepost($pidsdelete, 'pid', true, $posttableid, true);
  925. }
  926. unset($postlist);
  927. if($tidsdelete) {
  928. deletethread($tidsdelete, true, true, true);
  929. }
  930. }
  931. }
  932. ?>