comment-card.php
4 days ago
comment-form.php
4 days ago
comment-list.php
4 days ago
comment-replies.php
4 days ago
comment-single.php
4 days ago
qna-card.php
4 days ago
qna-form.php
4 days ago
qna-list.php
4 days ago
qna-replies.php
4 days ago
qna-single.php
4 days ago
comment-card.php
168 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tutor dashboard lesson comment card. |
| 4 | * |
| 5 | * @package Tutor\Templates |
| 6 | * @author Themeum <support@themeum.com> |
| 7 | * @link https://themeum.com |
| 8 | * @since 4.0.0 |
| 9 | */ |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | use Tutor\Components\Constants\Size; |
| 14 | use TUTOR\Icon; |
| 15 | use Tutor\Components\SvgIcon; |
| 16 | use Tutor\Components\Constants\Color; |
| 17 | use Tutor\Components\Avatar; |
| 18 | use Tutor\Components\Button; |
| 19 | use Tutor\Components\Constants\Variant; |
| 20 | use Tutor\Components\PreviewTrigger; |
| 21 | use Tutor\Helpers\UrlHelper; |
| 22 | use TUTOR\Lesson; |
| 23 | |
| 24 | $course = get_post( tutor_utils()->get_course_id_by( 'lesson', $lesson_comment->comment_post_ID ) ); |
| 25 | $last_reply = null; |
| 26 | $replies = Lesson::get_comments( |
| 27 | array( |
| 28 | 'parent' => $lesson_comment->comment_ID, |
| 29 | 'order' => 'DESC', |
| 30 | ) |
| 31 | ); |
| 32 | |
| 33 | if ( ! empty( $replies ) ) { |
| 34 | $last_reply = $replies[0]; |
| 35 | } |
| 36 | |
| 37 | $single_url = UrlHelper::add_query_params( |
| 38 | $discussion_url, |
| 39 | array( |
| 40 | 'tab' => 'lesson-comments', |
| 41 | 'id' => $lesson_comment->comment_ID, |
| 42 | ) |
| 43 | ); |
| 44 | ?> |
| 45 | <div class="tutor-discussion-card" data-comment-id="<?php echo esc_attr( (int) $lesson_comment->comment_ID ); ?>" x-data="tutorPopover({ placement: 'bottom-end' })" :class="{ 'active': open }"> |
| 46 | <div class="tutor-flex tutor-gap-4 tutor-w-full" x-show="editingId !== <?php echo (int) $lesson_comment->comment_ID; ?>"> |
| 47 | <?php Avatar::make()->user( $lesson_comment->user_id )->size( Size::SIZE_32 )->render(); ?> |
| 48 | <div class="tutor-discussion-card-content"> |
| 49 | <div class="tutor-discussion-card-top"> |
| 50 | <div class="tutor-discussion-card-author tutor-flex-shrink-0"><?php echo esc_html( $lesson_comment->comment_author ); ?></div> |
| 51 | <div class="tutor-flex tutor-items-center tutor-gap-2 tutor-overflow-hidden"> |
| 52 | <div class="tutor-flex tutor-items-center tutor-gap-2 tutor-min-w-0"> |
| 53 | <span class="tutor-text-subdued tutor-flex-shrink-0"><?php esc_html_e( 'comment on', 'tutor' ); ?></span> |
| 54 | <div class="tutor-min-w-0 tutor-flex-1"> |
| 55 | <?php PreviewTrigger::make()->id( $lesson_comment->comment_post_ID )->render(); ?> |
| 56 | </div> |
| 57 | </div> |
| 58 | <div class="tutor-flex tutor-items-center tutor-gap-2 tutor-min-w-0"> |
| 59 | <span class="tutor-text-subdued tutor-flex-shrink-0"><?php esc_html_e( 'in', 'tutor' ); ?></span> |
| 60 | <div class="tutor-min-w-0 tutor-flex-1"> |
| 61 | <?php PreviewTrigger::make()->id( $course->ID )->render(); ?> |
| 62 | </div> |
| 63 | </div> |
| 64 | </div> |
| 65 | </div> |
| 66 | <a href="<?php echo esc_url( $single_url ); ?>" class="tutor-discussion-card-title tutor-break-words" id="<?php echo esc_attr( 'tutor-lesson-comment-text-' . (int) $lesson_comment->comment_ID ); ?>"><?php echo wp_kses_post( $lesson_comment->comment_content ); ?></a> |
| 67 | <div class="tutor-discussion-card-meta tutor-sm-mt-4"> |
| 68 | <button |
| 69 | @click="toggleCommentReply(<?php echo (int) $lesson_comment->comment_ID; ?>)" |
| 70 | class="tutor-discussion-card-meta-reply-button" |
| 71 | type="button" |
| 72 | > |
| 73 | <?php esc_html_e( 'Reply', 'tutor' ); ?> |
| 74 | </button> |
| 75 | |
| 76 | <a href="<?php echo esc_url( $single_url ); ?>" class="tutor-flex tutor-items-center tutor-gap-2"> |
| 77 | <?php SvgIcon::make()->name( Icon::COMMENTS )->size( 20 )->render(); ?> |
| 78 | <span class="tutor-discussion-card-reply-count tutor-text-subdued"><?php echo esc_html( count( $replies ) ); ?></span> |
| 79 | </a> |
| 80 | |
| 81 | <?php if ( $last_reply ) { ?> |
| 82 | <div class="tutor-flex tutor-items-center tutor-gap-3 tutor-sm-ml-2"> |
| 83 | <?php Avatar::make()->user( $last_reply->user_id )->size( Size::SIZE_20 )->render(); ?> |
| 84 | <div class="tutor-text-small"><?php echo esc_html( sprintf( __( '%s ago', 'tutor' ), human_time_diff( strtotime( $last_reply->comment_date_gmt ) ) ) ); //phpcs:ignore ?></div> |
| 85 | </div> |
| 86 | <?php } else { ?> |
| 87 | <div class="tutor-text-small"><?php echo esc_html( sprintf( __( '%s ago', 'tutor' ), human_time_diff( strtotime( $lesson_comment->comment_date_gmt ) ) ) ); //phpcs:ignore ?></div> |
| 88 | <?php } ?> |
| 89 | </div> |
| 90 | </div> |
| 91 | <div class="tutor-discussion-card-actions" x-show="replyingCommentId !== <?php echo (int) $lesson_comment->comment_ID; ?>"> |
| 92 | <?php |
| 93 | Button::make() |
| 94 | ->variant( Variant::PRIMARY ) |
| 95 | ->size( Size::X_SMALL ) |
| 96 | ->label( __( 'Reply', 'tutor' ) ) |
| 97 | ->attr( '@click', 'toggleCommentReply(' . (int) $lesson_comment->comment_ID . ')' ) |
| 98 | ->attr( 'class', 'tutor-force-sm-hidden' ) |
| 99 | ->attr( 'type', 'button' ) |
| 100 | ->size( Size::X_SMALL ) |
| 101 | ->render(); |
| 102 | ?> |
| 103 | <?php if ( get_current_user_id() === (int) $lesson_comment->user_id ) : ?> |
| 104 | <div class="tutor-flex"> |
| 105 | <?php |
| 106 | Button::make() |
| 107 | ->label( __( 'More options', 'tutor' ) ) |
| 108 | ->variant( Variant::SECONDARY ) |
| 109 | ->size( Size::X_SMALL ) |
| 110 | ->icon( Icon::ELLIPSES, 'left', Size::SIZE_16, Color::SECONDARY ) |
| 111 | ->icon_only() |
| 112 | ->attr( 'x-ref', 'trigger' ) |
| 113 | ->attr( '@click', 'toggle()' ) |
| 114 | ->render(); |
| 115 | ?> |
| 116 | <div x-ref="content" x-show="open" x-cloak @click.outside="handleClickOutside()" class="tutor-popover"> |
| 117 | <div class="tutor-popover-menu" style="min-width: 104px;"> |
| 118 | <button class="tutor-popover-menu-item tutor-gap-5" @click="setEditing(<?php echo (int) $lesson_comment->comment_ID; ?>); hide()"> |
| 119 | <?php SvgIcon::make()->name( Icon::EDIT_2 )->size( 20 )->render(); ?> |
| 120 | <?php esc_html_e( 'Edit', 'tutor' ); ?> |
| 121 | </button> |
| 122 | <button class="tutor-popover-menu-item tutor-gap-5" @click="TutorCore.modal.showModal('tutor-comment-delete-modal', { commentId: <?php echo esc_html( $lesson_comment->comment_ID ); ?> }); hide()"> |
| 123 | <?php SvgIcon::make()->name( Icon::DELETE_2 )->size( 20 )->render(); ?> |
| 124 | <?php esc_html_e( 'Delete', 'tutor' ); ?> |
| 125 | </button> |
| 126 | </div> |
| 127 | </div> |
| 128 | </div> |
| 129 | <?php endif; ?> |
| 130 | </div> |
| 131 | </div> |
| 132 | |
| 133 | <?php if ( get_current_user_id() === (int) $lesson_comment->user_id ) : ?> |
| 134 | <div x-show="editingId === <?php echo (int) $lesson_comment->comment_ID; ?>" x-cloak class="tutor-w-full"> |
| 135 | <?php |
| 136 | tutor_load_template( |
| 137 | 'dashboard.discussions.comment-form', |
| 138 | array( |
| 139 | 'form_id' => 'lesson-comment-edit-' . (int) $lesson_comment->comment_ID, |
| 140 | 'default_value' => $lesson_comment->comment_content, |
| 141 | 'submit_handler' => '(data) => handleEditComment(data, ' . (int) $lesson_comment->comment_ID . ')', |
| 142 | 'cancel_handler' => 'reset(); editingId = null; focused = false', |
| 143 | 'is_pending' => 'editCommentMutation?.isPending', |
| 144 | 'placeholder' => __( 'Write your comment', 'tutor' ), |
| 145 | ) |
| 146 | ); |
| 147 | ?> |
| 148 | </div> |
| 149 | <?php endif; ?> |
| 150 | |
| 151 | <div x-show="replyingCommentId === <?php echo (int) $lesson_comment->comment_ID; ?>" x-cloak class="tutor-card tutor-surface-l1-hover tutor-mt-4 tutor-w-full"> |
| 152 | <?php |
| 153 | tutor_load_template( |
| 154 | 'dashboard.discussions.comment-form', |
| 155 | array( |
| 156 | 'form_id' => 'lesson-comment-reply-form-' . (int) $lesson_comment->comment_ID, |
| 157 | 'submit_handler' => '(data) => handleReplyComment(data, ' . (int) $lesson_comment->comment_ID . ', ' . (int) $lesson_comment->comment_post_ID . ', "list")', |
| 158 | 'cancel_handler' => 'setReplyingComment(null)', |
| 159 | 'is_pending' => 'replyCommentMutation?.isPending', |
| 160 | 'placeholder' => __( 'Write your reply', 'tutor' ), |
| 161 | 'label' => __( 'Reply', 'tutor' ), |
| 162 | 'submit_label' => __( 'Save', 'tutor' ), |
| 163 | ) |
| 164 | ); |
| 165 | ?> |
| 166 | </div> |
| 167 | </div> |
| 168 |