PATH:
home
/
letacommog
/
laindinois
/
OLD
/
wp-content
/
plugins
/
dwt-listing-rest-api
<?php if ( ! function_exists( 'dwt_listing_convert_uniText' ) ) { function dwt_listing_convert_uniText($string = '') { $string = preg_replace('/%u([0-9A-F]+)/', '&#x$1;', $string); return html_entity_decode($string, ENT_COMPAT, 'UTF-8'); } } if (!function_exists('dwt_listing_getReduxValue')) { function dwt_listing_getReduxValue($param1 = '', $param2 = '', $vaidate = false) { global $dwt_listing_api; $data = ''; if( $param1 != "" ) { $data = $dwt_listing_api["$param1"]; } if( $param1 != "" && $param2 != "") { $data = $dwt_listing_api["$param1"]["$param2"]; } if( $vaidate == true ) { $data = (isset( $data ) && $data != "" ) ? 1 : 0; } return $data; } } if (!function_exists('dwt_listing_appLogo')) { function dwt_listing_appLogo() { global $dwt_listing_api; $app_logo = ''; $defaultLogo = trailingslashit( get_template_directory_uri() ).'assets/images/logo.png'; $app_logo = (isset( $dwt_listing_api['dwt_app_logo'] )) ? $dwt_listing_api['dwt_app_logo']['url'] : $defaultLogo; return $app_logo; } } if (!function_exists('dwt_listing_home_adsLayouts')) { function dwt_listing_home_adsLayouts($type = '') { global $dwt_listing_api; /* Cat icons Starts */ if( $type == 'cat_icons' ) { $catData = array(); if( isset( $dwt_listing_api['adforest-api-ad-cats-multi'] ) ) { $cats = $dwt_listing_api['adforest-api-ad-cats-multi']; if( count( $cats ) > 0 ) { foreach($cats as $cat) { $term = get_term( $cat, 'l_category' ); //return $cat; $name = htmlspecialchars_decode($term->name, ENT_NOQUOTES); $imgUrl = dwt_listing_api_taxonomy_image_url( $cat, NULL, TRUE ); $catData[] = array("category_id" => $term->term_id, "name" => $name, "img" => $imgUrl); } } } return $catData; } /* Cat icons ends */ if( $type == 'all' ) { $catData = array(); $cats = dwt_listing_categories_fetch('l_category' , 0 ); //return $cats; if( count( $cats ) > 0 ) { foreach($cats as $cat) { $name = htmlspecialchars_decode($cat->name, ENT_NOQUOTES); $imgUrl = dwt_listing_api_taxonomy_image_url( $cat->term_id, NULL, TRUE ); $catData[] = array("category_id" => $cat->term_id, "name" => $name, "img" => $imgUrl); } } return $catData; } /*Multi Slider ads options sortable starts */ if( $type == 'multi_slider' ) { $sliderData = array(); if( isset( $dwt_listing_api['adforest-api-ad-cats-slider'] ) ) { $slider_ad_limit = (isset( $dwt_listing_api['slider_ad_limit'] ) ) ? $dwt_listing_api['slider_ad_limit'] : 5; $cats = $dwt_listing_api['adforest-api-ad-cats-slider']; foreach($cats as $cat) { $term = get_term( $cat, 'ad_cats' ); $name = htmlspecialchars_decode($term->name, ENT_NOQUOTES); $adData = dwt_listing_catSpecific_ads($cat, $slider_ad_limit); if( isset( $adData ) && count($adData) > 0 ) { $sliderData[] = array("cat_id" => $term->term_id, "name" => $name, "data" => $adData); } } } return $sliderData; } /*Multi Slider ads options sortable ends */ /*Featured Ads Starts Here */ if( $type == 'featured' ) { $fads['text'] = array(); $fads['ads'] = array(); $data = array(); $data['featured_ads'] = array(); $data['featured_position'] = (isset( $dwt_listing_api['home_featured_position'] ) && $dwt_listing_api['home_featured_position'] != "" ) ? $dwt_listing_api['home_featured_position'] : "1"; $data['is_show_featured'] = (isset( $dwt_listing_api['feature_on_home'] ) && $dwt_listing_api['feature_on_home'] == 1 ) ? true :false; if( isset( $dwt_listing_api['feature_on_home'] ) && $dwt_listing_api['feature_on_home'] == 1 ) { $featuredAdsCount = ( $dwt_listing_api['home_related_posts_count'] != "" ) ? $dwt_listing_api['home_related_posts_count'] : 5; $featuredAdsTitle = ( $dwt_listing_api['sb_home_ads_title'] != "" ) ? $dwt_listing_api['sb_home_ads_title'] : __("Featured Ads", "dwt-listing-api"); $featured_termID = ( isset( $json_data['ad_cats1'] ) && $json_data['ad_cats1'] != "" ) ? $json_data['ad_cats1'] : ''; $featuredAds = dwt_listing_featuredAds_slider( '', 'active', '1', $featuredAdsCount, $featured_termID, 'publish'); if( isset( $featuredAds ) && count( $featuredAds ) > 0 ) { $fads['text'] = $featuredAdsTitle; $fads['ads'] = $featuredAds; $data['is_show_featured'] = true; } else { $data['is_show_featured'] = false; } $data['featured_ads'] = $fads; } return $data; } /*Featured ads ends here*/ /*Latest Ads Start Here*/ if( $type == 'latest' ) { /*latest Layout*/ $latest['text'] = array(); $latest['ads'] = array(); $data = array(); $data['latest_ads'] = array(); $data['is_show_latest'] = (isset( $dwt_listing_api['latest_on_home'] ) && $dwt_listing_api['latest_on_home'] == 1 ) ? true : false; if( isset( $dwt_listing_api['latest_on_home'] ) && $dwt_listing_api['latest_on_home'] == 1 ) { $latestAdsCount = ( $dwt_listing_api['home_latest_posts_count'] != "" ) ? $dwt_listing_api['home_latest_posts_count'] : 5; $latestAdsAdsTitle = ( $dwt_listing_api['sb_home_latest_ads_title'] != "" ) ? $dwt_listing_api['sb_home_latest_ads_title'] : __("Latest Ads", "dwt-listing-api"); $latest_termID = ( isset( $json_data['ad_cats1'] ) && $json_data['ad_cats1'] != "" ) ? $json_data['ad_cats1'] : ''; $latestAds = dwt_listing_featuredAds_slider( '', 'active', '', $latestAdsCount, $latest_termID, 'publish'); if( isset( $latestAds ) && count( $latestAds ) > 0 ) { $latest['text'] = $latestAdsAdsTitle; $latest['ads'] = $latestAds; $data['is_show_latest'] = true; } else { $data['is_show_latest'] = false; } $data['latest_ads'] = $latest; } return $data; } /*Latest Ads Ends Here*/ /*nearby Ads Start Here*/ if( $type == 'nearby' ) { /*latest Layout*/ $latest['text'] = array(); $latest['ads'] = array(); $data = array(); $data['nearby_ads'] = array(); $data['is_show_nearby'] = (isset( $dwt_listing_api['nearby_on_home'] ) && $dwt_listing_api['nearby_on_home'] ) ? true : false; if( isset( $dwt_listing_api['nearby_on_home'] ) && $dwt_listing_api['nearby_on_home'] == 1 ) { $latestAdsCount = ( $dwt_listing_api['home_nearby_posts_count'] != "" ) ? $dwt_listing_api['home_nearby_posts_count'] : 5; $latestAdsAdsTitle = ( $dwt_listing_api['sb_home_nearby_ads_title'] != "" ) ? $dwt_listing_api['sb_home_nearby_ads_title'] : __("Nearby Ads", "dwt-listing-api"); $latest_termID = ( isset( $json_data['ad_cats1'] ) && $json_data['ad_cats1'] != "" ) ? $json_data['ad_cats1'] : ''; $latestAds = dwt_listing_featuredAds_slider( '', 'active', '', $latestAdsCount, $latest_termID, 'publish', 'nearby'); if( isset( $latestAds ) && count( $latestAds ) > 0 ) { $latest['text'] = $latestAdsAdsTitle; $latest['ads'] = $latestAds; $data['is_show_nearby'] = true; } else { $data['is_show_nearby'] = false; } $data['nearby_ads'] = $latest; } return $data; } /*nearby Ads Ends Here*/ /*Cat locations*/ if( $type == 'locations' ) { $loctData = array(); if( isset( $dwt_listing_api['adforest-api-ad-loc-multi'] ) && count($dwt_listing_api['adforest-api-ad-loc-multi']) > 0 ) { $loctData = array(); $cats = $dwt_listing_api['adforest-api-ad-loc-multi']; if( count( $cats ) > 0 ) { foreach($cats as $cat) { $term = get_term( $cat, 'ad_country' ); if($term) { $name = htmlspecialchars_decode($term->name, ENT_NOQUOTES); $imgUrl = dwt_listing_api_taxonomy_image_url( $cat, NULL, TRUE ); $count = "($term->count ". __("Ads", "dwt-listing-api").")"; $loctData[] = array("cat_id" => $term->term_id, "name" => $name, "img" => $imgUrl, "count" => $count); } } } } return $loctData; } /*Cat locations ends here */ /*blogNews starts */ if( $type == 'blogNews' ) { /*latest Layout*/ $blogs['text'] = array(); $blogs['blogs'] = array(); $data = array(); $data['latest_blog'] = array(); $data['is_show_blog'] = (isset( $dwt_listing_api['posts_blogNews_home'] ) && $dwt_listing_api['posts_blogNews_home'] ) ? true : false; if( isset( $dwt_listing_api['posts_blogNews_home'] ) && $dwt_listing_api['posts_blogNews_home'] ) { $latestPostsCount = ( $dwt_listing_api['home_blogNews_posts_count'] != "" ) ? $dwt_listing_api['home_blogNews_posts_count'] : 5; $latestPostsAdsTitle = ( $dwt_listing_api['api_blogNews_title'] != "" ) ? $dwt_listing_api['api_blogNews_title'] : __("Blog/News", "dwt-listing-api"); $latest_termID = ( isset( $dwt_listing_api['adforest-api-blogNews-multi'] ) && $dwt_listing_api['adforest-api-blogNews-multi'] ) ? $dwt_listing_api['adforest-api-blogNews-multi'] : array(); $latestPosts = dwt_listing_blogPosts($latest_termID, $latestPostsCount); if( isset( $latestPosts ) && count( $latestPosts ) > 0 ) { $blogs['text'] = $latestPostsAdsTitle; $blogs['blogs'] = $latestPosts; $data['is_show_blog'] = true; } else { $data['is_show_blog'] = false; } $data['latest_blog'] = $blogs; } return $data; } /*blogNews ends */ } } if (!function_exists('dwt_listing_adsLoop')) { function dwt_listing_adsLoop($args, $userid = '', $is_profile = false, $is_fav = false, $is_pagination = false) { $adsArr = array(); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $ad_id = get_the_ID(); $postAuthor = get_the_author_meta('ID'); if( $is_fav == false ) { if( $userid != "" && $postAuthor != $userid ) continue; } /*Get Categories*/ $cats = dwt_listing_get_ad_terms($ad_id, 'ad_cats'); $cats_name = dwt_listing_get_ad_terms_names($ad_id, 'ad_cats'); /*Get Image*/ $thumb_img = ''; $thumb_img = dwt_listing_get_ad_image($ad_id, 1, 'thumb'); /*Strip tags and limit ad description*/ $words = wp_trim_words( strip_tags(get_the_content()), 12, '...' ); $location = dwt_listing_get_adAddress($ad_id); $price = get_post_meta($ad_id, "_adforest_ad_price", true); $ad_count = get_post_meta($ad_id, "sb_post_views_count", true); $priceFinal = dwt_listing_get_price($price, $ad_id); $ad_status = dwt_listing_adStatus( $ad_id ); $adsArr[] = array ( "ad_author_id" => $postAuthor, "ad_id" => $ad_id, "ad_date" => get_the_date("", $ad_id), "ad_title" => dwt_listing_convert_uniText( get_the_title() ), "ad_desc" => $words, "ad_status" => $ad_status, "ad_cats_name" => $cats_name, "ad_cats" => $cats, "ad_images" => $thumb_img, "ad_location" => $location, "ad_price" => $priceFinal, "ad_views" => $ad_count , "ad_video" => dwt_listing_get_adVideo($ad_id), "ad_timer" => dwt_listing_get_adTimer($ad_id), "ad_saved" => array("is_saved" => 0, "text" => __("Save Ad", "dwt-listing-api")), ); } wp_reset_postdata(); } if( $is_pagination == false ) { return $adsArr; } else { return array("ads" => $adsArr, "found_posts" => $the_query->found_posts, "max_num_pages" => $the_query->max_num_pages); } } } if (!function_exists('dwt_listing_get_adTimer')) { function dwt_listing_get_adTimer($ad_id = '') { $ad_bidding_time = get_post_meta($ad_id, '_adforest_ad_bidding_date', true ); $myData = strtotime($ad_bidding_time); $current_data = strtotime(get_gmt_from_date( 'UTC', $format = 'Y-m-d H:i:s')); $differenceInSeconds = $myData - $current_data; $is_show = true; if( $myData <= $current_data && $ad_bidding_time == "" ) { $is_show = false; $timer['is_show'] = $is_show; $timer['timer'] = ''; /* Mili-seconds*/ } else { $timer['is_show'] = $is_show; $timer['timer'] = convert_seconds($differenceInSeconds); /* Mili-seconds*/ } return $timer; } } function convert_seconds($seconds) { $dt1 = new DateTime("@0"); $dt2 = new DateTime("@$seconds"); $final_date = $dt1->diff($dt2)->format("%a,%h,%i,%s"); return explode(",", $final_date); } /* Ads Loop Ends */ /* Ads Statuses Starts */ if (!function_exists('dwt_listing_adStatus')) { function dwt_listing_adStatus($ad_id = '') { $isFretured = get_post_meta($ad_id, "_adforest_is_feature", true); $ad_status = get_post_meta($ad_id, "_adforest_ad_status_", true); $feature_text = ( $isFretured == 1) ? __("Featured", "dwt-listing-api") : ''; $status_text = ''; if( $ad_status == 'active') {$status_text = __("Active", "dwt-listing-api");} else if( $ad_status == 'expired') {$status_text = __("Expired", "dwt-listing-api");} else if( $ad_status == 'sold') {$status_text = __("Sold", "dwt-listing-api");} $ad_status = array( "status" => $ad_status, "status_text" => $status_text, "featured_type" => $isFretured, "featured_type_text" => $feature_text, ); return $ad_status; } } /* Related Ads Starts */ if (!function_exists('dwt_listing_related_ads')) { function dwt_listing_related_ads($ad_id = '', $limit = 5) { $cats = wp_get_post_terms( $ad_id, 'ad_cats' ); $categories = array(); foreach( $cats as $cat ) $categories[] = $cat->term_id; $args = array( 'post_type' => 'ad_post', 'posts_per_page' => $limit, 'order'=> 'DESC', 'orderby'=> 'date', 'post__not_in' => array( $ad_id ), 'tax_query' => array( array( 'taxonomy' => 'ad_cats', 'field' => 'id', 'terms' => $categories, 'operator'=> 'IN' ) ) ); return dwt_listing_adsLoop($args); } } /* Related Ads Ends */ /* Category Specific Ads Starts */ if (!function_exists('dwt_listing_catSpecific_ads')) { function dwt_listing_catSpecific_ads($cat_id = '', $limit = 5) { //$cats = wp_get_post_terms( $ad_id, 'ad_cats' ); //$categories = array(); //foreach( $cats as $cat ) $categories[] = $cat->term_id; $categories = array($cat_id); $args = array( 'post_type' => 'ad_post', 'posts_per_page' => $limit, 'order'=> 'DESC', 'orderby'=> 'date', /*'post__not_in' => array( $ad_id ),*/ 'tax_query' => array( array( 'taxonomy' => 'ad_cats', 'field' => 'id', 'terms' => $categories, 'operator'=> 'IN' ) ) ); return dwt_listing_adsLoop($args); } } /* Category Specific Ads Ends */ if (!function_exists('dwt_listing_get_ad_terms')) { function dwt_listing_get_ad_terms($post_id = '', $term_type = 'ad_cats', $only_parent = '', $name = '') { $ad_trms = wp_get_object_terms( $post_id, $term_type); $termsArr = array(); if( count( $ad_trms ) ) { foreach( $ad_trms as $ad_trm ) { if( isset( $ad_trm->term_id ) && $ad_trm->term_id != "" ) { $termsArr[] = array ( "id" => $ad_trm->term_id, "name" => htmlspecialchars_decode($ad_trm->name, ENT_NOQUOTES), "slug" => $ad_trm->slug, "count" => $ad_trm->count, "taxonomy" => $ad_trm->taxonomy, ); } } } return ( $name == "" ) ? $termsArr : array($name, $termsArr); } } if (!function_exists('dwt_listing_get_ad_terms_names')) { function dwt_listing_get_ad_terms_names($post_id = '', $term_type = 'ad_cats', $only_parent = '', $name = '', $separator = '>') { $terms = wp_get_post_terms( $post_id, $term_type, array( 'orderby' => 'id', 'order' => 'DESC' ) ); $deepestTerm = false; $maxDepth = -1; $c = 0; $catNames = array(); if( count( $terms) > 0 ){ foreach ($terms as $term) { $ancestors = get_ancestors( $term->term_id, $term_type ); $termDepth = count($ancestors); $deepestTerm[$c] = $term->name; $maxDepth = $termDepth; $c++; } $terms = (isset($deepestTerm ) && count( $deepestTerm ) > 0 && $term_type != 'ad_tags' ) ? array_reverse($deepestTerm) : $deepestTerm; if( count( $terms ) > 0 ) { foreach( $terms as $tr ) { $trName = htmlspecialchars_decode($tr, ENT_NOQUOTES); $catNames[] = $trName; } } } $catNames = @implode(" $separator ", $catNames); return ( $name == "" ) ? $catNames : array($name, $catNames); } } if (!function_exists('dwt_listing_terms_seprates_by')) { function dwt_listing_terms_seprates_by($post_id, $taxonomy = 'ad_cats', $separator = '' ) { $terms = wp_get_post_terms( $post_id, $taxonomy, array( 'orderby' => 'id', 'order' => 'DESC' ) ); $deepestTerm = false; $maxDepth = -1; $c = 0; foreach ($terms as $term) { $ancestors = get_ancestors( $term->term_id, $taxonomy ); $termDepth = count($ancestors); $deepestTerm[$c] = $term->name; $maxDepth = $termDepth; $c++; } $terms = array_reverse($deepestTerm); $string = ''; if( count( $terms ) > 0 ) { foreach( $terms as $tr ) { $trName = htmlspecialchars_decode($tr, ENT_NOQUOTES); $string .= $trName.$separator; } } $string = rtrim($string, $separator); return $string; } } if (!function_exists('dwt_listing_get_ad_image')) { function dwt_listing_get_ad_image($post_id = '', $numOf = '', $size = 'both', $show_default = true) { $media = get_attached_media( 'image', $post_id ); $img_arr = array(); if( count( $media ) > 0 ) { $re_order = get_post_meta( $post_id, '_sb_photo_arrangement_', true ); if( $re_order != "" ) { $media = explode(",", $re_order); } $c = 1; foreach( $media as $m ) { $mid = ( isset( $m->ID ) ) ? $m->ID : $m; //$img = wp_get_attachment_image_src($mid, 'adforest-single-post'); //$full_img = wp_get_attachment_image_src($mid, 'full'); $img = wp_get_attachment_image_src($mid, 'adforest-app-thumb'); $full_img = wp_get_attachment_image_src($mid, 'adforest-app-full'); if(isset($img[0]) && isset($full_img[0])) { if($size == 'full') { $img_arr[] = array('full' => $full_img[0], "img_id" => $mid); } else if($size == 'thumb') { $img_arr[] = array('thumb' => $img[0] , "img_id" => $mid); } else { $img_arr[] = array('full' => $full_img[0], 'thumb' => $img[0], "img_id" => $mid ); } } if($numOf == $c ) break; $c++; } } else { if( $show_default == true ){ /*Need to add images from backend *********** */ global $dwt_listing_api; $default_img = dwt_listing_API_PLUGIN_URL."images/default-img.png"; $default_img = (isset( $dwt_listing_api['default_related_image'] )) ? $dwt_listing_api['default_related_image']['url'] : $default_img; $full_img = $default_img; $thumb_img = $default_img; if($size == 'full') { $img_arr[] = array('full' => $full_img ); } else if($size == 'thumb') { $img_arr[] = array('thumb' => $thumb_img ); } else { $img_arr[] = array('full' => $full_img, 'thumb' => $thumb_img ); } }else{$img_arr = array();} } return $img_arr; } } if (!function_exists('dwt_listing_get_ad_image_slider')) { function dwt_listing_get_ad_image_slider($post_id = '') { $media = get_attached_media( 'image', $post_id ); $img_arr = array(); if( count( $media ) > 0 ) { $re_order = get_post_meta( $post_id, '_sb_photo_arrangement_', true ); if( $re_order != "" ){ $media = explode(",", $re_order); } foreach( $media as $m ) { $mid = ( isset( $m->ID ) ) ? $m->ID : $m; $full_img = wp_get_attachment_image_src($mid, 'full'); if(isset($full_img[0])) { $img_arr[] = $full_img[0]; } } } return $img_arr; } } if (!function_exists('dwt_listing_get_price')) { function dwt_listing_get_price($price = '', $ad_id = '', $ad_currency_id = '') { $price_type = $ad_currency = $price_typeValue = ''; if( $ad_id != "" ) { $price_type = get_post_meta( $ad_id, '_adforest_ad_price_type', true ); $price = get_post_meta( $ad_id, '_adforest_ad_price', true ); $ad_currency = get_post_meta($ad_id, '_adforest_ad_currency', true ); $price_typeValue = ($price_type) ? dwt_listing_adPrice_typesValue($price_type) : ''; if( $price == "" && $price_type == "on_call" ) { $priceData = __("Price On Call", 'dwt-listing-api'); return array("price" => $priceData, "price_type" => $price_typeValue); } if( $price == "" && $price_type == "free" ) { $priceData = __("Free", 'dwt-listing-api'); return array("price" => $priceData, "price_type" => $price_typeValue); } if( $price == "" || $price_type == "no_price" ) { $priceData = ''; return array("price" => $priceData, "price_type" => $price_typeValue); } } if( $ad_currency_id != "" ) { $ad_currency = get_post_meta($ad_currency_id, '_adforest_ad_currency', true ); } /*Get Direction */ $position = 'left'; if( dwt_listing_getReduxValue( 'sb_price_direction', '', true)){ $position = dwt_listing_getReduxValue( 'sb_price_direction', '', false ); } /*Get Symbol */ $symbol = dwt_listing_getReduxValue( 'sb_currency', '', false ); if( $ad_currency != "" ) { $symbol = $ad_currency; } /*Get And Set Price Formate */ $thousands_sep = ","; if( dwt_listing_getReduxValue( 'sb_price_separator', '', true) ) { $thousands_sep = dwt_listing_getReduxValue( 'sb_price_separator', '', false); } $decimals = 0; if( dwt_listing_getReduxValue( 'sb_price_decimals', '', true) ) { $decimals = dwt_listing_getReduxValue( 'sb_price_decimals', '', false); } $decimals_separator = "."; if( dwt_listing_getReduxValue( 'sb_price_decimals_separator', '', true) ) { $decimals_separator = dwt_listing_getReduxValue( 'sb_price_decimals_separator', '', false); } $price = number_format( (int)$price, $decimals, $decimals_separator, $thousands_sep ); $price = ( isset( $price ) && $price != "") ? $price : 0; /*Get And Set Price Formate Ends*/ $pos = ( $position != 'left' ) ? $price. ' '.$symbol : $symbol.' '. $price; return array("price" => $pos, "price_type" => $price_typeValue); } } if (!function_exists('dwt_listing_get_adPrice')) { function dwt_listing_get_adPrice($ad_id = '', $symbol = '$') { $arr = array (); $ad_price = get_post_meta( $ad_id, '_adforest_ad_price', true ); $price_type = get_post_meta( $ad_id, '_adforest_ad_price_type', true ); $price_typeValue = ($price_type) ? dwt_listing_adPrice_typesValue($price_type) : ''; /*$symbol = "$";*/ $symbol = dwt_listing_getReduxValue( 'sb_currency', '', false ); $ad_currency = get_post_meta($ad_id, '_adforest_ad_currency', true ); if( $ad_currency != "" ) { $symbol = $ad_currency; } $arr = array("price" => $ad_price, "type" => $price_typeValue, "symbol" => $symbol); return $arr; } } if (!function_exists('dwt_listing_get_adAddress')) { function dwt_listing_get_adAddress($ad_id = '') { $location_arr = array(); $poster_location = get_post_meta( $ad_id, '_adforest_ad_location', true ); $map_lat = get_post_meta( $ad_id, '_adforest_ad_map_lat', true ); $map_long = get_post_meta( $ad_id, '_adforest_ad_map_long', true ); $map_lat = ( is_float($map_lat) || is_numeric ($map_lat) ) ? $map_lat : ''; $map_long = ( is_float($map_long) || is_numeric ($map_long) ) ? $map_long : ''; $location_arr = array("title" => __("Location", "dwt-listing-api"), "address" => $poster_location, "lat" => $map_lat, "long" => $map_long); return $location_arr; } } if (!function_exists('dwt_listing_get_adVideo')) { function dwt_listing_get_adVideo($ad_id = '') { $vid_arr = array (); $ad_video = get_post_meta($ad_id, '_adforest_ad_yvideo', true); preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $ad_video, $match); $vID = ( isset( $match[1] ) && $match[1] != "" ) ? $match[1] : ''; $vid_arr = array("video_url" => $ad_video, "video_id" => $vID); return $vid_arr; } } /* Custom Fields Starts */ if (!function_exists('dwt_listing_get_customFields')) { function dwt_listing_get_customFields($ad_id = '') { $result = dwt_listing_categoryForm_data($ad_id); //Static Iteams starts $type = sb_custom_form_data($result, '_sb_default_cat_ad_type_show'); $price = sb_custom_form_data($result, '_sb_default_cat_price_show'); $priceType = sb_custom_form_data($result, '_sb_default_cat_price_type_show'); $condition = sb_custom_form_data($result, '_sb_default_cat_condition_show'); $warranty = sb_custom_form_data($result, '_sb_default_cat_warranty_show'); $dynamicData = array(); $ad_cats = dwt_listing_get_ad_terms_names($ad_id, 'ad_cats', '', '', $separator = ','); //dwt_listing_terms_seprates_by($ad_id , 'ad_cats', ', '); $dynamicData[] = array("key" => __("Category", "dwt-listing-api"), "value" => $ad_cats, "type" => ''); $dynamicData[] = array("key" => __("Date", "dwt-listing-api"), "value" => get_the_date("", $ad_id), "type" => ''); if( $type == 1 && $result != "" ) { $custom_val = get_post_meta($ad_id, '_adforest_ad_type', true ); $dynamicData[] = array("key" => __("Type", "dwt-listing-api"), "value" => ($custom_val), "type" => ''); } else { $custom_val = get_post_meta($ad_id, '_adforest_ad_type', true ); $dynamicData[] = array("key" => __("Type", "dwt-listing-api"), "value" => ($custom_val), "type" => ''); } if( $price == 1 && $result != "" ) { $showType = ( $priceType == 1 ) ? true : false; $priceValue = dwt_listing_get_price('', $ad_id); if( isset( $priceValue['price'] ) && $priceValue['price'] != "" ) { $price_type = ( isset( $priceValue['price_type'] ) && $priceValue['price_type'] != "" ) ? " (".$priceValue['price_type'].")" : ''; $finalPrice = $priceValue['price'] . $price_type; $dynamicData[] = array("key" => __("Price", "dwt-listing-api"), "value" => $finalPrice, "type" => ''); } } else { $priceValue = dwt_listing_get_price('', $ad_id ); if( isset( $priceValue['price'] ) && $priceValue['price'] != "" ) { $price_type = ( isset( $priceValue['price_type'] ) && $priceValue['price_type'] != "" ) ? " (".$priceValue['price_type'].")" : ''; $finalPrice = $priceValue['price'] . $price_type; $dynamicData[] = array("key" => __("Price", "dwt-listing-api"), "value" => $finalPrice, "type" => ''); } } if( $condition == 1 && $result != "" ) { $custom_val = get_post_meta($ad_id, '_adforest_ad_condition', true ); $dynamicData[] = array("key" => __("Condition", "dwt-listing-api"), "value" => ($custom_val), "type" => ''); } else { $custom_val = get_post_meta($ad_id, '_adforest_ad_condition', true ); $dynamicData[] = array("key" => __("Condition", "dwt-listing-api"), "value" => ($custom_val), "type" => ''); } if( $warranty == 1 && $result != "" ) { $custom_val = get_post_meta($ad_id, '_adforest_ad_warranty', true ); $dynamicData[] = array("key" => __("Warranty", "dwt-listing-api"), "value" => ($custom_val), "type" => ''); } else { $custom_val = get_post_meta($ad_id, '_adforest_ad_warranty', true ); $dynamicData[] = array("key" => __("Warranty", "dwt-listing-api"), "value" => ($custom_val), "type" => ''); } $is_show_location = wp_count_terms( 'ad_country' ); if( isset($is_show_location) && $is_show_location > 0 ) { /*Some Location Code Goes Here */ //$ad_country = dwt_listing_get_ad_terms_names($ad_id, 'ad_country', '', '', $separator = ','); //dwt_listing_terms_seprates_by($ad_id , 'ad_cats', ', '); //$dynamicData[] = array("key" => __("Location", "dwt-listing-api"), "value" => $ad_country, "type" => ''); } //Static Iteams ends //Dynamic Cats $formData = sb_dynamic_form_data($result); if(count($formData) > 0) { foreach($formData as $data) { if($data['titles'] != "") { $values = get_post_meta($ad_id, "_adforest_tpl_field_".$data['slugs'], true ); $value = json_decode($values); $value = (is_array( $value ) ) ?implode($value, ", ") : $values; $titles = ($data['titles']); $status = ($data['status']); if( $value != "" && $status == 1) { $type = 'textfield'; if( $data['types'] == '1' ) {$type = 'textfield';} if( $data['types'] == '2' ) {$type = 'select';} if( $data['types'] == '3' ) {$type = 'checkbox';} $dynamicData[] = array("key" => esc_html($titles), "value" => esc_html($value), "type" => $type); } } } } global $wpdb; $rows = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE post_id = '$ad_id' AND meta_key LIKE '_sb_extra_%'"); if(count( $rows ) > 0 ) { foreach( $rows as $row ) { $caption = explode( '_', $row->meta_key ); $name = ucfirst( $caption[3] ); if( $row->meta_value == "" ) continue; $dynamicData[] = array("key" => esc_html($name), "value" => esc_html($row->meta_value), "type" => ''); } } return ($dynamicData); } } if ( ! function_exists( 'adforest_randomString' ) ) { function adforest_randomString($length = 50) { $str = ""; $characters = array_merge(range('A','Z'), range('a','z'), range('0','9')); $max = count($characters) - 1; for ($i = 0; $i < $length; $i++) { $rand = mt_rand(0, $max); $str .= $characters[$rand]; } return $str; } } /* User ads starts */ if (!function_exists('dwt_listing_userAds')) { function dwt_listing_userAds($userid = '', $status = '', $adType = '', $limit = 1, $adStatus = 'publish', $other = '') { if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); } else if ( isset( $limit ) ) { $paged = $limit; } else { $paged = 1; } $adType = ($adType != "" ) ? array('key' => '_adforest_is_feature', 'value' => $adType, 'compare' => '=') : array(); $status = ($status != "" ) ? array('key' => '_adforest_ad_status_', 'value' => $status, 'compare' => '=') : array(); $lat_lng_meta_query = array(); if($other == 'near_me' ) { $lats_longs = dwt_listing_determine_minMax_latLong(); if(isset($lats_longs) && count($lats_longs) > 0 ) { if( isset($lats_longs['lat']['original']) && $lats_longs['lat']['original'] > 0 ) { $lat_lng_meta_query[] = array( 'key' => '_adforest_ad_map_lat', 'value' => array($lats_longs['lat']['min'], $lats_longs['lat']['max']), 'compare' => 'BETWEEN', ); } else { $lat_lng_meta_query[] = array( 'key' => '_adforest_ad_map_lat', 'value' => array($lats_longs['lat']['max'], $lats_longs['lat']['min']), 'compare' => 'BETWEEN', ); } if( isset($lats_longs['long']['original']) && $lats_longs['long']['original'] > 0 ) { $lat_lng_meta_query[] = array( 'key' => '_adforest_ad_map_long', 'value' => array($lats_longs['long']['min'], $lats_longs['long']['max']), 'compare' => 'BETWEEN', ); } else { $lat_lng_meta_query[] = array( 'key' => '_adforest_ad_map_long', 'value' => array($lats_longs['long']['max'], $lats_longs['long']['min']), 'compare' => 'BETWEEN', ); } } } $posts_per_page = get_option( 'posts_per_page' ); if( $userid != "" ) { $args = array( 'author' => $userid, 'post_type' => 'ad_post', 'post_status' => $adStatus, 'posts_per_page' => $posts_per_page, 'paged' => $paged, 'order'=> 'DESC', 'orderby'=> 'date', 'meta_query' => array( $status, $adType, $lat_lng_meta_query ), ); } else { $args = array( 'post_type' => 'ad_post', 'post_status' => $adStatus, 'posts_per_page' => $posts_per_page, 'paged' => $paged, 'order'=> 'DESC', 'orderby'=> 'date', 'meta_query' => array( $status, $adType , $lat_lng_meta_query), ); } $ad_data = dwt_listing_adsLoop($args, $userid, true, false, true); $found_posts = $ad_data['found_posts']; $max_num_pages = $ad_data['max_num_pages']; $nextPaged = $paged + 1; $has_next_page = ( $nextPaged <= (int)$max_num_pages ) ? true : false; $adData = array(); $adData['ads'] = $ad_data['ads']; $adData['pagination'] = array("max_num_pages" => (int)$max_num_pages, "current_page" => (int)$paged, "next_page" => (int)$nextPaged, "increment" => (int)$posts_per_page , "current_no_of_ads" => (int)$found_posts, "has_next_page" => $has_next_page ); return $adData; } } /* User ads starts */ /* User ads starts */ if (!function_exists('dwt_listing_userAds_fav')) { function dwt_listing_userAds_fav($userid = '', $status = '', $adType = '', $limit = 1, $adStatus = 'publish') { $adType = ($adType != "" ) ? array('key' => '_adforest_is_feature', 'value' => $adType, 'compare' => '=') : array(); $status = ($status != "" ) ? array('key' => '_adforest_ad_status_', 'value' => $status, 'compare' => '=') : array(); global $wpdb; $rows = $wpdb->get_results( "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '$userid' AND meta_key LIKE '_sb_fav_id_%'" ); $pids = array(); if( count( $rows ) > 0 ){ foreach( $rows as $row ) { $pids[] = (int)$row->meta_value; } } else{$pids = array(0);} if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); } else if ( isset( $limit ) ) { $paged = $limit; } else { $paged = 1; } $posts_per_page = get_option( 'posts_per_page' ); $args = array( 'post__in' => $pids, 'post_type' => 'ad_post', 'post_status' => $adStatus, 'posts_per_page' => $posts_per_page, 'paged' => $paged, 'order' => 'DESC', 'orderby' => 'date', ); $ad_data = dwt_listing_adsLoop($args, $userid, true, true, true); $found_posts = $ad_data['found_posts']; $max_num_pages = $ad_data['max_num_pages']; $nextPaged = $paged + 1; $has_next_page = ( $nextPaged <= (int)$max_num_pages ) ? true : false; $adData = array(); $adData['ads'] = $ad_data['ads']; $adData['pagination'] = array("max_num_pages" => (int)$max_num_pages, "current_page" => (int)$paged, "next_page" => (int)$nextPaged, "increment" => (int)$posts_per_page , "current_no_of_ads" => (int)$found_posts, "has_next_page" => $has_next_page ); return $adData; } } /* User ads starts */ /* featured ad slider starts */ if (!function_exists('dwt_listing_featuredAds_slider')) { function dwt_listing_featuredAds_slider($userid = '', $status = '', $adType = '', $limit = -1, $term_id = '', $adStatus = 'publish', $other = '') { $adType = ($adType != "" ) ? array('key' => '_adforest_is_feature', 'value' => $adType, 'compare' => '=') : array(); $status = ($status != "" ) ? array('key' => '_adforest_ad_status_', 'value' => $status, 'compare' => '=') : array(); $lat_lng_meta_query = array(); if($other == 'nearby' ) { $lats_longs = dwt_listing_determine_minMax_latLong(); if(isset($lats_longs) && count($lats_longs) > 0 ) { if( isset($lats_longs['lat']['original']) && $lats_longs['lat']['original'] > 0 ) { $lat_lng_meta_query[] = array( 'key' => '_adforest_ad_map_lat', 'value' => array($lats_longs['lat']['min'], $lats_longs['lat']['max']), 'compare' => 'BETWEEN', ); } else { $lat_lng_meta_query[] = array( 'key' => '_adforest_ad_map_lat', 'value' => array($lats_longs['lat']['max'], $lats_longs['lat']['min']), 'compare' => 'BETWEEN', ); } if( isset($lats_longs['long']['original']) && $lats_longs['long']['original'] > 0 ) { $lat_lng_meta_query[] = array( 'key' => '_adforest_ad_map_long', 'value' => array($lats_longs['long']['min'], $lats_longs['long']['max']), 'compare' => 'BETWEEN', ); } else { $lat_lng_meta_query[] = array( 'key' => '_adforest_ad_map_long', 'value' => array($lats_longs['long']['max'], $lats_longs['long']['min']), 'compare' => 'BETWEEN', ); } } else{ return array(); } } $category = ''; if( $term_id != "" ) { $category = array( array( 'taxonomy' => 'ad_cats', 'field' => 'term_id', 'terms' => $term_id, ), ); } $args = array( 'post_type' => 'ad_post', 'post_status' => $adStatus, 'posts_per_page' => $limit, 'order'=> 'DESC', 'orderby'=> 'date', 'tax_query' => array( $category ), 'meta_query' => array( $status, $adType, $lat_lng_meta_query ), ); return dwt_listing_adsLoop($args, $userid, true); } } /* featured ad slider starts */ /* site ads starts */ if (!function_exists('dwt_listing_siteAds')) { function dwt_listing_siteAds($userid = '', $status = '', $adType = '', $limit = -1, $adStatus = 'publish') { $adType = ($adType != "" ) ? array('key' => '_adforest_is_feature', 'value' => $adType, 'compare' => '=') : array(); $status = ($status != "" ) ? array('key' => '_adforest_ad_status_', 'value' => $status, 'compare' => '=') : array(); $args = array( 'post_type' => 'ad_post', 'post_status' => $adStatus, 'posts_per_page' => $limit, 'order'=> 'DESC', 'orderby'=> 'date', 'meta_query' => array( $status, $adType ), ); return dwt_listing_adsLoop($args, $userid, true); } } /* site ads starts */ add_action( 'rest_api_init', 'add_thumbnail_to_JSON' ); function add_thumbnail_to_JSON() { register_rest_field( 'post', 'featured_image_src', array( 'get_callback' => 'get_image_src', 'update_callback' => null, 'schema' => null, ) ); } function get_image_src( $object, $field_name, $request ) { $feat_img_array = wp_get_attachment_image_src($object['featured_media'], 'adforest-single-post', true); return $feat_img_array[0]; } add_action( 'rest_api_init', 'add_post_comment_count' ); function add_post_comment_count() { register_rest_field( 'post', 'post_comment_count', array( 'get_callback' => 'add_post_comment_count_func', 'update_callback' => null, 'schema' => null, ) ); } function add_post_comment_count_func( $object, $field_name, $request ) { return 100; } /*Get login time*/ if (!function_exists('dwt_listing_getLastLogin')) { function dwt_listing_getLastLogin( $uid, $show_text = false ) { $from = get_user_meta( $uid, '_sb_last_login', true ); if($from != "" ) { /*DO Somethings*/ } else{$from = time();} $showText = ( $show_text ) ? __("Last Login:", "dwt-listing-api") : ''; return $showText .' '. human_time_diff($from, time() ); } } /*Input*/ if (!function_exists('dwt_listing_get_ad_terms_names_vals')) { function dwt_listing_get_ad_terms_names_vals($term_type = 'ad_cats', $only_parent = 0, $name = '',$placeholder = '') { $terms = get_terms( array( 'taxonomy' => $term_type, 'hide_empty' => false, 'parent' => $only_parent, ) ); $termsArr = array(); $catNames = ''; $catIDS = ''; $values = ''; if( count( $terms ) ) { foreach( $terms as $ad_trm ) { $catIDS[] = $ad_trm->term_id; $catNames[] = htmlspecialchars_decode($ad_trm->name, ENT_NOQUOTES); } } return $arr = array("ids" => $catIDS, "names" => $catNames, "title" => $name, "placeholder" => $placeholder); } } if (!function_exists('dwt_listing_get_search_inputs')) { function dwt_listing_get_search_inputs($title = '', $placeholder = '') { return $arr = array("title" => $title, "placeholder" => $placeholder); } } if (!function_exists('dwt_listing_getSubCats')) { function dwt_listing_getSubCats($field_type = '', $field_type_name = '', $term_type = 'ad_cats', $only_parent = 0, $name = '',$mainTitle = '', $show_count = true) { global $dwt_listing_api; $hasShow_template = false; if( isset($dwt_listing_api['adpost_cat_template']) && $dwt_listing_api['adpost_cat_template'] == true && $term_type == "ad_cats" ) { $hasShow_template = true; } $terms = get_terms( array( 'taxonomy' => $term_type, 'hide_empty' => false, 'parent' => $only_parent, ) ); $termsArr = array(); $values = ''; if( count( $terms ) > 0 ) { foreach( $terms as $ad_trm ) { $term_children = get_term_children( filter_var( $ad_trm->term_id, FILTER_VALIDATE_INT ), filter_var( $term_type, FILTER_SANITIZE_STRING ) ); $has_sub = ( empty( $term_children ) || is_wp_error( $term_children ) ) ? false : true; $result = adforest_dynamic_templateID($ad_trm->term_id); $templateID = get_term_meta( $result , '_sb_dynamic_form_fields' , true); $has_template = (isset($templateID) && $templateID != "") ? true : false; if( isset($dwt_listing_api['adpost_cat_template']) && $dwt_listing_api['adpost_cat_template'] == true && $term_type == "ad_cats" ) { $has_template = true; } if( isset($dwt_listing_api['adpost_cat_template']) && $dwt_listing_api['adpost_cat_template'] == false ) { $has_template = false; } $counts = ($show_count == true ) ? ' ('.$ad_trm->count. ')' : ""; $termsArr[] = array ( "id" => $ad_trm->term_id, "name" => htmlspecialchars_decode($ad_trm->name, ENT_NOQUOTES) . $counts, "has_sub" => $has_sub, "has_template" => $has_template, ); } $values = $termsArr; } if( isset($dwt_listing_api['adpost_cat_template']) && $dwt_listing_api['adpost_cat_template'] == false ) { $has_template = false; } return array("main_title" => $mainTitle, "field_type" => $field_type, "field_type_name" => $field_type_name,"field_val" => "", "field_name" => "", "title" => $name, "values" => $values, "has_cat_template" => $has_template); } } if (!function_exists('dwt_listing_is_multiArr')) { function dwt_listing_is_multiArr($a) { $rv = array_filter($a,'is_array'); if(count($rv)>0) return true; return false; } } add_action( 'rest_api_init', 'dwt_listing_some_test', 0 ); function dwt_listing_some_test() { register_rest_route( 'adforest/v1', '/sometest/', array( 'methods' => WP_REST_Server::READABLE, 'callback' => 'dwt_listing_adPrice_types', ) ); } if( !function_exists('dwt_listing_adPrice_typesValue' ) ) { function dwt_listing_adPrice_typesValue($selectVal = '') { $array = array(); $priceTypes = array( 'Fixed' => __( 'Fixed', 'dwt-listing-api' ),'', 'Negotiable' => __( 'Negotiable', 'dwt-listing-api' ), 'on_call' => __( 'Price on call', 'dwt-listing-api' ), 'auction' => __( 'Auction', 'dwt-listing-api' ), 'free' => __( 'Free', 'dwt-listing-api' ), 'no_price' => __( 'No price', 'dwt-listing-api' ), ); $returnValue = ''; if(isset($priceTypes[$selectVal]) && $priceTypes[$selectVal] != "" ) { $returnValue = $priceTypes[$selectVal]; } return $returnValue; } } if( !function_exists('dwt_listing_adPrice_types' ) ) { function dwt_listing_adPrice_types($selectVal = '') { global $dwt_listing_api; $array = array(); $priceTypes = array( 'Fixed' => __( 'Fixed', 'dwt-listing-api' ),'', 'Negotiable' => __( 'Negotiable', 'dwt-listing-api' ), 'on_call' => __( 'Price on call', 'dwt-listing-api' ), 'auction' => __( 'Auction', 'dwt-listing-api' ), 'free' => __( 'Free', 'dwt-listing-api' ), 'no_price' => __( 'No price', 'dwt-listing-api' ), ); if(isset( $dwt_listing_api['sb_price_types'] ) && $dwt_listing_api['sb_price_types'] && count($dwt_listing_api['sb_price_types']) > 0) { foreach( $dwt_listing_api['sb_price_types'] as $val) { $is_show = ( $val == "on_call" || $val == "free" || $val == "no_price" ) ? false : true; if(isset($priceTypes[$val]) && $priceTypes[$val] != "" && $val != "" ) { $value = $priceTypes[$val]; $array[] = array("key" => $val, "val" => $value, "is_show" => $is_show); } } } else { foreach( $priceTypes as $p_key => $p_val) { if( $p_key != "" && $p_val != "" ) { $is_show = ( $p_key == "on_call" || $p_key == "free" || $p_key == "no_price" ) ? false : true; $array[] = array("key" => $p_key, "val" => $p_val, "is_show" => $is_show); } } } if(isset( $dwt_listing_api['sb_price_types_more'] ) && $dwt_listing_api['sb_price_types_more'] != "" ) { $types = @explode("|", $dwt_listing_api['sb_price_types_more']); if(count($types) > 0 ) { foreach($types as $t ) { $custom_key = str_replace(' ', '_', $t); $array[] = array("key" => $custom_key, "val" => $t, "is_show" => true); } } } if( $selectVal != "" ) { $newKey = array(); foreach( $array as $key => $value ) { if( $selectVal == $value['key'] ) { $arrIndex = $value; $newKey = $arrIndex; unset($array[$key]); array_unshift($array, $newKey); } } } return $array; } } if ( ! function_exists( 'dwt_listing_arraySearch' ) ) { function dwt_listing_arraySearch($array, $index, $value) { if( $value != "" ) { $arr = array(); $count = 0; foreach( $array as $key => $val) { $data = ( $index != "" ) ? $val["$index"] : $val; if($data == $value) { $arr = ( $val ); unset($array[$count]); } $count++; } $array = array_merge(array( $arr ), $array); } return $array; } } if ( ! function_exists( 'dwt_listing_objArraySearch' ) ) { function dwt_listing_objArraySearch($array, $index, $value, $newIndex = array() ) { $extractedKey = array(); if( isset( $array ) && count($array) > 0 ) { foreach($array as $key => $arrayInf) { if($arrayInf->{$index} == $value) { unset($array[ $key ]); $extractedKey = $arrayInf; //return $arrayInf; } } } return ( isset( $newIndex ) && count( (array)$newIndex ) > 0 && $newIndex != "" ) ? array_merge(array( $newIndex ), $array) : $array ; } } if (!function_exists('dwt_listing_getPostAdFields')) { function dwt_listing_getPostAdFields($field_type = '', $field_type_name = '', $term_type = 'ad_cats', $only_parent = 0, $name = '',$mainTitle = '', $defaultValue = '', $has_page_number = 1, $is_required = false, $update_val = '', $ad_id = '') { global $dwt_listing_api; $values = ''; $returnType = 1; $values_arr = array(); $has_cat_template = false; if( $field_type == "select" ) { $termsArr = array(); if( is_array( $term_type ) ) { $is_multiArr = dwt_listing_is_multiArr( $term_type ); if( $is_multiArr == true ) { $term_type = dwt_listing_arraySearch($term_type, "key", $update_val); foreach( $term_type as $val ) { $termsArr[] = array ( "id" => (string)$val['key'], "name" => $val['val'], "has_sub" => false, "has_template" => false, "is_show" => $val['is_show'], ); } } else { foreach( $term_type as $key => $val ){ $termsArr[] = array ( "id" => (string)$key, "name" => $val, "has_sub" => false, "has_template" => false, "is_show" => true, ); } } } else{ $has_cat_template = ($term_type == "ad_cats") ? true : false; $terms = get_terms( array( 'taxonomy' => $term_type, 'hide_empty' => false, 'parent' => $only_parent, ) ); $ad_cats = array(); if( $ad_id != "" ) { $ad_cats = wp_get_object_terms( $ad_id, $term_type, array('fields' => 'ids') ); if($term_type == "ad_country") { $ad_cats = dwt_listing_getCats_idz($ad_id, 'ad_country', true); /*dwt_listing_cat_ancestors( $ad_cats, 'ad_country', true);*/ } if( count( $ad_cats ) > 0 ) { $count_update_val = count($ad_cats) - 1; $finalCatID = $ad_cats[$count_update_val]; $term_data = get_term_by('id', $finalCatID, $term_type); $terms = dwt_listing_objArraySearch($terms, 'term_id', $finalCatID, $term_data); } } if($term_type == "ad_country") //print_r( $ad_cats ); $termsArr = array(); $catNames = ''; $catIDS = ''; if( count( $terms ) ) { if( count( $ad_cats ) == 0) { $termsArr[] = array ( "id" => "", "name" => __("Select Option", "dwt-listing-api"), "has_sub" => false, "has_template" => false, "is_show" => true, ); } foreach( $terms as $ad_trm ) { $result = adforest_dynamic_templateID(@$ad_trm->term_id); $templateID = get_term_meta( $result , '_sb_dynamic_form_fields' , true); $has_template = (isset($templateID) && $templateID != "") ? true : false; if( isset($dwt_listing_api['adpost_cat_template']) && $dwt_listing_api['adpost_cat_template'] == true && $term_type == "ad_cats" ) { $has_template = true; } $term_children = get_term_children( filter_var( @$ad_trm->term_id, FILTER_VALIDATE_INT ), filter_var( $term_type, FILTER_SANITIZE_STRING)); $has_sub = ( empty( $term_children ) || is_wp_error( $term_children ) ) ? false : true; $termsArr[] = array ( "id" => (string)$ad_trm->term_id, "name" => htmlspecialchars_decode(@$ad_trm->name, ENT_NOQUOTES), "has_sub" => $has_sub, "has_template" => $has_template, "is_show" => true, /*"count" => $ad_trm->count,*/ ); } } } $values = $termsArr; $values_arr = $termsArr; } if( $field_type == "textfield" || "glocation_textfield" == $field_type || "textarea" == $field_type ) { $values = $defaultValue; $values_arr = ($defaultValue != "") ? array($defaultValue) : array(); if( $term_type != "" ) { $update_val = get_post_meta($ad_id, $term_type, true); } } if( $field_type == "image" ){ $values_arr = ($defaultValue != "") ? array($defaultValue) : array(); $values = $defaultValue; } if( $field_type == "map" ){ $values_arr = ($defaultValue != "") ? array($defaultValue) : array(); $values = $defaultValue; } if( isset($dwt_listing_api['adpost_cat_template']) && $dwt_listing_api['adpost_cat_template'] == false ) { $has_cat_template = false; } $values_data = $values; return array("main_title" => $mainTitle, "field_type" => $field_type, "field_type_name" => $field_type_name,"field_val" => $update_val, "field_name" => "", "title" => $name, "values" => $values_data, "has_page_number" => (string)$has_page_number, "is_required" => $is_required, "has_cat_template" => $has_cat_template); } } if (!function_exists('dwt_listing_getCats_idz')) { function dwt_listing_getCats_idz($postId, $term_name, $reverse_arr = false) { $terms = wp_get_post_terms( $postId, $term_name, array( 'orderby' => 'id', 'order' => 'DESC' ) ); $deepestTerm = false; $maxDepth = -1; $c = 0; if( isset( $terms ) && count( $terms ) > 0 ){ foreach ($terms as $term) { $ancestors = get_ancestors( $term->term_id, $term_name ); $termDepth = count($ancestors); $deepestTerm[$c] = $term->term_id; $maxDepth = $termDepth; $c++; } return ( $reverse_arr == false ) ? $deepestTerm : array_reverse( $deepestTerm ); } else { return array(); } } } if (!function_exists('dwt_listing_getUnreadMessageCount')) { function dwt_listing_getUnreadMessageCount() { global $wpdb; $user_id = get_current_user_id(); $unread_msgs = 0; if($user_id) { $unread_msgs = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = '$user_id' AND meta_value = '0' " ); } return $unread_msgs; } } if (!function_exists('dwt_listing_getSearchFields')) { function dwt_listing_getSearchFields($field_type = '', $field_type_name = '', $term_type = 'ad_cats', $only_parent = 0, $name = '',$mainTitle = '', $defaultValue = '', $is_id = true) { global $dwt_listing_api; $values = ''; $returnType = 1; $has_cat_template = false; if( $field_type == "select" ) { $termsArr = array(); if( is_array( $term_type ) ) { foreach( $term_type as $key => $val ){ $termsArr[] = array ( "id" => (string)$key, "name" => $val, "has_sub" => false, "has_template" => false, /*"count" => $ad_trm->count,*/ ); } } else{ $has_cat_template = ($term_type == "ad_cats") ? true : false; $show_counts = ($term_type == "ad_cats") ? true : false; $terms = get_terms( array( 'taxonomy' => $term_type, 'hide_empty' => false, 'parent' => $only_parent, ) ); $termsArr = array(); $catNames = ''; $catIDS = ''; if( count( $terms ) ) { $termsArr[] = array ( "id" => "", "name" => __("Select Option", "dwt-listing-api"), "has_sub" => false, "has_template" => false, ); foreach( $terms as $ad_trm ) { $result = adforest_dynamic_templateID($ad_trm->term_id); $templateID = get_term_meta( $result , '_sb_dynamic_form_fields' , true); $has_template = (isset($templateID) && $templateID != "") ? true : false; if( isset($dwt_listing_api['adpost_cat_template']) && $dwt_listing_api['adpost_cat_template'] == true ) { if( $term_type == "ad_cats" ){ $has_template = true; } } $countsNumber = ( $show_counts == true ) ? ' ('.$ad_trm->count. ')' : ''; $countsNumber = '';/*Tempraroty Off*/ $term_children = get_term_children( filter_var( $ad_trm->term_id, FILTER_VALIDATE_INT ), filter_var( $term_type, FILTER_SANITIZE_STRING ) ); $has_sub = ( empty( $term_children ) || is_wp_error( $term_children ) ) ? false : true; $idVal = ( $is_id == true ) ? $ad_trm->term_id : htmlspecialchars_decode($ad_trm->name, ENT_NOQUOTES); $termsArr[] = array ( "id" => (string)$idVal, "name" => htmlspecialchars_decode($ad_trm->name, ENT_NOQUOTES) . $countsNumber, "has_sub" => $has_sub, "has_template" => $has_template, /*"count" => $ad_trm->count,*/ ); } } } $values = $termsArr; } if( $field_type == "textfield" || "glocation_textfield" == $field_type || "textarea" == $field_type ) { $values = $defaultValue; } if( $field_type == "seekbar" ){ $values = $defaultValue; } if( $field_type == "image" ){ $values = $defaultValue; } if( $field_type == "map" ){ $values = $defaultValue; } if( "range_textfield" == $field_type ) { $title1 = $name[0]; $title2 = $name[1]; $array[] = array("title" => $title1); $array[] = array("title" => $title2); $returnType = 2; $values = ''; } if( $returnType == 2) { return array("title" => $mainTitle, "field_type_name" => $field_type_name, "field_type" => $field_type, "data" => $array); } else { if( isset($dwt_listing_api['adpost_cat_template']) && $dwt_listing_api['adpost_cat_template'] == false ) { $has_cat_template = false; } return array("main_title" => $mainTitle, "field_type" => $field_type, "field_type_name" => $field_type_name,"field_val" => "", "field_name" => "", "title" => $name, "values" => $values, "has_cat_template" => $has_cat_template); } } } function dwt_listing_categoryForm_data($postId) { $resultD = ''; $terms = wp_get_post_terms( $postId, 'ad_cats', array( 'orderby' => 'id', 'order' => 'DESC' ) ); $deepestTerm = false; $maxDepth = -1; $c = 0; foreach ($terms as $term) { $ancestors = get_ancestors( $term->term_id, 'ad_cats' ); $termDepth = count($ancestors); $deepestTerm[$c] = $term; $maxDepth = $termDepth; $c++; } $term_id = ''; if( isset($deepestTerm) && is_array($deepestTerm) && count($deepestTerm) > 0 ){ foreach ($deepestTerm as $term) { $term_id = $term->term_id; $t = adforest_dynamic_templateID($term_id); if($t) break; } $templateID = adforest_dynamic_templateID($term_id); $resultD = get_term_meta( $templateID , '_sb_dynamic_form_fields' , true); } return $resultD; } function dwt_listing_getCats_template($postId) { $result = dwt_listing_categoryForm_data($postId); $formData = sb_dynamic_form_data($result); $dynamicData = array(); if(count($formData) > 0) { foreach($formData as $data) { if($data['titles'] != "") { $values = get_post_meta($postId, "_adforest_tpl_field_".$data['slugs'], true ); $value = json_decode($values); $value = (is_array( $value ) ) ?implode($value, ", ") : $values; $titles = ($data['titles']); $status = ($data['status']); if( $value != "" && $status == 1) { $type = 'textfield'; if( $data['types'] == '1' ) {$type = 'textfield';} if( $data['types'] == '2' ) {$type = 'select';} if( $data['types'] == '3' ) {$type = 'checkbox';} $dynamicData[] = array("key" => esc_html($titles), "value" => esc_html($value), "type" => $type); } } } } return ($dynamicData); } function dwt_listing_get_posts_count() { global $wp_query; return $wp_query->post_count; } if (!function_exists('dwt_listing_get_customAdPostFields')) { function dwt_listing_get_customAdPostFields($form_type = '', $fieldsData = '', $extra_section_title = '') { $appArr['form_type'] = $form_type; $arr = array(); if(isset($fieldsData) && count( $fieldsData ) > 0 ) { $rows = $fieldsData; if( count( $rows[0] ) > 0 && count( $rows ) > 0 ) { foreach($rows as $row ) { if( isset( $row['title'] ) && isset( $row['type'] ) && isset( $row['slug'] ) ) { $option_values = ( isset( $row['option_values'] ) && $row['option_values'] != "" ) ? $row['option_values'] : ''; $arr[] = array( "section_title" => $extra_section_title, "type" => $row['type'], "title" =>$row['title'], "slug" =>$row['slug'], "option_values" => $option_values ); } } } } $appArr['custom_fields'] = $arr; $data = json_encode($appArr, true); update_option("_dwt_listing_customFields", $data); } } /*Time Ago*/ if ( ! function_exists( 'dwt_listing_timeago' ) ) { function dwt_listing_timeago($date) { $timestamp = strtotime($date); $strTime = array(__('second','dwt-listing-api'), __('minute','dwt-listing-api'),__('hour','dwt-listing-api'),__('day','dwt-listing-api'),__('month','dwt-listing-api'),__('year','dwt-listing-api') ); $length = array("60","60","24","30","12","10"); $currentTime = strtotime( current_time('mysql')); if($currentTime >= $timestamp) { $diff = $currentTime - $timestamp; for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) { $diff = $diff / $length[$i]; } $diff = round($diff); return $diff . " " . $strTime[$i] . __('(s) ago','dwt-listing-api' ); } } } // Time difference n days if ( ! function_exists( 'dwt_listing_days_diff' ) ) { function dwt_listing_days_diff( $now, $from ) { $datediff = $now - $from; return floor($datediff / (60 * 60 * 24)); } } if( ! function_exists( 'dwt_listing_do_register' ) ) { function dwt_listing_do_register($name = '' , $email= '', $password = '') { $u_name = dwt_listing_check_user_name( $name ); $uid = wp_create_user( $u_name, $password, $email ); wp_update_user( array( 'ID' => $uid, 'display_name' => $u_name ) ); } } if ( ! function_exists( 'dwt_listing_check_user_name' ) ) { function dwt_listing_check_user_name( $username = '' ) { if ( username_exists( $username ) ) { $random = mt_rand(); $username = $username . '-' . $random; dwt_listing_check_user_name($username); } return $username; } } if ( ! function_exists( 'dwt_listing_get_all_ratings' ) ) { function dwt_listing_get_all_ratings( $user_id ) { global $wpdb; $ratings = $wpdb->get_results( "SELECT * FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key like '_user_%' ORDER BY umeta_id DESC", OBJECT ); return $ratings; } } // Email on ad publish add_action( 'transition_post_status', 'dwt_listing_send_mails_on_publish', 10, 3 ); function dwt_listing_send_mails_on_publish( $new_status, $old_status, $post ) { if ( 'publish' !== $new_status or 'publish' === $old_status or 'ad_post' !== get_post_type( $post ) ) return; global $dwt_listing_api; if( isset( $dwt_listing_api['email_on_ad_approval'] ) && $dwt_listing_api['email_on_ad_approval'] ) { adforest_get_notify_on_ad_approval( $post ); } } // check permission for ad posting if ( ! function_exists( 'dwt_listing_check_ads_validity' ) ) { function dwt_listing_check_ads_validity() { global $dwt_listing_api; $user = wp_get_current_user(); $user_id = $user->data->ID; $uid = $user_id; if( get_user_meta( $user_id, '_sb_simple_ads', true ) == 0 || get_user_meta( $uid, '_sb_simple_ads', true ) == "" ) { $message = __( 'Please subscribe package for ad posting.', 'dwt-listing-api') ; } else { if( get_user_meta( $user_id, '_sb_expire_ads', true ) != '-1' ) { if( get_user_meta( $user_id, '_sb_expire_ads', true ) < date('Y-m-d') ) { update_user_meta( $user_id, '_sb_simple_ads', 0 ); update_user_meta( $user_id, '_sb_featured_ads', 0 ); $message = __( 'Your package has been expired.', 'dwt-listing-api') ; } } } } } if ( ! function_exists( 'dwt_listing_make_link' ) ) { function dwt_listing_make_link( $url, $text ) { return wp_kses( "<a href='". esc_url ( $url )."' target='_blank'>", dwt_listing_required_tags() ) . $text . wp_kses( '</a>', dwt_listing_required_tags() ); } } if ( ! function_exists( 'dwt_listing_required_attributes' ) ) { function dwt_listing_required_attributes() { return $default_attribs = array( 'id' => array(), 'src' => array(), 'href' => array(), 'target' => array(), 'class' => array(), 'title' => array(), 'type' => array(), 'style' => array(), 'data' => array(), 'role' => array(), 'aria-haspopup' => array(), 'aria-expanded' => array(), 'data-toggle' => array(), 'data-hover' => array(), 'data-animations' => array(), 'data-mce-id' => array(), 'data-mce-style' => array(), 'data-mce-bogus' => array(), 'data-href' => array(), 'data-tabs' => array(), 'data-small-header' => array(), 'data-adapt-container-width' => array(), 'data-height' => array(), 'data-hide-cover' => array(), 'data-show-facepile' => array(), ); } } if ( ! function_exists( 'dwt_listing_required_tags' ) ) { function dwt_listing_required_tags() { return $allowed_tags = array( 'div' => dwt_listing_required_attributes(), 'span' => dwt_listing_required_attributes(), 'p' => dwt_listing_required_attributes(), 'a' => array_merge( dwt_listing_required_attributes(), array( 'href' => array(), 'target' => array('_blank', '_top'), ) ), 'u' => dwt_listing_required_attributes(), 'br' => dwt_listing_required_attributes(), 'i' => dwt_listing_required_attributes(), 'q' => dwt_listing_required_attributes(), 'b' => dwt_listing_required_attributes(), 'ul' => dwt_listing_required_attributes(), 'ol' => dwt_listing_required_attributes(), 'li' => dwt_listing_required_attributes(), 'br' => dwt_listing_required_attributes(), 'hr' => dwt_listing_required_attributes(), 'strong' => dwt_listing_required_attributes(), 'blockquote' => dwt_listing_required_attributes(), 'del' => dwt_listing_required_attributes(), 'strike' => dwt_listing_required_attributes(), 'em' => dwt_listing_required_attributes(), 'code' => dwt_listing_required_attributes(), 'style' => dwt_listing_required_attributes(), 'script' => dwt_listing_required_attributes(), 'img' => dwt_listing_required_attributes(), ); } } if ( ! function_exists( 'dwt_listing_CustomFieldsVals' ) ) { function dwt_listing_CustomFieldsVals($post_id = '', $terms = array()) { if($post_id == "") return; /*$terms = wp_get_post_terms($post_id, 'ad_cats');*/ $is_show = ''; if(count($terms) > 0 ) { foreach ($terms as $term) { $term_id = $term; $t = adforest_dynamic_templateID($term_id); if($t) break; } $templateID = adforest_dynamic_templateID($term_id); $result = get_term_meta( $templateID , '_sb_dynamic_form_fields' , true); $is_show = ''; $html = ''; if(isset($result) && $result != "") { $is_show = sb_custom_form_data($result, '_sb_default_cat_image_required'); } } return ($is_show == 1) ? 1 : 0; } } // Bad word filter if ( ! function_exists( 'dwt_listing_badwords_filter' ) ) { function dwt_listing_badwords_filter( $words = array(), $string, $replacement ) { foreach( $words as $word ) { $string = str_replace($word, $replacement, $string); } return $string; } } function increase_timeout_for_api_requests_27091( $r, $url ) { if ( false !== strpos( $url, '//api.wordpress.org/' ) ) { $r['timeout'] = 60; } return $r; } add_filter( 'http_request_args', 'increase_timeout_for_api_requests_27091', 10, 2 ); // ------------------------------------------------ // // Get and Set Post Views // // ------------------------------------------------ // if ( ! function_exists( 'dwt_listing_getPostViews' ) ) { function dwt_listing_getPostViews($postID){ $postID = esc_html( $postID ); $count_key = 'sb_post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); return "0"; } return $count; } } if ( ! function_exists( 'dwt_listing_setPostViews' ) ) { function dwt_listing_setPostViews($postID) { $postID = esc_html( $postID ); $count_key = 'sb_post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); }else{ $count++; update_post_meta($postID, $count_key, $count); } } } if ( ! function_exists( 'dwt_listing_updateUser_onRegister' ) ) { function dwt_listing_updateUser_onRegister($uid = '') { if( dwt_listing_getReduxValue('sb_allow_ads', '', true) ) { $freeAds = dwt_listing_getReduxValue('sb_free_ads_limit', '', false); $featured = dwt_listing_getReduxValue('sb_featured_ads_limit', '', false); $validity = dwt_listing_getReduxValue('sb_package_validity', '', false); update_user_meta( $uid, '_sb_simple_ads', $freeAds ); update_user_meta( $uid, '_sb_featured_ads', $featured ); if( $validity == '-1' ) { update_user_meta( $uid, '_sb_expire_ads', $validity ); } else { $expiry_date = date('Y-m-d', strtotime("+$validity days")); update_user_meta( $uid, '_sb_expire_ads', $expiry_date ); } } else { update_user_meta( $uid, '_sb_simple_ads', 0 ); update_user_meta( $uid, '_sb_featured_ads', 0 ); update_user_meta( $uid, '_sb_expire_ads', date('Y-m-d') ); } update_user_meta( $uid, '_sb_pkg_type', 'free' ); } } if ( ! function_exists( 'dwt_listing_firebase_notify_func' ) ) { function dwt_listing_firebase_notify_func($firebase_id = '', $message_data = array()) { global $dwt_listing_api; if(isset( $dwt_listing_api['api_firebase_id'] ) && $dwt_listing_api['api_firebase_id'] != "" ) { $api_firebase_id = $dwt_listing_api['api_firebase_id']; define( 'API_ACCESS_KEY', $api_firebase_id ); $registrationIds = array( $firebase_id ); /*$msg = array ( 'message' => 'here is a message. message', 'title' => 'This is a title. title', 'subtitle' => 'This is a subtitle. subtitle', 'tickerText' => 'Ticker text here...Ticker text here...Ticker text here', 'vibrate' => 1, 'sound' => 1, 'largeIcon' => 'large_icon', 'smallIcon' => 'small_icon' );*/ $msg = ( isset($message_data) && count( $message_data ) > 0 ) ? $message_data : ''; if( $msg == "" ){ return ''; } $fields = array( 'registration_ids' => $registrationIds, 'data' => $msg ); $headers = array('Authorization: key=' . API_ACCESS_KEY, 'Content-Type: application/json' ); $ch = curl_init(); curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' ); curl_setopt( $ch,CURLOPT_POST, true ); curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers ); curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) ); $result = curl_exec($ch ); curl_close( $ch ); } } } if ( ! function_exists( 'dwt_listing_social_profiles' ) ) { function dwt_listing_social_profiles() { global $dwt_listing_api; $social_netwroks = array(); if( isset( $dwt_listing_api['sb_enable_social_links'] ) && $dwt_listing_api['sb_enable_social_links'] ) { $social_netwroks = array( 'facebook' => __('Facebook','dwt-listing-api'), 'twitter' => __('Twitter','dwt-listing-api') , 'linkedin' => __('Linkedin','dwt-listing-api'), 'google-plus' => __('Google+','dwt-listing-api') ); } return $social_netwroks; } } if ( ! function_exists( 'dwt_listing_after_payment' ) ) { function dwt_listing_payment_types($key = '') { global $dwt_listing_api; $paypalKey = ( isset( $dwt_listing_api['appKey_paypalKey'] ) && $dwt_listing_api['appKey_paypalKey'] != "" ) ? $dwt_listing_api['appKey_paypalKey'] : ''; $stripeSKey = ( isset( $dwt_listing_api['appKey_stripeSKey'] ) && $dwt_listing_api['appKey_stripeSKey'] != "" ) ? $dwt_listing_api['appKey_stripeSKey'] : ''; $arr = array(); $arr['stripe'] = __( 'Stripe', 'dwt-listing-api' ); $arr['paypal'] = __( 'PayPal', 'dwt-listing-api' ); $arr['in_app'] = __( 'In App Purchase', 'dwt-listing-api' ); /* $arr['bank_transfer'] = __( 'Bank Transfer', 'dwt-listing-api' ); $arr['cash_on_delivery'] = __( 'Cash On Delivery', 'dwt-listing-api' ); $arr['cheque'] = __( 'Payment By Check', 'dwt-listing-api' );*/ /*$arr['payu'] = __( 'PayU', 'dwt-listing-api' );*/ return ($key != "" ) ? $arr[$key] : $arr; } } if ( ! function_exists( 'dwt_listing_determine_minMax_latLong' ) ) { function dwt_listing_determine_minMax_latLong($data_arr = array(), $check_db = true ) { $data = array(); $user_id = get_current_user_id(); $success = false; if( isset( $data_arr ) && !empty( $data_arr ) ) { $nearby_data = $data_arr; } else if($user_id && $check_db) { $nearby_data = get_user_meta($user_id, '_sb_user_nearby_data', true ); } if( isset($nearby_data) && $nearby_data != "" ) { //array("latitude" => $latitude, "longitude" => $longitude, "distance" => $distance ); $original_lat = $nearby_data['latitude']; $original_long = $nearby_data['longitude']; $distance = $nearby_data['distance']; $lat = $original_lat; //latitude $lon = $original_long; //longitude $distance = $distance; //your distance in KM $R = 6371; //constant earth radius. You can add precision here if you wish $maxLat = $lat + rad2deg($distance/$R); $minLat = $lat - rad2deg($distance/$R); $maxLon = $lon + rad2deg(asin($distance/$R) / @cos(deg2rad($lat))); $minLon = $lon - rad2deg(asin($distance/$R) / @cos(deg2rad($lat))); $data['radius'] = $R; $data['distance'] = $distance; $data['lat']['original'] = $original_lat; $data['long']['original'] = $original_long; $data['lat']['min'] = $minLat; $data['lat']['max'] = $maxLat; $data['long']['min'] = $minLon; $data['long']['max'] = $maxLon; } return $data; } } if ( ! function_exists( 'dwt_listing_get_all_countries' ) ) { function dwt_listing_get_all_countries() { $args = array( 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'post_type' => '_sb_country', 'post_status' => 'publish', ); $countries = get_posts( $args ); $res = array(); foreach( $countries as $country ) { $res[$country->post_excerpt] = $country->post_title; } return $res; } } if ( ! function_exists( 'dwt_listing_randomString' ) ) { function dwt_listing_randomString($length = 50) { $str = ""; $characters = array_merge(range('A','Z'), range('a','z'), range('0','9')); $max = count($characters) - 1; for ($i = 0; $i < $length; $i++) { $rand = mt_rand(0, $max); $str .= $characters[$rand]; } return $str; } } /*Sonu Code Here*/ //Return Listing is Featured if ( ! function_exists( 'dwt_listing_is_listing_featured_app' ) ) { function dwt_listing_is_listing_featured_app($listing_id,$style = '') { //getting listing status if( get_post_meta( $listing_id, 'dwt_listing_is_feature', true ) == '1' && get_post_meta($listing_id, 'dwt_listing_listing_status', true ) == '1') { return '1'; } else { return '0'; } } } //Return Listing Categories if ( ! function_exists( 'dwt_listing_listing_assigned_cats_app' ) ) { function dwt_listing_listing_assigned_cats_app($listing_id, $html_type = '') { $cats = $link = ''; $cats_html = $cat_icon = ''; $listing_features = wp_get_object_terms( $listing_id, array('l_category'), array('orderby' => 'name' , 'order' => 'ASC') ); if(isset($listing_features) && $listing_features !="") { if ( ! is_wp_error( $listing_features ) ) { foreach( $listing_features as $term ) { if($term->parent == 0) { $cats = $term->term_id . ','. $term->name; break; } } return $cats; } } } } if (!function_exists('dwt_listing_listing_total_count')) { function dwt_listing_listing_total_count($status, $meta_key, $meta_val,$user_id = '') { $args = array("author" => $user_id, 'post_type' => 'listing', 'post_status' => $status, 'meta_key' => $meta_key, 'meta_value' => $meta_val, 'compare' => '='); $query = new WP_Query( $args ); wp_reset_postdata(); return $query->found_posts; } } if ( ! function_exists( 'dwt_listing_get_profile_fields' ) ) { function dwt_listing_get_profile_fields($main_title = '', $placeholder = '', $field_type = '', $field_type_name = '',$values = '', $selected_val = '', $is_required = '') { return array( "main_title" => $main_title, "placeholder" => $placeholder, "field_type" => $field_type, "field_type_name" => $field_type_name, "value" => $values, "option_dropdown" => $selected_val, "is_required" => $is_required, ); } } /*if ( ! function_exists( 'dwt_listing_get_all_timezones' ) ) { function dwt_listing_get_all_timezones() { $zones_array = array(); foreach(timezone_identifiers_list() as $key => $zone) { $zones_array[] = $zone; //break; } return $zones_array; } }*/ if ( ! function_exists( 'dwt_listing_events_assigned_cats_app' ) ) { function dwt_listing_events_assigned_cats_app($event_id) { $link = ''; $cats_html = ''; $listing_features = wp_get_object_terms($event_id, array('l_event_cat'), array('orderby' => 'name' , 'order' => 'ASC') ); if(isset($listing_features) && $listing_features !="") { if ( ! is_wp_error( $listing_features ) ) { foreach( $listing_features as $term ) { $link = get_term_link( $term->term_id ); $cats_html = $term->term_id . ','. $term->name; break; } return $cats_html; } } } } if ( ! function_exists( 'dwt_listing_get_fields' ) ) { function dwt_listing_get_fields($title = '', $placeholder = '' , $field_type = '', $field_type_name = '',$values = '', $selected_val = '') { return array( "title" => $title, "placeholder" => $placeholder, "type" => $field_type, "type_name" => $field_type_name, "value" => $values, "option_dropdown" => $selected_val, ); } } if (!function_exists('dwt_listing_youtube_url_to_iframe')) { function dwt_listing_youtube_url_to_iframe($string = '') { $pattern = '@(http|https)://(www\.)?youtu[^\s]*@i'; //This was just for test //$string = "abc def http://www.youtube.com/watch?v=t-ZRX8984sc ghi jkm"; $matches = array(); preg_match_all($pattern, $string, $matches); foreach ($matches[0] as $matchURL) { preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $matchURL, $match); $vID = (isset($match[1]) && $match[1] != "") ? $match[1] : ''; $vidURL = 'https://www.youtube.com/embed/'.$vID; $string = str_replace($matchURL, '<iframe src="' . esc_url($vidURL) . '" frameborder="0" allowfullscreen style="width:100%;"></iframe>', $string); } return $string; } } if (!function_exists('dwt_listing_payment_types')) { function dwt_listing_payment_types() { $arr = array(); $arr['stripe'] = __('Stripe', 'dwt-listing-api'); $arr['paypal'] = __('PayPal', 'adwt-listing-api'); $arr['bank_transfer'] = __('Bank Transfer', 'dwt-listing-api'); $arr['cash_on_delivery'] = __('Cash On Delivery', 'dwt-listing-api'); $arr['cheque'] = __('Payment By Check', 'dwt-listing-api'); return (isset($arr[$key]) && $key != "") ? $arr[$key] : $arr; } }
[+]
..
[-] functions.php
[edit]
[-] fetch_data.php
[edit]
[-] utilities.php
[edit]
[+]
inc
[+]
classes
[+]
languages
[-] index.php
[edit]
[+]
images