PageRenderTime 64ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/source/function/function_delete.php

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