Typecho 1.1实现评论回复可见

资源
550 2

测试评论回复可见,又加入了新的功能,虽然不知道能不能用得上。

新加入功能测试一下哦!

相关教程如下:

在文章模板post.php下加入以下代码:

//找到
<?php $this->content(); ?>
//修改成
<?php echo parse_content($this->content,$this->cid,$this->remember('mail',true),$this->user->hasLogin()); ?>

在模板函数文件functions.php文件下加入:

//添加下面的代码
function parse_content($content,$cid,$mail,$login){
    $db = Typecho_Db::get();
    $sql = $db->select()->from('table.comments')
    ->where('cid = ?',$cid)
    ->where('mail = ?', $mail)
    ->where('status = ?', 'approved')
    ->limit(1);
    $result = $db->fetchAll($sql);
    if($login || $result) {
        $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'$1',$content);
    }
    else{
        $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<div class="reply2view">此处内容已隐藏,您需要<a onclick="window.scrollTo(0, document.documentElement.clientHeight);">回复</a>才能显示此处内容。</div>',$content);
    }
    return $content;
}
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('moleft','one');
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('moleft','one');
class moleft {
    public static function one($con,$obj,$text)
    {
      $text = empty($text)?$con:$text;
      if(!$obj->is('single')){
      $text = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'此处内容已隐藏',$text);
      }
      return $text;
    }
}

根据自己的主题添加相应的前台样式,也可以直接用我的:

.reply2view {
    background:#f8f8f8;
    border-radius:5px;
    border:1px dashed #888888;
    padding:10px 10px 10px 10px;
    position:relative;
}

使用方法:[@hide]要隐藏的内容[/hide]

网上好多代码都是错的,不知道是不是Typecho的版本问题,本文所讲经过博主在Typecho1.1稳定版测试完全没问题。

简单痛快,就此完成。

参考:Typecho 教程 - 非插件实现回复可见

// 2020年12月28日

修复点击[回复]按钮无法定位到评论框的问题

具体详细代码如下:

//Typecho 1.1实现评论回复可见修复版,添加下面的代码

function parse_content($content,$cid,$mail,$login){
    $db = Typecho_Db::get();
    $sql = $db->select()->from('table.comments')
    ->where('cid = ?',$cid)
    ->where('mail = ?', $mail)
    ->where('status = ?', 'approved')
    ->limit(1);
    $result = $db->fetchAll($sql);
    if($login || $result) {
        $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'$1',$content);
    }
    else{
        $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<hide>此处内容已隐藏,您需要<a onclick="window.scrollTo(0,document.body.scrollHeight);">回复</a>才能显示该内容。</hide>',$content);
    }
    return $content;
}
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('moleft','one');
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('moleft','one');
class moleft {
    public static function one($con,$obj,$text)
    {
      $text = empty($text)?$con:$text;
      if(!$obj->is('single')){
      $text = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<hide>此处内容已隐藏</hide>',$text);
      }
      return $text;
    }
}
最后更新 2021-11-02
评论 ( 2 )
OωO
隐私评论
  1. 再测试一下 解决点击回复无法定位评论框问题

    4年前局域网回复
  2. 测试回复

    4年前局域网回复