Typecho内容回复可见功能

插件开发及发布

版主: woniou

回复
头像
muchun
帖子: 734
注册时间: 2011年 11月 24日 10:39

Re: Typecho内容回复可见功能

帖子 muchun »

cookie没了怎么办?
头像
ClayMore
帖子: 2481
注册时间: 2007年 11月 29日 02:55
来自: Sleeping Forest
联系:

Re: Typecho内容回复可见功能

帖子 ClayMore »

一般首页很少有全文输出的,而且一般隐藏内容都放在文章后面,所以就不需要处理首页了,直接处理post.php就可以了,使用下面的代码

代码: 全选

<?php
$db = Typecho_Db::get();
$sql = $db->select()->from('table.comments')
    ->where('cid = ?',$this->cid)
    ->where('mail = ?', $this->remember('mail',true))
    ->limit(1);
$result = $db->fetchAll($sql);
if($this->user->hasLogin() || $result) {
    $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<div class="reply2view"><i class="icon-lock-open"></i>$1</div>',$this->content);
}
else{
    $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<div class="reply2view"><i class="icon-lock"></i>此处内容需要评论回复后方可阅读。</div>',$this->content);
}
echo $content
?>

替换传统的

代码: 全选

<?php $this->content(''); ?>


使用方法

代码: 全选

[hide]要隐藏的内容[/hide]

css参考样式

代码: 全选

.reply2view {
    background:#f8f8f8;
    padding:10px 10px 10px 40px;
    position:relative
}
.reply2view i {
    display:block;
    font-size:20px;
    height:20px;
    left:10px;
    line-height:20px;
    position:absolute;
    top:15px
}
头像
linfeiyu
帖子: 39
注册时间: 2011年 12月 25日 13:24
联系:

Re: Typecho内容回复可见功能

帖子 linfeiyu »

谢谢分享哈!


ClayMore 写了:一般首页很少有全文输出的,而且一般隐藏内容都放在文章后面,所以就不需要处理首页了,直接处理post.php就可以了,使用下面的代码

代码: 全选

<?php
$db = Typecho_Db::get();
$sql = $db->select()->from('table.comments')
    ->where('cid = ?',$this->cid)
    ->where('mail = ?', $this->remember('mail',true))
    ->limit(1);
$result = $db->fetchAll($sql);
if($this->user->hasLogin() || $result) {
    $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<div class="reply2view"><i class="icon-lock-open"></i>$1</div>',$this->content);
}
else{
    $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<div class="reply2view"><i class="icon-lock"></i>此处内容需要评论回复后方可阅读。</div>',$this->content);
}
echo $content
?>

替换传统的

代码: 全选

<?php $this->content(''); ?>


使用方法

代码: 全选

[hide]要隐藏的内容[/hide]

css参考样式

代码: 全选

.reply2view {
    background:#f8f8f8;
    padding:10px 10px 10px 40px;
    position:relative
}
.reply2view i {
    display:block;
    font-size:20px;
    height:20px;
    left:10px;
    line-height:20px;
    position:absolute;
    top:15px
}
回复