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

  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 27060 2012-01-04 01:32:05Z songlixin $
  7. */
  8. if(!defined(‘IN_DISCUZ‘)) {
  9. exit(‘Access Denied‘);
  10. }
  11. require_once libfile(‘function/home‘);
  12. /**
  13. * 删除用户
  14. * @param string $uids 待删的 ID 数组
  15. * @param boolean $delpost 是否包含帖子信息
  16. */
  17. function deletemember($uids, $delpost = true) {
  18. if(!$uids) {
  19. return;
  20. }
  21. // 腾讯安全
  22. require_once libfile(‘function/sec‘);
  23. updateMemberOperate($uids, 2);
  24. if($delpost) {
  25. deleteattach($uids, ‘uid‘);
  26. deletepost($uids, ‘authorid‘);
  27. }
  28. require_once libfile(‘function/forum‘);
  29. foreach($uids as $uid) {
  30. my_thread_log(‘deluser‘, array(‘uid‘ => $uid));
  31. }
  32. $uids = dimplode($uids);
  33. $numdeleted = DB::result_first("SELECT COUNT(*) FROM ".DB::table(‘common_member‘)." WHERE uid IN ($uids)");
  34. foreach(array(‘common_member_field_forum‘, ‘common_member_field_home‘, ‘common_member_count‘, ‘common_member_log‘, ‘common_member_profile‘,
  35. ‘common_member_verify‘, ‘common_member_verify_info‘, ‘common_member_status‘, ‘common_member_validate‘, ‘common_member_magic‘,
  36. ‘forum_access‘, ‘forum_moderator‘, ‘common_member_action_log‘) as $table) {
  37. DB::delete($table, "uid IN ($uids)");
  38. }
  39. $doids = array();
  40. $query = DB::query("SELECT * FROM ".DB::table(‘home_doing‘)." WHERE uid IN ($uids)");
  41. while($value = DB::fetch($query)) {
  42. $doids[$value[‘doid‘]] = $value[‘doid‘];
  43. }
  44. $delsql = !empty($doids) ? "doid IN (".dimplode($doids).") OR " : "";
  45. DB::delete(‘home_docomment‘, "$delsql uid IN ($uids)");
  46. DB::delete(‘common_domain‘, "id IN ($uids) AND idtype=‘home‘");
  47. DB::delete(‘home_feed‘, "uid IN ($uids) OR (id IN ($uids) AND idtype=‘uid‘)");
  48. DB::delete(‘home_notification‘, "uid IN ($uids) OR authorid IN ($uids)");
  49. DB::delete(‘home_poke‘, "uid IN ($uids) OR fromuid IN ($uids)");
  50. DB::delete(‘home_comment‘, "(uid IN ($uids) OR authorid IN ($uids) OR (id IN ($uids) AND idtype=‘uid‘))");
  51. DB::delete(‘home_visitor‘, "uid IN ($uids) OR vuid IN ($uids)");
  52. DB::delete(‘home_friend‘, "uid IN ($uids) OR fuid IN ($uids)");
  53. DB::delete(‘home_friend_request‘, "uid IN ($uids) OR fuid IN ($uids)");
  54. DB::delete(‘common_invite‘, "uid IN ($uids) OR fuid IN ($uids)");
  55. DB::delete(‘common_myinvite‘, "touid IN ($uids) OR fromuid IN ($uids)");
  56. DB::delete(‘common_moderate‘, "id IN (".$uids.") AND idtype=‘uid_cid‘");
  57. //note 删除相册图片
  58. $query = DB::query("SELECT filepath, thumb, remote FROM ".DB::table(‘home_pic‘)." WHERE uid IN ($uids)");
  59. while($value = DB::fetch($query)) {
  60. $pics[] = $value;
  61. }
  62. deletepicfiles($pics);
  63. //note 删除相册封面图片
  64. include_once libfile(‘function/home‘);
  65. $query = DB::query("SELECT * FROM ".DB::table(‘home_album‘)." WHERE uid IN ($uids)");
  66. while($value = DB::fetch($query)) {
  67. pic_delete($value[‘pic‘], ‘album‘, 0, ($value[‘picflag‘] == 2 ? 1 : 0));
  68. }
  69. DB::query("DELETE FROM ".DB::table(‘common_mailcron‘).", ".DB::table(‘common_mailqueue‘)." USING ".DB::table(‘common_mailcron‘).", ".DB::table(‘common_mailqueue‘)." WHERE ".DB::table(‘common_mailcron‘).".touid IN ($uids) AND ".DB::table(‘common_mailcron‘).".cid=".DB::table(‘common_mailqueue‘).".cid", ‘UNBUFFERED‘);
  70. foreach(array(‘home_doing‘, ‘home_share‘, ‘home_album‘, ‘common_credit_rule_log‘, ‘common_credit_rule_log_field‘,
  71. ‘home_pic‘, ‘home_blog‘, ‘home_blogfield‘, ‘home_class‘, ‘home_clickuser‘,
  72. ‘home_userapp‘, ‘home_userappfield‘, ‘home_show‘, ‘common_member‘) as $table) {
  73. DB::delete($table, "uid IN ($uids)");
  74. }
  75. manyoulog(‘user‘, $uids, ‘delete‘);
  76. return $numdeleted;
  77. }
  78. /**
  79. * 删除帖子
  80. * @param array $ids 待删的 ID 数组
  81. * @param string $idtype authorid/tid/pid
  82. * @param boolean $credit 是否处理积分
  83. * @param int $posttableid post分表ID
  84. */
  85. function deletepost($ids, $idtype = ‘pid‘, $credit = false, $posttableid = false, $recycle = false) {
  86. global $_G;
  87. $recycle = $recycle && $idtype == ‘pid‘ ? true : false;
  88. if($_G[‘setting‘][‘plugins‘][HOOKTYPE.‘_deletepost‘]) {
  89. $_G[‘deletepostids‘] = & $ids;
  90. $hookparam = func_get_args();
  91. hookscript(‘deletepost‘, ‘global‘, ‘funcs‘, array(‘param‘ => $hookparam, ‘step‘ => ‘check‘), ‘deletepost‘);
  92. }
  93. if(!$ids || !in_array($idtype, array(‘authorid‘, ‘tid‘, ‘pid‘))) {
  94. return 0;
  95. }
  96. //note post分表缓存
  97. loadcache(‘posttableids‘);
  98. $posttableids = !empty($_G[‘cache‘][‘posttableids‘]) ? ($posttableid !== false && in_array($posttableid, $_G[‘cache‘][‘posttableids‘]) ? array($posttableid) : $_G[‘cache‘][‘posttableids‘]): array(‘0‘);
  99. if($idtype == ‘pid‘) {
  100. require_once libfile(‘function/forum‘);
  101. foreach($ids as $pid) {
  102. my_post_log(‘delete‘, array(‘pid‘ => $pid));
  103. }
  104. }
  105. $count = count($ids);
  106. $idsstr = dimplode($ids);
  107. //处理积分
  108. if($credit) {
  109. $tuidarray = $ruidarray = array();
  110. foreach($posttableids as $id) {
  111. $query = DB::query(‘SELECT tid, pid, first, authorid, replycredit, invisible FROM ‘.DB::table(getposttable($id))." WHERE $idtype IN ($idsstr)");
  112. while($post = DB::fetch($query)) {
  113. if($post[‘invisible‘] != -1 && $post[‘invisible‘] != -5) {
  114. if($post[‘first‘]) {
  115. $tuidarray[$post[‘fid‘]][] = $post[‘authorid‘];
  116. } else {
  117. $ruidarray[$post[‘fid‘]][] = $post[‘authorid‘];
  118. if($post[‘authorid‘] > 0 && $post[‘replycredit‘] > 0) {
  119. $replycredit_list[$post[‘authorid‘]][$post[‘tid‘]] += $post[‘replycredit‘];
  120. }
  121. }
  122. $tids[] = $post[‘tid‘];
  123. }
  124. }
  125. }
  126. if($tuidarray || $ruidarray) {
  127. require_once libfile(‘function/post‘);
  128. }
  129. //处理发贴的积分
  130. if($tuidarray) {
  131. foreach($tuidarray as $fid => $tuids) {
  132. updatepostcredits(‘-‘, $tuids, ‘post‘, $fid);
  133. }
  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. DB::query("UPDATE ".DB::table(getposttable($id))." SET invisible=‘-5‘ WHERE pid IN ($idsstr)");
  145. } else {
  146. foreach(array(getposttable($id), ‘forum_postcomment‘) as $table) {
  147. DB::delete($table, "$idtype IN ($idsstr)");
  148. }
  149. DB::delete(‘forum_trade‘, ($idtype == ‘authorid‘ ? ‘sellerid‘ : $idtype)." IN ($idsstr)");
  150. DB::delete(‘home_feed‘, "id IN ($idsstr) AND idtype=‘".($idtype == ‘authorid‘ ? ‘uid‘ : $idtype)."‘");
  151. }
  152. }
  153. if(!$recycle && $idtype != ‘authorid‘) {
  154. foreach(array(‘forum_postposition‘, ‘forum_poststick‘) as $table) {
  155. DB::delete($table, "$idtype IN ($idsstr)");
  156. }
  157. }
  158. if($idtype == ‘pid‘) {
  159. DB::delete(‘forum_postcomment‘, "rpid IN ($idsstr)");
  160. DB::delete(‘common_moderate‘, "id IN ($idsstr) AND idtype=‘pid‘");
  161. }
  162. if($replycredit_list) {
  163. $query = DB::query("SELECT tid, extcreditstype FROM ".DB::table(‘forum_replycredit‘)." WHERE tid IN (".dimplode($tids).")");
  164. while($rule = DB::fetch($query)) {
  165. $rule[‘extcreditstype‘] = $rule[‘extcreditstype‘] ? $rule[‘extcreditstype‘] : $_G[‘setting‘][‘creditstransextra‘][10] ;
  166. $replycredity_rule[$rule[‘tid‘]] = $rule;
  167. }
  168. foreach($replycredit_list AS $uid => $tid_credit) {
  169. foreach($tid_credit AS $tid => $credit) {
  170. $uid_credit[$replycredity_rule[$tid][‘extcreditstype‘]] -= $credit;
  171. }
  172. updatemembercount($uid, $uid_credit, true);
  173. }
  174. }
  175. if(!$recycle) {
  176. deleteattach($ids, $idtype);
  177. }
  178. if($_G[‘setting‘][‘plugins‘][HOOKTYPE.‘_deletepost‘]) {
  179. hookscript(‘deletepost‘, ‘global‘, ‘funcs‘, array(‘param‘ => $hookparam, ‘step‘ => ‘delete‘), ‘deletepost‘);
  180. }
  181. return $count;
  182. }
  183. function deletethreadcover($tids) {
  184. global $_G;
  185. loadcache(array(‘threadtableids‘, ‘posttableids‘));
  186. $threadtableids = !empty($_G[‘cache‘][‘threadtableids‘]) ? $_G[‘cache‘][‘threadtableids‘] : array(0);
  187. $deletecover = array();
  188. foreach($threadtableids as $tableid) {
  189. if(!$tableid) {
  190. $threadtable = "forum_thread";
  191. } else {
  192. $threadtable = "forum_thread_$tableid";
  193. }
  194. $query = DB::query("SELECT cover, tid FROM ".DB::table($threadtable)." WHERE tid IN ($tids)");
  195. while($row = DB::fetch($query)) {
  196. if($row[‘cover‘]) {
  197. $deletecover[$row[‘tid‘]] = $row[‘cover‘];
  198. }
  199. }
  200. }
  201. if($deletecover) {
  202. foreach($deletecover as $tid => $cover) {
  203. $filename = getthreadcover($tid, 0, 1);
  204. $remote = $cover < 0 ? 1 : 0;
  205. dunlink(array(‘attachment‘ => $filename, ‘remote‘ => $remote, ‘thumb‘ => 0));
  206. }
  207. }
  208. }
  209. /**
  210. * 删除主题
  211. * @param array $ids 待删的 ID 数组
  212. * @param boolean $membercount 是否更新用户帖数统计
  213. * @param boolean $credit 是否处理积分
  214. * @param boolean $ponly 是否只处理分表、入回收站时使用
  215. */
  216. function deletethread($tids, $membercount = false, $credit = false, $ponly = false) {
  217. global $_G;
  218. if($_G[‘setting‘][‘plugins‘][HOOKTYPE.‘_deletethread‘]) {
  219. $_G[‘deletethreadtids‘] = & $tids;
  220. $hookparam = func_get_args();
  221. hookscript(‘deletethread‘, ‘global‘, ‘funcs‘, array(‘param‘ => $hookparam, ‘step‘ => ‘check‘), ‘deletethread‘);
  222. }
  223. if(!$tids) {
  224. return 0;
  225. }
  226. require_once libfile(‘function/forum‘);
  227. foreach($tids as $tid) {
  228. my_post_log(‘delete‘, array(‘tid‘ => $tid));
  229. }
  230. $count = count($tids);
  231. $tids = dimplode($tids);
  232. //note 主题分表缓存
  233. loadcache(array(‘threadtableids‘, ‘posttableids‘));
  234. $threadtableids = !empty($_G[‘cache‘][‘threadtableids‘]) ? $_G[‘cache‘][‘threadtableids‘] : array();
  235. $posttableids = !empty($_G[‘cache‘][‘posttableids‘]) ? $_G[‘cache‘][‘posttableids‘] : array(‘0‘);
  236. //补充主题主表
  237. if(!in_array(0, $threadtableids)) {
  238. $threadtableids = array_merge(array(0), $threadtableids);
  239. }
  240. DB::delete(‘common_moderate‘, "id IN ($tids) AND idtype=‘tid‘");
  241. //note 收集待删的tid、fid、posttableid、threadtables
  242. $atids = $fids = $postids = $threadtables = array();
  243. foreach($threadtableids as $tableid) {
  244. $threadtable = !$tableid ? "forum_thread" : "forum_thread_$tableid";
  245. //note 收集待删的tid、fid、posttableid
  246. $query = DB::query("SELECT cover, tid, fid, posttableid FROM ".DB::table($threadtable)." WHERE tid IN ($tids)");
  247. while($row = DB::fetch($query)) {
  248. $atids[] = $row[‘tid‘];
  249. //note 整理出回帖分表
  250. $row[‘posttableid‘] = !empty($row[‘posttableid‘]) && in_array($row[‘posttableid‘], $posttableids) ? $row[‘posttableid‘] : ‘0‘;
  251. $postids[$row[‘posttableid‘]][$row[‘tid‘]] = $row[‘tid‘];
  252. if($tableid) {
  253. $fids[$row[‘fid‘]][] = $tableid;
  254. }
  255. }
  256. if(!$tableid && !$ponly) {
  257. $threadtables[] = $threadtable;
  258. }
  259. }
  260. //更新主题、帖子的积分或用户统计
  261. if($credit || $membercount) {
  262. $losslessdel = $_G[‘setting‘][‘losslessdel‘] > 0 ? TIMESTAMP - $_G[‘setting‘][‘losslessdel‘] * 86400 : 0;
  263. //note 从分表中得到所有的post列表
  264. $postlist = $uidarray = $tuidarray = $ruidarray = array();
  265. foreach($postids as $posttableid => $posttabletids) {
  266. $query = DB::query(‘SELECT tid, first, authorid, dateline, replycredit, invisible FROM ‘.DB::table(getposttable($posttableid)).‘ WHERE tid IN (‘.dimplode($posttabletids).‘)‘);
  267. while($post = DB::fetch($query)) {
  268. if($post[‘invisible‘] != -1 && $post[‘invisible‘] != -5) {
  269. $postlist[] = $post;
  270. }
  271. }
  272. }
  273. $query = DB::query("SELECT tid, extcreditstype FROM ".DB::table(‘forum_replycredit‘)." WHERE tid IN ($tids)");
  274. while($rule = DB::fetch($query)) {
  275. $rule[‘extcreditstype‘] = $rule[‘extcreditstype‘] ? $rule[‘extcreditstype‘] : $_G[‘setting‘][‘creditstransextra‘][10] ;
  276. $replycredit_rule[$rule[‘tid‘]] = $rule;
  277. }
  278. //note 处理post
  279. foreach($postlist as $post) {
  280. if($post[‘dateline‘] < $losslessdel) {
  281. if($membercount) {
  282. if($post[‘first‘]) {
  283. updatemembercount($post[‘authorid‘], array(‘threads‘ => -1, ‘post‘ => -1), false);
  284. } else {
  285. updatemembercount($post[‘authorid‘], array(‘posts‘ => -1), false);
  286. }
  287. }
  288. } else {
  289. if($credit) {
  290. if($post[‘first‘]) {
  291. $tuidarray[$post[‘fid‘]][] = $post[‘authorid‘];
  292. } else {
  293. $ruidarray[$post[‘fid‘]][] = $post[‘authorid‘];
  294. }
  295. }
  296. }
  297. if($credit || $membercount) {
  298. if($post[‘authorid‘] > 0 && $post[‘replycredit‘] > 0) {
  299. if($replycredit_rule[$post[‘tid‘]][‘extcreditstype‘]) {
  300. updatemembercount($post[‘authorid‘], array($replycredit_rule[$post[‘tid‘]][‘extcreditstype‘] => (int)(‘-‘.$post[‘replycredit‘])));
  301. }
  302. }
  303. }
  304. }
  305. if($credit) {
  306. if($tuidarray || $ruidarray) {
  307. require_once libfile(‘function/post‘);
  308. }
  309. if($tuidarray) {
  310. foreach($tuidarray as $fid => $tuids) {
  311. updatepostcredits(‘-‘, $tuids, ‘post‘, $fid);
  312. }
  313. }
  314. if($ruidarray) {
  315. foreach($ruidarray as $fid => $ruids) {
  316. updatepostcredits(‘-‘, $ruids, ‘reply‘, $fid);
  317. }
  318. }
  319. //note 处理附件积分
  320. $auidarray = $attachtables = array();
  321. foreach($atids as $tid) {
  322. $attachtables[getattachtablebytid($tid)][] = $tid;
  323. }
  324. foreach($attachtables as $attachtable => $attachtids) {
  325. $query = DB::query("SELECT uid, dateline FROM ".DB::table($attachtable)." WHERE tid IN (".dimplode($attachtids).")");
  326. while($attach = DB::fetch($query)) {
  327. if($attach[‘dateline‘] > $losslessdel) {
  328. $auidarray[$attach[‘uid‘]] = !empty($auidarray[$attach[‘uid‘]]) ? $auidarray[$attach[‘uid‘]] + 1 : 1;
  329. }
  330. }
  331. }
  332. if($auidarray) {
  333. $postattachcredits = !empty($_G[‘forum‘][‘postattachcredits‘]) ? $_G[‘forum‘][‘postattachcredits‘] : $_G[‘setting‘][‘creditspolicy‘][‘postattach‘];
  334. updateattachcredits(‘-‘, $auidarray, $postattachcredits);
  335. }
  336. }
  337. }
  338. if($ponly) {
  339. if($_G[‘setting‘][‘plugins‘][HOOKTYPE.‘_deletethread‘]) {
  340. hookscript(‘deletethread‘, ‘global‘, ‘funcs‘, array(‘param‘ => $hookparam, ‘step‘ => ‘delete‘), ‘deletethread‘);
  341. }
  342. DB::query("UPDATE ".DB::table(‘forum_thread‘)." SET displayorder=‘-1‘, digest=‘0‘, moderated=‘1‘ WHERE tid IN ($tids)");
  343. foreach($postids as $posttableid=>$oneposttids) {
  344. updatepost(array(‘invisible‘ => ‘-1‘), "tid IN ($tids)");
  345. }
  346. return $count;
  347. }
  348. //note 回帖奖励积分清理
  349. DB::delete(‘forum_replycredit‘, "tid IN ($tids)");
  350. DB::delete(‘common_credit_log‘, "operation IN (‘RCT‘, ‘RCA‘, ‘RCB‘) AND relatedid IN ($tids)");
  351. deletethreadcover($tids);
  352. //note 删除主题
  353. foreach($threadtables as $threadtable) {
  354. DB::delete($threadtable, "tid IN ($tids)");
  355. }
  356. //删除帖子、附件
  357. if($atids) {
  358. foreach($postids as $posttableid=>$oneposttids) {
  359. deletepost($oneposttids, ‘tid‘, false, $posttableid);
  360. }
  361. deleteattach($atids, ‘tid‘);
  362. }
  363. //note 更新分表主题帖子数
  364. if($fids) {
  365. foreach($fids as $fid => $tableids) {
  366. $tableids = array_unique($tableids);
  367. foreach($tableids as $tableid) {
  368. $query = DB::query("SELECT COUNT(*) AS threads, SUM(replies)+COUNT(*) AS posts FROM ".DB::table("forum_thread_$tableid")." WHERE fid=‘$fid‘");
  369. while($row = DB::fetch($query)) {
  370. DB::insert(‘forum_forum_threadtable‘, array(‘fid‘ => $fid, ‘threadtableid‘ => $tableid, ‘threads‘ => intval($row[‘threads‘]), ‘posts‘ => intval($row[‘posts‘])), false, true);
  371. }
  372. }
  373. }
  374. }
  375. //note 处理附属表 新增主题相关表的时候要在这里添加
  376. foreach(array(‘forum_forumrecommend‘, ‘forum_polloption‘, ‘forum_poll‘, ‘forum_activity‘, ‘forum_activityapply‘, ‘forum_debate‘,
  377. ‘forum_debatepost‘, ‘forum_threadmod‘, ‘forum_relatedthread‘, ‘forum_typeoptionvar‘,
  378. ‘forum_postposition‘, ‘forum_poststick‘, ‘forum_pollvoter‘, ‘forum_threadimage‘) as $table) {
  379. DB::delete($table, "tid IN ($tids)");
  380. }
  381. DB::query("DELETE FROM ".DB::table(‘home_feed‘)." WHERE id IN ($tids) AND idtype=‘tid‘", ‘UNBUFFERED‘);
  382. DB::query("DELETE FROM ".DB::table(‘common_tagitem‘)." WHERE idtype=‘tid‘ AND itemid IN ($tids)", ‘UNBUFFERED‘);
  383. DB::query("DELETE FROM ".DB::table(‘forum_threadrush‘)." WHERE tid IN ($tids)", ‘UNBUFFERED‘);
  384. if($_G[‘setting‘][‘plugins‘][HOOKTYPE.‘_deletethread‘]) {
  385. hookscript(‘deletethread‘, ‘global‘, ‘funcs‘, array(‘param‘ => $hookparam, ‘step‘ => ‘delete‘), ‘deletethread‘);
  386. }
  387. return $count;
  388. }
  389. /**
  390. * 删除论坛附件
  391. * @param type $ids 待删的 ID 数组
  392. * @param type $idtype uid/authorid/tid/pid
  393. */
  394. function deleteattach($ids, $idtype = ‘aid‘) {
  395. global $_G;
  396. if(!$ids || !in_array($idtype, array(‘authorid‘, ‘uid‘, ‘tid‘, ‘pid‘))) {
  397. return;
  398. }
  399. $idtype = $idtype == ‘authorid‘ ? ‘uid‘ : $idtype;
  400. $ids = dimplode($ids);
  401. $pics = $attachtables = array();
  402. $query = DB::query("SELECT aid, tableid FROM ".DB::table(‘forum_attachment‘)." WHERE $idtype IN ($ids) AND pid>0");
  403. while($attach = DB::fetch($query)) {
  404. $attachtables[$attach[‘tableid‘]][] = $attach[‘aid‘];
  405. }
  406. foreach($attachtables as $attachtable => $aids) {
  407. if($attachtable == 127) {
  408. continue;
  409. }
  410. $attachtable = ‘forum_attachment_‘.$attachtable;
  411. $aids = dimplode($aids);
  412. $query = DB::query("SELECT attachment, thumb, remote, aid, picid FROM ".DB::table($attachtable)." WHERE aid IN ($aids) AND pid>0");
  413. while($attach = DB::fetch($query)) {
  414. if($attach[‘picid‘]) {
  415. $pics[] = $attach[‘picid‘];
  416. }
  417. dunlink($attach);
  418. }
  419. DB::delete($attachtable, "aid IN ($aids) AND pid>0");
  420. }
  421. DB::delete(‘forum_attachment‘, "$idtype IN ($ids) AND pid>0");
  422. if($pics) {
  423. $albumids = array();
  424. $query = DB::query("SELECT albumid FROM ".DB::table(‘home_pic‘)." WHERE picid IN (".dimplode($pics).") GROUP BY albumid");
  425. DB::delete(‘home_pic‘, ‘picid IN (‘.dimplode($pics).‘)‘, 0);
  426. while($album = DB::fetch($query)) {
  427. DB::update(‘home_album‘, array(‘picnum‘ => getcount(‘home_pic‘, array(‘albumid‘ => $album[‘albumid‘]))), array(‘albumid‘ => $album[‘albumid‘]));
  428. }
  429. }
  430. }
  431. /**
  432. * 删除评论
  433. * @param array $cids 待删除的 ID 数组
  434. */
  435. function deletecomments($cids) {
  436. global $_G;
  437. $deltypes = $blognums = $newcids = $dels = $counts = array();
  438. $allowmanage = checkperm(‘managecomment‘);
  439. $query = DB::query("SELECT * FROM ".DB::table(‘home_comment‘)." WHERE cid IN (".dimplode($cids).")");
  440. while ($value = DB::fetch($query)) {
  441. if($allowmanage || $value[‘authorid‘] == $_G[‘uid‘] || $value[‘uid‘] == $_G[‘uid‘]) {
  442. $dels[] = $value;
  443. $newcids[] = $value[‘cid‘];
  444. $deltypes[$value[‘idtype‘]] = $value[‘idtype‘].‘_cid‘;
  445. //积分
  446. if($value[‘authorid‘] != $_G[‘uid‘] && $value[‘uid‘] != $_G[‘uid‘]) {
  447. $counts[$value[‘authorid‘]][‘coef‘] -= 1;
  448. }
  449. if($value[‘idtype‘] == ‘blogid‘) {
  450. $blognums[$value[‘id‘]]++;
  451. }
  452. }
  453. }
  454. if(empty($dels)) return array();
  455. //数据删除
  456. DB::delete(‘home_comment‘, "cid IN (".dimplode($newcids).")");
  457. DB::delete(‘common_moderate‘, "id IN (".dimplode($newcids).") AND idtype IN(".dimplode($deltypes).")");
  458. //扣除相应的积分
  459. if($counts) {
  460. foreach ($counts as $uid => $setarr) {
  461. batchupdatecredit(‘comment‘, $uid, array(), $setarr[‘coef‘]);
  462. }
  463. }
  464. //更新统计
  465. if($blognums) {
  466. $nums = renum($blognums);
  467. foreach ($nums[0] as $num) {
  468. DB::query("UPDATE ".DB::table(‘home_blog‘)." SET replynum=replynum-$num WHERE blogid IN (".dimplode($nums[1][$num]).")");
  469. }
  470. }
  471. return $dels;
  472. }
  473. /**
  474. * 删除博客
  475. * @param array $blogids 待删除的 ID 数组
  476. */
  477. function deleteblogs($blogids) {
  478. global $_G;
  479. //获取博客信息
  480. $blogs = $newblogids = $counts = array();
  481. $allowmanage = checkperm(‘manageblog‘);
  482. $query = DB::query("SELECT * FROM ".DB::table(‘home_blog‘)." WHERE blogid IN (".dimplode($blogids).")");
  483. while ($value = DB::fetch($query)) {
  484. if($allowmanage || $value[‘uid‘] == $_G[‘uid‘]) {
  485. $blogs[] = $value;
  486. $newblogids[] = $value[‘blogid‘];
  487. //积分
  488. if($value[‘uid‘] != $_G[‘uid‘]) {
  489. $counts[$value[‘uid‘]][‘coef‘] -= 1;
  490. }
  491. $counts[$value[‘uid‘]][‘blogs‘] -= 1;
  492. }
  493. }
  494. if(empty($blogs)) return array();
  495. //数据删除
  496. DB::delete(‘home_blog‘, "blogid IN (".dimplode($newblogids).")");
  497. DB::delete(‘home_blogfield‘, "blogid IN (".dimplode($newblogids).")");
  498. DB::delete(‘home_comment‘, "id IN (".dimplode($newblogids).") AND idtype=‘blogid‘");
  499. DB::delete(‘home_feed‘, "id IN (".dimplode($newblogids).") AND idtype=‘blogid‘");
  500. DB::delete(‘home_clickuser‘, "id IN (".dimplode($newblogids).") AND idtype=‘blogid‘");
  501. DB::delete(‘common_moderate‘, "id IN (".dimplode($newblogids).") AND idtype=‘blogid‘");
  502. DB::delete(‘common_moderate‘, "id IN (".dimplode($newblogids).") AND idtype=‘blogid_cid‘");
  503. //更新统计
  504. if($counts) {
  505. foreach ($counts as $uid => $setarr) {
  506. batchupdatecredit(‘publishblog‘, $uid, array(‘blogs‘ => $setarr[‘blogs‘]), $setarr[‘coef‘]);
  507. }
  508. }
  509. //删除标签关系
  510. DB::query("DELETE FROM ".DB::table(‘common_tagitem‘)." WHERE idtype=‘blogid‘ AND itemid IN (".dimplode($newblogids).")");
  511. return $blogs;
  512. }
  513. /**
  514. * 删除事件
  515. * @param array $feedids 待删除的 ID 数组
  516. */
  517. function deletefeeds($feedids) {
  518. global $_G;
  519. $allowmanage = checkperm(‘managefeed‘);
  520. $feeds = $newfeedids = array();
  521. $query = DB::query("SELECT * FROM ".DB::table(‘home_feed‘)." WHERE feedid IN (".dimplode($feedids).")");
  522. while ($value = DB::fetch($query)) {
  523. if($allowmanage || $value[‘uid‘] == $_G[‘uid‘]) {//管理员/作者
  524. $newfeedids[] = $value[‘feedid‘];
  525. $feeds[] = $value;
  526. }
  527. }
  528. if(empty($newfeedids)) return array();
  529. DB::query("DELETE FROM ".DB::table(‘home_feed‘)." WHERE feedid IN (".dimplode($newfeedids).")");
  530. return $feeds;
  531. }
  532. /**
  533. * 删除分享
  534. * @param array $sids 待删除的 ID 数组
  535. */
  536. function deleteshares($sids) {
  537. global $_G;
  538. $allowmanage = checkperm(‘manageshare‘);
  539. $shares = $newsids = $counts = array();
  540. $query = DB::query("SELECT * FROM ".DB::table(‘home_share‘)." WHERE sid IN (".dimplode($sids).")");
  541. while ($value = DB::fetch($query)) {
  542. if($allowmanage || $value[‘uid‘] == $_G[‘uid‘]) {//管理员/作者
  543. $shares[] = $value;
  544. $newsids[] = $value[‘sid‘];
  545. //积分
  546. if($value[‘uid‘] != $_G[‘uid‘]) {
  547. $counts[$value[‘uid‘]][‘coef‘] -= 1;
  548. }
  549. $counts[$value[‘uid‘]][‘sharings‘] -= 1;
  550. }
  551. }
  552. if(empty($shares)) return array();
  553. DB::delete(‘home_share‘, "sid IN (".dimplode($newsids).")");
  554. DB::delete(‘home_comment‘, "id IN (".dimplode($newsids).") AND idtype=‘sid‘");
  555. DB::delete(‘home_feed‘, "id IN (".dimplode($newsids).") AND idtype=‘sid‘");
  556. DB::delete(‘common_moderate‘, "id IN (".dimplode($newsids).") AND idtype=‘sid‘");
  557. DB::delete(‘common_moderate‘, "id IN (".dimplode($newsids).") AND idtype=‘sid_cid‘");
  558. //TODO 举报相关
  559. //  DB::query("DELETE FROM ".DB::table(‘home_report‘)." WHERE id IN (".dimplode($newsids).") AND idtype=‘sid‘");
  560. //更新统计
  561. if($counts) {
  562. foreach ($counts as $uid => $setarr) {
  563. batchupdatecredit(‘createshare‘, $uid, array(‘sharings‘ => $setarr[‘sharings‘]), $setarr[‘coef‘]);
  564. }
  565. }
  566. return $shares;
  567. }
  568. /**
  569. * 删除记录
  570. * @param array $ids 待删除的 ID 数组
  571. */
  572. function deletedoings($ids) {
  573. global $_G;
  574. $allowmanage = checkperm(‘managedoing‘);
  575. $doings = $newdoids = $counts = array();
  576. $query = DB::query("SELECT * FROM ".DB::table(‘home_doing‘)." WHERE doid IN (".dimplode($ids).")");
  577. while ($value = DB::fetch($query)) {
  578. if($allowmanage || $value[‘uid‘] == $_G[‘uid‘]) {//管理员/作者
  579. $doings[] = $value;
  580. $newdoids[] = $value[‘doid‘];
  581. //积分
  582. if($value[‘uid‘] != $_G[‘uid‘]) {
  583. $counts[$value[‘uid‘]][‘coef‘] -= 1;
  584. }
  585. $counts[$value[‘uid‘]][‘doings‘] -= 1;
  586. }
  587. }
  588. if(empty($doings)) return array();
  589. DB::delete(‘home_doing‘, "doid IN (".dimplode($newdoids).")");
  590. DB::delete(‘home_docomment‘, "doid IN (".dimplode($newdoids).")");
  591. DB::delete(‘home_feed‘, "id IN (".dimplode($newdoids).") AND idtype=‘doid‘");
  592. DB::delete(‘common_moderate‘, "id IN (".dimplode($newdoids).") AND idtype=‘doid‘");
  593. //更新统计
  594. if($counts) {
  595. foreach ($counts as $uid => $setarr) {
  596. batchupdatecredit(‘doing‘, $uid, array(‘doings‘ => $setarr[‘doings‘]), $setarr[‘coef‘]);
  597. }
  598. }
  599. return $doings;
  600. }
  601. /**
  602. * 删除空间
  603. * @param array $uid 待删除的用户 ID
  604. */
  605. function deletespace($uid) {
  606. global $_G;
  607. $allowmanage = checkperm(‘managedelspace‘);
  608. //软删除
  609. if($allowmanage) {
  610. DB::query("UPDATE ".DB::table(‘common_member‘)." SET status=‘1‘ WHERE uid=‘$uid‘");
  611. manyoulog(‘user‘, $uid, ‘delete‘);
  612. return true;
  613. } else {
  614. return false;
  615. }
  616. }
  617. /**
  618. * 删除图片
  619. * @param array $picids 待删除的 ID 数组
  620. */
  621. function deletepics($picids) {
  622. global $_G;
  623. $albumids = $sizes = $pics = $newids = array();
  624. $allowmanage = checkperm(‘managealbum‘);
  625. $haveforumpic = false;
  626. $query = DB::query("SELECT * FROM ".DB::table(‘home_pic‘)." WHERE picid IN (".dimplode($picids).")");
  627. while ($value = DB::fetch($query)) {
  628. if($allowmanage || $value[‘uid‘] == $_G[‘uid‘]) {
  629. //删除文件
  630. $pics[] = $value;
  631. $newids[] = $value[‘picid‘];
  632. $sizes[$value[‘uid‘]] = $sizes[$value[‘uid‘]] + $value[‘size‘];
  633. $albumids[$value[‘albumid‘]] = $value[‘albumid‘];
  634. if(!$haveforumpic && $value[‘remote‘] > 1) {
  635. $haveforumpic = true;
  636. }
  637. }
  638. }
  639. if(empty($pics)) return array();
  640. DB::query("DELETE FROM ".DB::table(‘home_pic‘)." WHERE picid IN (".dimplode($newids).")");
  641. if($haveforumpic) {
  642. for($i = 0;$i < 10;$i++) {
  643. DB::query("UPDATE ".DB::table(‘forum_attachment_‘.$i)." SET picid=‘0‘ WHERE picid IN (".dimplode($newids).")");
  644. }
  645. }
  646. DB::delete(‘home_comment‘, "id IN (".dimplode($newids).") AND idtype=‘picid‘");
  647. DB::delete(‘home_feed‘, "id IN (".dimplode($newids).") AND idtype=‘picid‘");
  648. DB::delete(‘home_clickuser‘, "id IN (".dimplode($newids).") AND idtype=‘picid‘");
  649. DB::delete(‘common_moderate‘, "id IN (".dimplode($newids).") AND idtype=‘picid‘");
  650. DB::delete(‘common_moderate‘, "id IN (".dimplode($newsids).") AND idtype=‘picid_cid‘");
  651. //更新统计
  652. if($sizes) {
  653. foreach ($sizes as $uid => $setarr) {
  654. $attachsize = intval($sizes[$uid]);
  655. updatemembercount($uid, array(‘attachsize‘ => -$attachsize), false);
  656. }
  657. }
  658. //更新相册封面
  659. require_once libfile(‘function/spacecp‘);
  660. foreach ($albumids as $albumid) {
  661. if($albumid) {
  662. album_update_pic($albumid);
  663. }
  664. }
  665. //删除图片
  666. deletepicfiles($pics);
  667. return $pics;
  668. }
  669. /**
  670. * 删除图片文件
  671. * @param array $pics 待删除的图片数组
  672. */
  673. function deletepicfiles($pics) {
  674. global $_G;
  675. $remotes = array();
  676. include_once libfile(‘function/home‘);
  677. foreach ($pics as $pic) {
  678. pic_delete($pic[‘filepath‘], ‘album‘, $pic[‘thumb‘], $pic[‘remote‘]);
  679. }
  680. }
  681. /**
  682. * 删除相册
  683. * @param array $albumids 待删除的 ID 数组
  684. */
  685. function deletealbums($albumids) {
  686. global $_G;
  687. $sizes = $dels = $newids = $counts = array();
  688. $allowmanage = checkperm(‘managealbum‘);
  689. $query = DB::query("SELECT * FROM ".DB::table(‘home_album‘)." WHERE albumid IN (".dimplode($albumids).")");
  690. while ($value = DB::fetch($query)) {
  691. if($allowmanage || $value[‘uid‘] == $_G[‘uid‘]) {
  692. $dels[] = $value;
  693. $newids[] = $value[‘albumid‘];
  694. if(!empty($value[‘pic‘])) {
  695. include_once libfile(‘function/home‘);
  696. pic_delete($value[‘pic‘], ‘album‘, 0, ($value[‘picflag‘] == 2 ? 1 : 0));
  697. }
  698. }
  699. $counts[$value[‘uid‘]][‘albums‘] -= 1;
  700. }
  701. if(empty($dels)) return array();
  702. //获取积分
  703. $pics = $picids = array();
  704. $query = DB::query("SELECT * FROM ".DB::table(‘home_pic‘)." WHERE albumid IN (".dimplode($newids).")");
  705. while ($value = DB::fetch($query)) {
  706. $pics[] = $value;
  707. $picids[] = $value[‘picid‘];
  708. $sizes[$value[‘uid‘]] = $sizes[$value[‘uid‘]] + $value[‘size‘];
  709. }
  710. DB::query("DELETE FROM ".DB::table(‘home_pic‘)." WHERE albumid IN (".dimplode($newids).")");
  711. DB::query("DELETE FROM ".DB::table(‘home_album‘)." WHERE albumid IN (".dimplode($newids).")");
  712. DB::query("DELETE FROM ".DB::table(‘home_feed‘)." WHERE id IN (".dimplode($newids).") AND idtype=‘albumid‘");
  713. //  DB::query("DELETE FROM ".DB::table(‘home_report‘)." WHERE id IN (".dimplode($newids).") AND idtype=‘albumid‘");
  714. if($picids) DB::query("DELETE FROM ".DB::table(‘home_clickuser‘)." WHERE id IN (".dimplode($picids).") AND idtype=‘picid‘");
  715. //更新统计
  716. if($sizes) {
  717. foreach ($sizes as $uid => $value) {
  718. $attachsize = intval($sizes[$uid]);
  719. $albumnum = $counts[$uid][‘albums‘] ? $counts[$uid][‘albums‘] : 0;
  720. updatemembercount($uid, array(‘albums‘ => $albumnum, ‘attachsize‘ => -$attachsize), false);
  721. }
  722. }
  723. //删除图片
  724. if($pics) {
  725. deletepicfiles($pics);//删除图片
  726. }
  727. return $dels;
  728. }
  729. /**
  730. * 删除投票
  731. * @param array $pids 待删除的 ID 数组
  732. */
  733. function deletepolls($pids) {
  734. global $_G;
  735. $counts = $polls = $newpids = array();
  736. $allowmanage = checkperm(‘managepoll‘);
  737. $query = DB::query("SELECT * FROM ".DB::table(‘home_poll‘)." WHERE pid IN (".dimplode($pids).")");
  738. while ($value = DB::fetch($query)) {
  739. if($allowmanage || $value[‘uid‘] == $_G[‘uid‘]) {
  740. $polls[] = $value;
  741. $newpids[] = $value[‘pid‘];
  742. if($value[‘uid‘] != $_G[‘uid‘]) {
  743. $counts[$value[‘uid‘]][‘coef‘] -= 1;
  744. }
  745. $counts[$value[‘uid‘]][‘polls‘] -= 1;
  746. }
  747. }
  748. if(empty($polls)) return array();
  749. //数据删除
  750. DB::query("DELETE FROM ".DB::table(‘home_poll‘)." WHERE pid IN (".dimplode($newpids).")");
  751. DB::query("DELETE FROM ".DB::table(‘home_pollfield‘)." WHERE pid IN (".dimplode($newpids).")");
  752. DB::query("DELETE FROM ".DB::table(‘home_polloption‘)." WHERE pid IN (".dimplode($newpids).")");
  753. DB::query("DELETE FROM ".DB::table(‘home_polluser‘)." WHERE pid IN (".dimplode($newpids).")");
  754. DB::query("DELETE FROM ".DB::table(‘home_comment‘)." WHERE id IN (".dimplode($newpids).") AND idtype=‘pid‘");
  755. DB::query("DELETE FROM ".DB::table(‘home_feed‘)." WHERE id IN (".dimplode($newpids).") AND idtype=‘pid‘");
  756. //  DB::query("DELETE FROM ".DB::table(‘home_report‘)." WHERE id IN (".dimplode($newpids).") AND idtype=‘pid‘");
  757. //更新统计
  758. if($counts) {
  759. foreach ($counts as $uid => $setarr) {
  760. batchupdatecredit(‘createpoll‘, $uid, array(‘polls‘ => $setarr[‘polls‘]), $setarr[‘coef‘]);
  761. }
  762. }
  763. return $polls;
  764. }
  765. function deletetrasharticle($aids) {
  766. global $_G;
  767. require_once libfile(‘function/home‘);
  768. $articles = $trashid = $pushs = $dels = array();
  769. $query = DB::query("SELECT * FROM ".DB::table(‘portal_article_trash‘)." WHERE aid IN (".dimplode($aids).")");
  770. while ($value = DB::fetch($query)) {
  771. $dels[$value[‘aid‘]] = $value[‘aid‘];
  772. $article = unserialize($value[‘content‘]);
  773. $articles[$article[‘aid‘]] = $article;
  774. if(!empty($article[‘idtype‘])) $pushs[$article[‘idtype‘]][] = $article[‘id‘];
  775. if($article[‘pic‘]) {
  776. pic_delete($article[‘pic‘], ‘portal‘, $article[‘thumb‘], $article[‘remote‘]);
  777. }
  778. }
  779. if($dels) {
  780. DB::query(‘DELETE FROM ‘.DB::table(‘portal_article_trash‘)." WHERE aid IN(".dimplode($dels).")", ‘UNBUFFERED‘);
  781. deletearticlepush($pushs);
  782. deletearticlerelated($dels);
  783. }
  784. return $articles;
  785. }
  786. /**
  787. * 删除门户文章
  788. * @param array $aids 待删除的 ID 数组
  789. * @param boolean $istrash
  790. */
  791. function deletearticle($aids, $istrash = true) {
  792. global $_G;
  793. if(empty($aids)) return false;
  794. $trasharr = $article = $bids = $dels = $attachment = $attachaid = $catids = $pushs = array();
  795. $query = DB::query("SELECT * FROM ".DB::table(‘portal_article_title‘)." WHERE aid IN (".dimplode($aids).")");
  796. while ($value = DB::fetch($query)) {
  797. $catids[] = intval($value[‘catid‘]);
  798. $dels[$value[‘aid‘]] = $value[‘aid‘];
  799. $article[] = $value;
  800. if(!empty($value[‘idtype‘])) $pushs[$value[‘idtype‘]][] = $value[‘id‘];
  801. }
  802. if($dels) {
  803. foreach($article as $key => $value) {
  804. if($istrash) {
  805. $valstr = daddslashes(serialize($value));
  806. $trasharr[] = "(‘$value[aid]‘, ‘$valstr‘)";
  807. } elseif($value[‘pic‘]) {
  808. //删除封面图片
  809. pic_delete($value[‘pic‘], ‘portal‘, $value[‘thumb‘], $value[‘remote‘]);
  810. $attachaid[] = $value[‘aid‘];
  811. }
  812. }
  813. if($istrash) {
  814. if($trasharr) {
  815. DB::query("INSERT INTO ".DB::table(‘portal_article_trash‘)." (`aid`, `content`) VALUES ".implode(‘,‘, $trasharr));
  816. }
  817. } else {
  818. deletearticlepush($pushs);
  819. deletearticlerelated($dels);
  820. }
  821. DB::delete(‘portal_article_title‘, "aid IN(".dimplode($dels).")");
  822. DB::delete(‘common_moderate‘, "id IN (".dimplode($dels).") AND idtype=‘aid‘");
  823. // 相关文章分类文章数目
  824. $catids = array_unique($catids);
  825. if($catids) {
  826. foreach($catids as $catid) {
  827. $cnt = DB::result_first(‘SELECT COUNT(*) FROM ‘.DB::table(‘portal_article_title‘)." WHERE catid = ‘$catid‘");
  828. DB::update(‘portal_category‘, array(‘articles‘=>$cnt), array(‘catid‘=>$catid));
  829. }
  830. }
  831. }
  832. return $article;
  833. }
  834. /**
  835. * 清除生成文章的标识
  836. */
  837. function deletearticlepush($pushs) {
  838. if(!empty($pushs) && is_array($pushs)) {
  839. foreach($pushs as $idtype=> $fromids) {
  840. switch ($idtype) {
  841. case ‘blogid‘:
  842. if(!empty($fromids)) DB::update(‘home_blogfield‘,array(‘pushedaid‘=>‘0‘), ‘blogid IN (‘.dimplode($fromids).‘)‘);
  843. break;
  844. case ‘tid‘:
  845. if(!empty($fromids)) $a = DB::update(‘forum_thread‘,array(‘pushedaid‘=>‘0‘), ‘tid IN (‘.dimplode($fromids).‘)‘);
  846. break;
  847. }
  848. }
  849. }
  850. }
  851. /**
  852. * 删除文章相关的数据
  853. */
  854. function deletearticlerelated($dels) {
  855. //统计
  856. DB::delete(‘portal_article_count‘, "aid IN(".dimplode($dels).")");
  857. //内容
  858. DB::delete(‘portal_article_content‘, "aid IN(".dimplode($dels).")");
  859. //附件
  860. $query = DB::query("SELECT * FROM ".DB::table(‘portal_attachment‘)." WHERE aid IN (".dimplode($dels).")");
  861. while ($value = DB::fetch($query)) {
  862. $attachment[] = $value;
  863. $attachdel[] = $value[‘attachid‘];
  864. }
  865. require_once libfile(‘function/home‘);
  866. foreach ($attachment as $value) {
  867. pic_delete($value[‘attachment‘], ‘portal‘, $value[‘thumb‘], $value[‘remote‘]);
  868. }
  869. DB::delete(‘portal_attachment‘, "aid IN (".dimplode($dels).")");
  870. //评论
  871. DB::delete(‘portal_comment‘, "id IN(".dimplode($dels).") AND idtype=‘aid‘");
  872. DB::delete(‘common_moderate‘, "id IN (".dimplode($dels).") AND idtype=‘aid_cid‘");
  873. //相关文章
  874. DB::delete(‘portal_article_related‘, "aid IN(".dimplode($dels).")");
  875. }
  876. function deleteportaltopic($dels) {
  877. if(empty($dels)) return false;
  878. //delete common_diy_data
  879. $targettplname = array();
  880. foreach ((array)$dels as $key => $value) {
  881. $targettplname[] = ‘portal/portal_topic_content_‘.$value;
  882. }
  883. DB::delete(‘common_diy_data‘, "targettplname IN (".dimplode($targettplname).")", 0, true);
  884. //删除模块权限
  885. require_once libfile(‘class/blockpermission‘);
  886. $tplpermission = & template_permission::instance();
  887. $templates = array();
  888. $tplpermission->delete_allperm_by_tplname($targettplname);
  889. //删除指定的域名
  890. deletedomain($dels, ‘topic‘);
  891. //delete 模块和页面的关联表
  892. DB::delete(‘common_template_block‘, ‘targettplname IN (‘.dimplode($targettplname).‘)‘, 0, true);
  893. //delete portal_topic_pic
  894. require_once libfile(‘function/home‘);
  895. $picids = array();
  896. $query = DB::query(‘SELECT * FROM ‘.DB::table(‘portal_topic‘).‘ WHERE topicid IN (‘.dimplode($dels).‘)‘);
  897. while ($value = DB::fetch($query)) {
  898. if($value[‘picflag‘] != ‘0‘) pic_delete(str_replace(‘portal/‘, ‘‘, $value[‘cover‘]), ‘portal‘, 0, $value[‘picflag‘] == ‘2‘ ? ‘1‘ : ‘0‘);
  899. }
  900. $picids = array();
  901. $query = DB::query(‘SELECT * FROM ‘.DB::table(‘portal_topic_pic‘).‘ WHERE topicid IN (‘.dimplode($dels).‘)‘);
  902. while ($value = DB::fetch($query)) {
  903. $picids[] = $value[‘picid‘];
  904. //delete pic
  905. pic_delete($value[‘filepath‘], ‘portal‘, $value[‘thumb‘], $value[‘remote‘]);
  906. }
  907. if (!empty($picids)) {
  908. DB::delete(‘portal_topic_pic‘, ‘picid IN (‘.dimplode($picids).‘)‘, 0, true);
  909. }
  910. //delete file
  911. foreach ($targettplname as $key => $value) {
  912. @unlink(DISCUZ_ROOT.‘./data/diy/‘.$value.‘.htm‘);
  913. @unlink(DISCUZ_ROOT.‘./data/diy/‘.$value.‘.htm.bak‘);
  914. @unlink(DISCUZ_ROOT.‘./data/diy/‘.$value.‘_preview.htm‘);
  915. }
  916. //delete topic
  917. DB::delete(‘portal_topic‘, ‘topicid IN (‘.dimplode($dels).‘)‘);
  918. //评论
  919. DB::delete(‘portal_comment‘, "id IN(".dimplode($dels).") AND idtype=‘topicid‘");
  920. DB::delete(‘common_moderate‘, "id IN (".dimplode($dels).") AND idtype=‘topicid_cid‘");
  921. //清除模块
  922. include_once libfile(‘function/block‘);
  923. block_clear();
  924. // 更新缓存
  925. include_once libfile(‘function/cache‘);
  926. updatecache(‘diytemplatename‘);
  927. }
  928. /**
  929. * 跟据id、idtype删除指定的域名
  930. * @param Integer $ids: 指写ids
  931. * @param String $idtype:对象类型subarea:分区、forum:版块、home:个人空间、group:群组、topic:专题、channel:频道
  932. */
  933. function deletedomain($ids, $idtype) {
  934. if($ids && $idtype) {
  935. $ids = !is_array($ids) ? array($ids) : $ids;
  936. DB::query(‘DELETE FROM ‘.DB::table(‘common_domain‘)." WHERE id IN(".dimplode($ids).") AND idtype=‘$idtype‘", ‘UNBUFFERED‘);
  937. }
  938. }
  939. ?>
时间: 2024-08-01 08:12:53

【discuzX2】/source/function/function_delete.php数据清理函数集合分析的相关文章

【discuzX2】/source/function/function_forum.php论坛模块通用函数集合分析

<?php /** *      [Discuz!] (C)2001-2099 Comsenz Inc. *      This is NOT a freeware, use is subject to license terms *      论坛模块通用函数集合 *      $Id: function_forum.php 24723 2011-10-09 12:50:14Z yangli $ */ if(!defined('IN_DISCUZ')) { exit('Access Denie

【discuzX2】/source/function/function_core.php通用核心函数库文件分析

[php] view plain copy print? <?php /** *      [Discuz!] (C)2001-2099 Comsenz Inc. *      This is NOT a freeware, use is subject to license terms * *      $Id: function_core.php 28890 2012-03-19 02:05:42Z liudongdong $ */ if(!defined('IN_DISCUZ')) { e

用Excel做数据分析常用函数(数据清理、关联匹配……)

本文总结在使用Excel进行数据分析时,最常用的功能和函数. Excel的功能和函数非常多,用进废退,除了学习基本的函数和功能,最重要的是遇到问题可以快速的搜索并解决. 首先Excel可以处理的数据量有大多? 使用Ctrl +  → , Ctrl + ↓可以看到下界为104,8576,右界为24(X)*6(F)*4(D)=576    (Excel 2010版本) 一.数据清理 1)Trim()--空格清理 清除掉字符串两边的空格 2)CONCATENATE()--连接 CONCATENATE函

Pandas Cookbook -- 08数据清理

数据清理 简书大神SeanCheney的译作,我作了些格式调整和文章目录结构的变化,更适合自己阅读,以后翻阅是更加方便自己查找吧 import pandas as pd import numpy as np 设定最大列数和最大行数 pd.set_option('max_columns',5 , 'max_rows', 5) 1 宽格式转长格式 state_fruit = pd.read_csv('data/state_fruit.csv', index_col=0) state_fruit .d

新浪微博爬取笔记(4):数据清理

数据清理的部分很多,其实爬数据的过程中步骤的间隔也要做数据清理,都是很琐碎繁杂的工作.总结经验的话,就是: 1.一定要用数据库存储数据 (我因为还不太会数据库,为了“节省学习时间”,所有数据项都用txt存储,直到最后出现了多个种类之间查找,文件夹树变得比较复杂,才觉得当初即使使用MySQL也会提高效率) 2.处理异常的语句不嫌多 3.处理数据的脚本最好打包成函数,尽量减少运行前需要改源码的机会,变量从外部传递 4.工作流程要整体写出来画成图方便查找,步骤和文件多了会有点混乱 以处理时间为例: 我

MySQL mysqldump 导入/导出 结构&amp;数据&amp;存储过程&amp;函数&amp;事件&amp;触发器

———————————————-库操作———————————————-1.①导出一个库结构 mysqldump -d dbname -u root -p > xxx.sql ②导出多个库结构 mysqldump -d -B dbname1 dbname2 -u root -p > xxx.sql 2.①导出一个库数据 mysqldump -t dbname -u root -p > xxx.sql ②导出多个库数据 mysqldump -t -B dbname1 dbname2 -u r

Spark Streaming发行版笔记16:数据清理内幕彻底解密

本讲从二个方面阐述: 数据清理原因和现象 数据清理代码解析 Spark Core从技术研究的角度讲 对Spark Streaming研究的彻底,没有你搞不定的Spark应用程序. Spark Streaming一直在运行,不断计算,每一秒中在不断运行都会产生大量的累加器.广播变量,所以需要对对象及 元数据需要定期清理.每个batch duration运行时不断触发job后需要清理rdd和元数据.Clinet模式 可以看到打印的日志,从文件日志也可以看到清理日志内容. 现在要看其背后的事情: Sp

mysql之数据处理函数与数据汇总函数

一.数据处理函数   1.函数 与其他大多数计算机语言一样, SQL支持利用函数来处理数据.函数一般是在数据上执行的,它给数据的转换和处理提供了方便. 注意:函数没有 SQL的可移植性强.能运行在多个系统上的代码称为可移植的( portable).相对来说,多数SQL语句是可移植的,在SQL实现之间有差异时,这些差异通常不那么难处理.而函数的可移植性却不强.几乎每种主要的 DBMS的实现都支持其他实现不支持的函数,而且有时差异还很大.为了代码的可移植,许多 SQL程序员不赞成使用特殊实现的功能.

POSIX 线程清理函数

POSIX 多线程的 cleanup 函数 控制清理函数的函数有两个,一个是 pthread_cleanup_push(), 用来把清理函数压入栈中,另一个是 pthread_cleanup_pop(), 用来把栈中的函数弹出来. 用这两个函数组合,可以达到在线程退出时,清理线程数据的作用, 例如对 mutex 进行解锁等. 下面是这两个函数的函数原型: #include<pthread.h>void pthread_cleanup_push(void(*routine)(void*),voi