PATH:
home
/
letacommog
/
laindinois
/
OLD
/
wp-content
/
plugins
/
dwt-listing-rest-api
/
classes
<?php add_action( 'rest_api_init', 'dwt_listing_listing_detial', 0 ); function dwt_listing_listing_detial() { register_rest_route( 'downtown/app', '/listing-detial/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_listing_detial_get', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } // Listing Detial Service if (!function_exists('dwt_listing_listing_detial_get')) { function dwt_listing_listing_detial_get($request) { global $dwt_listing_api; global $wpdb; $ad_ratings = $comments = $has_commentz = $rating_percentage = $based_on =$no_of_time_rated = $avg_txt = $total_avg = $get_percentagez = $has_reviews = $get_data = $get_single_id = $get_exploded_idz = $get_custom_fields = $video_id = $match = $video_link = $listing_longitude = $listing_lattitude = $menu_inner_items = $get_results = $listing_features = $author_loc = $author_name = $get_user_dp = $author_id = $listing_coupon_referral = $readable_time_till = $readable_time = $listing_coupon_code = $listing_coupon_desc = $coupon_expiry_date = $current_day = $timingz = $closed_txt = $listing_timezone = $color_code = $b_status = $status_type = $pricing_values = $listing_currency = $pricing = $street_addr = $web_url = $contact_no = $listing_custom_location = $is_featured = $total_views = $average = $rating_stars = $get_percentage = $pieces = $listing_cats = $get_user_location = $get_user_id = $get_user_name = $get_user_dp = $thumb_imgs = $full_img = $media = $enent_post = $title = $description = $event_long = $event_lat = $category_name = $categor_id = $fetch_listingz =''; $custom_fields_lst = $custom_fields = $inner_menu = $menu_objects = $amenties = $gallery = array(); $user = wp_get_current_user(); $user_id = $user->ID; $json_data = $request->get_json_params(); $listing_id = (isset($json_data['listing_id'])) ? trim($json_data['listing_id']) : ''; $listing_detials = get_post($listing_id); $description = $listing_detials->post_content; $title = $listing_detials->post_title; //listing categories $listing_cats = dwt_listing_listing_assigned_cats_app($listing_id); if(count((array) $listing_cats) > 0 && !empty($listing_cats)) { $pieces = explode(',', $listing_cats); $categor_id = $pieces[0]; $category_name = $pieces[1]; } //check ratings $rating_enabled = false; $get_percentage = dwt_listing_fetch_reviews_average($listing_id); if(isset($get_percentage) && count((array)$get_percentage['ratings']) > 0 && count((array)$get_percentage['rated_no_of_times']) > 0) { $rating_stars = $get_percentage['rated_no_of_times']; $average = $get_percentage['average']; } if( dwt_listing_text('dwt_listing_review_enable_stars') == '1') { $rating_enabled = true; } //views if( function_exists('pvc_get_post_views') ) $total_views = pvc_get_post_views( $listing_id); //is featured $is_featured = dwt_listing_is_listing_featured_app($listing_id); // listing gallery $has_gallery = false; $first_img = false; $media = dwt_listing_fetch_listing_gallery($listing_id); if( count((array) $media ) > 0 ) { $has_gallery = true; $first_img = true; foreach( $media as $m ) { $mid = ''; if ( isset( $m->ID ) ) { $mid = $m->ID; } else { $mid = $m; } $full_img = $thumb_imgs = ''; if( wp_get_attachment_image_src($mid, 'full') !="" && wp_get_attachment_image_src($mid, 'dwt_listing_list-view1') !="") { $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]), ); } } } if($first_img == true) { foreach( $media as $first_m ) { $midz = ''; if ( isset( $first_m->ID ) ) { $midz = $first_m->ID; } else { $midz = $first_m; } $full_imgz = ''; $full_imgz = wp_get_attachment_image_src($midz, 'dwt_listing_blogsingle-post'); $single_img = esc_url($full_imgz[0]); break; } } else { $single_img = dwt_listing_API_PLUGIN_URL."images/l_detail.jpg"; if(isset($dwt_listing_api['app_lisitng_detial_placeholder']['url']) && $dwt_listing_api['app_lisitng_detial_placeholder']['url'] != "") { $single_img = $dwt_listing_api['app_lisitng_detial_placeholder']['url']; } } //sidebar detials if(get_post_meta($listing_id, 'dwt_listing_listing_contact', true ) != "") { $contact_no = get_post_meta($listing_id, 'dwt_listing_listing_contact', true ); } if(get_post_meta($listing_id, 'dwt_listing_listing_weburl', true ) != "") { $web_url = esc_url(get_post_meta($listing_id, 'dwt_listing_listing_weburl', true )); } if(get_post_meta($listing_id, 'dwt_listing_listing_street', true ) != "") { $street_addr = get_post_meta($listing_id, 'dwt_listing_listing_street', true ); } //pricing if(get_post_meta($listing_id, 'dwt_listing_listing_pricefrom', true ) != "" && get_post_meta($listing_id, 'dwt_listing_listing_priceto', true ) != "" && get_post_meta($listing_id, 'dwt_listing_listing_currencyType', true ) != "") { if(get_post_meta($listing_id, 'dwt_listing_listing_priceType', true ) != "") { $pricing = get_post_meta($listing_id, 'dwt_listing_listing_priceType', true ); } $listing_currency = get_post_meta($listing_id, 'dwt_listing_listing_currencyType', true ); $pricing_values = esc_attr($listing_currency).' ' . get_post_meta($listing_id, 'dwt_listing_listing_pricefrom', true ). ' - ' .esc_attr($listing_currency).' ' . get_post_meta($listing_id, 'dwt_listing_listing_priceto', true ); } //if busines hours allowed $is_hours_allowed = false; if(get_post_meta($listing_id, 'dwt_listing_is_hours_allow', true ) == '1') { $is_hours_allowed = true; //now check if its 24/7 or selective timimgz if(get_post_meta($listing_id, 'dwt_listing_business_hours', true) == '1') { $b_status = esc_html__('Always Open','dwt-listing-api'); $color_code = '#fc0'; } else { $status_type = dwt_listing_business_hours_status($listing_id); if($status_type == 0) { $b_status = esc_html__('Closed','dwt-listing-api'); $color_code = '#c00'; } else { $b_status = esc_html__('Open Now','dwt-listing-api'); $color_code = '#25a25a'; if(get_post_meta($listing_id, 'dwt_listing_user_timezone', true) != "") { $listing_timezone = get_post_meta($listing_id, 'dwt_listing_user_timezone', true); } } } } // fetch all hours $show_all_days = false; if(get_post_meta($listing_id, 'dwt_listing_business_hours', true) == '0') { $show_all_days = true; } $hours_format = array(); $get_hours = dwt_listing_show_business_hours($listing_id); if( count((array) $get_hours) > 0 ) { foreach( $get_hours as $key=>$val) { $closed_txt = ''; $is_closed = false; if($val['closed'] == 1) { $is_closed = true; $closed_txt = __("Closed", "dwt-listing-api"); } if(array_key_exists('start_time',$val) && array_key_exists('end_time',$val)) { $timingz = esc_attr($val['start_time']).' - '.esc_attr($val['end_time']); } else { $timingz = ''; } //is current day if(array_key_exists('current_day',$val)) { if($val['current_day'] !="") { $current_day = true; } else { $current_day = false; } } $hours_format[] = array ( "day_name" => $val['day_name'], "is_closed" => $is_closed, "closed_txt" => $closed_txt, "current_day" => $current_day, "timingz" => $timingz, ); } } // coupon expiry check $has_coupon = false; if(dwt_listing_check_coupon_expiry($listing_id) == '1') { $has_coupon = true; $coupon_expiry_date = get_post_meta($listing_id, 'dwt_listing_coupon_expiry', true); $listing_coupon_desc = get_post_meta($listing_id, 'dwt_listing_coupon_desc', true); $listing_coupon_code = get_post_meta($listing_id, 'dwt_listing_coupon_code', true); $readable_time = new DateTime($coupon_expiry_date); $readable_time_till = esc_attr($readable_time->format('dS M, Y')); $listing_coupon_referral = get_post_meta($listing_id, 'dwt_listing_coupon_refer', true); } // listing owner detials $author_id = dwt_listing_listing_owner($listing_id,'id'); $author_name = dwt_listing_listing_owner($listing_id,'name'); $get_user_dp = dwt_listing_listing_owner($listing_id,'dp'); $author_loc = dwt_listing_listing_owner($listing_id,'location'); // amenties $has_ameneties = false; $listing_features = wp_get_object_terms( $listing_id, array('l_category'), array('orderby' => 'name' , 'order' => 'ASC') ); if(is_array($listing_features) && count($listing_features) > 1) { if(isset($listing_features) && $listing_features !="") { if ( ! is_wp_error( $listing_features ) ) { $has_ameneties = true; foreach( $listing_features as $term ) { if($term->parent == 0) { continue; } $amenties[] = array ( "amenties_values" => esc_attr( $term->name ), ); } } } } // menu $has_menu = false; $get_results = $wpdb->get_results( "SELECT * FROM $wpdb->postmeta WHERE post_id = '".$listing_id."' AND meta_key LIKE 'dwt_listing_menutype_%' ORDER BY meta_id ASC"); if(!empty($get_results) && count($get_results) > 0) { foreach($get_results as $results) { if(!empty($results->meta_key)) { $get_menu_itemz = $wpdb->get_results( "SELECT * FROM $wpdb->postmeta WHERE post_id = '".$listing_id."' AND meta_key LIKE 'menu_itemz_".$results->meta_key."%' ORDER BY meta_id ASC"); if(!empty($get_menu_itemz) && count($get_menu_itemz) > 0) { $has_menu = true; foreach($get_menu_itemz as $itemz) { $menu_inner_items = json_decode( stripslashes( $itemz->meta_value ) ); if(!empty($menu_inner_items) && count($menu_inner_items) > 0) { foreach($menu_inner_items as $men) { $inner_menu[] = array ( 'menu_title' => esc_attr($men->l_menu_title), 'menu_price' => esc_attr($men->l_menu_price), 'menu_desc' => esc_attr($men->l_menu_desc), ); } } } $menu_objects[] = array ( 'menu_name' => esc_attr($results->meta_value), 'inner_menu' => $inner_menu, ); } } } } // location $has_location = false; if( get_post_meta($listing_id, 'dwt_listing_listing_lat', true ) != "" && get_post_meta($listing_id, 'dwt_listing_listing_long', true ) != "" ) { $has_location = true; $listing_lattitude = get_post_meta($listing_id, 'dwt_listing_listing_lat', true); $listing_longitude = get_post_meta($listing_id, 'dwt_listing_listing_long', true); } // video $has_video = false; if( get_post_meta($listing_id, 'dwt_listing_listing_video', true ) != "" ) { $has_video = true; $video_link = get_post_meta($listing_id, 'dwt_listing_listing_video', true ); preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $video_link, $match); if( isset( $match[1] ) && $match[1] != "" ) { $video_id = $match[1]; } } // additional fields $has_additional_fields = false; $get_custom_fields = $wpdb->get_results( "SELECT meta_value , meta_key FROM $wpdb->postmeta WHERE post_id = '$listing_id' AND meta_key LIKE 'field_multi_%' ORDER BY meta_id ASC"); if(count($get_custom_fields) > 0) { $has_additional_fields = true; foreach($get_custom_fields as $value) { $get_exploded_idz = explode( '_', $value->meta_key); $get_single_id = $get_exploded_idz[3]; $get_data = explode('|',$value->meta_value); foreach($get_data as $add_data) { $custom_fields_lst[] = array ( "field_data" => esc_attr( $add_data ), ); } $custom_fields[] = array ( "field_name" => get_the_title($get_single_id), "field_listz" => $custom_fields_lst, ); } } //get reviews score $has_reviews = false; $get_percentagez = dwt_listing_fetch_reviews_score($listing_id); if(isset($get_percentagez) && count((array) $get_percentagez['ratings']) > 0) { $has_reviews = true; $total_avg = esc_attr($get_percentagez['average']); $avg_txt = __("average based on", "dwt-listing-api"); $no_of_time_rated = esc_attr($get_percentagez['rated_no_of_times']); $based_on = __("ratings", "dwt-listing-api"); $rating_percentage = array_reverse($get_percentagez['ratings']); } //get reviews comments //return dwt_listing_fetch_listing_reviews_app($listing_id); $data['listing_detial']['view_profile'] = esc_html__("View Profile", "dwt-listing-api"); $data['listing_detial']['view_desc'] = esc_html__("Description", "dwt-listing-api"); #saved $data['listing_detial']['is_saved'] = true; $data['listing_detial']['is_report'] = true; $data['listing_detial']['is_claim'] = true; $saved = esc_html__("Saved", "dwt-listing-api"); $report = esc_html__("Report", "dwt-listing-api"); $claimed = esc_html__("Claim", "dwt-listing-api"); if(isset( $dwt_listing_api['dwt_app_enabled_save_listing']) && $dwt_listing_api['dwt_app_enabled_save_listing'] != true) { $data['listing_detial']['is_saved'] = false; } if(isset( $dwt_listing_api['dwt_app_enabled_report_listing']) && $dwt_listing_api['dwt_app_enabled_report_listing'] != true) { $data['listing_detial']['is_report'] = false; } if(isset( $dwt_listing_api['dwt_app_enabled_claim_listing']) && $dwt_listing_api['dwt_app_enabled_claim_listing'] != true) { $data['listing_detial']['is_claim'] = false; } if(isset( $dwt_listing_api['dwt_app_enabled_save_txt']) && $dwt_listing_api['dwt_app_enabled_save_txt'] !='') { $saved = $dwt_listing_api['dwt_app_enabled_save_txt']; } if(isset( $dwt_listing_api['dwt_app_enabled_report_txt']) && $dwt_listing_api['dwt_app_enabled_report_txt'] !='') { $report = $dwt_listing_api['dwt_app_enabled_report_txt']; } if(isset( $dwt_listing_api['dwt_app_enabled_claim_txt']) && $dwt_listing_api['dwt_app_enabled_claim_txt'] !='') { $claimed = $dwt_listing_api['dwt_app_enabled_claim_txt']; } $is_pending = false; $listing_author_id = get_post_field( 'post_author', $listing_id ); if( get_post_status( $listing_id ) != 'publish' ) { $is_pending = true; } $is_listing_owner = false; if( get_post_field( 'post_author', $listing_id ) == $user_id ) { $is_listing_owner = true; } $data['listing_detial']['is_pending'] = $is_pending; $data['listing_detial']['pending_txt'] = esc_html__("Waiting For Admin Approval", "dwt-listing-api"); $data['listing_detial']['is_listing_owner'] = $is_listing_owner; $data['listing_detial']['save_listing'] = $saved; $data['listing_detial']['report_listing'] = $report; $data['listing_detial']['claim_listing'] = $claimed; $data['listing_detial']['listing_id'] = $listing_id; $data['listing_detial']['featured_txt'] = esc_html__("Featured", "dwt-listing-api"); $data['listing_detial']['listing_title'] = dwt_listing_convert_uniText($title); $data['listing_detial']['category_id'] = $categor_id; $data['listing_detial']['category_name'] = dwt_listing_convert_uniText($category_name); $data['listing_detial']['posted_date'] = get_the_date(get_option( 'date_format' ),$listing_id); $data['listing_detial']['is_rating_enabled'] = $rating_enabled; $data['listing_detial']['ratings']['rating_stars'] = $rating_stars; $data['listing_detial']['ratings']['rating_avg'] = $average; $data['listing_detial']['total_views'] = $total_views; $data['listing_detial']['is_featured'] = $is_featured; $data['listing_detial']['first_img'] = $single_img; $data['listing_detial']['has_gallery'] = $has_gallery; $data['listing_detial']['gallery_images'] = $gallery; $data['listing_detial']['street_address'] = $street_addr; $data['listing_detial']['contact_no'] = $contact_no; $data['listing_detial']['view_website'] = esc_html__("View Website ", "dwt-listing-api"); $data['listing_detial']['web_url'] = $web_url; $data['listing_detial']['pricing_txt'] = esc_html__("Pricing", "dwt-listing-api"); $data['listing_detial']['pricing'] = $pricing_values; $data['listing_detial']['is_hours_allowed'] = $is_hours_allowed; $data['listing_detial']['business_hours_status'] = $b_status; $data['listing_detial']['color_code'] = $color_code; $data['listing_detial']['show_all_days'] = $show_all_days; $data['listing_detial']['listing_hours'] = $hours_format; $data['listing_detial']['listing_has_coupon'] = $has_coupon; $data['listing_detial']['coupon_details']['expiry_txt'] = esc_html__("Expires In", "dwt-listing-api"); $data['listing_detial']['coupon_details']['btn_txt'] = esc_html__("Get Coupon Deal", "dwt-listing-api"); $data['listing_detial']['coupon_details']['expiry_date'] = $coupon_expiry_date; $data['listing_detial']['coupon_details']['days'] = esc_html__("Days", "dwt-listing-api"); $data['listing_detial']['coupon_details']['hours'] = esc_html__("Hours", "dwt-listing-api"); $data['listing_detial']['coupon_details']['mintes'] = esc_html__("Minutes", "dwt-listing-api"); $data['listing_detial']['coupon_details']['seconds'] = esc_html__("Seconds", "dwt-listing-api"); $data['listing_detial']['coupon_details']['title'] = dwt_listing_convert_uniText($title); $data['listing_detial']['coupon_details']['desc'] = esc_attr($listing_coupon_desc); $data['listing_detial']['coupon_details']['coupon_txt'] = esc_html__("Click below to get your coupon code", "dwt-listing-api"); $data['listing_detial']['coupon_details']['coupon_code'] = esc_attr($listing_coupon_code); $data['listing_detial']['coupon_details']['click_to_copy'] = esc_html__("Click to Copy", "dwt-listing-api"); $data['listing_detial']['coupon_details']['validity_txt'] = esc_html__("Valid Till : ", "dwt-listing-api"); $data['listing_detial']['coupon_details']['valid_till'] = $readable_time_till; $data['listing_detial']['coupon_details']['note'] = dwt_listing_text('dwt_listing_coupon_admin_note_desc'); $data['listing_detial']['coupon_details']['referal_btn_txt'] = esc_html__("Visit Referral Link", "dwt-listing-api"); $data['listing_detial']['coupon_details']['referal_link'] = esc_url($listing_coupon_referral); $data['listing_detial']['listing_author_id'] = $author_id; $data['listing_detial']['listing_author_name'] = $author_name; $data['listing_detial']['listing_author_dp'] = $get_user_dp; $data['listing_detial']['listing_author_location'] = $author_loc; $data['listing_detial']['desc']['tab_txt'] = dwt_listing_text('dl_desc'); $data['listing_detial']['desc']['tab_desc'] = $description; $data['listing_detial']['has_amenties'] = $has_ameneties; $data['listing_detial']['ameneties']['tab_txt'] = dwt_listing_text('dl_amenties'); $data['listing_detial']['ameneties']['tab_desc'] = $amenties; $data['listing_detial']['has_menu'] = $has_menu; $data['listing_detial']['menu']['tab_txt'] = dwt_listing_text('dl_menu'); $data['listing_detial']['menu']['tab_list'] = $menu_objects; $data['listing_detial']['has_location'] = $has_location; $data['listing_detial']['location']['tab_txt'] = dwt_listing_text('dl_location'); $data['listing_detial']['location']['latt'] = $listing_lattitude; $data['listing_detial']['location']['long'] = $listing_longitude; $data['listing_detial']['has_video'] = $has_video; $data['listing_detial']['video']['tab_txt'] = dwt_listing_text('dl_video'); $data['listing_detial']['video']['video_url'] = esc_url($video_link); $data['listing_detial']['video']['video_id'] = esc_attr($video_id); $data['listing_detial']['has_add_fields'] = $has_additional_fields; $data['listing_detial']['additional_fields']['tab_txt'] = dwt_listing_text('dl_custom'); $data['listing_detial']['additional_fields']['list'] = $custom_fields; $data['listing_detial']['has_reviews_score'] = $has_reviews; $data['listing_detial']['reviews']['tab_txt'] = __("Reviews", "dwt-listing-api"); $data['listing_detial']['reviews']['total_avg'] = $total_avg; $data['listing_detial']['reviews']['total_avg_txt'] = $avg_txt; $data['listing_detial']['reviews']['no_of_time_rated'] = $no_of_time_rated; $data['listing_detial']['reviews']['based_on'] = $based_on; $data['listing_detial']['reviews']['total_score'] = $rating_percentage; $data['listing_detial']['listing_comments'] = dwt_listing_fetch_listing_reviews_app($listing_id); // $is_user_logged_in = false; if (is_user_logged_in()) { $is_user_logged_in = true; } $data['listing_detial']['write_reviews']['tab_txt'] = __("Write A Review", "dwt-listing-api"); $data['listing_detial']['write_reviews']['is_user_logged_in'] = $is_user_logged_in; $data['listing_detial']['write_reviews']['message'] = __("Login To Write A Review", "dwt-listing-api"); $data['listing_detial']['write_reviews']['btn_txt'] = __("Submit Reply", "dwt-listing-api"); $data['listing_detial']['write_reviews']['stars_enabled'] = dwt_listing_text('dwt_listing_review_enable_stars'); $data['listing_detial']['write_reviews']['gallery_enabled'] = dwt_listing_text('dwt_listing_review_enable_gallery'); $data['listing_detial']['write_reviews']['for_title_placeholder'] = __("Place attractive title here", "dwt-listing-api"); $data['listing_detial']['write_reviews']['for_area_placeholder'] = __("Your comments, suggestions or experience at this place.", "dwt-listing-api"); $gallery_linkz = array(); $comment_images_up = ''; $comment_images_up = get_user_meta($user_id, 'reviews_comments_images', true); $has_comment_gallery = false; if( $comment_images_up != "" ) { $has_comment_gallery = true; $mediazz = explode( ',', $comment_images_up ); foreach( $mediazz as $mz ) { if ( isset( $mz->ID ) ) { $mid = $mz->ID; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); $gallery_linkz[] = array("urlz" => $source[0], "image_id" => $mid); } else { $mid = $mz; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); $gallery_linkz[] = array("urlz" => $source[0], "image_id" => $mid); } } } $data['listing_detial']['write_reviews']['has_comment_gallery'] = $has_comment_gallery; $data['listing_detial']['write_reviews']['comment_media'] = $gallery_linkz; $screen_txt['screen_title'] = __("Listing Detial", "dwt-listing-api"); return $response = array( 'success' => true, "screen_text" => $screen_txt, 'data' => $data, 'message' => ''); } } // Listing Reviews Reactions add_action( 'rest_api_init', 'dwt_listing_post_reviews', 0 ); function dwt_listing_post_reviews() { register_rest_route( 'downtown/app', '/listing-post-reviews/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_submit_listing_reviews', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_submit_listing_reviews')) { function dwt_listing_submit_listing_reviews($request) { $listing_id = $reaction_id = $comment_id = $get_comment = ''; if ( !is_user_logged_in() ) { return $response = array( 'success' => false, 'data' => '', 'message' => __("You need to logged in", "dwt-listing-api") ); } $user = wp_get_current_user(); $user_id = $user->ID; $json_data = $request->get_json_params(); $comment_id = (isset($json_data['comment_id'])) ? trim($json_data['comment_id']) : ''; $reaction_id = (isset($json_data['reaction_id'])) ? trim($json_data['reaction_id']) : ''; if(!empty($comment_id) && !empty($reaction_id)) { if( get_user_meta($user_id, 'dwt_listing_review_submit_id' . $comment_id, true ) == $comment_id ) { return $response = array( 'success' => false, 'data' => '', 'message' => __("You have already reated on this review.", "dwt-listing-api") ); } else { //get comment listing id and current user id $get_comment = get_comment($comment_id); $listing_id = $get_comment->comment_post_ID; update_user_meta($user_id, 'dwt_listing_review_submit_id' . $comment_id, $comment_id ); if($reaction_id == 1) { if(get_comment_meta($comment_id, 'review_like', true) != "") { $current_count = get_comment_meta($comment_id, 'review_like', true); $update_count = $current_count + 1; update_comment_meta($comment_id, 'review_like', $update_count); dwt_listing_track_activity($listing_id,'like','1'); } else { $update_count = '1'; update_comment_meta($comment_id, 'review_like', $update_count); dwt_listing_track_activity($listing_id,'like','1'); } } if($reaction_id == 2) { if(get_comment_meta($comment_id, 'review_love', true) != "") { $current_count = get_comment_meta($comment_id, 'review_love', true); $update_count = $current_count + 1; update_comment_meta($comment_id, 'review_love', $update_count); dwt_listing_track_activity($listing_id,'like','2'); } else { $update_count = '1'; update_comment_meta($comment_id, 'review_love', $update_count); dwt_listing_track_activity($listing_id,'like','2'); } } if($reaction_id == 3) { if(get_comment_meta($comment_id, 'review_wow', true) != "") { $current_count = get_comment_meta($comment_id, 'review_wow', true); $update_count = $current_count + 1; update_comment_meta($comment_id, 'review_wow', $update_count); dwt_listing_track_activity($listing_id,'like','3'); } else { $update_count = '1'; update_comment_meta($comment_id, 'review_wow', $update_count); dwt_listing_track_activity($listing_id,'like','3'); } } if($reaction_id == 4) { if(get_comment_meta($comment_id, 'review_angry', true) != "") { $current_count = get_comment_meta($comment_id, 'review_angry', true); $update_count = $current_count + 1; update_comment_meta($comment_id, 'review_angry', $update_count); dwt_listing_track_activity($listing_id,'like','4'); } else { $update_count = '1'; update_comment_meta($comment_id, 'review_angry', $update_count); dwt_listing_track_activity($listing_id,'like','4'); } } $data['total_count'] = $update_count; return $response = array( 'success' => true, 'data' => $data, 'message' => '' ); } } else { return $response = array( 'success' => false, 'data' => '', 'message' => __("Something went wrong please try again boy.", "dwt-listing-api") ); } } } // Listing Report Get Service add_action( 'rest_api_init', 'dwt_listing_report', 0 ); function dwt_listing_report() { register_rest_route( 'downtown/app', '/listing-report/', array( 'methods' => WP_REST_Server::READABLE, 'callback' => 'dwt_listing_single_report', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); register_rest_route( 'downtown/app', '/listing-report/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_single_report', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_single_report')) { function dwt_listing_single_report($request) { global $dwt_listing_options; $opt2 = $opt = $data = array(); $data['dialog_txt'] = __("Why are you reporting this listing?", "dwt-listing-api"); $data['dialog_placeholder'] = __("Select a reason", "dwt-listing-api"); $data['dialog_txtarea'] = __("Write your comments.", "dwt-listing-api"); $data['dialog_btn_txt'] = __("Submit", "dwt-listing-api"); if(!empty($dwt_listing_options['report_options'])) { $options = explode( '|', $dwt_listing_options['report_options'] ); if(count($options) > 0) { foreach($options as $option) { $opt[] = array( 'option_name' => esc_attr($option), 'option_value' => esc_attr($option) ); $opt2[] = array( 'value' => esc_attr($option) ); } } } $data['reasons'] = $opt; $data['reasons_updated'] = $opt2; return $response = array( 'success' => true, 'data' => $data, 'message' => '' ); } } // Listing Report Post Service add_action( 'rest_api_init', 'dwt_listing_report_post', 0 ); function dwt_listing_report_post() { register_rest_route( 'downtown/app', '/listing-report/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_report_post_service', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_report_post_service')) { function dwt_listing_report_post_service($request) { global $dwt_listing_options; $listing_id = ''; if ( !is_user_logged_in() ) { return $response = array( 'success' => false, 'data' => '', 'message' => __("You need to logged in", "dwt-listing-api") ); } $json_data = $request->get_json_params(); $report_reason = (isset($json_data['report_reason'])) ? $json_data['report_reason'] : ''; $report_comments = (isset($json_data['report_comments'])) ? $json_data['report_comments'] : ''; $listing_id = (isset($json_data['listing_id'])) ? $json_data['listing_id'] : ''; if( $report_reason == "" ) { $response = array( 'success' => false, 'data' => '' , 'message' => __("Select any reason.", "dwt-listing-api") ); return $response; } if( $report_comments == "" ) { $response = array( 'success' => false, 'data' => '' , 'message' => __("Why are you reporting this listing.", "dwt-listing-api") ); return $response; } if(!empty($listing_id)) { //check if already rated if( get_post_meta( $listing_id, 'dwt_listing_reported_user_id' .$user_id , true ) == $user_id ) { $response = array( 'success' => false, 'data' => '' , 'message' => __("You have reported this listing already.", "dwt-listing-api") ); return $response; } else { update_post_meta( $listing_id, 'dwt_listing_reported_user_id' . $user_id, $user_id ); update_post_meta( $listing_id, 'dwt_listing_report_category' . $user_id, $report_reason ); update_post_meta( $listing_id, 'dwt_listing_report_reason' . $user_id, $report_comments ); $count = get_post_meta( $listing_id, 'dwt_listing_report_count_limit', true ); $count = $count + 1; update_post_meta( $listing_id, 'dwt_listing_report_count_limit', $count ); if( $count >= $dwt_listing_options['report_limit'] ) { if( $dwt_listing_options['report_action'] == '1' ) { $my_post = array('ID' => $listing_id,'post_status'=>'pending'); wp_update_post( $my_post ); } else { // Sending email $to = $dwt_listing_options['report_email']; $subject = __('Ad Reported', 'dwt-listing-api'); $body = '<html><body><p>'.__('Users reported this listing, please check it. ','dwt-listing-api').'<a href="'.get_the_permalink( $listing_id ).'">' . get_the_title( $listing_id ) . '</a></p></body></html>'; $from = get_bloginfo( 'name' ); if( isset( $dwt_listing_options['sb_report_ad_from'] ) && $dwt_listing_options['sb_report_ad_from'] != "" ) { $from = $dwt_listing_options['sb_report_ad_from']; } $headers = array('Content-Type: text/html; charset=UTF-8',"From: $from" ); if( isset( $dwt_listing_options['sb_report_ad_message'] ) && $dwt_listing_options['sb_report_ad_message'] != "" ) { $subject_keywords = array('%site_name%', '%ad_title%'); $subject_replaces = array(get_bloginfo( 'name' ), get_the_title($listing_id)); $subject = str_replace($subject_keywords, $subject_replaces, $dwt_listing_options['sb_report_ad_subject']); $author_id = get_post_field ('post_author', $listing_id); $user_info = get_userdata($author_id); $msg_keywords = array('%site_name%', '%ad_title%', '%ad_link%', '%ad_owner%'); $msg_replaces = array(get_bloginfo( 'name' ), get_the_title($listing_id), get_the_permalink($listing_id), $user_info->display_name ); $body = str_replace($msg_keywords, $msg_replaces, $dwt_listing_options['sb_report_ad_message']); } wp_mail( $to, $subject, $body, $headers ); } } $response = array( 'success' => true, 'data' => '' , 'message' => __("You have reported this listing successfully..", "dwt-listing-api") ); return $response; } } else { $response = array( 'success' => false, 'data' => '' , 'message' => __("Listing Id is required.", "dwt-listing-api") ); return $response; } } } // Listing Claim Get Service add_action( 'rest_api_init', 'dwt_listing_claming', 0 ); function dwt_listing_claming() { register_rest_route( 'downtown/app', '/listing-claim/', array( 'methods' => WP_REST_Server::READABLE, 'callback' => 'dwt_listing_claimz', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_claimz')) { function dwt_listing_claimz() { global $dwt_listing_options; $user_info = $data = array(); $data['dialog_txt'] = __("Claim Listing", "dwt-listing-api"); $data['dialog_btn'] = __("Claim Your Business Now", "dwt-listing-api"); $data['name_label'] = __("Your Name.", "dwt-listing-api"); $data['name_placeholder'] = __("Your Name.", "dwt-listing-api"); $data['contact_label'] = __("Contact Number", "dwt-listing-api"); $data['contact_placeholder'] = __("Phone number or mobile number", "dwt-listing-api"); $data['proof_label'] = __("Additional Proof", "dwt-listing-api"); $data['proof_placeholder'] = __("Additional proof to expedite your claim approval...", "dwt-listing-api"); $response = array( 'success' => true, 'data' => $data); return $response; } } // Listing Claim Post Service add_action( 'rest_api_init', 'dwt_listing_claming_post', 0 ); function dwt_listing_claming_post() { register_rest_route( 'downtown/app', '/listing-claim/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_claimz_post', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_claimz_post')) { function dwt_listing_claimz_post($request) { global $dwt_listing_options; $claimer_message = $claimer_contact = $claimer_name = $claimer_id = $claimer_contact = $claim_listing_id = ''; if (!is_user_logged_in() ) { return $response = array( 'success' => false, 'data' => '', 'message' => __("You need to logged in", "dwt-listing-api") ); } $json_data = $request->get_json_params(); $claim_listing_id = (isset($json_data['claim_listing_id'])) ? $json_data['claim_listing_id'] : ''; $claimer_id = (isset($json_data['claimer_id'])) ? $json_data['claimer_id'] : ''; $claimer_name = (isset($json_data['claimer_name'])) ? $json_data['claimer_name'] : ''; $claimer_contact = (isset($json_data['claimer_contact'])) ? $json_data['claimer_contact'] : ''; $claimer_message = (isset($json_data['claimer_message'])) ? $json_data['claimer_message'] : ''; if( $claimer_name == "") { $response = array( 'success' => false, 'data' => '' , 'message' => __("Please fill out name field.", "dwt-listing-api") ); return $response; } if( $claimer_contact == "") { $response = array( 'success' => false, 'data' => '' , 'message' => __("Please fill out contact field.", "dwt-listing-api") ); return $response; } if( $claimer_message == "") { $response = array( 'success' => false, 'data' => '' , 'message' => __("Please fill out message field.", "dwt-listing-api") ); return $response; } if( $claimer_id == "" ) { $response = array('success' => false, 'data' => '' , 'message' => __("Claimer ID is required.", "dwt-listing-api") ); return $response; } if(!empty($claim_listing_id) && !empty($claimer_id)) { if( get_user_meta($claimer_id, 'dwt_listing_claimed_listing_id' . $claim_listing_id, true ) == $claim_listing_id ) { if (get_post_meta($claim_listing_id, 'd_listing_claim_status', true ) == 'decline' ) { $response = array('success' => false, 'data' => '' , 'message' => __("You claim has been declined.", "dwt-listing-api") ); return $response; } else { $response = array('success' => false, 'data' => '' , 'message' => __("You have claimed this listing already.", "dwt-listing-api") ); return $response; } } else { //get user that claim for listing $user = get_user_by('id', $claimer_id); if($user){ $user_id = $user->ID; $claimer_name = $user->display_name; $claimer_email = $user->user_email; } $status = 'pending'; //get post title $listing_post_title = get_the_title($claim_listing_id); // Create post object $my_post = array( 'post_title' => wp_strip_all_tags($listing_post_title), 'post_status' => 'publish', 'post_author' => $claimer_id, 'post_type' => 'l_claims', ); // Insert the post into the database $new_inserted_id = wp_insert_post( $my_post ); //Update post meta values update_post_meta($new_inserted_id, 'd_listing_original_id', $claim_listing_id ); update_post_meta($new_inserted_id, 'd_listing_claimer_id', $claimer_id ); update_post_meta($new_inserted_id, 'd_listing_claimer_msg', $claimer_message ); dwt_listing_l_claims_admin_tables_content('dwt_listing_claim_status',$status,$new_inserted_id); dwt_listing_l_claims_admin_tables_content('dwt_listing_claimner_no',$claimer_contact,$new_inserted_id); update_user_meta($claimer_id, 'dwt_listing_claimed_listing_id' . $claim_listing_id, $claim_listing_id ) ; // Sending email to admin if( isset( $dwt_listing_options['dwt_listing_is_admin_email'] ) && $dwt_listing_options['dwt_listing_is_admin_email'] == '1') { // Sending email to admin $listing_owner_id = dwt_listing_listing_owner($claim_listing_id,'id'); $listing_owner_name = dwt_listing_listing_owner($claim_listing_id,'name'); $to = get_option( 'admin_email' ); $subject = __('Claim Listing', 'dwt-listing-framework'); $body = '<html><body><p>'.__('Users claim this listing, please check it. ','dwt-listing-framework').'<a href="'.get_the_permalink( $claim_listing_id ).'">' . get_the_title( $claim_listing_id ) . '</a></p></body></html>'; $from = get_bloginfo( 'name' ); if( isset( $dwt_listing_options['downtwon_listing_claim_from'] ) && $dwt_listing_options['downtwon_listing_claim_from'] != "" ) { $from = $dwt_listing_options['downtwon_listing_claim_from']; } $headers = array('Content-Type: text/html; charset=UTF-8',"From: $from" ); if( isset( $dwt_listing_options['downtwon_listing_claim_message'] ) && $dwt_listing_options['downtwon_listing_claim_message'] != "" ) { $subject_keywords = array('%site_name%', '%ad_title%'); $subject_replaces = array(get_bloginfo( 'name' ), get_the_title($claim_listing_id)); $subject = str_replace($subject_keywords, $subject_replaces, $dwt_listing_options['downtwon_listing_subject']); $author_id = get_post_field ('post_author', $claim_listing_id); $user_info = get_userdata($author_id); $msg_keywords = array('%site_name%', '%ad_title%', '%ad_link%', '%ad_owner%' , '%claimed_by%' ,'%claimer_email%','%claimer_contact%','%claim_details%'); $msg_replaces = array(get_bloginfo( 'name' ), get_the_title($claim_listing_id), get_the_permalink($claim_listing_id), $listing_owner_name, $claimer_name, $claimer_email,$claimer_contact,$claimer_message); $body = str_replace($msg_keywords, $msg_replaces, $dwt_listing_options['downtwon_listing_claim_message']); } wp_mail( $to, $subject, $body, $headers ); } $response = array( 'success' => true, 'data' => '' , 'message' => __("Your claim has been submitted successfully & waiting for approval.", "dwt-listing-api") ); return $response; } } else { $response = array( 'success' => false, 'data' => '' , 'message' => __("Listing Id is required.", "dwt-listing-api")); return $response; } } } // Listing Load More Reviews Pagination add_action( 'rest_api_init', 'dwt_listing_load_more_reviews', 0 ); function dwt_listing_load_more_reviews() { register_rest_route( 'downtown/app', '/listing-more-reviews/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_fetch_more_reviews', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_fetch_more_reviews')) { function dwt_listing_fetch_more_reviews($request) { $listing_id = $next_page = ''; $data = array(); $json_data = $request->get_json_params(); $listing_id = (isset($json_data['listing_id'])) ? trim($json_data['listing_id']) : ''; $next_page = (isset($json_data['next_page'])) ? trim($json_data['next_page']) : ''; if($listing_id && $next_page) { $data['listing_comments'] = dwt_listing_fetch_listing_reviews_app($listing_id, $next_page); return $response = array( 'success' => true, 'data' => $data); } } } // Listing Bookmark Post add_action( 'rest_api_init', 'dwt_listing_book', 0 ); function dwt_listing_book() { register_rest_route( 'downtown/app', '/listing-bookmark/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_book_listing', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_book_listing')) { function dwt_listing_book_listing($request) { global $dwt_listing_options; if (!is_user_logged_in()) { return $response = array( 'success' => false, 'data' => '', 'message' => __("You need to logged in", "dwt-listing-api") ); } $json_data = $request->get_json_params(); if(!empty($json_data['listing_id'])) { $user = wp_get_current_user(); $user_id = $user->ID; $listing_id = $json_data['listing_id']; if( get_user_meta($user_id, 'dwt_listing_fav_listing_id'.$listing_id, true) == $listing_id ) { $response = array( 'success' => true, 'data' => '' , 'message' => __("You have bookmark this listing already.", "dwt-listing-api") ); return $response; } else { update_user_meta($user_id, 'dwt_listing_fav_listing_id' . $listing_id, $listing_id ) ; $response = array( 'success' => true, 'data' => '' , 'message' => __("Added to your favourites.", "dwt-listing-api") ); return $response; } } else { return $response = array( 'success' => false, 'data' => '' , 'message' => __("Listing Id is required.", "dwt-listing-api")); } } } // Remove Personal Listings Ad add_action( 'rest_api_init', 'dwt_p_listing_remove', 0 ); function dwt_p_listing_remove() { register_rest_route( 'downtown/app', '/listing-del/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_p_listing_del', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if ( ! function_exists( 'dwt_p_listing_del' ) ) { function dwt_p_listing_del($request) { global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $json_data = $request->get_json_params(); $listing_id = isset($json_data['listing_id']) ? sanitize_text_field($json_data['listing_id']) : ''; if(!empty($listing_id)) { if( dwt_listing_text('dwt_listing_disable_edit') == '1' && !is_super_admin($user_id)) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Disable for Demo.", 'dwt-listing-api'))); } if( wp_trash_post($listing_id)) { return rest_ensure_response(array( 'success' => true, 'data' => '', 'message' => __("Listing removed successfully.", 'dwt-listing-api'))); } else { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __("An error occurred, please try again later.", 'dwt-listing-api'))); } } else { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __("Whoops Listing ID is required.", 'dwt-listing-api'))); } } } // Pull to refresh current listing tab add_action( 'rest_api_init', 'dwt_p_listing_pull', 0 ); function dwt_p_listing_pull() { register_rest_route( 'downtown/app', '/pull-listings/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_p_listing_pull_listings', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_p_listing_pull_listings')) { function dwt_p_listing_pull_listings($request) { global $dwt_listing_api; $param = $request->get_json_params(); $data = array(); if(isset($param['listing_type']) && $param['listing_type'] !="" ) { $event_type = $param['listing_type']; $user = wp_get_current_user(); $user_id = $user->ID; $limit = 10; if(isset($dwt_listing_api['app_dashboard_user_listings']) && $dwt_listing_api['app_dashboard_user_listings'] !="") { $limit = $dwt_listing_api['app_dashboard_user_listings']; } $data = dwt_listing_fetch_owner_listings_inapp($event_type,$limit,$user_id); return rest_ensure_response(array( 'success' => true, 'data' => $data)); } } } // Soft Expire Personal Listings add_action( 'rest_api_init', 'dwt_p_listing_exp', 0 ); function dwt_p_listing_exp() { register_rest_route( 'downtown/app', '/expire-listings/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_p_listing_pull_listings_exp', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_p_listing_pull_listings_exp')) { function dwt_p_listing_pull_listings_exp($request) { global $dwt_listing_api; $param = $request->get_json_params(); $user = wp_get_current_user(); $user_id = $user->ID; $data = array(); if(isset($param['listing_id']) && $param['listing_id'] !="" ) { $listing_id = $param['listing_id']; if( dwt_listing_text('dwt_listing_disable_edit') == '1' && !is_super_admin($user_id)) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Disable for Demo.", 'dwt-listing-api'))); } //zero means its expire $status = '0'; update_post_meta($listing_id, 'dwt_listing_listing_status', $status ); return rest_ensure_response(array( 'success' => true, 'data' => '', 'message' => __("Listing Expired Successfully.", 'dwt-listing-api'))); } else { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __("Something went wrong please try later.", 'dwt-listing-api'))); } } } // Re-Active Soft Expire Listings add_action( 'rest_api_init', 'dwt_p_listing_exp_reactive', 0 ); function dwt_p_listing_exp_reactive() { register_rest_route( 'downtown/app', '/expire-listings-reactive/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_p_listing_pull_listings_exp_reactive', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_p_listing_pull_listings_exp_reactive')) { function dwt_p_listing_pull_listings_exp_reactive($request) { global $dwt_listing_api; $param = $request->get_json_params(); $data = array(); $user = wp_get_current_user(); $user_id = $user->ID; if(isset($param['listing_id']) && $param['listing_id'] !="" ) { $listing_id = $param['listing_id']; if( dwt_listing_text('dwt_listing_disable_edit') == '1' && !is_super_admin($user_id)) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Disable for Demo.", 'dwt-listing-api'))); } //zero means its expire $status = '1'; update_post_meta($listing_id, 'dwt_listing_listing_status', $status ); return rest_ensure_response(array( 'success' => true, 'data' => '', 'message' => __("Listing Active successfully.", 'dwt-listing-api'))); } else { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __("Something went wrong please try later.", 'dwt-listing-api'))); } } } /*Submit Listing Review On Detial Page*/ add_action( 'rest_api_init', 'dwt_submit_review_screen', 0 ); function dwt_submit_review_screen() { register_rest_route( 'downtown/app', '/submit-review/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_submit_review_screen_main', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_submit_review_screen_main')) { function dwt_submit_review_screen_main($request) { global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $user_name = $user->display_name; $user_email = $user->user_email; $json_data = $request->get_json_params(); $comment_title = (isset($json_data['comment_title'])) ? sanitize_text_field($json_data['comment_title']) : ''; $comment_desc = (isset($json_data['comment_desc'])) ? sanitize_text_field($json_data['comment_desc']) : ''; $comment_stars = (isset($json_data['comment_stars'])) ? sanitize_text_field($json_data['comment_stars']) : ''; $listing_id = (isset($json_data['listing_id'])) ? sanitize_text_field($json_data['listing_id']) : ''; if(empty($comment_title)) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __("Title is required.", "dwt-listing-api"))); } if(empty($comment_desc)) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __("Comment content is required.", "dwt-listing-api"))); } if(!is_user_logged_in()) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __("You need to logged in", "dwt-listing-api"))); } if( dwt_listing_text('dwt_listing_disable_edit') == '1' && !is_super_admin($user_id)) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Disable for Demo.", 'dwt-listing-api'))); } if(!empty($listing_id)) { //owner cant post rating if( get_post_field('post_author', $listing_id) == $user_id) { return rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => __("Listing author can't post review.", "dwt-listing-api"))); } else { //insert data $comments_approval = '0'; $comment_status = ''; $comments_approval = $dwt_listing_options['dwt_listing_review_permission']; $time = current_time('mysql'); $data = array( 'comment_post_ID' => $listing_id, 'comment_author' => $user_name, 'comment_author_email' => $user_email, 'comment_author_url' => '', 'comment_content' => $comment_desc, 'comment_type' => 'listing', 'user_id' => $user_id, 'comment_author_IP' => '', 'comment_date' => $time, 'comment_approved' => $comments_approval, ); $comment_id = wp_insert_comment($data); if($comment_id) { dwt_listing_track_activity($listing_id,'comments','yes',$comment_id); //if there is any image in user review field if(get_user_meta($user_id, 'reviews_comments_images', true) != "") { $get_diz = get_user_meta($user_id, 'reviews_comments_images', true); update_comment_meta($comment_id, 'review_images_idz', $get_diz); //remove image idz from user meta update_user_meta( $user_id, 'reviews_comments_images', '' ); } //not null if($comment_stars !="") { update_comment_meta($comment_id, 'review_stars', $comment_stars); } update_comment_meta($comment_id, 'review_main_title', $comment_title); dwt_listing_track_activity($listing_id,'rating',$comment_stars,$comment_id); //send email if( isset($dwt_listing_options['dwt_listing_review_send_email']) && $dwt_listing_options['dwt_listing_review_send_email'] == "1" && $comments_approval == 1) { // Sending email to listing owner $listing_owner_email = dwt_listing_listing_owner($listing_id,'email'); $listing_owner_name = dwt_listing_listing_owner($listing_id,'name'); $to = $listing_owner_email; $subject = __('New Review', 'dwt-listing-framework'); $body = '<html><body><p>'.__('You have a new review, please check it. ','dwt-listing-framework').'<a href="'.get_the_permalink( $listing_id ).'">' . get_the_title( $listing_id ) . '</a></p></body></html>'; $from = get_bloginfo( 'name' ); if( isset( $dwt_listing_options['downtwon_review_comment_email_from'] ) && $dwt_listing_options['downtwon_review_comment_email_from'] != "" ) { $from = $dwt_listing_options['downtwon_review_comment_email_from']; } $headers = array('Content-Type: text/html; charset=UTF-8',"From: $from" ); if( isset( $dwt_listing_options['downtwon_review_comment_email_message'] ) && $dwt_listing_options['downtwon_review_comment_email_message'] != "" ) { $subject_keywords = array('%site_name%', '%ad_title%'); $subject_replaces = array(get_bloginfo( 'name' ), get_the_title($listing_id)); $subject = str_replace($subject_keywords, $subject_replaces, $dwt_listing_options['downtwon_review_comment_email_change']); $author_id = get_post_field ('post_author', $listing_id); $user_info = get_userdata($author_id); $msg_keywords = array('%listing_owner_name%', '%ad_title%', '%ad_link%', '%listng_comment%'); $msg_replaces = array($listing_owner_name, get_the_title($listing_id), get_the_permalink($listing_id), $review_comments); $body = str_replace($msg_keywords, $msg_replaces, $dwt_listing_options['downtwon_review_comment_email_message']); wp_mail( $to,$subject,$body,$headers); } } $comment_status = wp_get_comment_status($comment_id); if ( $comment_status == "approved" ) { return rest_ensure_response(array( 'success' => true, 'data' => '' , 'message' => __("Review Posted Successfully.", "dwt-listing-api"))); } else { return rest_ensure_response(array( 'success' => true, 'data' => '' , 'message' => __("Review posted successfully & waiting for admin approval.", "dwt-listing-api"))); } } else { return rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => __("Please try again later.", "dwt-listing-api"))); } } } else { return rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => __("Listing Id is required.", "dwt-listing-api"))); } } }
[+]
..
[-] events.php
[edit]
[-] author-listings.php
[edit]
[-] fetch_data.php
[edit]
[-] forget.php
[edit]
[-] categories.php
[edit]
[-] listing-detail.php
[edit]
[-] packages.php
[edit]
[-] home.php
[edit]
[+]
packages
[-] reviews.php
[edit]
[+]
submit-listing
[-] profile.php
[edit]
[-] register.php
[edit]
[-] settings.php
[edit]
[-] events-search.php
[edit]
[-] listing-search.php
[edit]
[+]
profile
[-] event-detail.php
[edit]
[-] login.php
[edit]
[+]
payments
[-] blog.php
[edit]