[原创]Discuz论坛设置游客只能看贴子的部分内容
Discuz论坛设置游客只能看贴子的部分内容,不影响搜索引擎收录
基本思路:
判断用户权限,如果用户未登录,在帖子内容外嵌套一个DIV容器,并且使用css定义该DIV,定义行高为height,使之完整显示n行(如果显示2行,只需设置div高度为2×height)的内容,其余溢出部分不显示。
如此一来,相对于一般用户而言,内容是隐藏的,并且对搜索引擎而言,只是多加了一层div,对于索引内容并没有影响
具体实现:
修改 viewthread.php 文件!!
-
if($post['attachment']) {
-
if($allowgetattach && !$threadpay) {
-
$attachpids .= ",$post[pid]";
-
$post['attachment'] = 0;
-
if(preg_match_all("/\[attach\](\d+)\[\/attach\]/i", $post['message'], $matchaids)) {
-
$attachtags[$post['pid']] = $matchaids[1];
-
}
-
} else {
-
$post['message'] = preg_replace("/\[attach\](\d+)\[\/attach\]/i", '', $post['message']);
-
}
-
}
-
[color=Red]<代码>[/color]
-
$ratelogpids .= ($ratelogrecord && $post['rate']) ? ','.$post['pid'] : '';
-
$forum['allowbbcode'] = $forum['allowbbcode'] ? ($_DCACHE['usergroups'][$post['groupid']]['allowcusbbcode'] ? 2 : 1) : 0;
-
$post['signature'] = $post['usesig'] ? ($sigviewcond ? (strlen($post['message']) > $sigviewcond ? $post['signature'] : '') : $post['signature']) : '';
-
$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']);
-
$videoopen && $post['message'] = videocode($post['message'], $post['tid'], $post['pid']);
-
$post['first'] && $firstpid = $post['pid'];
-
$firstpid = intval($firstpid);
-
return $post;
-
}
复制代码
插入如下代码
//游客看貼限制
if(!$discuz_uid && $post['count'] == 0 && strlen($post['message']) > 200){
$post['message']=str_replace("\n","\n",$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)
评论