Typecho回复可见教程
步骤一
<?php
$db = Typecho_Db::get();
$user = Typecho_Widget::widget('Widget_User');
/*判断用户登录*/
if($user->uid > 0){
/*查询用户的id是否在评论表中*/
$sql = $db->select()->from('table.comments')
->where('cid = ?',$this->cid)
->where('authorId = ?', $user->uid)
->where('status = ?', 'approved')
->limit(1);
}else{
/*查询游客的邮箱是否在评论表中*/
$sql = $db->select()->from('table.comments')
->where('cid = ?',$this->cid)
->where('mail = ?', $this->remember('mail',true))
->where('status = ?', 'approved')
->limit(1);
}
$result = $db->fetchAll($sql);
/*文章作者和评论过的用户或者游客可以看见回复可见内容*/
if($user->uid==$this->authorId || $result) {
$content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<div class="reply2view">$1</div>',$this->content);
}
else{
$content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<div class="reply2view">此处内容需要评论回复后方可阅读。</div>',$this->content);
}
echo $content
?>
步骤二
解决缩略内容和feed暴露问题。
在functions.php
中加入如下代码即可
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('myyodux','one');
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('myyodux','one');
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('myyodux', 'san');
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('myyodux', 'san');
class myyodux {
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;
}
/*向后台编辑器插入回复可见按钮*/
public static function san()
{
?>
<style>.wmd-button-row {height: auto;}</style>
<script>
$(document).ready(function(){
$('#wmd-button-row').append('<li class="wmd-button" id="wmd-jrotty-button" title="回复可见"><span style="background: none;font-size: 16px;border: 1px solid #dedede;padding: 2px;color: #467B96;width: auto;height: auto;">回复可见</span></li>');
if($('#wmd-button-row').length !== 0){
$('#wmd-jrotty-button').click(function(){
var rs = "[@hide]回复可见内容{/hide}"; //去掉@
var myField = $('#text')[0];
insertAtCursor(myField,rs);
})
}
function insertAtCursor(myField, myValue) {
//IE 浏览器
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
sel.select();
}
//FireFox、Chrome等
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
// 保存滚动条
var restoreTop = myField.scrollTop;
myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
if (restoreTop > 0) {myField.scrollTop = restoreTop;}
myField.focus();
myField.selectionStart = startPos + myValue.length;
myField.selectionEnd = startPos + myValue.length;
} else {
myField.value += myValue;
myField.focus();
}
}
});
</script>
<?php
}
}
就是用插件接口,在缩略内容输出之前,隐藏掉或者替换掉回复可见内容,同时使用if判断,来针对非single
页面进行隐藏。
步骤三
使用方法
在写文章需要隐藏部分内容时用以下写法(去掉@)
[@hide]要隐藏的内容{/hide}
css参考样式
.reply2view {
background:#f8f8f8;
padding:10px 10px 10px 40px;
position:relative
}
上一篇:百度信风算法:杜绝翻页诱导
下一篇:织梦DedeCMS后台文件任意上传漏洞修复方案
文章评论 (0)
评论功能已被站长关闭