Files
tylkofotografia/comments.php
2026-01-15 12:23:11 +01:00

118 lines
3.7 KiB
PHP

<?php
/**
* Komentarze
*
* @link https://krzysztof-turek.com
*
* @package tylkofotografia.pl
* @version 0.1
*/
if ( post_password_required() ) {
return;
}
if ( comments_open() ) {
?>
<div class="container">
<div class="row">
<div id="comments" class="comments-area offset-lg-2 col-lg-8 col-xs-12">
<?php if ( have_comments() ) : ?>
<h2 class="comments-title">
<?php $comments_number = get_comments_number();
if ( '1' === $comments_number ) {
printf( _x( 'Jedna odpowiedź do &ldquo;%s&rdquo;', 'comments title' ), get_the_title() );
} else {
printf(_nx(
'%1$s Reply to &ldquo;%2$s&rdquo;',
'%1$s Odpowiedzi do &ldquo;%2$s&rdquo;',
$comments_number,
'comments title'
),
number_format_i18n( $comments_number ),
get_the_title()
);
}
?>
</h2>
<ol class="comment-list">
<?php
wp_list_comments( array(
'avatar_size' => 32,
'style' => 'ol',
'short_ping' => true,
) );
?>
</ol>
<?php endif;
if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) : ?>
<p class="no-comments"><?php _e( 'Comments are closed.', 'foto' ); ?></p>
<?php endif;
ob_start();
$commenter = wp_get_current_commenter();
$req = true;
$aria_req = ( $req ? " aria-required='true'" : '' );
$comments_arg = array(
'form' => array(
'class' => 'form-horizontal'
),
'fields' => apply_filters( 'comment_form_default_fields', array(
'autor' => '<div class="col-lg-6"><div class="form-group">' . '<label for="author">' . __( 'Imię - wymagane', 'foto' ) . '</label> ' . ( $req ? '<span>*</span>' : '' ) .
'<input id="author" name="author" class="form-control" type="text" value="" size="30"' . $aria_req . ' />'.
'<p id="d1" class="text-danger"></p>' . '</div></div>',
'email' => '<div class="col-lg-6"><div class="form-group">' .'<label for="email">' . __( 'Email - wymagany', 'foto' ) . '</label> ' . ( $req ? '<span>*</span>' : '' ) .
'<input id="email" name="email" class="form-control" type="text" value="" size="30"' . $aria_req . ' />'.
'<p id="d2" class="text-danger"></p>' . '</div></div></div></div>',
'url' => '')),
'comment_field' => '<div class="container"><div class="row"><div class="col-lg-12"><div class="form-group">' . '<label for="comment">' . __( 'Komentarz', 'foto' ) . '</label><span>*</span>' .
'<textarea id="comment" class="form-control" name="comment" rows="3" aria-required="true"></textarea><p id="d3" class="text-danger"></p>' . '</div></div>',
'comment_notes_after' => '',
'class_submit' => 'btn btn-primary'
);
comment_form($comments_arg);
echo str_replace('class="comment-form"','class="comment-form" name="commentForm" onsubmit="return validateForm();"',ob_get_clean());
?>
<script>
function validateForm() {
var form = document.forms.commentForm,
x = form.author.value,
y = form.email.value,
z = form.comment.value,
flag = true,
d1 = document.getElementById("d1"),
d2 = document.getElementById("d2"),
d3 = document.getElementById("d3");
if (x === null || x === "") {
d1.innerHTML = "<?php echo __('Imię jest wymagane', 'foto'); ?>";
flag = false;
} else {
d1.innerHTML = "";
}
if (y === null || y === "") {
d2.innerHTML = "<?php echo __('Email jest wymagany', 'foto'); ?>";
flag = false;
} else {
d2.innerHTML = "";
}
if (z === null || z === "") {
d3.innerHTML = "<?php echo __('Komentarz jest wymagany', 'foto'); ?>";
flag = false;
} else {
d3.innerHTML = "";
}
return flag;
}
</script>
</div>
</div>
</div>
</div>
</div>
</div>
<?php }