<?php 
function threadedComments($comments, $options) {
    $commentClass = '';
	if($comments->authorId){  //如果是博客的用户则判断是否为此文章的作者
	    if ($comments->authorId == $comments->ownerId) {
	    	$commentClass = ' comment-by-author';
	    } else {
	    	$commentClass = ' comment-by-user';
	    }
	}
	
	$commentLevelClass = $comments->_levels > 0 ? ' comment-child' : ' comment-parent';
	?> 
	<li id="li-<?php $comments->theId(); ?>" class="comment-body
		<?php
			if ($comments->_levels > 0) {
				echo ' comment-child';
				$comments->levelsAlt(' comment-level-odd', ' comment-level-even');
			} else {
				echo ' comment-parent';
			}
			$comments->alt(' comment-odd', ' comment-even');
			echo $commentClass;
		?>">
		<!-- 评论者信息及内容 -->
	    <article id="<?php $comments->theId(); ?>">
	    	<footer class="comment-meta">
	        	<!-- 评论者头像 -->
				<div class="">
				<label>
	            	<?php
	            		$comments->gravatar($options->avatarSize, $options->defaultAvatar);
	            	?>
					
	            <!-- 评论者名称 -->
	            	<?php
		            	$options->beforeAuthor();
		            	$comments->author();
		            	$options->afterAuthor();
	            	?>
				</label>
				
				&nbsp
	        	<!-- 评论时间 -->
	            <span class="comment-time">
	            	<a href="<?php $comments->permalink(); ?>">
	            		<?php
		            		$options->beforeDate();
		            		$comments->date($options->dateFormat);
		            		$options->afterDate();
	            		?>
	            	</a>
	            </span>
				</div>
	            <span class="comment-status">
	            	
	            </span>
	            <!-- 回复按钮 -->
	        	<span class="comment-reply"><?php $comments->reply($options->replyWord); ?></span>
	        </footer>
	        <!-- 评论内容 -->
	        <div class="comment-content">
	        	<?php $comments->content(); ?>
	        </div>
	    </article>
	    <?php if ($comments->children) { ?>
		<div class="comment-children">
			<!-- 嵌套评论 -->
		    <?php $comments->threadedComments($options); ?>
		</div>
		<?php } ?>
	</li>
<?php } ?>


<div class="comments" id="comments">
	<!-- 评论数 -->
	<h4 class="comments-title">《<?php $this->title();?>》上<?php $this->commentsNum('还没有评论', '有一条评论', '有 %d 条评论'); ?></h4>
	<?php  $comments=null; $this->comments()->to($comments); ?>
	<?php if ($comments->have()): ?>
		<!-- 评论分页 -->
		<div class="comments-pagination">
			<?php $comments->pageNav('←','→'); ?>
		</div>
		<!-- 评论列表 -->
		<?php $comments->listComments(); ?>
	<?php endif;?>
	
	<!-- 判断是否允许评论 -->
	<?php if($this->allow('comment')): ?>
	<!-- 评论表单 -->
	<div id="<?php $this->respondId(); ?>" class="respond">
		<h3 id="reply-title">发表评论</h3>
		<div id="cancel-comment-reply">
			<?php $comments->cancelReply(); ?>
	    </div>
		<!-- 输入表单开始 -->
	    <form method="post" action="<?php $this->commentUrl() ?>" id="comment_form">
	 		<p class="comment-notes">电子邮件地址不会被公开。 必填项已用 <span>*</span> 标注</p>
	        <!-- 如果当前用户已经登录 -->
	        <?php if($this->user->hasLogin()): ?>
	            <!-- 显示当前登录用户的用户名以及登出连接 -->
	            <p>当前登陆用户为：<i class="fa fa-user-o fa-fw" aria-hidden="true"></i>&nbsp;<a href="<?php $this->options->adminUrl(); ?>"><?php $this->user->screenName(); ?></a>&nbsp; 
	            <a href="<?php $this->options->index('action/logout'); ?>" title="Logout">，退出 &raquo;</a></p>
	        <!-- 若当前用户未登录 -->
	        <?php else: ?>
		        <!-- 要求输入名字、邮箱、网址 -->
			    <p><label for="author"><i class="fa fa-user fa-fw" aria-hidden="true"></i>&nbsp;姓名</label><span class="required">*</span><input type="text" class="text" name="author" size="35" value="<?php $this->remember('author'); ?>" /></p>
			    <p><label for="mail"><i class="fa fa-envelope fa-fw" aria-hidden="true"></i>&nbsp;电子邮件</label><span class="required">*</span><input type="text" class="text" name="mail" size="35" value="<?php $this->remember('mail'); ?>" /></p>
			    <p><label for="url"><i class="fa fa-link fa-fw" aria-hidden="true"></i>&nbsp;站点</label><input type="text" class="text" name="url" size="35" value="<?php $this->remember('url'); ?>" /></p>
	        <?php endif; ?>
	 		
	        <!-- 输入要回复的内容 -->
			<p><label for="comment"><i class="fa fa-commenting fa-fw" aria-hidden="true"></i>&nbsp;评论</label><textarea class="text" name="text"><?php $this->remember('text'); ?></textarea></p>
			<p><input name="submit" type="submit" id="submit" value="发表评论"></p>
	    </form>
	</div>
	<?php endif; ?>
</div>