Esempio n. 1
0
function getgroupranking($fid = '', $nowranking = '', $num = 100)
{
    $topgroup = $rankingdata = $topyesterday = array();
    if ($fid) {
        updateactivity($fid);
    }
    $ranking = 1;
    $query = DB::query("SELECT f.fid FROM " . DB::table('forum_forum') . " as f LEFT JOIN " . DB::table('forum_forumfield') . " as ff ON ff.fid=f.fid WHERE f.type='sub' AND f.status='3' ORDER BY ff.activity DESC LIMIT 0, 1000");
    while ($group = DB::fetch($query)) {
        $topgroup[$group['fid']] = $ranking++;
    }
    if ($fid && $topgroup) {
        $rankingdata['yesterday'] = intval($nowranking);
        $rankingdata['today'] = intval($topgroup[$fid]);
        $rankingdata['trend'] = $rankingdata['yesterday'] ? grouptrend($rankingdata['yesterday'], $rankingdata['today']) : 0;
        $topgroup = $rankingdata;
    } else {
        $query = DB::query("SELECT * FROM " . DB::table('forum_groupranking') . " ORDER BY today LIMIT 0, {$num}");
        while ($top = DB::fetch($query)) {
            $topyesterday[$top['fid']] = $top;
        }
        foreach ($topgroup as $forumid => $today) {
            $yesterday = intval($topyesterday[$forumid]);
            $trend = $yesterday ? grouptrend($yesterday, $today) : 0;
            DB::query("REPLACE INTO " . DB::table('forum_groupranking') . " (fid, yesterday, today, trend) VALUES ('{$forumid}', '{$yesterday}', '{$today}', '{$trend}')", 'UNBUFFERED');
        }
        $topgroup = $topyesterday;
    }
    return $topgroup;
}
Esempio n. 2
0
        if ($confirmjoin) {
            DB::query("INSERT INTO " . DB::table('forum_groupuser') . " (fid, uid, username, level, joindateline, lastupdate) VALUES ('{$_G['fid']}', '{$_G['uid']}', '{$_G['username']}', '{$modmember}', '" . TIMESTAMP . "', '" . TIMESTAMP . "')", 'UNBUFFERED');
            if ($_G['forum']['jointype'] == 2 && (empty($inviteuid) || empty($groupmanagers[$inviteuid]))) {
                foreach ($groupmanagers as $manage) {
                    notification_add($manage['uid'], 'group', 'group_member_join', array('fid' => $_G['fid'], 'groupname' => $_G['forum']['name'], 'url' => $_G['siteurl'] . 'forum.php?mod=group&action=manage&op=checkuser&fid=' . $_G['fid']), 1);
                }
            } else {
                update_usergroups($_G['uid']);
            }
            if ($inviteuid) {
                DB::query("DELETE FROM " . DB::table('forum_groupinvite') . " WHERE fid='{$_G['fid']}' AND inviteuid='{$_G['uid']}'");
            }
            if ($modmember == 4) {
                DB::query("UPDATE " . DB::table('forum_forumfield') . " SET membernum=membernum+1 WHERE fid='{$_G['fid']}'");
            }
            updateactivity($_G['fid'], 0);
        }
        include_once libfile('function/stat');
        updatestat('groupjoin');
        delgroupcache($_G['fid'], array('activityuser', 'newuserlist'));
        showmessage($showmessage, "forum.php?mod=group&fid={$_G['fid']}");
    }
} elseif ($action == 'out') {
    if ($_G['uid'] == $_G['forum']['founderuid']) {
        showmessage('group_exit_founder');
    }
    $showmessage = 'group_exit_succeed';
    DB::query("DELETE FROM " . DB::table('forum_groupuser') . " WHERE fid='{$_G['fid']}' AND uid='{$_G['uid']}'");
    DB::query("UPDATE " . DB::table('forum_forumfield') . " SET membernum=membernum+'-1' WHERE fid='{$_G['fid']}'");
    update_usergroups($_G['uid']);
    update_groupmoderators($_G['fid']);
Esempio n. 3
0
function article_move_forums($arr, $old_arr)
{
    global $_G;
    $arr['content'] = preg_replace(array('/<center>([\\s\\S]*?)<\\/center>/', '/\\s(?=\\s)/'), array("[align=center]\\1[/align]", ''), $arr['content']);
    $subject = addslashes(trim($arr['title']));
    if ($arr['check']) {
        if (!strlen($subject)) {
            return FALSE;
        }
        $num = DB::result_first('SELECT COUNT(*) FROM ' . DB::table('forum_thread') . " WHERE subject='{$subject}' AND displayorder > '-1'");
        if ($num) {
            return FALSE;
        }
    }
    if ($arr['contents'] > 1 && $arr['is_content_reply'] != 1) {
        $arr['reply'] = array();
    }
    $time_arr = create_public_time($arr, count($arr['reply']) + 1, 1);
    if ($arr['contents'] == 1) {
        $uid_arr = get_rand_uid($arr, 'reply');
    } else {
        if ($arr['is_content_reply'] != 1) {
            if ($arr['content_arr']) {
                $arr['content'] = content_merge($arr['content_arr']);
            }
            $uid_arr = get_rand_uid($arr);
        }
    }
    $arr['public_time'] = $arr['public_time'] ? $arr['public_time'] : array_shift($time_arr);
    require_once libfile('function/editor');
    require_once libfile('function/forum');
    $subject = htmlspecialchars_decode(format_html($subject));
    $subject = htmlspecialchars_decode(format_html($subject));
    $arr['content'] = dstripslashes($arr['content']);
    $arr['content'] = img_htmlbbcode($arr['content'], $arr['page_url']);
    $arr['content'] = media_htmlbbcode($arr['content'], $arr['page_url']);
    $arr['content'] = audio_htmlbbcode($arr['content'], $arr['page_url']);
    $message = htmlspecialchars_decode(html2bbcode($arr['content']));
    $message = dstripslashes(format_html($message));
    $arr['fid'] = $_G['fid'] = $_GET['forums'] ? $_GET['forums'] : $arr['forum_fid'];
    $_G['uid'] = $arr['uid'] ? $arr['uid'] : $_G['uid'];
    $view_num = $arr['view_num'];
    require_once libfile('function/post');
    $special = 0;
    if (trim($subject) == '' || trim($message) == '') {
        return -1;
    }
    if (!$sortid && !$special && trim($message) == '') {
        return -1;
    }
    $_GET['save'] = $arr['uid'] ? $arr['uid'] : $_G['uid'];
    $uid = $_GET['save'];
    $typeid = intval($_GET['threadtypeid']) ? intval($_GET['threadtypeid']) : $arr['forum_typeid'];
    $displayorder = 0;
    $digest = $_G['forum']['ismoderator'] && $_G['group']['allowdigestthread'] && !empty($_GET['addtodigest']) ? 1 : 0;
    $readperm = $_G['group']['allowsetreadperm'] ? $readperm : 0;
    $isanonymous = $_G['group']['allowanonymous'] && $_GET['isanonymous'] ? 1 : 0;
    $price = intval($price);
    $price = $_G['group']['maxprice'] && !$special ? $price <= $_G['group']['maxprice'] ? $price : $_G['group']['maxprice'] : 0;
    if (!$typeid && $_G['forum']['threadtypes']['required'] && !$special) {
        return -2;
    }
    if (!$sortid && $_G['forum']['threadsorts']['required'] && !$special) {
        return -3;
    }
    if ($price > 0 && floor($price * (1 - $_G['setting']['creditstax'])) == 0) {
        return -4;
    }
    $_G['forum'] = DB::fetch_first("SELECT * FROM " . DB::table('forum_forum') . " WHERE fid = '{$arr['fid']}'");
    //查询版块信息
    if (!$_G['forum']) {
        return -5;
    }
    $sortid = $special && $_G['forum']['threadsorts']['types'][$sortid] ? 0 : $sortid;
    $typeexpiration = intval($_GET['typeexpiration']);
    if ($_G['forum']['threadsorts']['expiration'][$typeid] && !$typeexpiration) {
        return -5;
    }
    $_G['forum_optiondata'] = array();
    if ($_G['forum']['threadsorts']['types'][$sortid] && !$_G['forum']['allowspecialonly']) {
        $_G['forum_optiondata'] = threadsort_validator($_GET['typeoption'], $pid);
    }
    $author = !$arr['username'] ? $_G['username'] : $arr['username'];
    $moderated = $digest || $displayorder > 0 ? 1 : 0;
    $thread['status'] = 0;
    $_GET['ordertype'] && ($thread['status'] = setstatus(4, 1, $thread['status']));
    $_GET['hiddenreplies'] && ($thread['status'] = setstatus(2, 1, $thread['status']));
    $_GET['allownoticeauthor'] && ($thread['status'] = setstatus(6, 1, $thread['status']));
    $isgroup = $_G['forum']['status'] == 3 ? 1 : 0;
    //检查各项设置
    $bbcodeoff = checkbbcodes($message, FALSE);
    $smileyoff = checksmilies($message, FALSE);
    $parseurloff = FALSE;
    $htmlon = $_G['group']['allowhtml'] && !empty($_GET['htmlon']) ? 1 : 0;
    if ($_G['group']['allowreplycredit']) {
        $_GET['replycredit_extcredits'] = intval($_GET['replycredit_extcredits']);
        $_GET['replycredit_times'] = intval($_GET['replycredit_times']);
        $_GET['replycredit_membertimes'] = intval($_GET['replycredit_membertimes']);
        $_GET['replycredit_random'] = intval($_GET['replycredit_random']);
        $_GET['replycredit_random'] = $_GET['replycredit_random'] < 0 || $_GET['replycredit_random'] > 99 ? 0 : $_GET['replycredit_random'];
        $replycredit = $replycredit_real = 0;
    }
    if ($old_arr['forum_id']) {
        $info = DB::fetch_first("SELECT p.pid,p.tid,t.tid,p.first FROM " . DB::table('forum_post') . " p Inner Join " . DB::table('forum_thread') . " t  ON p.tid = t.tid WHERE p.first = '1' AND t.tid='" . $old_arr['forum_id'] . "' AND t.displayorder > '-1'");
    }
    $reply_count = count($arr['reply']);
    $view_num = $view_num < $reply_count - 1 ? rand($reply_count * 2, $reply_count * 10) : $view_num;
    if ($info['tid']) {
        //更新
        DB::query("UPDATE " . DB::table('forum_thread') . " SET typeid='{$typeid}', author='{$author}', authorid='{$uid}', subject='{$subject}', dateline='{$arr['public_time']}', lastpost='{$arr['public_time']}', fid='{$arr['fid']}', lastposter='{$author}', views='{$view_num}', attachment='0' WHERE tid='{$info['tid']}'", 'UNBUFFERED');
        $tid = $info['tid'];
    } else {
        //添加
        DB::query("INSERT INTO " . DB::table('forum_thread') . " (fid, posttableid, readperm, price, typeid, sortid, author, authorid, subject, dateline, lastpost, lastposter, views, displayorder, digest, special, attachment, moderated, status, isgroup, replycredit, closed)\r\n\t\t\tVALUES ('{$_G['fid']}', '0', '{$readperm}', '{$price}', '{$typeid}', '{$sortid}', '{$author}', '{$_G['uid']}', '{$subject}', '{$arr['public_time']}', '{$arr['public_time']}', '{$author}', '{$view_num}', '{$displayorder}', '{$digest}', '{$special}', '0', '{$moderated}', '32', '{$isgroup}', '{$replycredit}', '" . ($closed ? "1" : '0') . "')");
        $tid = DB::insert_id();
        useractionlog($uid, 'tid');
    }
    DB::update('common_member_field_home', array('recentnote' => $subject), array('uid' => $uid));
    if ($moderated) {
        updatemodlog($tid, $displayorder > 0 ? 'STK' : 'DIG');
        updatemodworks($displayorder > 0 ? 'STK' : 'DIG', 1);
    }
    if (DISCUZ_VERSION == 'X2') {
        //2.0版本
        $tagstr = addthreadtag($arr['article_tag'], $tid);
    } else {
        $class_tag = new tag();
        $tagstr = $class_tag->add_tag($arr['article_tag'], $tid, 'tid');
    }
    if ($_G['group']['allowreplycredit']) {
        if ($replycredit > 0 && $replycredit_real > 0) {
            updatemembercount($_G['uid'], array('extcredits' . $_G['setting']['creditstransextra'][10] => -$replycredit_real), 1, 'RCT', $tid);
            DB::query("INSERT INTO " . DB::table('forum_replycredit') . " (tid, extcredits, extcreditstype, times, membertimes, random)VALUES('{$tid}', '{$_G['gp_replycredit_extcredits']}', '{$_G[setting][creditstransextra][10]}', '{$_G['gp_replycredit_times']}', '{$_G['gp_replycredit_membertimes']}', '{$_G['gp_replycredit_random']}')");
        }
    }
    if ($_G['group']['allowpostrushreply'] && $_GET['rushreply']) {
        DB::query("INSERT INTO " . DB::table('forum_threadrush') . " (tid, stopfloor, starttimefrom, starttimeto, rewardfloor) VALUES ('{$tid}', '{$_G['gp_stopfloor']}', '{$_G['gp_rushreplyfrom']}', '{$_G['gp_rushreplyto']}', '{$_G['gp_rewardfloor']}')");
    }
    $message = preg_replace('/\\[attachimg\\](\\d+)\\[\\/attachimg\\]/is', '[attach]\\1[/attach]', $message);
    $post_setarr = array('fid' => $arr['fid'], 'tid' => $tid, 'first' => '1', 'author' => $author, 'authorid' => $_G['uid'], 'subject' => $subject, 'dateline' => $arr['public_time'], 'message' => $message, 'useip' => $_G['clientip'], 'invisible' => 0, 'anonymous' => $isanonymous, 'usesig' => 1, 'htmlon' => $htmlon, 'bbcodeoff' => $bbcodeoff, 'smileyoff' => $smileyoff, 'parseurloff' => $parseurloff, 'attachment' => '0', 'replycredit' => 0, 'status' => defined('IN_MOBILE') ? 8 : 0);
    if (DISCUZ_VERSION != 'X2') {
        //2.5版本 2.5版本多了一个position字段
        $post_setarr['position'] = 1;
        $post_setarr = dstripslashes($post_setarr);
    } else {
        $post_setarr = daddslashes($post_setarr);
    }
    $post_setarr['tags'] = $tagstr;
    $replys = 0;
    if ($info['tid']) {
        //更新
        //发布时间要做更改
        $new_post_arr = DB::fetch_first("SELECT dateline FROM " . DB::table('forum_post') . " WHERE tid='{$tid}' ORDER BY dateline ASC limit 1");
        $post_setarr['dateline'] = $new_post_arr['dateline'] - 3600;
        DB::update('forum_post', $post_setarr, array('pid' => $info['pid']));
        $pid = $info['pid'];
    } else {
        $pid = insertpost($post_setarr);
        $post_setarr = array();
        //发布回复
        if ($arr['is_public_reply'] == 1 && $arr['reply'] || $arr['is_content_reply'] == 1) {
            //是否开启发布回复
            if ($arr['is_content_reply'] == 1) {
                $uid_arr = $time_arr = array();
            }
            $reply_arr = $arr['reply'];
            $replys = count($reply_arr);
            if ($arr['public_reply_seq'] == 1) {
                shuffle($reply_arr);
            }
            foreach ((array) $reply_arr as $k => $v) {
                $message = dstripslashes($v['content']);
                $message = media_htmlbbcode($message, $arr['page_url']);
                $message = img_htmlbbcode($message, $arr['page_url']);
                $message = htmlspecialchars_decode(html2bbcode($message));
                //print_r($v['content']);exit();
                if (!$message || strlen($message) < 2) {
                    continue;
                }
                $post_setarr = array('fid' => $arr['fid'], 'tid' => $tid, 'first' => '0', 'author' => $uid_arr[$k]['username'] ? $uid_arr[$k]['username'] : $arr['username'], 'authorid' => $uid_arr[$k]['uid'] ? $uid_arr[$k]['uid'] : $arr['uid'], 'subject' => '', 'dateline' => $time_arr[$k] ? $time_arr[$k] : $arr['public_time'], 'message' => $message, 'useip' => $_G['clientip'], 'invisible' => 0, 'anonymous' => $_G['group']['allowanonymous'] && !empty($_GET['isanonymous']) ? 1 : 0, 'usesig' => 1, 'htmlon' => $_G['group']['allowhtml'] && !empty($_GET['htmlon']) ? 1 : 0, 'bbcodeoff' => checkbbcodes($message, !empty($_GET['bbcodeoff'])), 'smileyoff' => checksmilies($message, !empty($_GET['smileyoff'])), 'parseurloff' => !empty($_GET['parseurloff']), 'attachment' => '0', 'tags' => 0, 'replycredit' => 0, 'status' => defined('IN_MOBILE') ? 8 : 0);
                $lastpost = $post_setarr['dateline'];
                $lastposter = $post_setarr['author'];
                if (DISCUZ_VERSION != 'X2') {
                    //2.5版本 2.5版本多了一个position字段
                    $post_setarr['position'] = $k + 2;
                    $post_setarr = dstripslashes($post_setarr);
                } else {
                    $post_setarr = daddslashes($post_setarr);
                }
                $reply_pid = insertpost($post_setarr);
                $v['tid'] = $tid;
                $v['pid'] = $reply_pid;
                $v['is_post'] = 1;
                //标识是回复
                $v['cookie'] = $arr['cookie'];
                $v['is_water_img'] = $arr['is_water_img'];
                $v['is_download_img'] = $arr['is_download_img'];
                $v['is_download_file'] = $arr['is_download_file'];
                $forum_arr['tid'] = $tid;
                $forum_arr['pid'] = $reply_pid;
                $forum_arr['is_post'] = 1;
                //标识是回复
                $forum_arr['cookie'] = $arr['cookie'];
                $forum_arr['is_water_img'] = $arr['is_water_img'];
                $forum_arr['is_download_img'] = $arr['is_download_img'];
                $forum_arr['content'] = $v['content'];
                //$re_arr = forum_downremotefile($forum_arr);
                if ($arr['is_download_img'] == 1) {
                    $re_arr = forum_downremotefile($v);
                }
                DB::query("UPDATE " . DB::table('common_member_count') . " SET posts=posts+1 WHERE uid='{$post_setarr['authorid']}'");
                //更新数
                $new[$k] = $post_setarr;
            }
            unset($post_setarr);
            DB::update('forum_thread', array('replies' => count($reply_arr), 'lastpost' => $lastpost, 'lastposter' => $lastposter), array('tid' => $tid));
        }
    }
    //exit();
    $re = $arr;
    $re['fid'] = $fid;
    $re['tid'] = $tid;
    $re['fid'] = $fid;
    $re['uid'] = $arr['uid'];
    $re['username'] = $author;
    $re['pid'] = $pid;
    $re['message'] = $message;
    if ($pid && getstatus($thread['status'], 1)) {
        savepostposition($tid, $pid);
    }
    $threadimageaid = 0;
    $threadimage = array();
    //print_r($message);exit();
    if ($_G['forum']['threadsorts']['types'][$sortid] && !empty($_G['forum_optiondata']) && is_array($_G['forum_optiondata']) && $sortaids) {
        foreach ($sortaids as $sortaid) {
            convertunusedattach($sortaid, $tid, $pid);
        }
    }
    if (($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) && ($_GET['attachnew'] || $sortid || !empty($_GET['activityaid']))) {
        updateattach($displayorder == -4 || $modnewthreads, $tid, $pid, $_GET['attachnew']);
        if (!$threadimageaid) {
            $threadimage = DB::fetch_first("SELECT aid, attachment, remote FROM " . DB::table(getattachtablebytid($tid)) . " WHERE tid='{$tid}' AND isimage IN ('1', '-1') ORDER BY width DESC LIMIT 1");
            $threadimageaid = $threadimage['aid'];
        }
        if ($_G['forum']['picstyle']) {
            setthreadcover($pid, 0, $threadimageaid);
        }
    }
    /*删除附件*/
    if ($old_arr['forum_id']) {
        $query = DB::query("SELECT attachment, thumb, remote, aid FROM " . DB::table(getattachtablebytid($old_arr['forum_id'])) . " WHERE tid='{$old_arr['forum_id']}'");
        while ($v = DB::fetch($query)) {
            $attach[] = $v;
        }
        dunlink($attach);
        DB::query("DELETE FROM " . DB::table('forum_attachment') . " WHERE tid='{$old_arr['forum_id']}'");
        DB::query("DELETE FROM " . DB::table(getattachtablebytid($old_arr['forum_id'])) . " WHERE tid='{$old_arr['forum_id']}'");
        DB::delete('forum_threadimage', "tid='{$old_arr['forum_id']}'");
        //图片表
    }
    $param = array('fid' => $arr['fid'], 'tid' => $tid, 'pid' => $pid);
    $statarr = array(0 => 'thread', 1 => 'poll', 2 => 'trade', 3 => 'reward', 4 => 'activity', 5 => 'debate', 127 => 'thread');
    include_once libfile('function/stat');
    updatestat($isgroup ? 'groupthread' : $statarr[$special]);
    dsetcookie('clearUserdata', 'forum');
    if ($specialextra) {
        $classname = 'threadplugin_' . $specialextra;
        if (class_exists($classname) && method_exists($threadpluginclass = new $classname(), 'newthread_submit_end')) {
            $threadpluginclass->newthread_submit_end($_G['fid'], $tid);
        }
    }
    $feed = array('icon' => '', 'title_template' => '', 'title_data' => array(), 'body_template' => '', 'body_data' => array(), 'title_data' => array(), 'images' => array());
    if (!empty($_GET['addfeed']) && $_G['forum']['allowfeed'] && !$isanonymous) {
        $message = !$price ? $message : '';
        if ($special == 0) {
            $feed['icon'] = 'thread';
            $feed['title_template'] = 'feed_thread_title';
            $feed['body_template'] = 'feed_thread_message';
            $feed['body_data'] = array('subject' => "<a href=\"forum.php?mod=viewthread&tid={$tid}\">{$subject}</a>", 'message' => messagecutstr($message, 150));
            if (!empty($_G['forum_attachexist'])) {
                $firstaid = DB::result_first("SELECT aid FROM " . DB::table(getattachtablebytid($tid)) . " WHERE pid='{$pid}' AND dateline>'0' AND isimage='1' ORDER BY dateline LIMIT 1");
                if ($firstaid) {
                    $feed['images'] = array(getforumimg($firstaid));
                    $feed['image_links'] = array("forum.php?mod=viewthread&do=tradeinfo&tid={$tid}&pid={$pid}");
                }
            }
        }
    }
    $feed['title_data']['hash_data'] = "tid{$tid}";
    $feed['id'] = $tid;
    $feed['idtype'] = 'tid';
    if ($feed['icon']) {
        postfeed($feed);
    }
    if ($displayorder != -4) {
        if ($digest) {
            updatepostcredits('+', $_G['uid'], 'digest', $_G['fid']);
        }
        updatepostcredits('+', $_G['uid'], 'post', $_G['fid']);
        if ($isgroup) {
            DB::query("UPDATE " . DB::table('forum_groupuser') . " SET threads=threads+1, lastupdate='" . $arr['public_time'] . "' WHERE uid='{$_G['uid']}' AND fid='{$_G['fid']}'");
        }
        $subject = str_replace("\t", ' ', $subject);
        $f_lastpost = "{$tid}\t{$subject}\t" . $arr['public_time'] . "\t{$author}";
        if ($_G['forum']['type'] == 'sub') {
            DB::query("UPDATE " . DB::table('forum_forum') . " SET lastpost='{$f_lastpost}' WHERE fid='" . $_G['forum'][fup] . "'", 'UNBUFFERED');
        }
    }
    $subject = str_replace("\t", ' ', $subject);
    $replys = $replys ? $replys : 1;
    //今日发帖
    $todayposts = date("Yjn", $arr['public_time']) == date("Yjn", $v) ? 1 : 0;
    foreach ((array) $time_arr as $k => $v) {
        if (date("Yjn", $_G['timestamp']) == date("Yjn", $v)) {
            $todayposts++;
        }
    }
    DB::query("UPDATE " . DB::table('forum_forum') . " SET lastpost='{$f_lastpost}', threads=threads+1, posts=posts+{$replys}, todayposts=todayposts+{$todayposts} WHERE fid='{$arr['fid']}'", 'UNBUFFERED');
    //更新今日发帖这些数据
    if ($_G['forum']['status'] == 3) {
        require_once libfile('function/group');
        updateactivity($_G['fid'], 0);
        require_once libfile('function/grouplog');
        updategroupcreditlog($_G['fid'], $_G['uid']);
    }
    return $re;
}