打印 上一主题 下一主题

Discuz帖子浏览记录

跳转到指定楼层
楼主
SetYun 发表于 2018-10-20 10:39:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Discuz! X 在后台可以设置记录浏览过的帖子,这样当我们找刚浏览过的帖子时就会方便很多。
后台开启方法:进入后台->界面->界面设置->帖子内容页,里面有一个设置项: 显示最近访问帖子数量
如果这里设置了数字,那么会记录我们浏览过帖子的信息,设置为 0 则表示不启用该功能。

这里开启后,我们在浏览的帖子的时候,会做记录,具体的代码是在 /source/module/forum/forum_viewthread.php ,打开这个文件,
看到代码
  • $oldthreads = viewthread_oldtopics(!$archiveid ? $_G['tid'] : 0);


这里执行了函数  viewthread_oldtopics  函数,对当前浏览的主题做了记录,这个函数就在这个文件得下面,代码如下:
  • function viewthread_oldtopics($tid = 0) {
  •         global $_G;

  •         $oldthreads = array();

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

  •         if($_G['setting']['visitedthreads']) {
  •                 $oldtids = array_slice(explode('D', $oldtopics), 0, $_G['setting']['visitedthreads']);
  •                 $oldtidsnew = array();
  •                 foreach($oldtids as $oldtid) {
  •                         $oldtid && $oldtidsnew[] = $oldtid;
  •                 }
  •                 if($oldtidsnew) {
  •                         $query = DB::query("SELECT tid, subject FROM ".DB::table('forum_thread')." WHERE tid IN (".dimplode($oldtidsnew).")");
  •                         while($oldthread = DB::fetch($query)) {
  •                                 $oldthreads[$oldthread['tid']] = $oldthread['subject'];
  •                         }
  •                 }
  •                 array_unshift($oldtidsnew, $tid);
  •                 dsetcookie('oldtopics', implode('D', array_slice($oldtidsnew, 0, $_G['setting']['visitedthreads'])), 3600);                ;
  •         }

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

  •         return $oldthreads;
  • }


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

在帖子显示的模板页面 /template/default/forum/view_thread.htm
下面有代码:
  • <!--{if ($_G['setting']['visitedforums'] || $oldthreads) && $_G['forum']['status'] != 3}-->
  •         <div id="visitedforums_menu" class="{if $oldthreads}visited_w {/if}p_pop blk cl" style="display: none;">
  •                 <table cellspacing="0" cellpadding="0">
  •                         <tr>
  •                                 <!--{if $oldthreads}-->
  •                                         <td id="v_threads">
  •                                                 <h3 class="mbn pbn bbda xg1">{lang viewd_threads}</h3>
  •                                                 <ul class="xl xl1">
  •                                                 <!--{loop $oldthreads $oldtid $oldsubject}-->
  •                                                         <li><a href="forum.php?mod=viewthread&tid=$oldtid">$oldsubject</a></li>
  •                                                 <!--{/loop}-->
  •                                                 </ul>
  •                                         </td>
  •                                 <!--{/if}-->
  •                                 <!--{if $_G['setting']['visitedforums']}-->
  •                                         <td id="v_forums">
  •                                                 <h3 class="mbn pbn bbda xg1">{lang viewed_forums}</h3>
  •                                                 <ul class="xl xl1">
  •                                                         $_G['setting']['visitedforums']
  •                                                 </ul>
  •                                         </td>
  •                                 <!--{/if}-->
  •                         </tr>
  •                 </table>
  •         </div>
  • <!--{/if}-->



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

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|SetYun ( 辽ICP备16005250号

GMT+8, 2024-4-25 07:13 , Processed in 0.037655 second(s), 4 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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