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

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

帖子浏览记录

[复制链接]
零风 发表于 2011-4-26 16:52:32 | 显示全部楼层 |阅读模式
Discuz! X 在后台可以设置记录浏览过的帖子,这样当我们找刚浏览过的帖子时就会方便很多。
后台开启方法:进入后台->界面->界面设置->帖子内容页,里面有一个设置项: 显示最近访问帖子数量
如果这里设置了数字,那么会记录我们浏览过帖子的信息,设置为 0 则表示不启用该功能。

这里开启后,我们在浏览的帖子的时候,会做记录,具体的代码是在 /source/module/forum/forum_viewthread.php ,打开这个文件,
看到代码
  1. $oldthreads = viewthread_oldtopics(!$archiveid ? $_G['tid'] : 0);
复制代码
这里执行了函数  viewthread_oldtopics  函数,对当前浏览的主题做了记录,这个函数就在这个文件得下面,代码如下:
  1. function viewthread_oldtopics($tid = 0) {
  2.         global $_G;

  3.         $oldthreads = array();

  4.         $oldtopics = isset($_G['cookie']['oldtopics']) ? $_G['cookie']['oldtopics'] : 'D';

  5.         if($_G['setting']['visitedthreads']) {
  6.                 $oldtids = array_slice(explode('D', $oldtopics), 0, $_G['setting']['visitedthreads']);
  7.                 $oldtidsnew = array();
  8.                 foreach($oldtids as $oldtid) {
  9.                         $oldtid && $oldtidsnew[] = $oldtid;
  10.                 }
  11.                 if($oldtidsnew) {
  12.                         $query = DB::query("SELECT tid, subject FROM ".DB::table('forum_thread')." WHERE tid IN (".dimplode($oldtidsnew).")");
  13.                         while($oldthread = DB::fetch($query)) {
  14.                                 $oldthreads[$oldthread['tid']] = $oldthread['subject'];
  15.                         }
  16.                 }
  17.                 array_unshift($oldtidsnew, $tid);
  18.                 dsetcookie('oldtopics', implode('D', array_slice($oldtidsnew, 0, $_G['setting']['visitedthreads'])), 3600);                ;
  19.         }

  20.         
  21.         if($_G['member']['lastvisit'] < $_G['forum_thread']['lastpost'] && (!isset($_G['cookie']['fid'.$_G['fid']]) || $_G['forum_thread']['lastpost'] > $_G['cookie']['fid'.$_G['fid']])) {
  22.                 dsetcookie('fid'.$_G['fid'], $_G['forum_thread']['lastpost'], 3600);
  23.         }

  24.         return $oldthreads;
  25. }
复制代码
这个函数首先判断如果开启了记录浏览记录的话,则把当前浏览的帖子记录存到当前的 cookie 中,然后返回给变量  $oldthreads 。

在帖子显示的模板页面 /template/default/forum/view_thread.htm
下面有代码:
  1. <!--{if ($_G['setting']['visitedforums'] || $oldthreads) && $_G['forum']['status'] != 3}-->
  2.         <div id="visitedforums_menu" class="{if $oldthreads}visited_w {/if}p_pop blk cl" style="display: none;">
  3.                 <table cellspacing="0" cellpadding="0">
  4.                         <tr>
  5.                                 <!--{if $oldthreads}-->
  6.                                         <td id="v_threads">
  7.                                                 <h3 class="mbn pbn bbda xg1">{lang viewd_threads}</h3>
  8.                                                 <ul class="xl xl1">
  9.                                                 <!--{loop $oldthreads $oldtid $oldsubject}-->
  10.                                                         <li><a href="forum.php?mod=viewthread&tid=$oldtid">$oldsubject</a></li>
  11.                                                 <!--{/loop}-->
  12.                                                 </ul>
  13.                                         </td>
  14.                                 <!--{/if}-->
  15.                                 <!--{if $_G['setting']['visitedforums']}-->
  16.                                         <td id="v_forums">
  17.                                                 <h3 class="mbn pbn bbda xg1">{lang viewed_forums}</h3>
  18.                                                 <ul class="xl xl1">
  19.                                                         $_G['setting']['visitedforums']
  20.                                                 </ul>
  21.                                         </td>
  22.                                 <!--{/if}-->
  23.                         </tr>
  24.                 </table>
  25.         </div>
  26. <!--{/if}-->
复制代码

这里处理把 PHP 得到的变量放到页面中,然后默认是隐藏的,当鼠标放到帖子列表页的返回时,触发 JS 代码 showmenu ,同时将隐藏的浏览记录在这个位置显示,从而显示出自己的浏览记录。。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-6-16 23:23 , Processed in 0.092281 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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