Skip to content

Commit

Permalink
评论样式重构
Browse files Browse the repository at this point in the history
  • Loading branch information
jrotty authored Sep 21, 2017
1 parent dedce52 commit 803b3fb
Showing 1 changed file with 144 additions and 69 deletions.
213 changes: 144 additions & 69 deletions comments.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php if (!empty($this->options->sidebarBlock) && in_array('pltx', $this->options->sidebarBlock)): ?>
<?php function threadedComments($comments, $options) {
<div id="comments">
<?php
function threadedComments($comments, $options) {
$commentClass = '';
if ($comments->authorId) {
if ($comments->authorId == $comments->ownerId) {
Expand All @@ -8,11 +9,15 @@
$commentClass .= ' comment-by-user';
}
}

$commentLevelClass = $comments->levels > 0 ? ' comment-child' : ' comment-parent';
if ($comments->url) {
$author = '<a href="' . $comments->url . '" target="_blank"' . ' rel="external nofollow">' . $comments->author . '</a>';
} else {
$author = $comments->author;
}
?>
<li id="li-<?php $comments->theId(); ?>" class="comment-body<?php

<li data-no-instant id="li-<?php $comments->theId(); ?>" class="comment-body<?php
if ($comments->levels > 0) {
echo ' comment-child';
$comments->levelsAlt(' comment-level-odd', ' comment-level-even');
Expand All @@ -23,77 +28,147 @@
echo $commentClass;
?>">
<div id="<?php $comments->theId(); ?>">
<div class="comment-author">
<?php
//头像CDN by Rich
$host = 'https://secure.gravatar.com'; //自定义头像CDN服务器
$url = '/avatar/'; //自定义头像目录,一般保持默认即可
$size = '32'; //自定义头像大小
<?php
$host = '//cdn.v2ex.com';
$url = '/gravatar/';
$size = '80';
$rating = Helper::options()->commentsAvatarRating;
$hash = md5(strtolower($comments->mail));
$avatar = $host . $url . $hash . '?s=' . $size . '&r=' . $rating . '&d=';
?>
<img class="avatar" src="<?php echo $avatar ?>" alt="<?php echo $comments->author; ?>" width="<?php echo $size ?>" height="<?php echo $size ?>" />
<cite class="fn"><?php $comments->author(); ?></cite>
</div>
<div class="comment-meta">
<a href="<?php $comments->permalink(); ?>"><?php $comments->date('Y-m-d H:i'); ?></a>
<span class="comment-reply"><?php $comments->reply(); ?></span>
?>

<img class="avatar" src="<?php echo $avatar ?>" alt="<?php echo $comments->author; ?>" width="<?php echo $size ?>" height="<?php echo $size ?>" />
<div class="comment-main">
<span class="comment-at"><?php get_comment_at($comments->coid)?></span>
<?php $comments->content(); ?>
<div class="comment-meta">
<span class="comment-author"><?php echo $author; ?></span>
<time class="comment-time"><?php echo timesince($comments->created);?></time>
<span class="comment-reply"><?php $comments->reply(); ?></span>
</div>
</div>
<?php $comments->content(); ?>
</div>
<?php if ($comments->children) { ?>
<div class="comment-children">
<?php $comments->threadedComments($options); ?>
</div>
<?php } ?>


<?php if ($comments->children) { ?>
<div class="comment-children">
<?php $comments->threadedComments($options); ?>
</div>
<?php } ?>

</li>
<?php } ?>
<?php endif; ?>
<div class="comments" id="comments">
<?php $this->comments()->to($comments);?>

<div id="comments" class="cf">
<?php $this->comments()->to($comments); ?>
<?php if ($comments->have()): ?>
<span class="widget-title"><?php $this->commentsNum(_t('暂无评论'), _t('仅有 1 条评论'), _t('已有 %d 条评论'));?></span>
<?php $comments->listComments();?>
<?php $comments->pageNav('&laquo; ', ' &raquo;', 5, '...', array('wrapTag' => 'nav', 'wrapClass' => 'pagination', 'itemTag' => '', 'prevClass' => 'extend prev', 'nextClass' => 'extend next', 'currentClass' => 'page-number current'));?>
<?php endif;?>
<?php if ($this->allow('comment')): ?>
<div id="<?php $this->respondId();?>" class="respond">
<div class="cancel-comment-reply">
<?php $comments->cancelReply();?>
</div>
<span id="response" class="widget-title"><?php _e('添加新评论');?></span>
<form method="post" action="<?php $this->commentUrl()?>" id="comment-form">
<div>
<?php if ($this->user->hasLogin()): ?>
<p><?php _e('登录身份:');?><a href="<?php $this->options->profileUrl();?>"><?php $this->user->screenName();?></a>. <a href="<?php $this->options->logoutUrl();?>" title="Logout"><?php _e('退出');?> &raquo;</a></p>
<?php else: ?>
<p class="comment-about">
<label for="author" class="required"><?php _e('称呼');?></label>
<input type="text" name="author" id="author" class="text" value="<?php $this->remember('author');?>"/>
</p>
<p class="comment-about">
<label for="mail"<?php if ($this->options->commentsRequireMail): ?> class="required"<?php endif;?>><?php _e('邮箱');?></label>
<input type="email" name="mail" id="mail" class="text" value="<?php $this->remember('mail');?>"/>
</p>
<p class="comment-about">
<label for="url"<?php if ($this->options->commentsRequireURL): ?> class="required"<?php endif;?>><?php _e('网站');?></label>
<input type="url" name="url" id="url" class="text" placeholder="<?php _e('http://example.com');?>" value="<?php $this->remember('url');?>"/>
</p>
<?php endif;?>
<p>
<textarea rows="8" cols="50" name="text" class="text-area"><?php $this->remember('text');?></textarea>
</p>
</div>
<div class="col2">
<p>
<button type="submit" class="submit"><?php _e('提交评论');?></button>
</p>
</div>
<div class="clear"></div>
</form>
</div>
<span class="comment-num"><?php $this->commentsNum(_t('暂无评论'), _t('仅有 1 条评论'), _t('已有 %d 条评论')); ?></span>
<?php $comments->listComments(); ?>

<?php $comments->pageNav('&laquo;', '&raquo;'); ?>

<?php endif; ?>

<?php if($this->allow('comment')): ?>
<div id="<?php $this->respondId(); ?>" class="respond">
<div class="cancel-comment-reply"><span class="response"><?php _e('发表新评论'); ?></span><span class="cancel-reply"><?php $comments->cancelReply(); ?></span></div>
<form method="post" action="<?php $this->commentUrl() ?>" id="comment-form" role="form">
<?php if($this->user->hasLogin()): ?>
<span style="padding-top:10px;"><?php _e('已登入: '); ?><a href="<?php $this->options->profileUrl(); ?>"><?php $this->user->screenName(); ?></a>. <a href="<?php $this->options->logoutUrl(); ?>" title="Logout"><?php _e('退出'); ?> &raquo;</a></span>
<?php else: ?>
<?php if($this->remember('author',true) != "" && $this->remember('mail',true) != "") : ?>

<p style="padding-top:10px;color:#aaa;">
<span onClick='showhidediv("author_info")'; style="cursor:pointer;color:#2479cc;"><?php $this->remember('author'); ?></span>,<?php _e('欢迎回来'); ?>
<span id="cancel-comment-reply"><?php $comments->cancelReply(); ?></span>
</p>
<div id="author_info" style="display:none;">
<?php else : ?>
<div id="author_info">
<?php endif ; ?>
<input type="text" name="author" maxlength="12" id="author" class="form-control" placeholder="<?php _e('称呼 *'); ?>" value="<?php $this->remember('author'); ?>">
<input type="email" name="mail" id="mail" class="form-control" placeholder="<?php _e('电子邮箱 *'); ?>" value="<?php $this->remember('mail'); ?>">
<input type="url" name="url" id="url" class="form-control" placeholder="<?php _e('网址(http://)'); ?>" value="<?php $this->remember('url'); ?>">
</div>
<?php endif; ?>

<textarea name="text" id="textarea" class="form-control" onkeydown="if(event.ctrlKey&&event.keyCode==13){document.getElementById('misubmit').click();return false};" placeholder="<?php _e('在这里输入你的评论(Ctrl/Cmd+Enter也可以提交)...'); ?>" required ><?php $this->remember('text',false); ?></textarea>
<button type="submit" class="submit" id="misubmit"><?php _e('提交评论'); ?></button>
<?php $security = $this->widget('Widget_Security'); ?>
<input type="hidden" name="_" value="<?php echo $security->getToken($this->request->getReferer())?>">
</form>
</div>
</div>
<?php else: ?>
评论已关闭
<?php endif;?>
<h4 class="comment-close">此处评论已关闭</h4>
<?php endif; ?>
<script>
function showhidediv(id){
var sbtitle=document.getElementById(id);
if(sbtitle){
if(sbtitle.style.display=='block'){
sbtitle.style.display='none';
}else{
sbtitle.style.display='block';
}
}
}

(function () {
window.TypechoComment = {
dom : function (id) {
return document.getElementById(id);
},
create : function (tag, attr) {
var el = document.createElement(tag);
for (var key in attr) {
el.setAttribute(key, attr[key]);
}
return el;
},
reply : function (cid, coid) {
var comment = this.dom(cid), parent = comment.parentNode,
response = this.dom('<?php echo $this->respondId(); ?>'),
input = this.dom('comment-parent'),
form = 'form' == response.tagName ? response : response.getElementsByTagName('form')[0],
textarea = response.getElementsByTagName('textarea')[0];
if (null == input) {
input = this.create('input', {
'type' : 'hidden',
'name' : 'parent',
'id' : 'comment-parent'
});
form.appendChild(input);
}
input.setAttribute('value', coid);
if (null == this.dom('comment-form-place-holder')) {
var holder = this.create('div', {
'id' : 'comment-form-place-holder'
});
response.parentNode.insertBefore(holder, response);
}
comment.appendChild(response);
this.dom('cancel-comment-reply-link').style.display = '';
if (null != textarea && 'text' == textarea.name) {
textarea.focus();
}
return false;
},
cancelReply : function () {
var response = this.dom('<?php echo $this->respondId(); ?>'),
holder = this.dom('comment-form-place-holder'),
input = this.dom('comment-parent');
if (null != input) {
input.parentNode.removeChild(input);
}
if (null == holder) {
return true;
}
this.dom('cancel-comment-reply-link').style.display = 'none';
holder.parentNode.insertBefore(response, holder);
return false;
}
};
})();
</script>
</div>

0 comments on commit 803b3fb

Please sign in to comment.