PATH:
home
/
letacommog
/
laindinois
/
OLD
/
wp-content
/
plugins
/
downtown-rest-api
<?php /*Sonu Code Here*/ // Fetch users leads & activities if ( ! function_exists( 'dwt_listing_fetch_leads_activities_app' ) ) { function dwt_listing_fetch_leads_activities_app($user_id) { global $wpdb; global $dwt_listing_api; $total_leads = $response = ''; $next = ''; $likes = array(1 => esc_html__('Like','dwt-listing-api'),2 => esc_html__('Love','dwt-listing-api'),3 => esc_html__('Wow','dwt-listing-api'),4 => esc_html__('Angry','dwt-listing-api')); $emotion_icons = array(1 => 'like',2 => 'love',3 => 'emoji',4 => 'dislike'); $leads = array('contact' => esc_html__('Contact No','dwt-listing-api'),'web' => esc_html__('Website Link','dwt-listing-api')); $leads_icons = array('contact' => 'mobile','web' => 'globle'); $query_args = array( 'author' => $user_id, 'post_type' => 'listing' , 'post_status' => 'publish' ); $query = new WP_Query( $query_args ); $listing_id = ''; if ( $query->have_posts() ) { while($query->have_posts()) { $query->the_post(); $listing_id .= get_the_ID() .','; } } $listing_id = rtrim($listing_id,","); if(!empty($listing_id)) { $leads_limit = 10; if(isset( $dwt_listing_api['app_dashboard_leads']) && $dwt_listing_api['app_dashboard_leads'] !="") { $leads_limit = $dwt_listing_api['app_dashboard_leads']; } $page = 1; $results = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key LIKE '_activity_%' AND post_id IN ($listing_id) ORDER BY meta_id DESC LIMIT ".$page.", ".$leads_limit."" ); if(is_array($results) && count($results) > 0) { foreach($results as $result) { $post_id = $result->post_id; $user_name = ''; $icon = ''; $statement = ''; $user_id =''; $get_time = ''; $get_time = explode('_',$result->meta_value); $activity_time = $get_time[0]; $activity_value = $get_time[1]; $activity_time = strtotime($activity_time); $reaction = (isset($likes[$activity_value])) ? $likes[$activity_value] : ''; $get_uid = explode('_', $result->meta_key); $get_uid[4]; $user = get_user_by('id', $get_uid[4]); if ( ! empty( $user ) ) { $user_name = $user->display_name; $user_id = $user->ID; } else { $user_name = esc_html__('Someone','dwt-listing-api'); $user_id = ''; } $on = esc_html__(' on','dwt-listing-api'); $clicked = esc_html__('clicked your ','dwt-listing-api'); $reacted = esc_html__('reacted as ','dwt-listing-api'); $ago = esc_html__(' ago','dwt-listing-api'); $type = ''; if (strpos($result->meta_key, 'leads_userid_unknown')) { $icon = 'bell'; $reaction = (isset($leads[$activity_value])) ? $leads[$activity_value] : ''; $statement = $clicked . $reaction .$on; } else if (strpos($result->meta_key, 'rating')) { $icon = 'star'; $statement = __('posted a Rating on','dwt-listing-api'); } else if (strpos($result->meta_key, 'comments')) { $icon = 'comment'; $statement = __('post a Comment on','dwt-listing-api'); } else if (strpos($result->meta_key, 'like')) { $icon = (isset($emotion_icons[$activity_value])) ? $emotion_icons[$activity_value] : ''; $statement = $reacted. $reaction .$on; } else if (strpos($result->meta_key, 'leads')) { $icon = (isset($leads_icons[$activity_value])) ? $leads_icons[$activity_value] : ''; $reaction = (isset($leads[$activity_value])) ? $leads[$activity_value] : ''; $statement = $clicked .$reaction .$on; } $lead_activities[] = array( "user_name" => $user_name, "user_id" => $user_id, "listing_title" => dwt_listing_convert_uniText(get_the_title($post_id)), "statement" => $statement, "icon_type" => $icon, "activity_time" => human_time_diff($activity_time, current_time('timestamp')) . $ago ); } $data['lead_activities'] = $lead_activities; //leads pagination $total_leads = $wpdb->get_var("SELECT count(meta_id) from $wpdb->postmeta WHERE meta_key LIKE '_activity_%' AND post_id IN ($listing_id) ORDER BY meta_id DESC"); $next = $page + 1; $lastpage = ceil($total_leads/$leads_limit); $has_next_page = ($next <= (int)$lastpage) ? true : false; $data['pagination'] = array("total_leads" => $total_leads, "current_page" => (int)$page, "next_page" => (int)$next, "has_next_page" => $has_next_page ); $response = array( 'success' => true, 'data' => $data , 'message' => ''); wp_reset_postdata(); return $response; } else { $response = array( 'success' => false, 'data' => '' , 'message' => __("Recent activities about your listings will be here!", "dwt-listing-api") ); return $response; } } else { $response = array( 'success' => false, 'data' => '' , 'message' => __("Recent activities about your listings will be here!", "dwt-listing-api") ); return $response; } } } //Fetch all Listings if ( ! function_exists( 'dwt_listing_fetch_owner_listings_inapp' ) ) { function dwt_listing_fetch_owner_listings_inapp($listing_status, $limit , $user_id) { $response = ''; $meta_query_args = $listingz = array(); $meta_key = ''; $meta_value = ''; $meta_compare = '='; if($listing_status == 'publish') { $listing_status = 'publish'; $meta_query_args = array(array('key'=>'dwt_listing_listing_status','value' => 1,'compare' => '=')); } else if($listing_status == 'pending') { $listing_status = 'pending'; } else if($listing_status == 'featured') { $listing_status = 'publish'; $meta_key = 'dwt_listing_is_feature'; $meta_value = '1'; } else if($listing_status == 'expired') { $listing_status = 'publish'; $meta_key = 'dwt_listing_listing_status'; $meta_value = '0'; } else { $listing_status = 'publish'; $meta_query_args = array(array('key'=>'dwt_listing_listing_status','value' => 1,'compare' => '=')); } $page = 1; $args = array ( 'post_type' => 'listing', 'author' => $user_id, 'post_status' => $listing_status, 'posts_per_page' => $limit, 'paged' => $page, 'order'=> 'DESC', 'orderby' => 'date', 'meta_key' => $meta_key , 'meta_value' =>$meta_value, 'meta_query' => $meta_query_args ); $my_listings = new WP_Query( $args ); if ( $my_listings->have_posts() ) { $lists = array(); $pieces = $category_name = $categor_id = $listing_cats = $total_leads = $contact_leads = $web_leads = $total_views = $status_type = $b_status = $is_featured = ''; while ( $my_listings->have_posts() ) { $my_listings->the_post(); $listing_id = get_the_ID(); $media = dwt_listing_fetch_listing_gallery($listing_id); $is_featured = dwt_listing_is_listing_featured_app($listing_id); if(dwt_listing_business_hours_status($listing_id) !="") { $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 if($status_type == 2) { $b_status = esc_html__('Always Open','dwt-listing-api'); $color_code = '#fc0'; } else { $b_status = esc_html__('Open Now','dwt-listing-api'); $color_code = '#25a25a'; } } if(get_post_meta( $listing_id, '_dowtown_web_leads',true) !="") { $web_leads = get_post_meta( $listing_id, '_dowtown_web_leads',true); } if(get_post_meta( $listing_id, '_dowtown_contact_leads',true) !="") { $contact_leads = get_post_meta( $listing_id, '_dowtown_contact_leads',true); } if($web_leads != 0 && $contact_leads !=0) { $total_leads = $web_leads + $contact_leads; } $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]; } if( function_exists('pvc_get_post_views') ) $total_views = pvc_get_post_views( $listing_id); $listingz[] = array( "listing_id" => $listing_id , "category_id" => $categor_id , "category_name" => dwt_listing_convert_uniText($category_name), "listing_title" => dwt_listing_convert_uniText(get_the_title($listing_id)) , "image" => dwt_listing_return_listing_idz($media,'downtown-mylistings'), "is_featured" => $is_featured, "business_hours_status" => $b_status, "color_code" => $color_code, "total_views" => $total_views, "web_clicks" => $web_leads, "contact_clicks" => $contact_leads, "total_click" => $total_leads, "posted_date" => get_the_date(get_option('date_format'),$listing_id), ); } wp_reset_postdata(); } $lists['has_list'] = (count((array) $listingz) > 0) ? true : false; if(count((array) $listingz) > 0) { $lists['listing'] = $listingz; } else { $lists['message'] = __("You don't have any listing yet!", "dwt-listing-api"); } $has_next_page = $lastpage = $next = ''; //pagination $next = $page + 1; $lastpage = ceil($my_listings->found_posts/$limit); $has_next_page = ($next <= (int)$lastpage) ? true : false; $lists[$listing_status.'_'.'pagination'] = array("total_listings" => $my_listings->found_posts, "current_page" => (int)$page, "next_page" => (int)$next, "has_next_page" => $has_next_page ); return $lists; } } //Return Profile Data if (!function_exists('dwt_listing_basic_profile_data')){ function dwt_listing_basic_profile_data($user_id = '') { if( $user_id == "" ) { $user = wp_get_current_user(); $user_id = $user->ID; } else { $user = get_userdata( $user_id ); } if(!$user_id) return ''; $profile_arr['id'] = $user_id; $profile_arr['name'] = $user->display_name; $profile_arr['email'] = $user->user_email; $profile_arr['street_address'] = get_user_meta($user_id, 'd_user_location', true ); $profile_arr['phone_no'] = get_user_meta($user_id, 'd_user_contact', true ); $profile_arr['user_timezone'] = get_user_meta($user_id, 'd_user_timezone', true ); $profile_arr['about_user'] = get_user_meta($user_id, 'd_about_user', true ); $profile_arr['fb_link'] = get_user_meta($user_id, 'd_fb_link', true ); $profile_arr['google_link'] = get_user_meta($user_id, 'd_google_link', true ); $profile_arr['twitter_link'] = get_user_meta($user_id, 'd_twitter_link', true ); $profile_arr['linkedin_link'] = get_user_meta($user_id, 'd_linked_link', true ); $profile_arr['profile_img'] = dwt_listing_get_user_dp($user_id,'downtown-user-dp'); $has_pkg = false; if( get_user_meta($user_id, 'd_user_package_id', true ) != "" ) { $has_pkg = true; } $profile_arr['have_pkg'] = $has_pkg; /*all active ads*/ //publish listings $ads_total_text = __("All Listings", "dwt-listing-api"); $profile_arr['all_listings'] = $ads_total_text; $valz = dwt_listing_listing_total_count('publish','dwt_listing_listing_status','1',$user_id); $profile_arr['all_listings_count'] = (int)dwt_listing_listing_total_count('publish','dwt_listing_listing_status','1',$user_id); //pending listings $pending_text = __("Pending Listings", "dwt-listing-api"); $profile_arr['pending_listings'] = $pending_text; $profile_arr['pending_listings_count'] = dwt_listing_listing_total_count('pending','dwt_listing_listing_status','1',$user_id); $profile_arr['pending_listings_msg'] = __('Waiting for admin approval.','dwt-listing-api'); //featured listings $featured_text = __("Featured Listings", "dwt-listing-api"); $profile_arr['featured_listings'] = $featured_text; $profile_arr['featured_listings_count'] = (int)dwt_listing_listing_total_count('publish','dwt_listing_is_feature','1',$user_id); //featured listings $expired_text = __("Expired Listings ", "dwt-listing-api"); $profile_arr['expired_listings'] = $expired_text; $profile_arr['expired_listings_count'] = (int)dwt_listing_listing_total_count('publish','dwt_listing_listing_status','0',$user_id); $rec_reviesc_text = __("Received Reviews", "dwt-listing-api"); $profile_arr['received_rev'] = $rec_reviesc_text; $profile_arr['received_rev_count'] = (int)dwt_listing_received_reviews($user_id); $submitted_reviesc_text = __("Submited Reviews", "dwt-listing-api"); $profile_arr['submitted_rev'] = $submitted_reviesc_text; $profile_arr['submitted_rev_count'] = (int)dwt_listing_submitted_reviews($user_id); $t_event_text = __("Total Events", "dwt-listing-api"); $profile_arr['total_events_text'] = $t_event_text; $profile_arr['total_events_count'] = (int)dwt_listing_get_all_events_count($user_id); $t_event_active = __("Active Events", "dwt-listing-api"); $profile_arr['total_events_active'] = $t_event_active; $profile_arr['active_events_count'] = (int)dwt_listing_get_events_status_count($user_id,'1'); return $profile_arr; } } //Fetch all bookmarks listings if (!function_exists('dwt_listing_fetch_bookmark_listings')) { function dwt_listing_fetch_bookmark_listings_inapp($user_id,$paged = '') { global $wpdb; $rows = $wpdb->get_results( "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key LIKE 'dwt_listing_fav_listing_id%'" ); $listing_idz = array(0); foreach( $rows as $row ) { $listing_idz[] = $row->meta_value; } $args = array( 'post_type' => 'listing', 'post__in' => $listing_idz, 'post_status' => 'publish', 'posts_per_page' => get_option( 'posts_per_page' ), 'paged' => $paged, 'order'=> 'DESC', 'orderby' => 'ID' ); return $args; } } //Received Reviews if ( ! function_exists( 'dwt_listing_fetch_my_reviewz' ) ) { function dwt_listing_fetch_my_reviewz($user_id) { $param = array('status'=>'approve','post_type' => 'listing', 'post_author__in' => array($user_id), 'orderby' => 'post_date' ,'order' => 'DESC'); $comments = get_comments($param); $has_comments = false; if(count((array) $comments) > 0 ) { $has_reply = ''; $has_comments = true; foreach($comments as $comment) { $reply_comment_id = ''; $replier_msg = ''; $comment_id = $comment->comment_ID; $listing_id = $comment->comment_post_ID; $commenter_dp = dwt_listing_fetch_comment_poster($comment->user_id,'dp'); $rated = get_comment_meta($comment_id, 'review_stars', true); $main_title = get_comment_meta( $comment_id, 'review_main_title', true ); //fetch replies of that post $replies = get_comments( array( 'parent' => $comment_id, 'status' => 'approve', 'orderby' => 'comment_date' , 'order' => 'DESC' ) ); $has_reply = false; $reply_comment = array(); if(count((array) $replies) > 0) { $has_reply = true; foreach($replies as $reply) { $reply_comment_id = $reply->comment_ID; $replier_msg = esc_attr($reply->comment_content); $reply_comment[] = array("replyer_message" => $replier_msg); } } $statement = __(' posted a review on','dwt-listing-api'); $received_cmntz[] = array( "comment_id" => $comment_id, "listing_id" => $listing_id, "commenter_name" => esc_attr($comment->comment_author), "commenter_dp" => $commenter_dp, "commenter_id" => $comment->user_id, "listing_title" => get_the_title($listing_id) , "listing_link" => get_the_permalink($listing_id), "statement" => $statement, "rating_stars" => $rated, "total_rating" => ($rated.'/'.'5'), "comment_desc" => esc_attr($comment->comment_content), "comment_time" => date_i18n( 'j F, Y', strtotime( get_the_time($comment->comment_date) ) ), "has_reply" => $has_reply, "replyed_comment_id" => $reply_comment_id, "reply_comment" => $reply_comment ); } $lists['has_comments'] = $has_comments; $lists['commnets'] = $received_cmntz; } else { $lists['has_comments'] = $has_comments; $lists['message'] = __("Your don't received any review yet!", "dwt-listing-api"); } return $lists; } } //Submitted Reviews if ( ! function_exists( 'dwt_listing_fetch_my_submitted_reviewz' ) ) { function dwt_listing_fetch_my_submitted_reviewz($user_id) { $param = array('status'=>'approve','user_id'=>$user_id,'post_type' => 'listing', 'orderby' => 'post_date' ,'order' => 'DESC'); $comments = get_comments($param); $has_comments = false; if(count((array) $comments) > 0 ) { foreach($comments as $comment) { $has_comments = true; $comment_id = $comment->comment_ID; $listing_id = $comment->comment_post_ID; $commenter_dp = dwt_listing_fetch_comment_poster($comment->user_id,'dp'); $rated = get_comment_meta($comment_id, 'review_stars', true); $main_title = get_comment_meta( $comment_id, 'review_main_title', true ); $main_desc = esc_attr($comment->comment_content); //comments gallery $has_media = false; $gallery_link = array(); if(get_comment_meta($comment_id, 'review_images_idz', true ) !="") { $has_media = true; $comment_images = get_comment_meta($comment_id, 'review_images_idz', true); if($comment_images !="") { $media = explode( ',', $comment_images ); foreach( $media as $m ) { if ( isset( $m->ID ) ) { $mid = $m->ID; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); //$gallery_link[] = $source[0]; $gallery_link[] = array("urlz" => $source[0], "image_id" => $mid); } else { $mid = $m; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); //$gallery_link[] = $source[0]; $gallery_link[] = array("urlz" => $source[0], "image_id" => $mid); } } } } $statement = __(' submitted a review on','dwt-listing-api'); $submitted_cmntz[] = array( "comment_id" => $comment_id, "listing_id" => $listing_id, "commenter_name" => esc_attr($comment->comment_author), "commenter_dp" => $commenter_dp, "commenter_id" => $comment->user_id, "listing_title" => get_the_title($listing_id) , "listing_link" => get_the_permalink($listing_id), "statement" => $statement, "rating_stars" => $rated, "total_rating" => ($rated.'/'.'5'), "comment_desc" => esc_attr($comment->comment_content), "comment_time" => date_i18n( 'j F, Y', strtotime( get_the_time($comment->comment_date) ) ), "comment_form_title" => $main_title, "comment_form_desc" => esc_attr($comment->comment_content), "has_media" => $has_media, "comment_media" => $gallery_link, ); } $lists['has_comments'] = $has_comments; $lists['commnets'] = $submitted_cmntz; } else { $lists['has_comments'] = $has_comments; $lists['message'] = __("Your haven't submitted any review yet!", "dwt-listing-api"); } return $lists; } } //Fetch All Events if ( ! function_exists( 'dwt_listing_fetch_owner_eventz_inapp' ) ) { function dwt_listing_fetch_owner_eventz_inapp($event_status, $paged = '', $user_id) { $eventz = array(); $meta_query_args = array(); $total_views = $meta_key = ''; $meta_value = ''; $meta_compare = '='; if($event_status == 'publish') { $event_status = 'publish'; $meta_query_args = array(array('key'=>'dwt_listing_event_status','value' => 1,'compare' => '=')); } else if($event_status == 'pending') { $event_status = 'pending'; } else if($event_status == 'expired') { $event_status = 'publish'; $meta_key = 'dwt_listing_event_status'; $meta_value = '0'; } else { $event_status = 'publish'; $meta_query_args = array(array('key'=>'dwt_listing_event_status','value' => 1,'compare' => '=')); } $get_args = array ( 'post_type' => 'events', 'author' => $user_id, 'post_status' => $event_status, 'posts_per_page' => -1, 'order'=> 'DESC', 'orderby' => 'date', 'meta_key' => $meta_key, 'meta_value' =>$meta_value, 'meta_query' => $meta_query_args ); $my_events = new WP_Query( $get_args ); $event_venue_loc = $event_end = $event_start = $term_list = $event_venue = $event_end_date = $media =$event_start_date = ''; if ( $my_events->have_posts() ) { $lists = array(); while ( $my_events->have_posts() ) { $my_events->the_post(); $event_id = get_the_ID(); //get media $media = dwt_listing_fetch_event_gallery($event_id); $event_start_date = get_post_meta($event_id, 'dwt_listing_event_start_date', true ); $event_end_date = get_post_meta($event_id, 'dwt_listing_event_end_date', true ); $event_venue = get_post_meta($event_id, 'dwt_listing_event_venue', true); $term_list = wp_get_post_terms($event_id, 'l_event_cat', array("fields" => "names")); if($event_start_date !="") { $event_start = date_i18n( get_option( 'date_format').' '.get_option( 'time_format'), strtotime( $event_start_date ) ); } if($event_end_date !="") { $event_end = date_i18n( get_option( 'date_format').' '.get_option( 'time_format'), strtotime( $event_end_date ) ); } if($event_venue !="") { $event_venue_loc = $event_venue; } if( function_exists('pvc_get_post_views') ) { $total_views = pvc_get_post_views( $event_id); } $event_cat = ''; if(!empty($term_list) && count($term_list) > 0) { $event_cat = $term_list[0] ; } $eventz[] = array( "event_id" => $event_id , "category_name" => $event_cat , "event_title" => get_the_title($event_id) , "event_to" => $event_start, "event_from" => $event_end , "event_venue" => $event_venue_loc , "featured_img" => dwt_listing_return_listing_idz($media,'downtown-mylistings'), "total_views" => $total_views, ); } wp_reset_postdata(); } $lists['has_events'] = (count((array) $eventz) > 0) ? true : false; if(count((array) $eventz) > 0) { $lists['events'] = $eventz; } else { $lists['message'] = __("You don't have any event", "dwt-listing-api"); } return $lists; } } if ( ! function_exists( 'dwt_listing_fetch_my_listings_inapp' ) ) { function dwt_listing_fetch_my_listings_inapp($user_id) { $mylisting = array(); $meta_query_args = array(array('key'=>'dwt_listing_listing_status','value' => 1,'compare' => '=')); $args = array ( 'post_type' => 'listing', 'author' => $user_id, 'post_status' => 'publish', 'posts_per_page' => -1, 'order'=> 'DESC', 'orderby' => 'date', 'meta_query' => $meta_query_args ); $my_listings = new WP_Query( $args ); if ( $my_listings->have_posts() ) { while ( $my_listings->have_posts() ) { $my_listings->the_post(); $listing_id = get_the_ID(); $mylisting[] = array( 'listing_id' => $listing_id, 'listing_title' => get_the_title($listing_id), ); } return $mylisting; } } } //Fetch all Listings if ( ! function_exists( 'dwt_listing_fetchlistings' ) ) { function dwt_listing_fetchlistings($listing_status, $per_page = '') { $average = $rating_stars = $get_percentage = $response = ''; $meta_query_args = $listingz = array(); $meta_key = ''; $meta_value = ''; $meta_compare = '='; if($listing_status == 'publish') { $listing_status = 'publish'; $meta_query_args = array(array('key'=>'dwt_listing_listing_status','value' => 1,'compare' => '=')); } else { $listing_status = 'publish'; $meta_query_args = array(array('key'=>'dwt_listing_listing_status','value' => 1,'compare' => '=')); } $args = array ( 'post_type' => 'listing', 'post_status' => $listing_status, 'posts_per_page' => $per_page, 'order'=> 'DESC', 'orderby' => 'date', 'meta_key' => $meta_key , 'meta_value' =>$meta_value, 'meta_query' => $meta_query_args ); $my_listings = new WP_Query( $args ); if ( $my_listings->have_posts() ) { $lists = array(); $color_code = $pieces = $category_name = $categor_id = $listing_cats = $total_views = $status_type = $b_status = $is_featured = ''; while ( $my_listings->have_posts() ) { $my_listings->the_post(); $listing_id = get_the_ID(); $media = dwt_listing_fetch_listing_gallery($listing_id); $is_featured = dwt_listing_is_listing_featured_app($listing_id); $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_business_hours_status($listing_id) !="") { $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 if($status_type == 2) { $b_status = esc_html__('Always Open','dwt-listing-api'); $color_code = '#fc0'; } else { $b_status = esc_html__('Open Now','dwt-listing-api'); $color_code = '#25a25a'; } } $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]; } $rated = get_comment_meta($listing_id, 'review_stars', true); if( function_exists('pvc_get_post_views') ) $total_views = pvc_get_post_views( $listing_id); $listingz[] = array( "listing_id" => $listing_id, "category_id" => $categor_id, "category_name" => dwt_listing_convert_uniText($category_name), "listing_title" => dwt_listing_convert_uniText(get_the_title($listing_id)), "image" => dwt_listing_return_listing_idz($media,'dwt_listing_list-view1'), "is_featured" => $is_featured, "business_hours_status" => $b_status, "color_code" => $color_code, "rating_stars" => $rating_stars, "rating_avg" => $average, "total_views" => $total_views, "posted_date" => get_the_date(get_option('date_format'),$listing_id), ); } wp_reset_postdata(); } return $listingz; } } //Fetch all events if ( ! function_exists( 'dwt_listing_fetcheventz' ) ) { function dwt_listing_fetcheventz($listing_status, $no_of_ads = '') { //query $active_listings = array( 'key' => 'dwt_listing_event_status', 'value' => '1', 'compare' => '=' ); $order = 'DESC'; $order_by = 'date'; $args= array ( 'post_type' => 'events', 'post_status' => 'publish', 'posts_per_page' => 18, 'meta_query' => array( $active_listings, ), 'order'=> $order, 'orderby' => $order_by, ); $eventz = array(); $category_name = $categor_id = $fetch_listingz =''; $results = new WP_Query( $args ); if ( $results->have_posts() ) { while( $results->have_posts() ) { $results->the_post(); $event_id = get_the_ID(); $media = dwt_listing_fetch_event_gallery($event_id); $event_start_date = get_post_meta($event_id, 'dwt_listing_event_start_date', true ); $event_end_date = get_post_meta($event_id, 'dwt_listing_event_end_date', true ); $event_venue = get_post_meta($event_id, 'dwt_listing_event_venue', true); $eventz_cats = dwt_listing_events_assigned_cats_app($event_id); if(count((array) $eventz_cats) > 0 && !empty($eventz_cats)) { $pieces = explode(',', $eventz_cats); $categor_id = $pieces[0]; $category_name = $pieces[1]; } if($event_start_date !="" && $event_end_date !="") { $event_start = date_i18n( get_option( 'date_format'), strtotime( $event_start_date ) ); $event_end = date_i18n( get_option( 'date_format'), strtotime( $event_end_date ) ); } $eventz[] = array( "event_id" => $event_id, "event_category_id" => $categor_id, "event_category_name" => dwt_listing_convert_uniText($category_name), "event_title" => dwt_listing_convert_uniText(get_the_title($event_id)), "image" => dwt_listing_return_event_idz($media,'dwt_listing_locations-thumb'), "event_loc" => $event_venue, "event_start_date" => $event_start, "event_end_date" => $event_end, ); } } wp_reset_postdata(); return $eventz; } } //Fetch latest posted comment if (!function_exists( 'dwt_listing_latest_comment' )) { function dwt_listing_latest_comment($blog_id,$post_type = '') { $type = 'post'; if(!empty($post_type)) { $type = 'events'; } $arr = array(); $comments = get_comments(array('post_id' => $blog_id, 'orderby' => 'post_date' ,'order' => 'DESC', 'post_type' => $type, 'status' => 'approve', 'number'=>'1')); if( count((array) $comments ) > 0 ) { foreach($comments as $comment) { $arr['blog_id'] = $blog_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'] = $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", "nokri-rest-api"); } return $arr; } } } // Featch more leads on request add_action( 'rest_api_init', 'dwt_listing_load_more_leads', 0 ); function dwt_listing_load_more_leads() { register_rest_route( 'downtown/app', '/get-more-leads/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_get_leadz', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_get_leadz')) { function dwt_listing_get_leadz($request) { global $wpdb; global $dwt_listing_api; $user = wp_get_current_user(); $user_id = $user->ID; if(!empty($user_id)) { $data = array(); $json_data = $request->get_json_params(); $next_page = (isset($json_data['next_page'])) ? trim($json_data['next_page']) : ''; $total_leads = $response = ''; $next = ''; $likes = array(1 => esc_html__('Like','dwt-listing-api'),2 => esc_html__('Love','dwt-listing-api'),3 => esc_html__('Wow','dwt-listing-api'),4 => esc_html__('Angry','dwt-listing-api')); $emotion_icons = array(1 => 'like',2 => 'love',3 => 'emoji',4 => 'dislike'); $leads = array('contact' => esc_html__('Contact No','dwt-listing-api'),'web' => esc_html__('Website Link','dwt-listing-api')); $leads_icons = array('contact' => 'mobile','web' => 'globle'); $query_args = array( 'author' => $user_id, 'post_type' => 'listing' , 'post_status' => 'publish' ); $query = new WP_Query( $query_args ); $listing_id = ''; if ( $query->have_posts() ) { while($query->have_posts()) { $query->the_post(); $listing_id .= get_the_ID() .','; } } $listing_id = rtrim($listing_id,","); if(!empty($listing_id)) { $leads_limit = 10; if(isset( $dwt_listing_api['app_dashboard_leads']) && $dwt_listing_api['app_dashboard_leads'] !="") { $leads_limit = $dwt_listing_api['app_dashboard_leads']; } $page = $next_page; $next_limit = $next_page.'0'; if($next_page == 2) { $next_limit = 10; } $results = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key LIKE '_activity_%' AND post_id IN ($listing_id) ORDER BY meta_id DESC LIMIT ".$next_limit.", ".$leads_limit."" ); if(is_array($results) && count($results) > 0) { foreach($results as $result) { $post_id = $result->post_id; $user_name = ''; $icon = ''; $statement = ''; $user_id =''; $get_time = ''; $get_time = explode('_',$result->meta_value); $activity_time = $get_time[0]; $activity_value = $get_time[1]; $activity_time = strtotime($activity_time); $reaction = (isset($likes[$activity_value])) ? $likes[$activity_value] : ''; $get_uid = explode('_', $result->meta_key); $get_uid[4]; $user = get_user_by('id', $get_uid[4]); if ( ! empty( $user ) ) { $user_name = $user->display_name; $user_id = $user->ID; } else { $user_name = esc_html__('Someone','dwt-listing-api'); $user_id = ''; } $on = esc_html__(' on','dwt-listing-api'); $clicked = esc_html__('clicked your ','dwt-listing-api'); $reacted = esc_html__('reacted as ','dwt-listing-api'); $ago = esc_html__(' ago','dwt-listing-api'); $type = ''; if (strpos($result->meta_key, 'leads_userid_unknown')) { $icon = 'bell'; $reaction = (isset($leads[$activity_value])) ? $leads[$activity_value] : ''; $statement = $clicked . $reaction .$on; } else if (strpos($result->meta_key, 'rating')) { $icon = 'star'; $statement = __('posted a Rating on','dwt-listing-api'); } else if (strpos($result->meta_key, 'comments')) { $icon = 'comment'; $statement = __('post a Comment on','dwt-listing-api'); } else if (strpos($result->meta_key, 'like')) { $icon = (isset($emotion_icons[$activity_value])) ? $emotion_icons[$activity_value] : ''; $statement = $reacted. $reaction .$on; } else if (strpos($result->meta_key, 'leads')) { $icon = (isset($leads_icons[$activity_value])) ? $leads_icons[$activity_value] : ''; $reaction = (isset($leads[$activity_value])) ? $leads[$activity_value] : ''; $statement = $clicked .$reaction .$on; } $lead_activities[] = array( "user_name" => $user_name, "user_id" => $user_id, "listing_title" => dwt_listing_convert_uniText(get_the_title($post_id)), "statement" => $statement, "icon_type" => $icon, "activity_time" => human_time_diff($activity_time, current_time('timestamp')) . $ago ); } $data['lead_activities'] = $lead_activities; //leads pagination $total_leads = $wpdb->get_var("SELECT count(meta_id) from $wpdb->postmeta WHERE meta_key LIKE '_activity_%' AND post_id IN ($listing_id) ORDER BY meta_id DESC"); $next = $page + 1; $lastpage = ceil($total_leads/$leads_limit); $has_next_page = ($next <= (int)$lastpage) ? true : false; $data['pagination'] = array("total_leads" => $total_leads, "current_page" => (int)$page, "next_page" => (int)$next, "has_next_page" => $has_next_page ); $response = array( 'success' => true, 'data' => $data , 'message' => ''); wp_reset_postdata(); return $response; } else { $response = array( 'success' => false, 'data' => '' , 'message' => __("Recent activities about your listings will be here!", "dwt-listing-api") ); return $response; } } else { $response = array( 'success' => false, 'data' => '' , 'message' => __("Recent activities about your listings will be here!", "dwt-listing-api") ); return $response; } } } } // Fetch authour own listings load more add_action( 'rest_api_init', 'dwt_listing_user_own_listing_dash', 0 ); function dwt_listing_user_own_listing_dash() { register_rest_route( 'downtown/app', '/my-own-listings/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_author_listing_load_more', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } // Listing Detial Service if (!function_exists('dwt_listing_author_listing_load_more')) { function dwt_listing_author_listing_load_more($request) { global $dwt_listing_api; $param = $request->get_json_params(); if(isset($param['listing_type']) && $param['listing_type'] !="" ) { $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']; } $user = wp_get_current_user(); $user_id = $user->ID; $listing_status = $param['listing_type']; $response = ''; $meta_query_args = $listingz = array(); $meta_key = ''; $meta_value = ''; $meta_compare = '='; if($listing_status == 'publish') { $listing_status = 'publish'; $meta_query_args = array(array('key'=>'dwt_listing_listing_status','value' => 1,'compare' => '=')); } else if($listing_status == 'pending') { $listing_status = 'pending'; } else if($listing_status == 'featured') { $listing_status = 'publish'; $meta_key = 'dwt_listing_is_feature'; $meta_value = '1'; } else if($listing_status == 'expired') { $listing_status = 'publish'; $meta_key = 'dwt_listing_listing_status'; $meta_value = '0'; } else { $listing_status = 'publish'; $meta_query_args = array(array('key'=>'dwt_listing_listing_status','value' => 1,'compare' => '=')); } if(!empty($param['next_page'])) { $page = $param['next_page']; } else { $page = 2; } $args = array ( 'post_type' => 'listing', 'author' => $user_id, 'post_status' => $listing_status, 'posts_per_page' => $limit, 'paged' => $page, 'order'=> 'DESC', 'orderby' => 'date', 'meta_key' => $meta_key , 'meta_value' =>$meta_value, 'meta_query' => $meta_query_args ); $my_listings = new WP_Query( $args ); if ( $my_listings->have_posts() ) { $lists = array(); $pieces = $category_name = $categor_id = $listing_cats = $total_leads = $contact_leads = $web_leads = $total_views = $status_type = $b_status = $is_featured = ''; while ( $my_listings->have_posts() ) { $my_listings->the_post(); $listing_id = get_the_ID(); $media = dwt_listing_fetch_listing_gallery($listing_id); $is_featured = dwt_listing_is_listing_featured_app($listing_id); if(dwt_listing_business_hours_status($listing_id) !="") { $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 if($status_type == 2) { $b_status = esc_html__('Always Open','dwt-listing-api'); $color_code = '#fc0'; } else { $b_status = esc_html__('Open Now','dwt-listing-api'); $color_code = '#25a25a'; } } if(get_post_meta( $listing_id, '_dowtown_web_leads',true) !="") { $web_leads = get_post_meta( $listing_id, '_dowtown_web_leads',true); } if(get_post_meta( $listing_id, '_dowtown_contact_leads',true) !="") { $contact_leads = get_post_meta( $listing_id, '_dowtown_contact_leads',true); } if($web_leads != 0 && $contact_leads !=0) { $total_leads = $web_leads + $contact_leads; } $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]; } if( function_exists('pvc_get_post_views') ) $total_views = pvc_get_post_views( $listing_id); $listingz[] = array( "listing_id" => $listing_id , "category_id" => $categor_id , "category_name" => dwt_listing_convert_uniText($category_name), "listing_title" => dwt_listing_convert_uniText(get_the_title($listing_id)) , "image" => dwt_listing_return_listing_idz($media,'downtown-mylistings'), "is_featured" => $is_featured, "business_hours_status" => $b_status, "color_code" => $color_code, "total_views" => $total_views, "web_clicks" => $web_leads, "contact_clicks" => $contact_leads, "total_click" => $total_leads, "posted_date" => get_the_date(get_option('date_format'),$listing_id), ); } wp_reset_postdata(); } $lists['listing'] = $listingz; $has_next_page = $lastpage = $next = ''; //pagination $next = $page + 1; $lastpage = ceil($my_listings->found_posts/$limit); $has_next_page = ($next <= (int)$lastpage) ? true : false; $lists[$listing_status.'_'.'pagination'] = array("total_listings" => $my_listings->found_posts, "current_page" => (int)$page, "next_page" => (int)$next, "has_next_page" => $has_next_page ); return $lists; } else { $response = array( 'success' => false, 'data' => '' , 'message' => __("Something went wrong please try later!", "dwt-listing-api") ); return $response; } } }
[+]
..
[-] utilities.php
[edit]
[+]
languages
[+]
classes
[-] index.php
[edit]
[+]
inc
[-] fetch_data.php
[edit]
[-] functions.php
[edit]
[+]
images