PageRenderTime 44ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/source/function/function_delete.php

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