[原创]Discuz论坛设置游客只能看贴子的部分内容

Discuz论坛设置游客只能看贴子的部分内容,不影响搜索引擎收录

基本思路

判断用户权限,如果用户未登录,在帖子内容外嵌套一个DIV容器,并且使用css定义该DIV,定义行高为height,使之完整显示n行(如果显示2行,只需设置div高度为2×height)的内容,其余溢出部分不显示。

如此一来,相对于一般用户而言,内容是隐藏的,并且对搜索引擎而言,只是多加了一层div,对于索引内容并没有影响

具体实现:

修改 viewthread.php 文件!!

  1. if($post['attachment']) {

  2. if($allowgetattach && !$threadpay) {

  3. $attachpids .= ",$post[pid]";

  4. $post['attachment'] = 0;

  5. if(preg_match_all("/\[attach\](\d+)\[\/attach\]/i", $post['message'], $matchaids)) {

  6. $attachtags[$post['pid']] = $matchaids[1];

  7. }

  8. } else {

  9. $post['message'] = preg_replace("/\[attach\](\d+)\[\/attach\]/i", '', $post['message']);

  10. }

  11. }

  12. [color=Red]<代码>[/color]

  13. $ratelogpids .= ($ratelogrecord && $post['rate']) ? ','.$post['pid'] : '';

  14. $forum['allowbbcode'] = $forum['allowbbcode'] ? ($_DCACHE['usergroups'][$post['groupid']]['allowcusbbcode'] ? 2 : 1) : 0;

  15. $post['signature'] = $post['usesig'] ? ($sigviewcond ? (strlen($post['message']) > $sigviewcond ? $post['signature'] : '') : $post['signature']) : '';

  16. $post['message'] = discuzcode($post['message'], $post['smileyoff'], $post['bbcodeoff'], $post['htmlon'] & 1, $forum['allowsmilies'], $forum['allowbbcode'], ($forum['allowimgcode'] && $showimages ? 1 : 0), $forum['allowhtml'], ($forum['jammer'] && $post['authorid'] != $discuz_uid ? 1 : 0), 0, $post['authorid'], $forum['allowmediacode'], $post['pid']);

  17. $videoopen && $post['message'] = videocode($post['message'], $post['tid'], $post['pid']);

  18. $post['first'] && $firstpid = $post['pid'];

  19. $firstpid = intval($firstpid);

  20. return $post;

  21. }

复制代码

插入如下代码


//游客看貼限制

if(!$discuz_uid && $post['count'] == 0 && strlen($post['message']) > 200){

$post['message']=str_replace("\n","\n",$post['message']);

$post['message']="

".$post['message']."
";

$post['messagedesc']="歡迎訪問創業論壇您目前的身份是游客,所以只能閱讀部分內容,請注冊或者登錄,謝謝!期待您的加入!";

$post['message'] = "[align=center][quote][b]帖子預覽[/b]".$post['message']."\n".'................[/quote][/align]'.$post['messagedesc'];

$post['bbcodeoff'] = 0;

}

//cary edit end

代码添加的位置可以参考(游客只能看贴子的部分内容 FOR 7.0

评论

此博客中的热门博文

你的妈妈已经等了二十几年

时间管理:每天挤出一小时

教您如何认识植柔皮,头层皮革,修面皮革,油蜡皮、水染皮、摔纹皮、纳帕皮、打蜡皮、压花皮、修面皮、漆光皮、磨砂皮、贴膜皮