Skip to content

Commit

Permalink
畅言替换原有的多说评论 可选则默认或畅言
Browse files Browse the repository at this point in the history
  • Loading branch information
InsertSweat authored and InsertSweat committed Jun 14, 2017
1 parent 0762b05 commit 7cf84be
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 237 deletions.
42 changes: 42 additions & 0 deletions comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* The template for displaying comments
*
* This is the template that displays the area of the page that contains both the current comments
* and the comment form.
*
* @link https://insertsweat.cn
*
* @subpackage NexT theme
* @version 3.1
*/

/*
* If the current post is protected by a password and
* the visitor has not yet entered the password we will
* return early without loading the comments.
*/
?>
<?php function qiuye_comment($comment, $args, $depth)
{ $GLOBALS['comment'] = $comment; ?>
<li class="comment" id="li-comment-<?php comment_ID(); ?>">
<div class="comment-body">
<div class="comment-author">
<?php if (function_exists('get_avatar') && get_option('show_avatars')) { echo get_avatar($comment, 48); } ?>
</div><div class="comment_content" id="comment-<?php comment_ID(); ?>">
<div class="comment_text">
<?php printf(__('<cite class="fn">%s</cite>'), get_comment_author_link()); ?>
<?php if ($comment->comment_approved == '0') : ?>
<span>你的评论正在审核,稍后会显示出来!</span><br />
<?php endif; ?><?php comment_text(); ?>
<div class="reply">
<div class="comment-meta commentmetadata">发表于:<?php echo get_comment_time('Y-m-d H:i'); ?> </div>
<?php comment_reply_link(array_merge( $args, array('reply_text' => '回复','depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
<?php edit_comment_link('修改'); ?>
</div></div></div></div></li><?php } ?>
<?php wp_list_comments('type=comment&callback=qiuye_comment');?>


<div class="pagination comments-pagination">
<?php paginate_comments_links('prev_text=«&next_text=»');?>
</div>
19 changes: 19 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,25 @@ function wpdx_paging_nav(){
}
}

/* 获取文章的评论人数 */
function zfunc_comments_users($postid=0,$which=0) {
$comments = get_comments('status=approve&type=comment&post_id='.$postid); //获取文章的所有评论
if ($comments) {
$i=0; $j=0; $commentusers=array();
foreach ($comments as $comment) {
++$i;
if ($i==1) { $commentusers[] = $comment->comment_author_email; ++$j; }
if ( !in_array($comment->comment_author_email, $commentusers) ) {
$commentusers[] = $comment->comment_author_email;
++$j;
}
}
$output = array($j,$i);
$which = ($which == 0) ? 0 : 1;
return $output[$which]; //返回评论人数
}
return 0; //没有评论返回0
}

class FontAwesomeFour {

Expand Down
18 changes: 7 additions & 11 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
<div class="tag">
<span class="item">发表于 <?php the_date() ?></span>
<span class="item"><?php the_category(‘,’) ?></span>
<span class="item ds-thread-count" data-thread-key="<?php the_id() ?>"></span>
<span class="item">阅读次数 <?php get_post_views($post -> ID); ?></span>
<?php if(get_option('next_comment_type') == 'sohucs'){ ?>
<span class="item"><span id = "sourceId::<?php echo $post -> ID ?>" class = "cy_cmt_count" ></span>条评论</span>
<?php } else {?>
<span class="item ds-thread-count"><?php echo get_post($post -> ID)->comment_count; ?>条评论</span>
<?php } ?>
<span class="item">阅读次数 <?php get_post_views($post -> ID); ?></span>
</div>
</div>
<div class="content">
Expand Down Expand Up @@ -41,14 +45,6 @@
<div id="backTop" class="hide">
<i class="fa fa-arrow-up"></i>
</div>
<script type="text/javascript">
var duoshuoQuery = {short_name:"<?php echo get_option('next_duoshuo_shortname'); ?>"};
(function() {
var ds = document.createElement('script');
ds.type = 'text/javascript';ds.async = true;
ds.src = 'http://static.duoshuo.com/embed.js';
ds.charset = 'UTF-8';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ds);
})();
<script id="cy_cmt_num" src="https://changyan.sohu.com/upload/plugins/plugins.list.count.js?clientId=cyt0HdcCq">
</script>
<?php get_footer() ?>
23 changes: 18 additions & 5 deletions option.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php add_action('admin_menu', 'next_page');
function next_page (){
if ( count($_POST) > 0 && isset($_POST['next_settings']) ){
$options = array ('author','avator','site_time','duoshuo_shortname','scheme');
$options = array ('author','avator','site_time','comment_type','scheme', 'sohucs_appid', 'sohucs_conf');
foreach ( $options as $opt ){
delete_option ( 'next_'.$opt, $_POST[$opt] );
add_option ( 'next_'.$opt, $_POST[$opt] );
Expand Down Expand Up @@ -48,14 +48,27 @@ function next_settings(){?>
<label for="">头像路径:</label>
<input name="avator" id="avator" type="text" name="" value="<?php echo get_option('next_avator'); ?>">
</div>
<div class="form-group">
<label for="">你的多说short_name:</label>
<input name="duoshuo_shortname" id="duoshuo_shortname" type="text" name="" value="<?php echo get_option('next_duoshuo_shortname'); ?>">
</div>
<div class="form-group">
<label for="">底部时间设置:</label>
<input name="site_time" id="site_time" type="text" name="" value="<?php echo get_option('next_site_time'); ?>">
</div>
<div class="form-group">
<label for="">评论框:</label>
<select name="comment_type" id="">
<option value="default" <?php if(get_option('next_comment_type') == 'default'){ ?> selected="selected" <?php
} ?>>默认</option>
<option value="sohucs" <?php if(get_option('next_comment_type') == 'sohucs'){ ?> selected="selected"<?php
} ?>>畅言评论框</option>
</select>
</div>
<?php if(get_option('next_comment_type') == 'sohucs'){ ?>
<div class="form-group">
<label for="">畅言appid:</label>
<input name="sohucs_appid" id="site_time" type="text" name="" value="<?php echo get_option('next_sohucs_appid'); ?>">
<label for="">畅言conf:</label>
<input name="sohucs_conf" id="site_time" type="text" name="" value="<?php echo get_option('next_sohucs_conf'); ?>">
</div>
<?php }?>
<div class="form-group">
<label for="">主题方案:</label>
<select name="scheme" id="">
Expand Down
156 changes: 121 additions & 35 deletions single.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
<span class="item"><i class="fa fa-fw fa-calendar-check-o"></i> <?php the_date() ?></span>
<span class="item"><i class="fa fa-fw fa-folder-o"></i>
<?php the_category(‘,’) ?></span>
<span class="item ds-thread-count" data-thread-key="<?php the_id() ?>"></span>
<?php if(get_option('next_comment_type') == 'sohucs'){ ?>
<span class="item"><span href="#SOHUCS" id="changyan_count_unit" ></span>条评论</span>
<?php } else {?>
<span class="item ds-thread-count"><?php echo get_post($post -> ID)->comment_count; ?>条评论</span>
<?php } ?>
<span class="item">阅读次数 <?php get_post_views($post -> ID); ?></span>
</div>
</div>
Expand All @@ -26,42 +30,124 @@
</div>
<div class="next">
<?php if (get_next_post()) { next_post_link('%link <i class="fa fa-chevron-right"></i> ');} ?>
</div>
</div>
<div class="ds-share flat" data-thread-key="<?php the_ID() ?>" data-title="<?php the_title(); ?>" data-url="<?php the_permalink() ?>">
<div class="ds-share-inline">
<ul class="ds-share-icons-16">

<li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到:</a></li>
<li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
<li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
<li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
<li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

</ul>
<div class="ds-share-icons-more">
</div>
</div>
</div>

<!-- 多说评论框 start -->
<div class="ds-thread" data-thread-key="<?php the_ID() ?>" data-title="<?php the_title(); ?>" data-url="<?php the_permalink() ?>"></div>

<!-- 多说评论框 end -->
</div>
<?php if (get_option('next_comment_type') == 'sohucs') { ?>
<!-- 畅言评论框 start -->
<style>
#SOHUCS #SOHU_MAIN .module-cmt-header .section-cbox-w .block-head-w .header-login{
border-radius: 0;
padding: 0 15px;
height: 30px;
line-height: 30px!important;
-webkit-transition: .3s;
-moz-transition: .3s ;
-ms-transition: .3s ;
-o-transition: .3s ;
transition: .3s ;
}
#SOHUCS #SOHU_MAIN .module-cmt-header .section-cbox-w .block-head-w .header-login:hover{
background: #000000;
color: #FFFFFF;
}
#SOHUCS #SOHU_MAIN .module-cmt-box .post-wrap-w div.post-wrap-border-l,
#SOHUCS #SOHU_MAIN .module-cmt-box .post-wrap-w div.post-wrap-border-r,
#SOHUCS #SOHU_MAIN .module-cmt-box .post-wrap-w div.post-wrap-border-t .post-wrap-border-t-l,
#SOHUCS #SOHU_MAIN .module-cmt-box .post-wrap-w .post-wrap-main
{
background-image: none;
}
#SOHUCS #SOHU_MAIN .module-cmt-box .post-wrap-w div.post-wrap-border-r{
border-left: 1px solid #000;
}
#SOHUCS #SOHU_MAIN .module-cmt-box .post-wrap-w div.post-wrap-border-l{
border-right: 1px solid #000;
}
#SOHUCS #SOHU_MAIN .module-cmt-box .post-wrap-w div.post-wrap-border-t .post-wrap-border-t-l{
border-top: 1px solid #000;
}
#SOHUCS #SOHU_MAIN .module-cmt-box .post-wrap-w .post-wrap-border-t div.post-wrap-border-t-r{
margin-left: 0 !important;
}
#SOHUCS #SOHU_MAIN .module-cmt-box .post-wrap-w .post-wrap-main .wrap-area-w .textarea-fw{
font-family: inherit;
}
#SOHUCS #SOHU_MAIN .module-cmt-box .post-wrap-w .wrap-action-w .action-issue-w .issue-btn-w a button.btn-fw{
background-image: none;
border: 1px solid #000;
margin-right: 8px;
-webkit-transition: .3s;
-moz-transition: .3s ;
-ms-transition: .3s ;
-o-transition: .3s ;
transition: .3s ;
outline: none;
}
#SOHUCS #SOHU_MAIN .module-cmt-box .post-wrap-w .wrap-action-w .action-issue-w .issue-btn-w a button.btn-fw:after{
content: "发 送"
}
#SOHUCS #SOHU_MAIN .module-cmt-box .post-wrap-w .wrap-action-w .action-issue-w .issue-btn-w a button.btn-fw:hover{
background-image: none;
background-color: #000;
color: #fff;
}
#SOHUCS #SOHU_MAIN .module-cmt-header .section-cbox-w .block-head-w .head-img-w{
top: 11px
}
#SOHUCS #SOHU_MAIN .module-cmt-header .section-title-w .title-user-w .user-wrap-w{
top: 26px;
}
#SOHUCS #SOHU_MAIN .module-cmt-list .cmt-list-type .type-lists li.active{
background-image: none;
border: 1px solid #000;
}
#SOHUCS #SOHU_MAIN .module-cmt-list .cmt-list-type .cmt-list-border{
bottom: 2px;
left: 67px;
}
#SOHUCS #SOHU_MAIN .module-cmt-list .block-title-gw ul li .title-name-gw div.title-name-gw-tag{
background-image: none;
border-left: 5px solid #000;
}
#SOHUCS #SOHU_MAIN .module-cmt-header .section-cbox-w .block-head-w .head-img-w img,
#SOHUCS #SOHU_MAIN .module-cmt-list .block-cont-gw .cont-head-gw .head-img-gw img{
border: 2px solid #ddd;
-webkit-transition: .5s;
-moz-transition: .5s ;
-ms-transition: .5s ;
-o-transition: .5s ;
transition: .5s ;
width: 42px;
height: 42px;
}
#SOHUCS #SOHU_MAIN .module-cmt-header .section-cbox-w .block-head-w .head-img-w img:hover,
.clear-g.block-cont-gw:hover img{
-webkit-transform: rotateZ(360deg);
-moz-transform: rotateZ(360deg);
-ms-transform: rotateZ(360deg);
-o-transform: rotateZ(360deg);
transform: rotateZ(360deg);
}
#SOHUCS #SOHU_MAIN .module-cmt-list .block-cont-gw .cont-head-gw .head-img-gw{
width: 46px;
height: 46px;
}
</style>
<div id="SOHUCS" sid="<?php the_ID() ?>" ></div>
<!-- 畅言评论框 end -->

<!-- 多说公共JS代码 start (一个网页只需插入一次) -->
<script type="text/javascript">
var duoshuoQuery = {short_name:"<?php echo get_option('next_duoshuo_shortname'); ?>"};
(function() {
var ds = document.createElement('script');
ds.type = 'text/javascript';ds.async = true;
ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
ds.charset = 'UTF-8';
(document.getElementsByTagName('head')[0]
|| document.getElementsByTagName('body')[0]).appendChild(ds);
})();
</script>
<!-- 多说公共JS代码 end -->
<!-- 畅言公共JS代码 start (一个网页只需插入一次) -->
<script charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/changyan.js" ></script>
<script type="text/javascript">
window.changyan.api.config({
appid: '<?php echo get_option('next_sohucs_appid') ?>',
conf: '<?php echo get_option('next_sohucs_conf') ?>'
});
</script>
<script type="text/javascript" src="https://assets.changyan.sohu.com/upload/plugins/plugins.count.js">
</script>
<!-- 畅言公共JS代码 end -->
<?php } else { comments_template(); comment_form(); } ?>
</div>
</div>
</div>
Expand Down
10 changes: 10 additions & 0 deletions static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,14 @@ window.onload=(function(){
}

$('#sidebar-toggle').click(toggleSidebar)
$('.depth-8').children('.children').find('.reply').click(function(){ //class=".depth-8"子元素class=".children"下的class=".reply"的点击事件,注意:模板不同HTML结构可能不同,需调整!
var rid= $(this).parent().attr("id"); //取得所回复的评论id,可能需要调整!
var rna= $(this).next().text(); //取得所回复的评论用户名,可能需要调整!
$("#comment").attr("value","<a href='#"+rid+"'>@"+rna+"</a> ").focus(); //在输入框添加"@用户名"和链接

});

$('#cancel-comment-reply-link').click(function() {
$("#comment").attr("value",''); //点击取消回复时清空输入框
});
})
Loading

0 comments on commit 7cf84be

Please sign in to comment.