Discuz!默认只计算本月在线时间和累计在线时间,但是这对大部分论坛来说是不够用的,现在我的修改拓展了这个功能,可以计算当日在线时间和本周在线时间。这个修改只是个基础,因为这个功能会有利于不少插件的设计和使用……
另外修改成功的请发下你的论坛对应的效果图吧(和我下面的那个类似),有金币奖励的哦~~
SQL:- ALTER TABLE `cdb_onlinetime` ADD `thisday` SMALLINT( 6 ) UNSIGNED NOT NULL DEFAULT '0',
- ADD `thisweek` SMALLINT( 6 ) UNSIGNED NOT NULL DEFAULT '0';
- INSERT INTO cdb_crons (available,type,name,filename,weekday,day,hour,minute)
- VALUES ('1','user','清空本周在线时间','onlinetime_weekly.inc.php','0','-1','0','0');
- INSERT INTO cdb_crons (available,type,name,filename,weekday,day,hour,minute)
- VALUES ('1','user','清空本日在线时间','onlinetime_daily.inc.php','-1','-1','0','0');
复制代码 打开include/global.func.php
找到:- total=total+'$oltimespan', thismonth=thismonth+'$oltimespan',
复制代码 在后面加:- thisday=thisday+'$oltimespan', thisweek=thisweek+'$oltimespan',
复制代码 找到:- $db->query("INSERT INTO {$tablepre}onlinetime (uid, thismonth, total, lastupdate)
- VALUES ('$discuz_uid', '$oltimespan', '$oltimespan', '$timestamp')", 'SILENT');
复制代码 替换成:- $db->query("INSERT INTO {$tablepre}onlinetime (uid, thismonth, thisweek, thisday, total, lastupdate)
- VALUES ('$discuz_uid', '$oltimespan', '$oltimespan','$oltimespan', '$oltimespan', '$timestamp')", 'SILENT');
复制代码 打开space.php
找到:- $oltimeadd1 = ', o.thismonth AS thismonthol, o.total AS totalol';
复制代码 替换成:- $oltimeadd1 = ', o.thismonth AS thismonthol, o.thisweek AS thisweekol, o.thisday AS thisdayol, o.total AS totalol';
复制代码 找到:- $member['thismonthol'] = gmdate('Yn', $member['lastactivity']) == gmdate('Yn', $timestamp) ? round($member['thismonthol'] / 60, 2) : 0;
复制代码 在下面加:- $member['thisweekol'] = gmdate('Yn', $member['lastactivity']) == gmdate('Yn', $timestamp) ? round($member['thisweekol'] / 60, 2) : 0;
- $member['thisdayol'] = gmdate('Yn', $member['lastactivity']) == gmdate('Yn', $timestamp) ? round($member['thisdayol'] / 60, 2) : 0;
复制代码 打开templates/default/viewpro_classic.htm
找到:- {lang onlinetime_thismonth} <em>$member[thismonthol]</em> {lang hours}
复制代码 在后面加:- , 本周在线 <em>$member[thisweekol]</em> {lang hours}, 本日在线 <em>$member[thisdayol]</em> {lang hours}
复制代码 打开stats.php
找到:- $newstatvars[] = "'onlines', 'thismonth', '".addslashes(serialize($thismonth))."'";
- }
复制代码 在下面加:- if(isset($statvars['thisweek'])) {
- $thisweek = unserialize($statvars['thisweek']);
- } else {
- $dateline = strtotime(gmdate('Y-n-01', $timestamp));
- $query = $db->query("SELECT o.uid, m.username, o.thisweek AS time
- FROM {$tablepre}onlinetime o, {$tablepre}members m
- WHERE o.uid=m.uid AND m.lastactivity>='$dateline'
- ORDER BY o.thismonth DESC LIMIT 20");
- while($online = $db->fetch_array($query)) {
- $online['time'] = round($online['time'] / 60, 2);
- $thisweek[] = $online;
- }
- $newstatvars[] = "'onlines', 'thisweek', '".addslashes(serialize($thisweek))."'";
- }
-
- if(isset($statvars['thisday'])) {
- $thisday = unserialize($statvars['thisday']);
- } else {
- $dateline = strtotime(gmdate('Y-n-01', $timestamp));
- $query = $db->query("SELECT o.uid, m.username, o.thisday AS time
- FROM {$tablepre}onlinetime o, {$tablepre}members m
- WHERE o.uid=m.uid AND m.lastactivity>='$dateline'
- ORDER BY o.thismonth DESC LIMIT 20");
- while($online = $db->fetch_array($query)) {
- $online['time'] = round($online['time'] / 60, 2);
- $thisday[] = $online;
- }
- $newstatvars[] = "'onlines', 'thisday', '".addslashes(serialize($thisday))."'";
- }
复制代码 找到:- "<td class="stat_subject"><a href="space.php?uid={$thismonth[$i]['uid']}" target="_blank">{$thismonth[$i]['username']}</a></td><td class="stat_num">{$thismonth[$i]['time']}</td></tr>\n";
复制代码 替换成:- "<td class="stat_subject"><a href="space.php?uid={$thismonth[$i]['uid']}" target="_blank">{$thismonth[$i]['username']}</a></td><td class="stat_num">{$thismonth[$i]['time']}</td>\n".
- "<td class="stat_subject"><a href="space.php?uid={$thisweek[$i]['uid']}" target="_blank">{$thisweek[$i]['username']}</a></td><td class="stat_num">{$thisweek[$i]['time']}</td>\n".
- "<td class="stat_subject"><a href="space.php?uid={$thisday[$i]['uid']}" target="_blank">{$thisday[$i]['username']}</a></td><td class="stat_num">{$thisday[$i]['time']}</td></tr>\n";
复制代码 打开templates/default/stats_onlinetime.htm
找到:- <td colspan="2" width="50%">{lang stats_onlinetime_total}</td>
- <td colspan="2" width="50%">{lang stats_onlinetime_thismonth}</td>
复制代码 替换成:- <td colspan="2" width="25%">{lang stats_onlinetime_total}</td>
- <td colspan="2" width="25%">{lang stats_onlinetime_thismonth}</td>
- <td colspan="2" width="25%">本周在线时间排行(小时)</td>
- <td colspan="2" width="25%">本日在线时间排行(小时)</td>
复制代码 把文件上传到include/crons/目录中,可能需要在工具——计划任务中触发一次(仅一次)任务
|