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

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