Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

主题热度功能分析

[复制链接]
dongdong0925 发表于 2011-6-20 08:50:11 | 显示全部楼层 |阅读模式
本帖最后由 dongdong0925 于 2011-6-27 09:15 编辑

主题热度的设置在后台-》全局-》站点功能-》主题热度下,如图。



热度的计算方式有两种:按参与人次或者按热度公式。

按参与人次的方式下:
以天为单位,一个周期内某用户多次参与主题,只加一次热度。(回复、点评、评论、收藏、分享等都算作参与主题的动作)

按热度公式的方式下:
按相应的热度公式,参与主题增加相应的热度。(只有回复、评价算作参与主题的动作)

下面以帖子的回帖分别对两种方式做下说明。

回帖的操作处理是在source\include\post\post_newreply.php文件,在322行附近可以找到如下代码。
  1. if($thread['lastposter'] != $_G['member']['username'] && $_G['uid']) {
  2.                 if($_G['setting']['heatthread']['type'] == 1 && $_G['setting']['heatthread']['reply']) {
  3.                         $posttable = getposttablebytid($_G['tid']);
  4.                         $userreplies = DB::result_first("SELECT COUNT(*) FROM ".DB::table($posttable)." WHERE tid='$_G[tid]' AND first='0' AND authorid='$_G[uid]'");
  5.                         $thread['heats'] += round($_G['setting']['heatthread']['reply'] * pow(0.8, $userreplies));
  6.                         DB::query("UPDATE ".DB::table('forum_thread')." SET heats='$thread[heats]' WHERE tid='$_G[tid]'", 'UNBUFFERED');
  7.                 } elseif($_G['setting']['heatthread']['type'] == 2) {
  8.                         update_threadpartake($_G['tid']);
  9.                 }
  10.         }
复制代码

按热度公式方式的处理:
  1. if($_G['setting']['heatthread']['type'] == 1 && $_G['setting']['heatthread']['reply']) {
  2. $posttable = getposttablebytid($_G['tid']);
  3. $userreplies = DB::result_first("SELECT COUNT(*) FROM ".DB::table($posttable)." WHERE tid='$_G[tid]' AND first='0' AND authorid='$_G[uid]'");
  4. $thread['heats'] += round($_G['setting']['heatthread']['reply'] * pow(0.8, $userreplies));
  5. DB::query("UPDATE ".DB::table('forum_thread')." SET heats='$thread[heats]' WHERE tid='$_G[tid]'", 'UNBUFFERED');
  6. }
复制代码


$_G['setting']['heatthread']['type'] == 1为按热度公式计算的方式。
$_G['setting']['heatthread']['reply']为后台设置的单次回复热度值。

  1. $posttable = getposttablebytid($_G['tid']);
  2. $userreplies = DB::result_first("SELECT COUNT(*) FROM ".DB::table($posttable)." WHERE tid='$_G[tid]' AND first='0' AND authorid='$_G[uid]'");
复制代码
这段为当前用户在这个主题所有回复的总数,$userreplies为总数。

  1. $thread['heats'] += round($_G['setting']['heatthread']['reply'] * pow(0.8, $userreplies));
复制代码
计算该帖子的热度数,此处即为热度的公式。

  1. DB::query("UPDATE ".DB::table('forum_thread')." SET heats='$thread[heats]' WHERE tid='$_G[tid]'", 'UNBUFFERED');
复制代码
更新表forum_thread中这个帖子的热度值(更新为根据热度公式计算的热度值$thread[heats])。

按参与人次方式的处理:
  1. elseif($_G['setting']['heatthread']['type'] == 2) {
  2. update_threadpartake($_G['tid']);
  3. }
复制代码
$_G['setting']['heatthread']['type'] == 2为按参与人次的方式。
update_threadpartake的函数在source/function/function_forum.php文件中.
具体代码如下:
  1. function update_threadpartake($tid) {
  2.         global $_G;
  3.         if($_G['uid'] && $tid) {
  4.                 if($_G['setting']['heatthread']['period']) {
  5.                         $partaked = DB::result_first("SELECT uid FROM ".DB::table('forum_threadpartake')." WHERE tid='$tid' AND uid='$_G[uid]'");
  6.                         if(!$partaked) {
  7.                                 DB::query("INSERT INTO ".DB::table('forum_threadpartake')." (tid, uid, dateline) VALUES ('$tid', '$_G[uid]', ".TIMESTAMP.")");
  8.                                 DB::query("UPDATE ".DB::table('forum_thread')." SET heats=heats+1 WHERE tid='$tid'", 'UNBUFFERED');
  9.                         }
  10.                 } else {
  11.                         DB::query("UPDATE ".DB::table('forum_thread')." SET heats=heats+1 WHERE tid='$tid'", 'UNBUFFERED');

  12.                 }
  13.         }
  14. }
复制代码

  1. if($_G['uid'] && $tid) {
  2. if($_G['setting']['heatthread']['period']) {
复制代码
判断是否为登录会员同时存在tid,同时后台设置了用户热度值周期(天)。
$_G['setting']['heatthread']['period']为后台设置的用户热度值周期(天)。

  1. $partaked = DB::result_first("SELECT uid FROM ".DB::table('forum_threadpartake')." WHERE tid='$tid' AND uid='$_G[uid]'");
复制代码
根据tid和uid查询表forum_threadpartake中是否存在相应的记录。

如果不存在,则执行下面的操作。
  1. if(!$partaked) {
  2. DB::query("INSERT INTO ".DB::table('forum_threadpartake')." (tid, uid, dateline) VALUES ('$tid', '$_G[uid]', ".TIMESTAMP.")");
  3. DB::query("UPDATE ".DB::table('forum_thread')." SET heats=heats+1 WHERE tid='$tid'", 'UNBUFFERED');
  4. }
复制代码
往表forum_threadpartake中插入一条新数据,同时更新表forum_thread中这个帖子的热度(+1)。

如果存在,则执行下面的操作。
  1. else {
  2. DB::query("UPDATE ".DB::table('forum_thread')." SET heats=heats+1 WHERE tid='$tid'", 'UNBUFFERED');

  3. }
复制代码
更新表forum_thread中这个帖子的热度(+1)。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
wukunda 发表于 2011-6-20 10:03:19 | 显示全部楼层
代码太多了。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-3-29 22:25 , Processed in 0.104220 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表