Last active
June 23, 2017 22:21
-
-
Save contempoinc/f360871a7be751db190ab40617b2ed73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*-----------------------------------------------------------------------------------*/ | |
/* Google Places API */ | |
/*-----------------------------------------------------------------------------------*/ | |
if(!function_exists('ct_google_places_nearby')) { | |
function ct_google_places_nearby($type,$location) { | |
global $ct_options; | |
$ct_google_maps_api_key = isset($ct_options['ct_google_maps_api_key'] ) ? stripslashes( $ct_options['ct_google_maps_api_key']) : ''; | |
$ct_google_places_radius = isset($ct_options['ct_google_places_radius'] ) ? esc_html( $ct_options['ct_google_places_radius']) : ''; | |
$ct_google_places_limit = isset($ct_options['ct_yelp_limit'] ) ? esc_html( $ct_options['ct_yelp_limit']) : ''; | |
$ct_google_places_links = isset($ct_options['ct_yelp_links'] ) ? esc_html( $ct_options['ct_yelp_links']) : ''; | |
$google_places = new joshtronic\GooglePlaces($ct_google_maps_api_key); | |
$google_places->location = $location; | |
$google_places->radius = $ct_google_places_radius; | |
//$google_places->rankby = 'distance'; | |
$google_places->types = $type; | |
$results = $google_places->nearbySearch(); | |
if( $results && !empty($results['results']) && is_array($results['results'])) { | |
echo '<ul class="marB20 places-nearby">'; | |
foreach($results['results'] as $result){ | |
$ct_result_link = preg_replace('/\s+/', '+', $result['name']); | |
echo '<li>'; | |
echo '<div class="col span_9 first">'; | |
echo '<a href="https://www.google.com/maps/place/' . strtolower($ct_result_link) . '" target="' . $ct_google_places_links . '">' . $result['name'] . '</a>'; | |
echo '</div>'; | |
echo '<div class="col span_3">'; | |
echo '<span class="places-rating right">'; | |
$float_rating = (float)$result['rating']; | |
$has_half_star = ($float_rating * 10) % 10; | |
$star_count = (int)$float_rating; | |
if($has_half_star) { | |
echo '<img src="' . get_template_directory_uri() . '/images/stars/small_' . $star_count . '_half.png" srcset="' . get_template_directory_uri() . '/images/stars/small_' . $star_count . '[email protected] 2x" />'; | |
} else { | |
echo '<img src="' . get_template_directory_uri() . '/images/stars/small_' . $star_count . '.png" srcset="' . get_template_directory_uri() . '/images/stars/small_' . $star_count . '@2x.png 2x" />'; | |
} | |
echo '</span>'; | |
//echo '<span class="review-count muted right">' . $response->businesses[$i]->review_count . ' ' . __('reviews', 'contempo') . '</span></a>'; | |
echo '</div>'; | |
echo '<div class="clear"></div>'; | |
echo '</li>'; | |
$i++; | |
if($i == $ct_google_places_limit) break; | |
} | |
echo '</ul>'; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment