You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
cosmopet-architecture/wp-content/themes/cosmopet/comments.php

211 lines
9.5 KiB

<?php
if (!defined('ABSPATH')) {
exit;
}
function count_nested_replies($comment_id) {
$count = 0;
$replies = get_comments(array(
'post_id' => get_the_ID(),
'status' => 'approve',
'parent' => $comment_id,
'order' => 'ASC'
));
if ($replies) {
$count += count($replies);
foreach ($replies as $reply) {
$count += count_nested_replies($reply->comment_ID);
}
}
return $count;
}
if (post_password_required()) {
return;
}
if (!is_user_logged_in()) {
?>
<div class="comment-block">
<p class="comment-block_text">
<a href="#modal"><?php pll_e('Войдите'); ?></a>, <?php pll_e('чтобы оставлять комментарии'); ?>
</p>
</div>
<?php
}
$top_level_comments = get_comments(array(
'post_id' => get_the_ID(),
'status' => 'approve',
'parent' => 0,
'order' => 'ASC'
));
if ($top_level_comments) {
echo '<div class="comment-block_wrapper">';
foreach ($top_level_comments as $comment) {
?>
<div class="comment-block" id="comment-<?php echo $comment->comment_ID; ?>">
<div class="comment-user">
<?php echo get_avatar($comment, 50); ?>
<div class="comment-user_text">
<h6><?php echo get_comment_author($comment); ?></h6>
<span><?php echo get_comment_date('d F Y', $comment); ?></span>
</div>
</div>
<p><?php echo get_comment_text($comment); ?></p>
<div class="comment-btns">
<button class="reply-to-comment" data-comment-id="<?php echo $comment->comment_ID; ?>" data-post-id="<?php echo get_the_ID(); ?>" data-reply-to="<?php echo esc_attr(get_comment_author($comment)); ?>">
<svg width="11" height="8" viewBox="0 0 11 8" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9.5 3H3.25C2.00736 3 1 4.00736 1 5.25V5.25C1 6.49264 2.00736 7.5 3.25 7.5H3.5" stroke="#666666"></path>
<path d="M7 0.5L9.5 3L7 5.5" stroke="#666666"></path>
</svg>
<?php pll_e('Ответить'); ?>
</button>
<button class="comment-like-btn<?php echo is_user_liked_comment($comment->comment_ID) ? ' active' : ''; ?>" data-comment-id="<?php echo $comment->comment_ID; ?>">
<svg width="15" height="13" viewBox="0 0 15 13" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10.7745 1C8.67239 1 7.7426 2.5355 7.54047 3.30325C7.39224 2.5355 6.49748 1 4.10427 1C1.11276 1 -0.221288 4.85199 2.40639 8.14801C4.50853 10.7848 6.705 11.8147 7.54047 12C8.47026 11.8279 10.8311 10.761 12.8363 7.87004C15.3427 4.25632 13.4022 1 10.7745 1Z" <?php echo is_user_liked_comment($comment->comment_ID) ? 'stroke="#ff0000" fill="rgba(255, 0, 0, 0.7)"' : 'stroke="#666666"'; ?>></path>
</svg>
<?php echo get_comment_likes_count($comment->comment_ID); ?>
</button>
<?php
comment_reply_link(array(
'reply_text' => pll__('Ответить'),
'depth' => 1,
'max_depth' => get_option('thread_comments_depth'),
'before' => '<span style="display:none;">',
'after' => '</span>',
), $comment->comment_ID, get_the_ID());
?>
</div>
<div class="reply-form-container" id="reply-form-<?php echo $comment->comment_ID; ?>" style="display: none;"></div>
</div>
<?php
$all_nested_replies = get_all_nested_replies($comment->comment_ID);
if (!empty($all_nested_replies)) {
$total_reply_count = count($all_nested_replies);
?>
<button class="answer-btn">
<svg width="15" height="10" viewBox="0 0 15 10" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14 1.41406L7.5 7.91406L1 1.41406" stroke="#76CE75" stroke-width="2"></path>
</svg>
<?php echo $total_reply_count; ?>
<span>
<?php echo ($total_reply_count == 1) ? pll__('ответ') : pll__('ответа'); ?>
</span>
</button>
<?php
foreach ($all_nested_replies as $reply) {
?>
<div class="comment-block answer-block" id="comment-<?php echo $reply->comment_ID; ?>">
<div class="comment-user">
<?php echo get_avatar($reply, 50); ?>
<div class="comment-user_text">
<h6><?php echo get_comment_author($reply); ?></h6>
<span><?php echo get_comment_date('d F Y', $reply); ?></span>
</div>
</div>
<p><?php echo get_comment_text($reply); ?></p>
<div class="comment-btns">
<button class="reply-to-comment" data-comment-id="<?php echo $reply->comment_ID; ?>" data-post-id="<?php echo get_the_ID(); ?>" data-reply-to="<?php echo esc_attr(get_comment_author($reply)); ?>">
<svg width="11" height="8" viewBox="0 0 11 8" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9.5 3H3.25C2.00736 3 1 4.00736 1 5.25V5.25C1 6.49264 2.00736 7.5 3.25 7.5H3.5" stroke="#666666"></path>
<path d="M7 0.5L9.5 3L7 5.5" stroke="#666666"></path>
</svg>
<?php pll_e('Ответить'); ?>
</button>
<button class="comment-like-btn<?php echo is_user_liked_comment($reply->comment_ID) ? ' active' : ''; ?>" data-comment-id="<?php echo $reply->comment_ID; ?>">
<svg width="15" height="13" viewBox="0 0 15 13" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10.7745 1C8.67239 1 7.7426 2.5355 7.54047 3.30325C7.39224 2.5355 6.49748 1 4.10427 1C1.11276 1 -0.221288 4.85199 2.40639 8.14801C4.50853 10.7848 6.705 11.8147 7.54047 12C8.47026 11.8279 10.8311 10.761 12.8363 7.87004C15.3427 4.25632 13.4022 1 10.7745 1Z" <?php echo is_user_liked_comment($reply->comment_ID) ? 'stroke="#ff0000" fill="rgba(255, 0, 0, 0.7)"' : 'stroke="#666666"'; ?>></path>
</svg>
<?php echo get_comment_likes_count($reply->comment_ID); ?>
</button>
<?php
comment_reply_link(array(
'reply_text' => pll__('Ответить'),
'depth' => 2,
'max_depth' => get_option('thread_comments_depth'),
'before' => '<span style="display:none;">',
'after' => '</span>',
), $reply->comment_ID, get_the_ID());
?>
</div>
<div class="reply-form-container" id="reply-form-<?php echo $reply->comment_ID; ?>" style="display: none;"></div>
</div>
<?php
}
}
}
echo '</div>';
}
function get_all_nested_replies($comment_id) {
$all_replies = array();
$direct_replies = get_comments(array(
'post_id' => get_the_ID(),
'status' => 'approve',
'parent' => $comment_id,
'order' => 'ASC'
));
$all_replies = array_merge($all_replies, $direct_replies);
foreach ($direct_replies as $reply) {
$deeper_replies = get_all_nested_replies_recursive($reply->comment_ID);
$all_replies = array_merge($all_replies, $deeper_replies);
}
return $all_replies;
}
function get_all_nested_replies_recursive($comment_id) {
$replies = get_comments(array(
'post_id' => get_the_ID(),
'status' => 'approve',
'parent' => $comment_id,
'order' => 'ASC'
));
$all_replies = $replies;
foreach ($replies as $reply) {
$deeper_replies = get_all_nested_replies_recursive($reply->comment_ID);
$all_replies = array_merge($all_replies, $deeper_replies);
}
return $all_replies;
}
if (is_user_logged_in()) {
$commenter = wp_get_current_commenter();
$args = array(
'fields' => array(
'author' => '',
'email' => '',
'url' => '',
'cookies' => '',
),
'comment_field' => '<div class="comment-form-comment"><textarea id="comment" name="comment" placeholder="' . pll__('Ваш комментарий') . '" required></textarea></div>',
'title_reply' => pll__('Оставить комментарий'),
'title_reply_to' => pll__('Ответить %s'),
'class_submit' => 'comment-submit-btn',
'submit_button' => '<button name="%1$s" type="submit" id="%2$s" class="%3$s">%4$s</button>',
'submit_field' => '<div class="form-submit">%1$s %2$s</div>',
'cancel_reply_link' => pll__('Отменить'),
'id_form' => 'commentform',
'id_submit' => 'submit',
'title_reply_before' => '<h3 id="reply-title" class="comment-reply-title">',
'title_reply_after' => '</h3>',
);
comment_form($args);
}
?>