PATH:
home
/
letacommog
/
laindinois
/
OLD
/
wp-content
/
plugins
/
dwt-listing-rest-api
<?php function dwt_listing_fetch_comments_count_app($id){ global $wpdb; $query = "SELECT COUNT(comment_post_id) AS count FROM $wpdb->comments WHERE `comment_approved` = 1 AND `comment_post_ID` = ".$id." AND `comment_parent` = 0"; $parents = $wpdb->get_row($query); return $parents->count; } if( !function_exists('dwt_listing_fetch_comments_app' ) ) { function dwt_listing_fetch_comments_app( $post_id, $comments_count = '' ,$page_num = '') { $paged = $page_num; $parent_comments = dwt_listing_fetch_comments_count_app($post_id); $posts_per_page = get_option( 'posts_per_page' ); $max_num_pages = ceil($parent_comments/$posts_per_page); $paged = (int)$paged; $get_offset = ($paged - 1); $offset = $get_offset * $posts_per_page; $args = array( 'number' => $posts_per_page, 'order' => 'DESC', 'orderby' => 'comment_ID','status' => 'approve', 'parent' => 0, 'post_id' => $post_id, 'offset' => $offset); $comments = get_comments($args); $arr = array(); $carray = array(); $reply_list = array(); if( count((array) $comments ) > 0 ) { foreach($comments as $comment) { $arr['post_id'] = $post_id; $arr['comment_author_img'] = get_avatar_url($comment->user_id, array('size' => 120)); $arr['comment_id'] = $comment->comment_ID; $arr['comment_author_id'] = dwt_listing_fetch_comment_poster($comment->user_id,'id'); $arr['comment_author_name'] = dwt_listing_fetch_comment_poster($comment->user_id,'name'); $arr['comment_content'] = dwt_listing_convert_uniText($comment->comment_content); $arr['comment_date'] = date_i18n( 'j F, Y', strtotime( get_the_time($comment->comment_date) ) ); $arr['comment_parent'] = $comment->comment_parent; $arr['reply_btn_text'] = __("Reply", "dwt-listing-api"); $arr['can_reply'] = true; $arr['has_reply'] = false; //fetch replies of that post $replies = get_comments( array( 'parent' => $comment->comment_ID, 'status' => 'approve', 'orderby' => 'comment_date' , 'order' => 'DESC' ) ); if(count((array) $replies) > 0) { $arr['has_reply'] = true; foreach($replies as $reply) { $reply_list[] = array( 'post_id' => $post_id, 'comment_author_img' => get_avatar_url($reply->user_id, array('size' => 120)), 'comment_id' => $reply->comment_ID, 'comment_author_id' => $reply->user_id, 'comment_author_name' => $reply->comment_author, 'comment_content' => dwt_listing_convert_uniText($reply->comment_content), 'comment_date' => date_i18n( 'j F, Y', strtotime( get_the_time($reply->comment_date) ) ), 'can_reply' => false, 'has_reply' => false ); } } $arr['reply'] = $reply_list; $carray[] = $arr; } } else { $carray = []; } $nextPaged = (int)($paged) + 1; $has_next_page = ( $nextPaged <= (int)$max_num_pages ) ? true : false; $data['comments'] = $carray; $data['pagination'] = array("max_num_pages" => (int)$max_num_pages, "current_page" => (int)$paged, "next_page" => (int)$nextPaged, "increment" => (int)$posts_per_page , "current_no_of_ads" => (int)$parent_comments, "has_next_page" => $has_next_page ); return $data; } } //Submit Comments add_action( 'rest_api_init', 'nokriAPI_hook_for_getting_commentss', 0 ); function nokriAPI_hook_for_getting_commentss() { register_rest_route( 'downtown/app', '/submit-event-comments/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_submit_comments_events', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if( !function_exists('dwt_listing_submit_comments_events')) { function dwt_listing_submit_comments_events($request) { $comment_id = $post_id = $message = $user_email = $display_name = $user_id = ''; $json_data = $request->get_json_params(); $user = wp_get_current_user(); $user_id = $user->data->ID; $display_name = $user->data->display_name; $user_email = $user->data->user_email; $message = (isset( $json_data['message'] )) ? $json_data['message'] : ''; $post_id = (isset( $json_data['event_id'] )) ? $json_data['event_id'] : ''; $comment_id = (isset( $json_data['comment_id'] )) ? $json_data['comment_id'] : 0; $commentdata = array( 'comment_post_ID' => $post_id, 'comment_author' => $display_name, 'comment_author_email' => $user_email, 'comment_content' => $message, 'comment_author_url' => get_author_posts_url($user_id), 'comment_type' => 'comments', 'comment_parent' => $comment_id, 'user_id' => $user_id, ); /*Insert new comment and get the comment ID*/ $comment_id = wp_new_comment( $commentdata ); $arr = array(); if( $comment_id ) { $success = true; $arr['comments'] = dwt_listing_fetch_comments_app($post_id); $status = wp_get_comment_status( $comment_id ); if ($status == "approved") { $message = __("Comment Posted Successfully.", "dwt-listing-api"); } else { $message = __("Comment sent for approval." , "dwt-listing-api"); } } else { $arr['comments'] = array(); $success = false; $message = __("Some Error Ocuured While Posting Ad" , "dwt-listing-api"); } return $response = array( 'success' => $success, 'data' => $arr, 'message' => $message); } } if( !function_exists('dwt_listing_fetch_listing_reviews_app' ) ) { function dwt_listing_fetch_listing_reviews_app($listing_id , $next_page = '') { global $dwt_listing_api; $repiler = $gallery = array(); $arr = $reviews = $listing_reviews = array(); $replier_comment_id = $replies = $full_img = $thumb_imgs = '';$total_reviews = $total_count = $rated = $commenter_profile_url = $commenter_name = $commenter_dp = $commenter_id = $replier_comment_id = ''; $replier_user_id = ''; $replier_remarks = ''; $has_next_page = $nextPaged = $total_comments = $offset = $page = $limit = $main_title = $got_likes = '';$got_love = '';$got_wow ='';$got_angry =''; //pagination $limit = $dwt_listing_api['app_listing_pagination_review_limit']; $page = 1; if(!empty($next_page)) {$page = $next_page;} $offset = ($page * $limit) - $limit; $total_comments = get_comments(array('post_type' => 'listing', 'post_id'=>$listing_id,'status' => 'approve','parent'=>0)); if(isset($limit) && $limit !="") { $pages = ceil(count($total_comments)/$limit); } $nextPaged = (int)($page) + 1; $has_next_page = ( $nextPaged <= (int)$pages ) ? true : false; //get actual comments $comments = get_comments(array('post_id' => $listing_id, 'orderby' => 'post_date' ,'order' => 'DESC', 'post_type' => 'listing', 'status' => 'approve', 'offset'=>$offset,'number'=>$limit ,'parent'=>0)); $arr['has_commentz'] = false; if(count((array) $comments) > 0 ) { $arr['has_commentz'] = true; // show user rank $arr['show_user_rank'] = false; if( dwt_listing_text('dwt_listing_enable_names') == "1" ) { $arr['show_user_rank'] = true; } $arr['show_emojis'] = false; if( dwt_listing_text('dwt_listing_review_enable_emoji') == "1" ) { $arr['show_emojis'] = true; } $arr['show_user_ratings'] = false; if( dwt_listing_text('dwt_listing_show_total_ratings') == "1" ) { $arr['show_user_ratings'] = true; } $arr['tab_txt'] = __("User Reviews", "dwt-listing-api"); $arr['load_more'] = __("Load More", "dwt-listing-api"); foreach($comments as $comment) { $commenter_id = dwt_listing_fetch_comment_poster($comment->user_id,'id'); $commenter_dp = dwt_listing_fetch_comment_poster($comment->user_id,'dp'); $commenter_name = dwt_listing_fetch_comment_poster($comment->user_id,'name'); $commenter_profile_url = dwt_listing_fetch_comment_poster($comment->user_id,'url'); $rated = get_comment_meta( $comment->comment_ID, 'review_stars', true ); $main_title = get_comment_meta( $comment->comment_ID, 'review_main_title', true ); $total_count = dwt_listing_submitted_reviews($comment->user_id); if(dwt_listing_review_user_tagline($total_count) !='' ) { $total_reviews = dwt_listing_review_user_tagline($total_count); } $got_likes = $got_love = $got_wow = $got_angry = '' ; // comments likes & dislikes if(get_comment_meta($comment->comment_ID, 'review_like', true) !="") { $got_likes = get_comment_meta($comment->comment_ID, 'review_like', true); } if(get_comment_meta($comment->comment_ID, 'review_love', true) !="") { $got_love = get_comment_meta($comment->comment_ID, 'review_love', true); } if(get_comment_meta($comment->comment_ID, 'review_wow', true) !="") { $got_wow = get_comment_meta($comment->comment_ID, 'review_wow', true); } if(get_comment_meta($comment->comment_ID, 'review_angry', true) !="") { $got_angry = get_comment_meta($comment->comment_ID, 'review_angry', true); } //comments gallery $has_gallery = false; $gallery = array(); if(get_comment_meta( $comment->comment_ID, 'review_images_idz', true ) !="") { //get images idz $images_idz = get_comment_meta( $comment->comment_ID, 'review_images_idz', true ); if(!empty($images_idz)) { $comment_media = explode( ',', $images_idz ); if(count((array) $comment_media) > 0 ) { $thumb_imgs = $full_img = ''; $has_gallery = true; foreach( $comment_media as $m ) { $mid = ''; if ( isset( $m->ID ) ) { $mid = $m->ID; } else { $mid = $m; } $full_img = wp_get_attachment_image_src($mid, 'full'); $thumb_imgs = wp_get_attachment_image_src($mid, 'dwt_listing_list-view1'); $gallery[] = array( "small_img" => esc_url($thumb_imgs[0]), "url" => esc_url($full_img[0]), ); } } } } //replies $has_reply = false; $replies = get_comments( array( 'parent' => $comment->comment_ID, 'status' => 'approve', 'orderby' => 'comment_date' , 'order' => 'DESC' , 'number' => '1' ) ); if(count((array) $replies) > 0) { $has_reply = true; foreach($replies as $reply) { $repiler = array(); $replier_comment_id = $reply->comment_ID; $repiler[] = array( 'author_responded_txt' => __("Author responded on", "dwt-listing-api"), 'repiler_id' => $replier_comment_id, 'responded_on' => date_i18n( 'j F, Y', strtotime( get_the_time($reply->comment_date) ) ), 'responded_msg' => '<p>' .dwt_listing_convert_uniText($reply->comment_content).'</p>', ); } } $total_ratingz = dwt_listing_submitted_reviews($comment->user_id) . ' '.esc_html__('ratings','dwt-listing-api'); $listing_reviews[] = array ( 'comment_id' =>$comment->comment_ID, 'user_id' => $commenter_id, 'user_dp' => $commenter_dp, 'user_name' => $commenter_name, 'user_rank_txt' => $total_reviews, 'user_ratings' => $total_ratingz, 'comment_date' => date_i18n( 'j F, Y', strtotime( get_the_time($comment->comment_date) ) ), 'comment_stars' => (int)$rated, 'comment_title' => $main_title, 'comment_content' => '<p>' .dwt_listing_convert_uniText(esc_attr($comment->comment_content)).'</p>', 'has_gallery' => $has_gallery, 'gallery_images' => $gallery, 'reaction_txt' => __("Your reaction about this review", "dwt-listing-api"), 'likes' => $got_likes, 'love' => $got_love, 'wows' => $got_wow, 'angry' => $got_angry, 'has_reply' => $has_reply, 'author_reply' => $repiler, ); } } $arr['listing_reviews'] = $listing_reviews; $arr['pagination'] = array("max_num_pages" => (int)$pages, "current_page" => (int)$page, "next_page" => (int)$nextPaged, "increment" => (int)$limit , "has_next_page" => $has_next_page ); return $arr; } } // Get Listing Owner Details if ( ! function_exists( 'dwt_listing_fetch_reviews_score') ) { function dwt_listing_fetch_reviews_score($listing_id) { $comments = ''; $rated = $get_rating_avrage = ''; $one_star = ''; $two_star = ''; $three_star = ''; $four_star = ''; $five_star = ''; $star1 = $star2 = $star3 = $star4 = $star5 = 0; $comments = get_comments(array('post_id' => $listing_id, 'post_type' => 'listing', 'status' => 'approve')); if(count( $comments) > 0 ) { $sum_of_rated = 0; $no_of_times_rated = 0; foreach($comments as $comment) { if(get_comment_meta($comment->comment_ID, 'review_stars', true) !="") { $rated = get_comment_meta($comment->comment_ID, 'review_stars', true); if($rated !="" && $rated > 0) { $sum_of_rated+= $rated; $no_of_times_rated++; //now rated percentage if($rated == 1) { $star1++; } if($rated == 2) { $star2++; } if($rated == 3) { $star3++; } if($rated == 4) { $star4++; } if($rated == 5) { $star5++; } } } } //loop end get avrage value if($rated !="" && $rated > 0) { $get_rating_avrage = round($sum_of_rated / $no_of_times_rated,2); $get_rating_avrage1 = round($sum_of_rated / $no_of_times_rated,1); $one_star = round(($star1/$no_of_times_rated) * 100); $two_star = round(($star2/$no_of_times_rated) * 100); $three_star = round(($star3/$no_of_times_rated) * 100); $four_star = round(($star4/$no_of_times_rated) * 100); $five_star = round(($star5/$no_of_times_rated) * 100); $total_stars = explode(".",$get_rating_avrage1); $stars_html = ''; $first_part = (isset($total_stars[0]) && $total_stars[0] > 0 && $total_stars[0] != "" ) ? $total_stars[0] : 0; $second_part = (isset($total_stars[1]) && $total_stars[1] > 0 && $total_stars[1] != "" ) ? $total_stars[1] : 0; for($stars = 1; $stars <= 5; $stars++) { if($stars <= $first_part && $first_part > 0) { $stars_html .= '<i class="fa fa-star color" aria-hidden="true"></i>'; } else if( $stars == $first_part+1 && $second_part <= 5 && $second_part > 0) { $stars_html .= '<i class="fa fa-star-half-o color" aria-hidden="true"></i>'; } else if( $stars == $first_part+1 && $second_part > 5 && $second_part > 0) { $stars_html .= '<i class="fa fa-star color" aria-hidden="true"></i>'; } else { $stars_html .= '<i class="fa fa-star" aria-hidden="true"></i>'; } } if(strpos($get_rating_avrage,".") !== false){ $get_rating_avrage = $get_rating_avrage; }else{ $get_rating_avrage = $get_rating_avrage.'.0'; } $array = array(); $array['total_stars'] = $stars_html; $array['average'] = $get_rating_avrage; $array['rated_no_of_times'] = $no_of_times_rated; $array['ratings'] = array('star_1' => $one_star,'star_2' => $two_star,'star_3' => $three_star,'star_4' => $four_star,'star_5' => $five_star); //update avrage in post mera update_post_meta($listing_id, 'listing_total_average', $get_rating_avrage ); return $array; } } } } if ( ! function_exists( 'dwt_listing_return_listing_idz_app' ) ) { function dwt_listing_return_listing_idz_app($media,$thumbnail_size) { global $dwt_listing_api; if( count((array) $media ) > 0 ) { $i = 1; foreach( $media as $m ) { if( $i > 1 ) break; $mid = ''; if ( isset( $m->ID ) ) { $mid = $m->ID; } else { $mid = $m; } if ( wp_attachment_is_image($mid ) ) { $image = wp_get_attachment_image_src( $mid, $thumbnail_size); return $image[0]; } else { return $dwt_listing_api['app_lisitng_thumb']['url']; } } } else { return $dwt_listing_api['app_lisitng_thumb']['url']; } } } // Return Event Images media if ( ! function_exists( 'dwt_listing_return_event_idz_app' ) ) { function dwt_listing_return_event_idz_app($media,$thumbnail_size) { global $dwt_listing_api; if( count( $media ) > 0 ) { $i = 1; foreach( $media as $m ) { if( $i > 1 ) break; $mid = ''; if ( isset( $m->ID ) ) { $mid = $m->ID; } else { $mid = $m; } if ( wp_attachment_is_image($mid ) ) { $image = wp_get_attachment_image_src( $mid, $thumbnail_size); return $image[0]; } else { return $dwt_listing_api['app_lisitng_thumb']['url']; } } } else { return $dwt_listing_api['app_lisitng_thumb']['url']; } } } // Check User Package History if (! function_exists ( 'dwt_listing_check_package_history_app' )) { function dwt_listing_check_package_history_app($listing_id = '', $is_user = '') { if(isset($is_user) && $is_user !="") { $user_id = $is_user; } else { $user = wp_get_current_user(); $user_id = $user->ID; } if(isset($listing_id) && $listing_id !="") { } else { if( get_user_meta($user_id, 'd_user_package_id', true ) != "" ) { $regular_listing = get_user_meta($user_id, 'dwt_listing_regular_listing', true); $expiry_date = get_user_meta($user_id, 'dwt_listing_package_expiry', true ); $current_date = date( 'Y-m-d'); if($regular_listing == '-1' || $regular_listing > 0) { if($expiry_date == '-1') { $has_package = true; $message = ''; } // need to check expiry else if( $current_date > $expiry_date) { //package is expired $has_package = false; $message = esc_html__('Your package has expired.', 'dwt-listing-api'); } else { $has_package = true; $message = ''; } } else { // regular listing is expired $has_package = false; $message = esc_html__('Listings expired purchase package to continue.', 'dwt-listing-api'); } } else { $has_package = false; $message = esc_html__('Package is required to submit listings.', 'dwt-listing-api'); } return array( 'has_package' =>$has_package,"message" => $message); } } }
[+]
..
[-] functions.php
[edit]
[-] fetch_data.php
[edit]
[-] utilities.php
[edit]
[+]
inc
[+]
classes
[+]
languages
[-] index.php
[edit]
[+]
images