<?php
/**
 * Comments List for page/post/image
 *
 * @package WPlook
 * @subpackage Benevolence
 * @since Benevolence 1.0
*/

if ( ! function_exists( 'wplook_comment' ) ) :

function wplook_comment( $comment, $args, $depth ) {
	$GLOBALS['comment'] = $comment;
	switch ( $comment->comment_type ) :
		case '' :
	?>

	<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>" itemscope itemtype="https://schema.org/UserComments">

		<div class="comment-inner">
			<div class="comment-image">
				<?php echo get_avatar( $comment, 72 ); ?>
			</div><!-- /.comment-image -->

			<div class="comment-content">
				<div class="comment-head clearfix">
					<h4 class="comment-author left">
						<?php echo get_comment_author_link(); ?> / <?php printf( __( '%1$s', 'charity-wpl' ), get_comment_date(), get_comment_time() ); ?>
					</h4>

					<div class="comment-reply right">
						<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
					</div>
				</div><!-- /.comment-head clearfix -->

				<div class="comment-text" itemprop="commentText">
					<?php if ( $comment->comment_approved == '0' ) : ?>
						<div class="comment-awaiting-moderation">
							<?php _e( 'Your comment is awaiting moderation.', 'charity-wpl' ); ?>
						</div>
						<br />
					<?php endif; ?>
					<?php comment_text(); ?>
				</div>
			</div><!-- /.comment-content -->
		</div><!-- /.comment-inner -->
	<!-- </li># comment #-->
<?php
	break;
	case 'pingback' :
	case 'trackback' :
	?>

	<li <?php comment_class(''); ?> id="trackback-<?php comment_ID(); ?>">
		<img src="http://www.gravatar.com/avatar/00000000000000000000000000000000?d=identicon&s=50">

		<h5><?php _e( 'Pingback/Trackback', 'charity-wpl' ); ?></h5>
		<h6><?php printf( __( '%1$s at %2$s', 'charity-wpl' ), get_comment_date(), get_comment_time() ); ?></h6>
		<p>
			<?php if ( $comment->comment_approved == '0' ) : ?>
				<div class="comment-awaiting-moderation">
					<?php _e( 'Your comment is awaiting moderation.', 'charity-wpl' ); ?>
				</div>
				<br />
			<?php endif; ?>
			<?php comment_author_link(); ?>
		</p>
	<!-- </li># ping #-->
<?php break; 	endswitch;
} endif; ?>
<?php
// create new comment form
// Credits: http://snipplr.com
function wplook_comment_form( $args = array(), $post_id = null ) {
	global $user_identity, $id;
	if ( null === $post_id )
		$post_id = $id;
	else
		$id = $post_id;
	$commenter = wp_get_current_commenter();
	$req = get_option( 'require_name_email' );
	$aria_req = ( $req ? " aria-required='true'" : '' );

	$fields =  array(

		'author' => '<div class="grid-x grid-margin-x"> <p class="comment-form-author cell medium-6">
		 <input id="author" name="author" type="text"  class="field" placeholder="' . __( 'Name:', 'charity-wpl' ) . ( $req ? '*' : '' ). '" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
		'email'  => '<p class="comment-form-email cell medium-6">
		 <input class="field" id="email" name="email" type="text" placeholder="' . __( 'Email:', 'charity-wpl' ) . ( $req ? '*' : '' ). '" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p></div>',
		'url'    => '<div class="grid-x grid-margin-x"><p class="comment-form-url cell medium-12">' .
		'<input id="url" name="url" type="url" class="field"  placeholder="' . __( 'Website URL:', 'charity-wpl' ) .'" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p></div><!-- /.form-row -->',
	);
	$required_text = sprintf( ' ' . __('Required fields are marked %s', 'charity-wpl' ), '<span class="required">*</span>' );
	$defaults = array(
		'fields'		=> apply_filters( 'comment_form_default_fields', $fields ),
		'comment_field'		=> '<p class="comment-form-comment"><textarea placeholder="'.__('Comment', 'charity-wpl').'" class="textarea" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
		'must_log_in'		=> '<p class="must-log-in">' .  sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.', 'charity-wpl' ), esc_url(wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) ) . '</p>',
		'logged_in_as'		=> '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>', 'charity-wpl' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
		'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.', 'charity-wpl' ) . ( $req ? $required_text : '' ) . '</p>',
		'id_form'						=> 'commentform',
		'id_submit'					=> 'submit',
		'title_reply'				=> __( 'Leave a Comment', 'charity-wpl' ),
		'title_reply_to'		=> __( 'Leave a Reply to %s', 'charity-wpl' ),
		'cancel_reply_link'	=> __( 'or Cancel reply', 'charity-wpl' ),
		'label_submit'			=> __( 'Send Comment', 'charity-wpl' ),
	);

	$args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );	?>
		<?php if ( comments_open() ) : ?>
			<?php do_action( 'comment_form_before' ); ?>
			<div id="respond" class="form form-comment">
				<div class="form-head">
					<a name="tocommentform"></a>
					<h3 class="widget-title page-_comment-title" id="reply-title">
						<?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?>   <?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?>
					</h3>
				</div><!-- /.form-head -->
				<?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
					<?php echo $args['must_log_in']; ?>
					<?php do_action( 'comment_form_must_log_in_after' ); ?>
				<?php else : ?>
					<div class="form-body">
						<form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>">
							<?php do_action( 'comment_form_top' ); ?>
							<?php if ( is_user_logged_in() ) : ?>
								<?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?>
								<?php do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); ?>
							<?php else : ?>
								<?php echo $args['comment_notes_before']; ?>

								<?php
								do_action( 'comment_form_before_fields' );
								foreach ( (array) $args['fields'] as $name => $field ) {
									echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
								}
							do_action( 'comment_form_after_fields' );
							?>
							<?php endif; ?>

								<div class="form-row">
									<?php echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); ?>
								</div><!-- /.form-row -->

								<p class="form-submit">
									<input class="button" name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
									<?php comment_id_fields(); ?>
								</p><!-- /.form-actions -->

							<?php do_action( 'comment_form', $post_id ); ?>
						</form>
					</div>
				<?php endif; ?>
			</div><!-- #respond -->
			<?php do_action( 'comment_form_after' ); ?>
		<?php else : ?>
			<?php do_action( 'comment_form_comments_closed' ); ?>
		<?php endif; ?>
	<?php
}
