给typecho程序Joe主题添加隐私评论功能(其他主题部分通用)
本帖最后由 kingkare 于 2024-7-30 22:26 编辑教程开始
将下面这段代码插入评论区(请自行美化样式),一般放在提交评论的按钮前
<input type="checkbox" name="is-private" id="PrivateComments"><label for="PrivateComments" class="PrivateCommentsLable">
代码位置在Joe主题public\comment.php中查找如下代码
<span class="cancle joe_comment__cancle">取消</span>
<button type="submit">发送评论</button>
其他主题可以在comment.php搜索你主题提交评论按钮的汉字,并放入前方
插入JS,将下面这段代码插入 comment.php 最下方
<script>
document.getElementById('PrivateComments').addEventListener('click',function(){var commentField=document.getElementById('comment');if(document.getElementById('PrivateComments').checked){Qmsg.info('已开启密语');var currentValue=commentField.value;commentField.value='密语# '+currentValue;commentField.addEventListener('input',preventDeletingText)}else{Qmsg.info('已关闭密语');commentField.value=commentField.value.replace('密语# ','');commentField.removeEventListener('input',preventDeletingText)}});function preventDeletingText(){var commentField=document.getElementById('comment');if(!commentField.value.startsWith('密语# ')){commentField.value='密语# '+commentField.value.substring(3)}}
</script>
修改评论输出语句(以Joe主题为例) 在comment.php
<?php _parseCommentReply($comments->content);
修改为以下代码
<?php _getParentReply($comments->parent) ?>
<?php
$db = Typecho_Db::get();
$smyk = $db->fetchRow($db->select('mail')->from('table.comments')->where('coid = ?', $comments->parent)->limit(1));
$smhf = $comments->mail;
$user = Typecho_Widget::widget('Widget_User');
if (strpos($comments->content, '密语# ') == true) {
$ykmail = Typecho_Cookie::get('__typecho_remember_mail');
if ($smhf == $user->mail or $smhf == $ykmail or $user->group == 'administrator' or $smyk['mail'] == $ykmail and !empty($smyk['mail'])) {
_parseCommentReply(str_replace('密语# ', '', $comments->content));
} else {
echo '<div class="secret">此条为密语,发布者可见</div>';
}
} else {
echo _parseCommentReply($comments->content);
}
?>
修改文本输入框,给文本框添加 id="comment"
<div class="body">
<textarea class="text joe_owo__target" name="text" value="" autocomplete="new-password" placeholder="说点什么吧,点击右上方切换成画图试试?"><?php echo random_comment(); ?></textarea>
如果你的主题输入框已有id值,就将js中的'comment' 修改为主题的id值
💪 强力顶贴,内容非常有价值! 💪—— 来自:荷包蛋部落(HBD0.CN)已读乱回
页:
[1]