Beispiel #1
0
function deletethread($tids, $membercount = false, $credit = false, $ponly = false)
{
    global $_G;
    if ($_G['setting']['plugins']['func'][HOOKTYPE]['deletethread']) {
        $_G['deletethreadtids'] =& $tids;
        $hookparam = func_get_args();
        hookscript('deletethread', 'global', 'funcs', array('param' => $hookparam, 'step' => 'check'), 'deletethread');
    }
    if (!$tids) {
        return 0;
    }
    $count = count($tids);
    $arrtids = $tids;
    $tids = dimplode($tids);
    loadcache(array('threadtableids', 'posttableids'));
    $threadtableids = !empty($_G['cache']['threadtableids']) ? $_G['cache']['threadtableids'] : array();
    $posttableids = !empty($_G['cache']['posttableids']) ? $_G['cache']['posttableids'] : array('0');
    if (!in_array(0, $threadtableids)) {
        $threadtableids = array_merge(array(0), $threadtableids);
    }
    C::t('common_moderate')->delete($arrtids, 'tid');
    C::t('forum_threadclosed')->delete($arrtids);
    $cachefids = $atids = $fids = $postids = $threadtables = array();
    foreach ($threadtableids as $tableid) {
        foreach (C::t('forum_thread')->fetch_all_by_tid($arrtids, 0, 0, $tableid) as $row) {
            $atids[] = $row['tid'];
            $row['posttableid'] = !empty($row['posttableid']) && in_array($row['posttableid'], $posttableids) ? $row['posttableid'] : '0';
            $postids[$row['posttableid']][$row['tid']] = $row['tid'];
            if ($tableid) {
                $fids[$row['fid']][] = $tableid;
            }
            $cachefids[$row['fid']] = $row['fid'];
        }
        if (!$tableid && !$ponly) {
            $threadtables[] = $tableid;
        }
    }
    if ($credit || $membercount) {
        $losslessdel = $_G['setting']['losslessdel'] > 0 ? TIMESTAMP - $_G['setting']['losslessdel'] * 86400 : 0;
        $postlist = $uidarray = $tuidarray = $ruidarray = array();
        foreach ($postids as $posttableid => $posttabletids) {
            foreach (C::t('forum_post')->fetch_all_by_tid($posttableid, $posttabletids, false) as $post) {
                if ($post['invisible'] != -1 && $post['invisible'] != -5) {
                    $postlist[] = $post;
                }
            }
        }
        foreach (C::t('forum_replycredit')->fetch_all($arrtids) as $rule) {
            $rule['extcreditstype'] = $rule['extcreditstype'] ? $rule['extcreditstype'] : $_G['setting']['creditstransextra'][10];
            $replycredit_rule[$rule['tid']] = $rule;
        }
        foreach ($postlist as $post) {
            if ($post['dateline'] < $losslessdel) {
                if ($membercount) {
                    if ($post['first']) {
                        updatemembercount($post['authorid'], array('threads' => -1, 'post' => -1), false);
                    } else {
                        updatemembercount($post['authorid'], array('posts' => -1), false);
                    }
                }
            } else {
                if ($credit) {
                    if ($post['first']) {
                        $tuidarray[$post['fid']][] = $post['authorid'];
                    } else {
                        $ruidarray[$post['fid']][] = $post['authorid'];
                    }
                }
            }
            if ($credit || $membercount) {
                if ($post['authorid'] > 0 && $post['replycredit'] > 0) {
                    if ($replycredit_rule[$post['tid']]['extcreditstype']) {
                        updatemembercount($post['authorid'], array($replycredit_rule[$post['tid']]['extcreditstype'] => (int) ('-' . $post['replycredit'])));
                    }
                }
            }
        }
        if ($credit) {
            if ($tuidarray || $ruidarray) {
                require_once libfile('function/post');
            }
            if ($tuidarray) {
                foreach ($tuidarray as $fid => $tuids) {
                    updatepostcredits('-', $tuids, 'post', $fid);
                }
            }
            if ($ruidarray) {
                foreach ($ruidarray as $fid => $ruids) {
                    updatepostcredits('-', $ruids, 'reply', $fid);
                }
            }
            $auidarray = $attachtables = array();
            foreach ($atids as $tid) {
                $attachtables[getattachtableid($tid)][] = $tid;
            }
            foreach ($attachtables as $attachtable => $attachtids) {
                foreach (C::t('forum_attachment_n')->fetch_all_by_id($attachtable, 'tid', $attachtids) as $attach) {
                    if ($attach['dateline'] > $losslessdel) {
                        $auidarray[$attach['uid']] = !empty($auidarray[$attach['uid']]) ? $auidarray[$attach['uid']] + 1 : 1;
                    }
                }
            }
            if ($auidarray) {
                $postattachcredits = !empty($_G['forum']['postattachcredits']) ? $_G['forum']['postattachcredits'] : $_G['setting']['creditspolicy']['postattach'];
                updateattachcredits('-', $auidarray, $postattachcredits);
            }
        }
    }
    $relatecollection = C::t('forum_collectionthread')->fetch_all_by_tids($arrtids);
    if (count($relatecollection) > 0) {
        $collectionids = array();
        foreach ($relatecollection as $collection) {
            $collectionids[] = $collection['ctid'];
        }
        $collectioninfo = C::t('forum_collection')->fetch_all($collectionids);
        foreach ($relatecollection as $collection) {
            $decthread = C::t('forum_collectionthread')->delete_by_ctid_tid($collection['ctid'], $arrtids);
            $lastpost = null;
            if (in_array($collectioninfo[$collection['ctid']]['lastpost'], $arrtids) && $collectioninfo[$collection['ctid']]['threadnum'] - $decthread > 0) {
                $collection_thread = C::t('forum_collectionthread')->fetch_by_ctid_dateline($collection['ctid']);
                if ($collection_thread) {
                    $thread = C::t('forum_thread')->fetch($collection_thread['tid']);
                    $lastpost = array('lastpost' => $thread['tid'], 'lastsubject' => $thread['subject'], 'lastposttime' => $thread['dateline'], 'lastposter' => $thread['authorid']);
                }
            }
            C::t('forum_collection')->update_by_ctid($collection['ctid'], -$decthread, 0, 0, 0, 0, 0, $lastpost);
        }
        C::t('forum_collectionrelated')->delete($arrtids);
    }
    if ($cachefids) {
        C::t('forum_thread')->clear_cache($cachefids, 'forumdisplay_');
    }
    if ($ponly) {
        if ($_G['setting']['plugins']['func'][HOOKTYPE]['deletethread']) {
            hookscript('deletethread', 'global', 'funcs', array('param' => $hookparam, 'step' => 'delete'), 'deletethread');
        }
        C::t('forum_thread')->update($arrtids, array('displayorder' => -1, 'digest' => 0, 'moderated' => 1));
        foreach ($postids as $posttableid => $oneposttids) {
            C::t('forum_post')->update_by_tid($posttableid, $oneposttids, array('invisible' => '-1'));
        }
        return $count;
    }
    C::t('forum_replycredit')->delete($arrtids);
    C::t('forum_post_location')->delete_by_tid($arrtids);
    C::t('common_credit_log')->delete_by_operation_relatedid(array('RCT', 'RCA', 'RCB'), $arrtids);
    deletethreadcover($arrtids);
    foreach ($threadtables as $tableid) {
        C::t('forum_thread')->delete_by_tid($arrtids, false, $tableid);
    }
    if ($atids) {
        foreach ($postids as $posttableid => $oneposttids) {
            deletepost($oneposttids, 'tid', false, $posttableid);
        }
        deleteattach($atids, 'tid');
    }
    if ($fids) {
        loadcache('forums');
        foreach ($fids as $fid => $tableids) {
            if (empty($_G['cache']['forums'][$fid]['archive'])) {
                continue;
            }
            foreach (C::t('forum_thread')->count_posts_by_fid($fid) as $row) {
                C::t('forum_forum_threadtable')->insert(array('fid' => $fid, 'threadtableid' => $tableid, 'threads' => $row['threads'], 'posts' => $row['posts']), false, true);
            }
        }
    }
    foreach (array('forum_forumrecommend', 'forum_polloption', 'forum_poll', 'forum_activity', 'forum_activityapply', 'forum_debate', 'forum_debatepost', 'forum_threadmod', 'forum_relatedthread', 'forum_pollvoter', 'forum_threadimage', 'forum_threadpreview') as $table) {
        C::t($table)->delete_by_tid($arrtids);
    }
    C::t('forum_typeoptionvar')->delete_by_tid($arrtids);
    C::t('forum_poststick')->delete_by_tid($arrtids);
    C::t('home_feed')->delete_by_id_idtype($arrtids, 'tid');
    C::t('common_tagitem')->delete(0, $tids, 'tid');
    C::t('forum_threadrush')->delete($arrtids);
    if ($_G['setting']['plugins']['func'][HOOKTYPE]['deletethread']) {
        hookscript('deletethread', 'global', 'funcs', array('param' => $hookparam, 'step' => 'delete'), 'deletethread');
    }
    return $count;
}
function deletethread($tids, $membercount = false, $credit = false, $ponly = false)
{
    global $_G;
    if ($_G['setting']['plugins'][HOOKTYPE . '_deletethread']) {
        $_G['deletethreadtids'] =& $tids;
        $hookparam = func_get_args();
        hookscript('deletethread', 'global', 'funcs', array('param' => $hookparam, 'step' => 'check'), 'deletethread');
    }
    if (!$tids) {
        return 0;
    }
    require_once libfile('function/forum');
    foreach ($tids as $tid) {
        my_post_log('delete', array('tid' => $tid));
    }
    $count = count($tids);
    $tids = dimplode($tids);
    loadcache(array('threadtableids', 'posttableids'));
    $threadtableids = !empty($_G['cache']['threadtableids']) ? $_G['cache']['threadtableids'] : array();
    $posttableids = !empty($_G['cache']['posttableids']) ? $_G['cache']['posttableids'] : array('0');
    if (!in_array(0, $threadtableids)) {
        $threadtableids = array_merge(array(0), $threadtableids);
    }
    DB::delete('common_moderate', "id IN ({$tids}) AND idtype='tid'");
    $atids = $fids = $postids = $threadtables = array();
    foreach ($threadtableids as $tableid) {
        $threadtable = !$tableid ? "forum_thread" : "forum_thread_{$tableid}";
        $query = DB::query("SELECT cover, tid, fid, posttableid FROM " . DB::table($threadtable) . " WHERE tid IN ({$tids})");
        while ($row = DB::fetch($query)) {
            $atids[] = $row['tid'];
            $row['posttableid'] = !empty($row['posttableid']) && in_array($row['posttableid'], $posttableids) ? $row['posttableid'] : '0';
            $postids[$row['posttableid']][$row['tid']] = $row['tid'];
            if ($tableid) {
                $fids[$row['fid']][] = $tableid;
            }
        }
        if (!$tableid && !$ponly) {
            $threadtables[] = $threadtable;
        }
    }
    if ($credit || $membercount) {
        $losslessdel = $_G['setting']['losslessdel'] > 0 ? TIMESTAMP - $_G['setting']['losslessdel'] * 86400 : 0;
        $postlist = $uidarray = $tuidarray = $ruidarray = array();
        foreach ($postids as $posttableid => $posttabletids) {
            $query = DB::query('SELECT tid, first, authorid, dateline, replycredit, invisible FROM ' . DB::table(getposttable($posttableid)) . ' WHERE tid IN (' . dimplode($posttabletids) . ')');
            while ($post = DB::fetch($query)) {
                if ($post['invisible'] != -1 && $post['invisible'] != -5) {
                    $postlist[] = $post;
                }
            }
        }
        $query = DB::query("SELECT tid, extcreditstype FROM " . DB::table('forum_replycredit') . " WHERE tid IN ({$tids})");
        while ($rule = DB::fetch($query)) {
            $rule['extcreditstype'] = $rule['extcreditstype'] ? $rule['extcreditstype'] : $_G['setting']['creditstransextra'][10];
            $replycredit_rule[$rule['tid']] = $rule;
        }
        foreach ($postlist as $post) {
            if ($post['dateline'] < $losslessdel) {
                if ($membercount) {
                    if ($post['first']) {
                        updatemembercount($post['authorid'], array('threads' => -1, 'post' => -1), false);
                    } else {
                        updatemembercount($post['authorid'], array('posts' => -1), false);
                    }
                }
            } else {
                if ($credit) {
                    if ($post['first']) {
                        $tuidarray[] = $post['authorid'];
                    } else {
                        $ruidarray[] = $post['authorid'];
                    }
                }
            }
            if ($credit || $membercount) {
                if ($post['authorid'] > 0 && $post['replycredit'] > 0) {
                    if ($replycredit_rule[$post['tid']]['extcreditstype']) {
                        updatemembercount($post['authorid'], array($replycredit_rule[$post['tid']]['extcreditstype'] => (int) ('-' . $post['replycredit'])));
                    }
                }
            }
        }
        if ($credit) {
            if ($tuidarray || $ruidarray) {
                require_once libfile('function/post');
            }
            if ($tuidarray) {
                updatepostcredits('-', $tuidarray, 'post', $_G['forum']['fid']);
            }
            if ($ruidarray) {
                updatepostcredits('-', $ruidarray, 'reply', $_G['forum']['fid']);
            }
            $auidarray = $attachtables = array();
            foreach ($atids as $tid) {
                $attachtables[getattachtablebytid($tid)][] = $tid;
            }
            foreach ($attachtables as $attachtable => $attachtids) {
                $query = DB::query("SELECT uid, dateline FROM " . DB::table($attachtable) . " WHERE tid IN (" . dimplode($attachtids) . ")");
                while ($attach = DB::fetch($query)) {
                    if ($attach['dateline'] > $losslessdel) {
                        $auidarray[$attach['uid']] = !empty($auidarray[$attach['uid']]) ? $auidarray[$attach['uid']] + 1 : 1;
                    }
                }
            }
            if ($auidarray) {
                $postattachcredits = !empty($_G['forum']['postattachcredits']) ? $_G['forum']['postattachcredits'] : $_G['setting']['creditspolicy']['postattach'];
                updateattachcredits('-', $auidarray, $postattachcredits);
            }
        }
    }
    if ($ponly) {
        if ($_G['setting']['plugins'][HOOKTYPE . '_deletethread']) {
            hookscript('deletethread', 'global', 'funcs', array('param' => $hookparam, 'step' => 'delete'), 'deletethread');
        }
        return $count;
    }
    DB::delete('forum_replycredit', "tid IN ({$tids})");
    DB::delete('common_credit_log', "operation IN ('RCT', 'RCA', 'RCB') AND relatedid IN ({$tids})");
    deletethreadcover($tids);
    foreach ($threadtables as $threadtable) {
        DB::delete($threadtable, "tid IN ({$tids})");
    }
    if ($atids) {
        foreach ($postids as $posttableid => $oneposttids) {
            deletepost($oneposttids, 'tid', false, $posttableid);
        }
        deleteattach($atids, 'tid');
    }
    if ($fids) {
        foreach ($fids as $fid => $tableids) {
            $tableids = array_unique($tableids);
            foreach ($tableids as $tableid) {
                $query = DB::query("SELECT COUNT(*) AS threads, SUM(replies)+COUNT(*) AS posts FROM " . DB::table("forum_thread_{$tableid}") . " WHERE fid='{$fid}'");
                while ($row = DB::fetch($query)) {
                    DB::insert('forum_forum_threadtable', array('fid' => $fid, 'threadtableid' => $tableid, 'threads' => intval($row['threads']), 'posts' => intval($row['posts'])), false, true);
                }
            }
        }
    }
    foreach (array('forum_forumrecommend', 'forum_polloption', 'forum_poll', 'forum_activity', 'forum_activityapply', 'forum_debate', 'forum_debatepost', 'forum_threadmod', 'forum_relatedthread', 'forum_typeoptionvar', 'forum_postposition', 'forum_poststick', 'forum_pollvoter', 'forum_threadimage') as $table) {
        DB::delete($table, "tid IN ({$tids})");
    }
    DB::query("DELETE FROM " . DB::table('home_feed') . " WHERE id IN ({$tids}) AND idtype='tid'", 'UNBUFFERED');
    DB::query("DELETE FROM " . DB::table('common_tagitem') . " WHERE idtype='tid' AND itemid IN ({$tids})", 'UNBUFFERED');
    DB::query("DELETE FROM " . DB::table('forum_threadrush') . " WHERE tid IN ({$tids})", 'UNBUFFERED');
    if ($_G['setting']['plugins'][HOOKTYPE . '_deletethread']) {
        hookscript('deletethread', 'global', 'funcs', array('param' => $hookparam, 'step' => 'delete'), 'deletethread');
    }
    return $count;
}
 } elseif ($optype == 'delete') {
     require_once libfile('function/delete');
     deletethread($tidsarray, !$_G['gp_donotupdatemember'], !$_G['gp_donotupdatemember']);
     if ($_G['setting']['globalstick']) {
         updatecache('globalstick');
     }
     foreach (explode(',', $_G['gp_fids']) as $fid) {
         updateforumcount(intval($fid));
     }
     foreach ($_G['gp_tidarray'] as $tid) {
         my_thread_log('delete', array('tid' => $tid));
     }
     $cpmsg = cplang('threads_succeed');
 } elseif ($optype == 'deleteattach') {
     require_once libfile('function/delete');
     deleteattach($tidsarray, 'tid');
     DB::query("UPDATE " . DB::table('forum_thread') . " SET attachment='0' WHERE {$tidsadd}");
     updatepost(array('attachment' => '0'), $tidsadd);
     $cpmsg = cplang('threads_succeed');
 } elseif ($optype == 'stick') {
     DB::query("UPDATE " . DB::table('forum_thread') . " SET displayorder='{$_G['gp_stick_level']}' WHERE {$tidsadd}");
     $my_act = $_G['gp_stick_level'] ? 'sticky' : 'update';
     foreach ($_G['gp_tidarray'] as $tid) {
         my_thread_log($my_act, array('tid' => $tid));
     }
     if ($_G['setting']['globalstick']) {
         updatecache('globalstick');
     }
     $cpmsg = cplang('threads_succeed');
 } elseif ($optype == 'adddigest') {
     $query = DB::query("SELECT tid, fid, authorid, digest FROM " . DB::table('forum_thread') . " WHERE {$tidsadd}");
Beispiel #4
0
function deletethread($condition, $unbuffered = true)
{
    $deletedthreads = 0;
    deleteattach($condition, $unbuffered);
    foreach (array('forum_thread', 'forum_polloption', 'forum_poll', 'forum_trade', 'forum_activity', 'forum_activityapply', 'forum_debate', 'forum_debatepost', 'forum_threadmod', 'forum_relatedthread', 'forum_typeoptionvar', 'forum_postposition', 'forum_poststick', 'forum_pollvoter') as $table) {
        DB::delete($table, $condition, 0, $unbuffered);
        if ($table == 'forum_thread') {
            $deletedthreads = DB::affected_rows();
        }
    }
    DB::query("DELETE FROM " . DB::table('home_feed') . " WHERE " . str_replace('tid', 'id', $condition) . " AND idtype='tid'", 'UNBUFFERED');
    DB::query("DELETE FROM " . DB::table('forum_postcomment') . " WHERE {$condition}", 'UNBUFFERED');
    return $deletedthreads;
}