本帖最后由 dongdong0925 于 2011-6-27 09:15 编辑
主题热度的设置在后台-》全局-》站点功能-》主题热度下,如图。
热度的计算方式有两种:按参与人次或者按热度公式。
按参与人次的方式下:
以天为单位,一个周期内某用户多次参与主题,只加一次热度。(回复、点评、评论、收藏、分享等都算作参与主题的动作)
按热度公式的方式下:
按相应的热度公式,参与主题增加相应的热度。(只有回复、评价算作参与主题的动作)
下面以帖子的回帖分别对两种方式做下说明。
回帖的操作处理是在source\include\post\post_newreply.php文件,在322行附近可以找到如下代码。- if($thread['lastposter'] != $_G['member']['username'] && $_G['uid']) {
- if($_G['setting']['heatthread']['type'] == 1 && $_G['setting']['heatthread']['reply']) {
- $posttable = getposttablebytid($_G['tid']);
- $userreplies = DB::result_first("SELECT COUNT(*) FROM ".DB::table($posttable)." WHERE tid='$_G[tid]' AND first='0' AND authorid='$_G[uid]'");
- $thread['heats'] += round($_G['setting']['heatthread']['reply'] * pow(0.8, $userreplies));
- DB::query("UPDATE ".DB::table('forum_thread')." SET heats='$thread[heats]' WHERE tid='$_G[tid]'", 'UNBUFFERED');
- } elseif($_G['setting']['heatthread']['type'] == 2) {
- update_threadpartake($_G['tid']);
- }
- }
复制代码
按热度公式方式的处理:
- if($_G['setting']['heatthread']['type'] == 1 && $_G['setting']['heatthread']['reply']) {
- $posttable = getposttablebytid($_G['tid']);
- $userreplies = DB::result_first("SELECT COUNT(*) FROM ".DB::table($posttable)." WHERE tid='$_G[tid]' AND first='0' AND authorid='$_G[uid]'");
- $thread['heats'] += round($_G['setting']['heatthread']['reply'] * pow(0.8, $userreplies));
- DB::query("UPDATE ".DB::table('forum_thread')." SET heats='$thread[heats]' WHERE tid='$_G[tid]'", 'UNBUFFERED');
- }
复制代码
$_G['setting']['heatthread']['type'] == 1为按热度公式计算的方式。
$_G['setting']['heatthread']['reply']为后台设置的单次回复热度值。
- $posttable = getposttablebytid($_G['tid']);
- $userreplies = DB::result_first("SELECT COUNT(*) FROM ".DB::table($posttable)." WHERE tid='$_G[tid]' AND first='0' AND authorid='$_G[uid]'");
复制代码 这段为当前用户在这个主题所有回复的总数,$userreplies为总数。
- $thread['heats'] += round($_G['setting']['heatthread']['reply'] * pow(0.8, $userreplies));
复制代码 计算该帖子的热度数,此处即为热度的公式。
- DB::query("UPDATE ".DB::table('forum_thread')." SET heats='$thread[heats]' WHERE tid='$_G[tid]'", 'UNBUFFERED');
复制代码 更新表forum_thread中这个帖子的热度值(更新为根据热度公式计算的热度值$thread[heats])。
按参与人次方式的处理:
- elseif($_G['setting']['heatthread']['type'] == 2) {
- update_threadpartake($_G['tid']);
- }
复制代码 $_G['setting']['heatthread']['type'] == 2为按参与人次的方式。
update_threadpartake的函数在source/function/function_forum.php文件中.
具体代码如下:
- function update_threadpartake($tid) {
- global $_G;
- if($_G['uid'] && $tid) {
- if($_G['setting']['heatthread']['period']) {
- $partaked = DB::result_first("SELECT uid FROM ".DB::table('forum_threadpartake')." WHERE tid='$tid' AND uid='$_G[uid]'");
- if(!$partaked) {
- DB::query("INSERT INTO ".DB::table('forum_threadpartake')." (tid, uid, dateline) VALUES ('$tid', '$_G[uid]', ".TIMESTAMP.")");
- DB::query("UPDATE ".DB::table('forum_thread')." SET heats=heats+1 WHERE tid='$tid'", 'UNBUFFERED');
- }
- } else {
- DB::query("UPDATE ".DB::table('forum_thread')." SET heats=heats+1 WHERE tid='$tid'", 'UNBUFFERED');
- }
- }
- }
复制代码
- if($_G['uid'] && $tid) {
- if($_G['setting']['heatthread']['period']) {
复制代码 判断是否为登录会员同时存在tid,同时后台设置了用户热度值周期(天)。
$_G['setting']['heatthread']['period']为后台设置的用户热度值周期(天)。
- $partaked = DB::result_first("SELECT uid FROM ".DB::table('forum_threadpartake')." WHERE tid='$tid' AND uid='$_G[uid]'");
复制代码 根据tid和uid查询表forum_threadpartake中是否存在相应的记录。
如果不存在,则执行下面的操作。
- if(!$partaked) {
- DB::query("INSERT INTO ".DB::table('forum_threadpartake')." (tid, uid, dateline) VALUES ('$tid', '$_G[uid]', ".TIMESTAMP.")");
- DB::query("UPDATE ".DB::table('forum_thread')." SET heats=heats+1 WHERE tid='$tid'", 'UNBUFFERED');
- }
复制代码 往表forum_threadpartake中插入一条新数据,同时更新表forum_thread中这个帖子的热度(+1)。
如果存在,则执行下面的操作。
- else {
- DB::query("UPDATE ".DB::table('forum_thread')." SET heats=heats+1 WHERE tid='$tid'", 'UNBUFFERED');
- }
复制代码 更新表forum_thread中这个帖子的热度(+1)。
|