comment-card.php
4 days ago
comment-form.php
4 days ago
comment-list.php
4 days ago
comment-replies.php
4 days ago
comments.php
4 days ago
content.php
4 days ago
exercise-files.php
4 days ago
footer.php
4 days ago
nav-item.php
4 days ago
overview.php
4 days ago
comment-card.php
142 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Comment Card Template |
| 4 | * |
| 5 | * @package Tutor\Templates |
| 6 | * @subpackage LearningArea\Lesson |
| 7 | * @author Themeum <support@themeum.com> |
| 8 | * @link https://themeum.com |
| 9 | * @since 4.0.0 |
| 10 | */ |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | use Tutor\Components\Avatar; |
| 15 | use Tutor\Components\Constants\Size; |
| 16 | use Tutor\Components\Constants\Color; |
| 17 | use TUTOR\Icon; |
| 18 | use Tutor\Components\SvgIcon; |
| 19 | |
| 20 | /** |
| 21 | * Variables available: |
| 22 | * |
| 23 | * @var $comment_item Object The comment object |
| 24 | * @var $lesson_id Int The lesson ID |
| 25 | * @var $user_id Int The current user ID |
| 26 | * @var $is_reply Bool Whether this is a reply (default false) |
| 27 | */ |
| 28 | |
| 29 | $is_reply = $is_reply ?? false; |
| 30 | $id_prefix = $is_reply ? 'tutor-comment-reply-' : 'tutor-comment-'; |
| 31 | $class = $is_reply ? 'tutor-comment-reply-item' : 'tutor-comment-item'; |
| 32 | ?> |
| 33 | |
| 34 | <div class="<?php echo esc_attr( $class ); ?>" id="<?php echo esc_attr( $id_prefix . $comment_item->comment_ID ); ?>"> |
| 35 | <div |
| 36 | class="tutor-comment" |
| 37 | x-data="{ repliesExpanded: false }" |
| 38 | x-show="editingId !== <?php echo (int) $comment_item->comment_ID; ?>" |
| 39 | x-cloak |
| 40 | <?php if ( ! $is_reply ) : ?> |
| 41 | @tutor:comment:replied.window="if ($event.detail.parentId === <?php echo (int) $comment_item->comment_ID; ?>) { repliesExpanded = true; replyingId = null; }" |
| 42 | <?php endif; ?> |
| 43 | > |
| 44 | <?php Avatar::make()->user( $comment_item->user_id )->size( Size::SIZE_40 )->render(); ?> |
| 45 | |
| 46 | <div class="tutor-comment-content tutor-flex-1"> |
| 47 | <div class="tutor-flex tutor-justify-between"> |
| 48 | <div> |
| 49 | <div class="tutor-flex tutor-items-center tutor-gap-5 tutor-mb-2 tutor-small"> |
| 50 | <span class="tutor-discussion-card-author"> |
| 51 | <?php echo esc_html( $comment_item->comment_author ); ?> |
| 52 | </span> |
| 53 | <span class="tutor-text-subdued"> |
| 54 | <?php |
| 55 | /* translators: %s human-readable time difference. */ |
| 56 | echo esc_html( sprintf( __( '%s ago', 'tutor' ), human_time_diff( strtotime( $comment_item->comment_date_gmt ) ) ) ); |
| 57 | ?> |
| 58 | </span> |
| 59 | </div> |
| 60 | <div class="tutor-p2 tutor-text-secondary"> |
| 61 | <?php echo wp_kses_post( $comment_item->comment_content ); ?> |
| 62 | </div> |
| 63 | </div> |
| 64 | |
| 65 | <?php if ( $user_id === (int) $comment_item->user_id ) : ?> |
| 66 | <div x-data="tutorPopover({ placement: 'bottom-end' })"> |
| 67 | <button x-ref="trigger" @click="toggle()" class="tutor-btn tutor-btn-ghost tutor-btn-x-small tutor-btn-icon"> |
| 68 | <?php SvgIcon::make()->name( Icon::ELLIPSES )->size( 16 )->color( Color::SECONDARY )->render(); ?> |
| 69 | </button> |
| 70 | <div x-ref="content" x-show="open" x-cloak @click.outside="handleClickOutside()" class="tutor-popover"> |
| 71 | <div class="tutor-popover-menu" style="min-width: 104px;"> |
| 72 | <button class="tutor-popover-menu-item" @click="editingId = <?php echo (int) $comment_item->comment_ID; ?>; $nextTick(() => $dispatch('tutor-focus-form-<?php echo esc_attr( $id_prefix . 'edit-form-' . (int) $comment_item->comment_ID ); ?>')); hide()"> |
| 73 | <?php SvgIcon::make()->name( Icon::EDIT_2 )->render(); ?> |
| 74 | <?php esc_html_e( 'Edit', 'tutor' ); ?> |
| 75 | </button> |
| 76 | <button class="tutor-popover-menu-item" @click="handleDeleteComment({commentId: <?php echo esc_html( $comment_item->comment_ID ); ?>}); hide()"> |
| 77 | <?php SvgIcon::make()->name( Icon::DELETE_2 )->render(); ?> |
| 78 | <?php esc_html_e( 'Delete', 'tutor' ); ?> |
| 79 | </button> |
| 80 | </div> |
| 81 | </div> |
| 82 | </div> |
| 83 | <?php endif; ?> |
| 84 | </div> |
| 85 | |
| 86 | <?php if ( ! $is_reply ) : ?> |
| 87 | <div class="tutor-mt-6"> |
| 88 | <button class="tutor-comment-action-btn tutor-comment-action-btn-reply" @click="replyingId = replyingId === <?php echo (int) $comment_item->comment_ID; ?> ? null : <?php echo (int) $comment_item->comment_ID; ?>; if (replyingId) $nextTick(() => $dispatch('tutor-focus-form-lesson-comment-reply-form-<?php echo (int) $comment_item->comment_ID; ?>'))"> |
| 89 | <?php SvgIcon::make()->name( Icon::COMMENTS )->render(); ?> |
| 90 | <?php esc_html_e( 'Reply', 'tutor' ); ?> |
| 91 | </button> |
| 92 | </div> |
| 93 | |
| 94 | <?php |
| 95 | tutor_load_template( |
| 96 | 'learning-area.lesson.comment-form', |
| 97 | array( |
| 98 | 'form_id' => 'lesson-comment-reply-form-' . (int) $comment_item->comment_ID, |
| 99 | 'placeholder' => __( 'Write your reply', 'tutor' ), |
| 100 | 'submit_handler' => 'handleReplyComment(data, ' . (int) $comment_item->comment_ID . ')', |
| 101 | 'cancel_handler' => 'reset(); replyingId = null', |
| 102 | 'is_pending' => 'replyCommentMutation?.isPending', |
| 103 | 'class' => 'tutor-comment-reply-form tutor-mt-6', |
| 104 | 'x_show' => 'replyingId === ' . (int) $comment_item->comment_ID, |
| 105 | ) |
| 106 | ); |
| 107 | ?> |
| 108 | |
| 109 | <!-- Display Comment Replies --> |
| 110 | <?php |
| 111 | tutor_load_template( |
| 112 | 'learning-area.lesson.comment-replies', |
| 113 | array( |
| 114 | 'lesson_id' => $lesson_id, |
| 115 | 'comment_item' => $comment_item, |
| 116 | 'user_id' => $user_id, |
| 117 | ) |
| 118 | ); |
| 119 | ?> |
| 120 | <?php endif; ?> |
| 121 | </div> |
| 122 | </div> |
| 123 | |
| 124 | <?php if ( $user_id === (int) $comment_item->user_id ) : ?> |
| 125 | <?php |
| 126 | tutor_load_template( |
| 127 | 'learning-area.lesson.comment-form', |
| 128 | array( |
| 129 | 'form_id' => $id_prefix . 'edit-form-' . (int) $comment_item->comment_ID, |
| 130 | 'placeholder' => $is_reply ? __( 'Write your reply', 'tutor' ) : __( 'Write your comment', 'tutor' ), |
| 131 | 'submit_handler' => 'handleEditComment(data,' . (int) $comment_item->comment_ID . ')', |
| 132 | 'cancel_handler' => 'reset(); editingId = null', |
| 133 | 'is_pending' => 'editCommentMutation?.isPending', |
| 134 | 'class' => 'tutor-comment-edit-form', |
| 135 | 'x_show' => 'editingId === ' . (int) $comment_item->comment_ID, |
| 136 | 'default_value' => $comment_item->comment_content, |
| 137 | ) |
| 138 | ); |
| 139 | ?> |
| 140 | <?php endif; ?> |
| 141 | </div> |
| 142 |