<?php
/**
 * The template for displaying comments.
 *
 * The area of the page that contains both current comments
 * and the comment form.
 *
 * @package daisy
 */

/*
 * 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.
 */
if ( post_password_required() ) {
	return;
}
?>
<div id="comments" class="comments-area">
<div class="comments">		
<?php if ( have_comments() ) : ?>
	<div class="section-title">
		<h4 class="title"><?php comments_number('COMMENT', '1 COMMENT', '% COMMENTS');?></h4>
	</div>
	<ol class="comment-list">
		<?php
			/* Loop through and list the comments. Tell wp_list_comments()
			 * to use marketify_comment() to format the comments.
			 * If you want to override this in a child theme, then you can
			 * define marketify_comment() and that will be used instead.
			 * See marketify_comment() in inc/template-tags.php for more.
			 */
			wp_list_comments( array( 'callback' => 'rst_mytheme_comment', 'avatar_size' => 80 ) );
		?>
	</ol><!-- .comment-list -->

	<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
	<nav id="comment-nav-below" class="comment-navigation" role="navigation">
		<h1 class="screen-reader-text"><?php _e( 'Comment navigation', 'marketify' ); ?></h1>
		<div class="nav-previous"><?php previous_comments_link( '<i class="icon-arrow-left4"></i> <span class="nav-title">' . __( 'Older Comments', 'marketify' ) . '</span>' ); ?></div>
		<div class="nav-next"><?php next_comments_link( '<span class="nav-title">' . __( 'Newer Comments', 'marketify' ) . '</span> <i class="icon-arrow-right4"></i>' ); ?></div>
	</nav><!-- #comment-nav-below -->
	<?php endif; // check for comment navigation ?>
<?php endif; // have_comments() ?>
</div>
<?php
function rst_mytheme_comment($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment;
	extract($args, EXTR_SKIP);

	if ( 'div' == $args['style'] ) {
		$tag = 'div';
		$add_below = 'comment';
	} else {
		$tag = 'li';
		$add_below = 'div-comment';
	}
?>
	<<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
	<?php if ( 'div' != $args['style'] ) : ?>
	<div id="div-comment-<?php comment_ID() ?>" class="media comment">
		<?php endif; ?>
		<div class="media-left">            			<div class="inner-media-left">
				<?php
				$user_ID = ($comment->user_id);
				if($value_avatar_id = (rs::getField('your_avatar', 'user_'.$user_ID))){
					$value_avatar = (int)$value_avatar_id[0];
					$value_avatar = wp_get_attachment_url($value_avatar);
					?>
					<img src="<?php echo esc_url( bfi_thumb($value_avatar, array('width'=>80,'height'=>80)) ); ?>" alt="" />
					<?php
				}
				elseif ( $args['avatar_size'] != 0 ) {
					echo get_avatar( $comment, $args['avatar_size'] ); 
				}	
				?>			</div>
		
		</div>
		<div class="media-body">
			<?php if ( $comment->comment_approved == '0' ) : ?>
				<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.','your_text_domain' ); ?></em>
				<br />
			<?php endif; ?>
			<h5 class="media-heading">
				<?php
					if($comment->comment_author_url != ''){
				?>
					<a href="<?php echo esc_url($comment->comment_author_url) ?>">
					<?php
						echo esc_html($comment->comment_author);
					?>
					</a>
				<?php
					}else{
						echo esc_html($comment->comment_author);
					}
				?>	
				|  <small><em>
				<?php	
					printf( __('%1$s','your_text_domain'), get_comment_date('jS M y'));
				?></em></small>
			</h5>
			<?php comment_text(); ?>
			<div class="clear"></div>
			
			<?php
				if ( is_user_logged_in() ){
			?>
			<div class="reply pull-right">
			<?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'reply_text' => '<span class="fa fa-long-arrow-left"></span>Reply' ,'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
			</div>
			<?php
				}
			?>
		</div>
		<?php if ( 'div' != $args['style'] ) : ?>
	</div>
	<?php endif; ?>
<?php
}
?>
<div class="comment-form">	
	<div class="section-title">
		<h4 class="title"><?php rst_the_translate('Leave A Comment','translation_leave_comment') ?></h4>
	</div>
	<?php
		$commenter = wp_get_current_commenter();
		$req = get_option( 'require_name_email' );
		$aria_req = ( $req ? " aria-required='true'" : '' );
		$args = array(
			'id_form' => 'contact-form',
			'class_form' => 'form',
			'cancel_reply_link' => __( 'Cancel Reply','your_text_domain' ),
			'fields' => apply_filters(
				'comment_form_default_fields', array(
					'author' => '<div class="row">
									<div class="col-md-6">	
										
										<input class="form-control" id="author" name="author" placeholder="Your Name*" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '"' . $aria_req . ' />
									</div>',
					'email' => '<div class="col-md-6">
									<input class="form-control" id="email" name="email" placeholder="Your Email*" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '"' . $aria_req . ' />
									
								</div></div>',
					'url' => '<input class="form-control" id="url" name="url" placeholder="Your Website*" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" />'
				)
			),
			'comment_field' => '<textarea class="form-control" id="comment" name="comment" placeholder="Your Comment*..." cols="" rows="6" aria-required="true"></textarea>',
			'comment_notes_after' => '',
			'comment_notes_before' => '<p>Your email address will not be published. Required fields are marked *</p>',
			'title_reply' => '',
			'format'            => 'xhtml',
			'label_submit' => rst_get_translate('Submit Comment','sent_comment'),
			'class_submit' => 'btn btn-default tf-btn color',
		);
	  ?>
	<?php comment_form($args, get_the_ID()); ?>
</div>

</div><!-- #comments -->
