Esempio n. 1
0
function deletethreads($tids = array())
{
    global $_G;
    static $cleartable = array('forum_threadmod', 'forum_relatedthread', 'forum_post', 'forum_poll', 'forum_polloption', 'forum_trade', 'forum_activity', 'forum_activityapply', 'forum_debate', 'forum_debatepost', 'forum_attachment', 'forum_typeoptionvar', 'forum_forumrecommend', 'forum_postposition');
    foreach ($tids as $tid) {
        my_thread_log('delete', array('tid' => $tid));
    }
    $threadsdel = 0;
    if ($tids = dimplode($tids)) {
        $auidarray = array();
        $query = DB::query("SELECT uid, attachment, dateline, thumb, remote, aid FROM " . DB::table('forum_attachment') . " WHERE tid IN ({$tids})");
        while ($attach = DB::fetch($query)) {
            dunlink($attach);
            if ($attach['dateline'] > $_G['setting']['losslessdel']) {
                $auidarray[$attach['uid']] = !empty($auidarray[$attach['uid']]) ? $auidarray[$attach['uid']] + 1 : 1;
            }
        }
        if ($auidarray) {
            updateattachcredits('-', $auidarray, $_G['setting']['creditspolicy']['postattach']);
        }
        require_once libfile('function/delete');
        foreach ($cleartable as $tb) {
            if ($tb == 'forum_post') {
                deletepost("tid IN ({$tids})");
                continue;
            }
            DB::query("DELETE FROM " . DB::table($tb) . " WHERE tid IN ({$tids})", 'UNBUFFERED');
        }
        DB::query("DELETE FROM " . DB::table('forum_thread') . " WHERE tid IN ({$tids})");
        $threadsdel = DB::affected_rows();
    }
    return $threadsdel;
}
Esempio n. 2
0
function deletethreads($tids = array())
{
    global $db, $tablepre, $losslessdel, $creditspolicy;
    static $cleartable = array('threadsmod', 'relatedthreads', 'posts', 'polls', 'polloptions', 'trades', 'activities', 'activityapplies', 'debates', 'videos', 'debateposts', 'attachments', 'favorites', 'mythreads', 'myposts', 'subscriptions', 'typeoptionvars', 'forumrecommend');
    $threadsdel = 0;
    if ($tids = implodeids($tids)) {
        $auidarray = array();
        $query = $db->query("SELECT uid, attachment, dateline, thumb, remote FROM {$tablepre}attachments WHERE tid IN ({$tids})");
        while ($attach = $db->fetch_array($query)) {
            dunlink($attach['attachment'], $attach['thumb'], $attach['remote']);
            if ($attach['dateline'] > $losslessdel) {
                $auidarray[$attach['uid']] = !empty($auidarray[$attach['uid']]) ? $auidarray[$attach['uid']] + 1 : 1;
            }
        }
        if ($auidarray) {
            updateattachcredits('-', $auidarray, $creditspolicy['postattach']);
        }
        $videoopen && videodelete($moderate, TRUE);
        foreach ($cleartable as $tb) {
            $db->query("DELETE FROM {$tablepre}{$tb} WHERE tid IN ({$tids})", 'UNBUFFERED');
        }
        $db->query("DELETE FROM {$tablepre}threads WHERE tid IN ({$tids})");
        $threadsdel = $db->affected_rows();
    }
    return $threadsdel;
}
Esempio n. 3
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;
}
Esempio n. 4
0
     }
 }
 if ($puidarray) {
     updatepostcredits('-', $puidarray, 'reply', $_G['fid']);
 }
 if ($pids) {
     $query = DB::query("SELECT uid, attachment, thumb, remote, aid FROM " . DB::table('forum_attachment') . " WHERE pid IN ({$pids})");
 }
 while ($attach = DB::fetch($query)) {
     if (in_array($attach['uid'], $puidarray)) {
         $auidarray[$attach['uid']] = !empty($auidarray[$attach['uid']]) ? $auidarray[$attach['uid']] + 1 : 1;
     }
     dunlink($attach);
 }
 if ($auidarray) {
     updateattachcredits('-', $auidarray, $postattachcredits);
 }
 $logs = array();
 if ($pids) {
     $query = DB::query("SELECT r.extcredits, r.score, p.authorid, p.author FROM " . DB::table('forum_ratelog') . " r LEFT JOIN " . DB::table($posttable) . " p ON r.pid=p.pid WHERE r.pid IN ({$pids})");
     while ($author = DB::fetch($query)) {
         if ($author['score'] > 0) {
             updatemembercount($author['authorid'], array($author['extcredits'] => -$author['score']));
             $author['score'] = $_G['setting']['extcredits'][$id]['title'] . ' ' . -$author['score'] . ' ' . $_G['setting']['extcredits'][$id]['unit'];
             $logs[] = dhtmlspecialchars("{$_G['timestamp']}\t{$_G[member][username]}\t{$_G['adminid']}\t{$author['author']}\t{$author['extcredits']}\t{$author['score']}\t{$thread['tid']}\t{$thread['subject']}\t{$delpostsubmit}");
         }
     }
 }
 if (!empty($logs)) {
     writelog('ratelog', $logs);
     unset($logs);
Esempio n. 5
0
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;
}