function check_return_comments() { global $rtmedia_query; if ('comment' !== $rtmedia_query->action_query->action) { return; } if (isset($rtmedia_query->action_query->id) && count($_POST)) { // @codingStandardsIgnoreLine /** * /media/comments [POST] * Post a comment to the album by post id */ $nonce = isset($_REQUEST['rtmedia_comment_nonce']) ? wp_unslash($_REQUEST['rtmedia_comment_nonce']) : ''; $comment_content = isset($_REQUEST['comment_content']) ? sanitize_text_field(wp_unslash($_REQUEST['comment_content'])) : ''; if (wp_verify_nonce($nonce, 'rtmedia_comment_nonce')) { if (empty($comment_content)) { return false; } $comment = new RTMediaComment(); $attr = $_POST; $media_model = new RTMediaModel(); $result = $media_model->get(array('id' => $rtmedia_query->action_query->id)); if (!isset($attr['comment_post_ID'])) { $attr['comment_post_ID'] = $result[0]->media_id; } $id = $comment->add($attr); if (!is_null($result[0]->activity_id)) { global $rtmedia_buddypress_activity; remove_action('bp_activity_comment_posted', array($rtmedia_buddypress_activity, 'comment_sync'), 10, 2); if (function_exists('bp_activity_new_comment')) { $comment_activity_id = bp_activity_new_comment(array('content' => $comment_content, 'activity_id' => $result[0]->activity_id)); do_action('rtm_bp_activity_comment_posted', $comment_activity_id, $result[0]); } } if (!empty($comment_activity_id)) { $rtmedia_activity_comment = rtmedia_activity_comment($comment_activity_id); if ($rtmedia_activity_comment['content']) { update_comment_meta($id, 'activity_comment_content', $rtmedia_activity_comment['content']); } update_comment_meta($id, 'activity_id', $comment_activity_id); } $_rt_ajax = filter_input(INPUT_POST, 'rtajax', FILTER_SANITIZE_STRING); if (!empty($_rt_ajax)) { global $wpdb; $comments = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d limit 100", $id), ARRAY_A); echo rmedia_single_comment($comments); // @codingStandardsIgnoreLine exit; } } else { esc_html_e('Ooops !!! Invalid access. No nonce was found !!', 'buddypress-media'); } } }
/** * Render single comment, * And display show all comment link to display all comment * @param [array] $comment [comment] * @param [int] $count [default false other ways comment count] * @param [int] $i [default false other ways increment with loop] * By: Yahil */ function rmedia_single_comment($comment, $count = false, $i = false) { $html = ''; $class = ''; if (isset($count) && $count) { $hide = $count - 5; if ($i < $hide) { $class = 'hide'; if (0 == $i) { echo '<div class="rtmedia-like-info"><span id="rtmedia_show_all_comment"> ' . esc_html('Show all ' . $count . ' comments', 'rtmedia') . ' </span></div>'; } } } global $allowedtags, $rtmedia_media; $html .= '<li class="rtmedia-comment ' . $class . ' ">'; if ($comment['user_id']) { $user_link = "<a href='" . esc_url(get_rtmedia_user_link($comment['user_id'])) . "' title='" . esc_attr(rtmedia_get_author_name($comment['user_id'])) . "'>" . esc_html(rtmedia_get_author_name($comment['user_id'])) . '</a>'; $user_name = apply_filters('rtmedia_comment_author_name', $user_link, $comment); $profile_pic = rtmedia_author_profile_pic($show_link = true, $echo = false, $comment['user_id']); } else { $user_name = 'Annonymous'; $profile_pic = ''; } if (!empty($profile_pic)) { $html .= "<div class='rtmedia-comment-user-pic cleafix'>" . $profile_pic . '</div>'; } $html .= "<div class='rtm-comment-wrap'><div class='rtmedia-comment-details'>"; $html .= '<span class ="rtmedia-comment-author">' . $user_name . '</span>'; $html .= '<span class ="rtmedia-comment-date"> ' . apply_filters('rtmedia_comment_date_format', rtmedia_convert_date($comment['comment_date_gmt']), $comment) . '</span>'; $comment_content = $comment['comment_content']; $activity_comment_content = get_comment_meta($comment['comment_ID'], 'activity_comment_content', true); if (empty($activity_comment_content)) { $activity_id = (int) get_comment_meta($comment['comment_ID'], 'activity_id', true); if ($activity_id) { $rtmedia_activity_comment = rtmedia_activity_comment($activity_id); if ($rtmedia_activity_comment['content']) { $comment_content = $rtmedia_activity_comment['content']; update_comment_meta($comment['comment_ID'], 'activity_comment_content', $rtmedia_activity_comment['content']); } } } else { $comment_content = $activity_comment_content; } $comment_string = wp_kses($comment_content, $allowedtags); $html .= '<div class="rtmedia-comment-content">' . wpautop(make_clickable(apply_filters('bp_get_activity_content', $comment_string))) . '</div>'; $html .= '<div class="rtmedia-comment-extra">' . apply_filters('rtmedia_comment_extra', '', $comment) . '</div>'; if (is_rt_admin() || isset($comment['user_id']) && (get_current_user_id() === intval($comment['user_id']) || intval($rtmedia_media->media_author) === get_current_user_id()) || apply_filters('rtmedia_allow_comment_delete', false)) { // show delete button for comment author and admins $html .= '<i data-id="' . esc_attr($comment['comment_ID']) . '" class = "rtmedia-delete-comment dashicons dashicons-no-alt rtmicon" title="' . esc_attr__('Delete Comment', 'buddypress-media') . '"></i>'; } $html .= '<div class="clear"></div></div></div></li>'; return apply_filters('rtmedia_single_comment', $html, $comment); }