PATH:
home
/
letacommog
/
laindinois
/
OLD
/
wp-content
/
plugins
/
dwt-listing-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 = ''; $final_title = $limited_title = ''; $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; } if(isset($dwt_listing_api['app_title_limit']) && $dwt_listing_api['app_title_limit'] !="") { $limited_title = dwt_listing_words_count(get_the_title($post_id), $dwt_listing_api['app_title_limit']); $final_title = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title))); } else { $final_title = get_the_title($post_id); } $lead_activities[] = array( "listing_id" => $post_id , "user_name" => $user_name, "user_id" => $user_id, "listing_title" => dwt_listing_convert_uniText($final_title), "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) { global $dwt_listing_api; $my_count = $original_status = $response = ''; $meta_query_args = $listingz = array(); $meta_key = ''; $meta_value = ''; $meta_compare = '='; $original_status = $listing_status; 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'; $meta_query_args = array(array('key'=>'dwt_listing_listing_status','value' => 1,'compare' => '=')); } 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); $color_code = ''; 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; } $category_name = $categor_id = '' ; $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]; } $final_title = $limited_title = ''; if(isset($dwt_listing_api['app_title_limit']) && $dwt_listing_api['app_title_limit'] !="") { $limited_title = dwt_listing_words_count(get_the_title($post_id), $dwt_listing_api['app_title_limit']); $final_title = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title))); } else { $final_title = get_the_title($post_id); } 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($final_title) , "image" => dwt_listing_return_listing_idz_app($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; $lists['listing_type'] = $original_status; $lists['listing_count'] = esc_html__("Total Listings : ", "dwt-listing-api") . $my_listings->found_posts; 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[$original_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; 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; } } //Submitted Reviews if ( ! function_exists( 'dwt_listing_fetch_my_submitted_reviewz' ) ) { function dwt_listing_fetch_my_submitted_reviewz($user_id,$review_type, $next_page='') { global $dwt_listing_api; $limit = 10; if(isset($dwt_listing_api['app_received_subb_limit'] ) && $dwt_listing_api['app_received_subb_limit'] != "" ) { $limit = $dwt_listing_api['app_received_subb_limit']; } if(!empty($next_page)) { $page = $next_page; } else { $page = 1; } $offset = ($page * $limit) - $limit; $param = array('status'=>'approve','user_id'=>$user_id,'post_type' => 'listing', 'orderby' => 'post_date' ,'order' => 'DESC','number'=>$limit, 'offset'=>$offset , 'parent' => 0); $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); } } } } $final_title = $limited_title = ''; if(isset($dwt_listing_api['app_title_limit']) && $dwt_listing_api['app_title_limit'] !="") { $limited_title = dwt_listing_words_count(get_the_title($listing_id), $dwt_listing_api['app_title_limit']); $final_title = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title))); } else { $final_title = get_the_title($listing_id); } $statement = __('You have posted a review on ','dwt-listing-api'); $submitted_cmntz[] = array( "comment_id" => $comment_id, "listing_id" => $listing_id, "commenter_name" => dwt_listing_convert_uniText(esc_attr($comment->comment_author)), "commenter_dp" => $commenter_dp, "user_id" => $comment->user_id, "listing_title" => dwt_listing_convert_uniText($final_title) , "statement" => $statement, "rating_stars" => $rated, "total_rating" => ($rated.'/'.'5'), "comment_desc" => dwt_listing_convert_uniText(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" => dwt_listing_convert_uniText(esc_attr($comment->comment_content)), "has_media" => $has_media, "comment_media" => $gallery_link, ); } $lists['has_comments'] = $has_comments; $lists['review_type'] = $review_type; $lists['commnets'] = $submitted_cmntz; //pagination $has_next_page = $lastpage = $next = $total_comments = ''; $total_comments = dwt_listing_submitted_reviews($user_id); $next = $page + 1; $lastpage = ceil($total_comments/$limit); $has_next_page = ($next <= (int)$lastpage) ? true : false; $lists[$review_type.'_pagination'] = array("totalsubmitted_reviews" => $total_comments, "current_page" => (int)$page, "next_page" => (int)$next, "has_next_page" => $has_next_page ); } else { $lists['has_comments'] = $has_comments; $lists['message'] = __("Your haven't submitted any review yet!", "dwt-listing-api"); } return $lists; } } //Received Reviews if ( ! function_exists( 'dwt_listing_fetch_my_received_reviewz' ) ) { function dwt_listing_fetch_my_received_reviewz($user_id,$review_type,$next_page='') { global $dwt_listing_api; $limit = 10; if(isset($dwt_listing_api['app_received_rev_limit'] ) && $dwt_listing_api['app_received_rev_limit'] != "" ) { $limit = $dwt_listing_api['app_received_rev_limit']; } if(!empty($next_page)) { $page = $next_page; } else { $page = 1; } $offset = ($page * $limit) - $limit; $param = array('status'=>'approve','post_type' => 'listing', 'post_author__in' => array($user_id), 'orderby' => 'post_date' ,'order' => 'DESC', 'number'=>$limit, 'offset'=>$offset, 'parent' => 0); $comments = get_comments($param); $has_comments = false; $replies = ''; if(count((array) $comments) > 0 ) { foreach($comments as $comment) { $replier_msg = $reply_comment_id = ''; $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); //fetch replies of that post $replies = get_comments( array( 'parent' => $comment->comment_ID, 'status' => 'approve', 'orderby' => 'comment_date' , 'order' => 'DESC' ) ); $has_reply = false; if(count((array) $replies) > 0) { $has_reply = true; foreach($replies as $reply) { $reply_comment_id = $reply->comment_ID; $replier_msg = dwt_listing_convert_uniText(esc_attr($reply->comment_content)); } } $final_title = $limited_title = ''; if(isset($dwt_listing_api['app_title_limit']) && $dwt_listing_api['app_title_limit'] !="") { $limited_title = dwt_listing_words_count(get_the_title($listing_id), $dwt_listing_api['app_title_limit']); $final_title = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title))); } else { $final_title = get_the_title($listing_id); } $statement = esc_html__('posted a review on ','dwt-listing-api'); $submitted_cmntz[] = array( "comment_id" => $comment_id, "listing_id" => $listing_id, "commenter_name" => dwt_listing_convert_uniText(esc_attr($comment->comment_author)), "commenter_dp" => $commenter_dp, "user_id" => $comment->user_id, "listing_title" => dwt_listing_convert_uniText($final_title) , "statement" => $statement, "rating_stars" => $rated, "total_rating" => ($rated.'/'.'5'), "comment_desc" => dwt_listing_convert_uniText(esc_attr($comment->comment_content)), "comment_time" => date_i18n( 'j F, Y', strtotime( get_the_time($comment->comment_date) ) ), "has_reply" => $has_reply, "reply_comment_id" => $reply_comment_id, "replier_msg" => $replier_msg, ); } $lists['has_comments'] = $has_comments; $lists['review_type'] = $review_type; $lists['commnets'] = $submitted_cmntz; //pagination $has_next_page = $lastpage = $next = $total_comments = ''; $total_comments = dwt_listing_received_reviews($user_id); $next = $page + 1; $lastpage = ceil($total_comments/$limit); $has_next_page = ($next <= (int)$lastpage) ? true : false; $lists[$review_type.'_pagination'] = array("totalreceived_reviews" => $total_comments, "current_page" => (int)$page, "next_page" => (int)$next, "has_next_page" => $has_next_page ); } else { $lists['has_comments'] = $has_comments; $lists['message'] = __("You dont received any review yet!", "dwt-listing-api"); } return $lists; } } // Fetch authour own reviews add_action( 'rest_api_init', 'dwt_listing_user_own_reviews', 0 ); function dwt_listing_user_own_reviews() { register_rest_route( 'downtown/app', '/my-own-reviews/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_author_reviews_load_more', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } // Fetch Load More Reviews if (!function_exists('dwt_listing_author_reviews_load_more')) { function dwt_listing_author_reviews_load_more($request) { global $dwt_listing_api; $param = $request->get_json_params(); if(isset($param['review_type']) && $param['review_type'] !="" ) { $review_type = $param['review_type']; $user = wp_get_current_user(); $user_id = $user->ID; if($review_type == "submitted") { return dwt_listing_fetch_my_submitted_reviewz($user_id,'submitted',$param['next_page']); } if($review_type == "received") { return dwt_listing_fetch_my_received_reviewz($user_id,'received',$param['next_page']); } } else { $response = array( 'success' => false, 'data' => '' , 'message' => __("Something went wrong please try later!", "dwt-listing-api") ); return $response; } } } 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' => dwt_listing_convert_uniText(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]; } $final_title = $limited_title = ''; global $dwt_listing_api; if(isset($dwt_listing_api['app_title_limit']) && $dwt_listing_api['app_title_limit'] !="") { $limited_title = dwt_listing_words_count(get_the_title($listing_id), $dwt_listing_api['app_title_limit']); $final_title = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title))); } else { $final_title = get_the_title($listing_id); } $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($final_title), "image" => dwt_listing_return_listing_idz_app($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' => $no_of_ads, '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 ) ); } $final_title = $limited_title = ''; global $dwt_listing_api; if(isset($dwt_listing_api['app_title_limit']) && $dwt_listing_api['app_title_limit'] !="") { $limited_title = dwt_listing_words_count(get_the_title($event_id), $dwt_listing_api['app_title_limit']); $final_title = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title))); } else { $final_title = get_the_title($event_id); } $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($final_title), "image" => dwt_listing_return_event_idz_app($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'] = 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"); } 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']) : '1'; $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)) { $post_per_page = 10; if(isset( $dwt_listing_api['app_dashboard_leads']) && $dwt_listing_api['app_dashboard_leads'] !="") { $post_per_page = $dwt_listing_api['app_dashboard_leads']; } $paged = $next_page; $offset = ($paged-1)*$post_per_page; $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 ".$offset.", ".$post_per_page."" ); 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; } if(isset($dwt_listing_api['app_title_limit']) && $dwt_listing_api['app_title_limit'] !="") { $limited_title = dwt_listing_words_count(get_the_title($post_id), $dwt_listing_api['app_title_limit']); $final_title = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title))); } else { $final_title = get_the_title($post_id); } $lead_activities[] = array( "user_name" => $user_name, "user_id" => $user_id, "listing_title" => dwt_listing_convert_uniText($final_title), "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"); $lastpage = ceil($total_leads / $post_per_page); $next = $paged + 1; $has_next_page = ($next <= (int)$lastpage) ? true : false; $data['leads_pagination'] = array("total_leads" => $total_leads, "current_page" => (int)$paged, "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 = 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]; } $limited_title = $final_title = ''; if(isset($dwt_listing_api['app_title_limit']) && $dwt_listing_api['app_title_limit'] !="") { $limited_title = dwt_listing_words_count(get_the_title($listing_id), $dwt_listing_api['app_title_limit']); $final_title = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title))); } else { $final_title = get_the_title($listing_id); } 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($final_title) , "image" => dwt_listing_return_listing_idz_app($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; } } } //Fetch all Personal Events if ( ! function_exists('dwt_listing_get_my_personal_reviews')) { function dwt_listing_get_my_personal_reviews($event_status, $limit , $user_id) { global $dwt_listing_api; $my_count = $original_status = $response = ''; $meta_query_args = $listingz = array(); $meta_key = ''; $meta_value = ''; $meta_compare = '='; $original_status = $event_status; 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'; $meta_query_args = array(array('key'=>'dwt_listing_event_status','value' => 1,'compare' => '=')); } 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' => '=')); } $page = 1; $args = array ( 'post_type' => 'events', 'author' => $user_id, 'post_status' => $event_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_events = new WP_Query($args); if ($my_events->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_events->have_posts() ) { $my_events->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); $term_list = wp_get_post_terms($event_id, 'l_event_cat', array("fields" => "all")); if(!empty($term_list)) { $link = get_term_link($term_list[0]->term_id); $category_name = $term_list[0]->name; } 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 ) ); } $final_title = $limited_title = ''; if(isset($dwt_listing_api['app_title_limit']) && $dwt_listing_api['app_title_limit'] !="") { $limited_title = dwt_listing_words_count(get_the_title($event_id), $dwt_listing_api['app_title_limit']); $final_title = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title))); } else { $final_title = get_the_title($event_id); } $limited_title_venue = $e_vanue; if(isset($dwt_listing_api['app_title_event_venue']) && $dwt_listing_api['app_title_event_venue'] !="") { $limited_title_venue = dwt_listing_words_count($event_venue, $dwt_listing_api['app_title_event_venue']); $e_vanue = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title_venue))); } $eventz[] = array( "event_id" => $event_id, "event_category_name" => dwt_listing_convert_uniText($category_name), "event_title" => dwt_listing_convert_uniText($final_title), "image" => dwt_listing_return_event_idz_app($media,'dwt_listing_locations-thumb'), "event_loc" => $e_vanue, "event_start_date" => $event_start, "event_end_date" => $event_end, ); } wp_reset_postdata(); } $lists['has_events'] = (count((array) $eventz) > 0) ? true : false; $lists['event_type'] = $original_status; $lists['event_count'] = esc_html__("Total Events : ", "dwt-listing-api") . $my_events->found_posts; if(count((array) $eventz) > 0) { $lists['events'] = $eventz; } else { $lists['message'] = esc_html__("You dont have any event yet!", "dwt-listing-api"); } $has_next_page = $lastpage = $next = ''; //pagination $next = $page + 1; $lastpage = ceil($my_events->found_posts/$limit); $has_next_page = ($next <= (int)$lastpage) ? true : false; $lists[$original_status.'_'.'pagination'] = array("total_events" => $my_events->found_posts, "current_page" => (int)$page, "next_page" => (int)$next, "has_next_page" => $has_next_page ); return $lists; } } //Fetch all Personal Events if ( ! function_exists('dwt_listing_get_single_event')) { function dwt_listing_get_single_event($event_id) { if(!empty($event_id)) { $lists = array(); $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" => "all")); if(!empty($term_list)) { $link = get_term_link($term_list[0]->term_id); $category_name = $term_list[0]->name; } 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 ) ); } $final_title = $limited_title = ''; if(isset($dwt_listing_api['app_title_limit']) && $dwt_listing_api['app_title_limit'] !="") { $limited_title = dwt_listing_words_count(get_the_title($event_id), $dwt_listing_api['app_title_limit']); $final_title = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title))); } else { $final_title = get_the_title($event_id); } $limited_title_venue = $e_vanue = ''; if(isset($dwt_listing_api['app_title_event_venue']) && $dwt_listing_api['app_title_event_venue'] !="") { $limited_title_venue = dwt_listing_words_count($event_venue, $dwt_listing_api['app_title_event_venue']); $e_vanue = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title_venue))); } $eventz[] = array( "event_id" => $event_id, "event_category_name" => dwt_listing_convert_uniText($category_name), "event_title" => dwt_listing_convert_uniText($final_title), "image" => dwt_listing_return_event_idz_app($media,'dwt_listing_locations-thumb'), "event_loc" => $e_vanue, "event_start_date" => $event_start, "event_end_date" => $event_end, ); return $eventz; } else { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Event Id is not generated. Please try later", 'dwt-listing-api') , 'event_id' => $event_id)); } } }
[+]
..
[-] functions.php
[edit]
[-] fetch_data.php
[edit]
[-] utilities.php
[edit]
[+]
inc
[+]
classes
[+]
languages
[-] index.php
[edit]
[+]
images