Skip to content

Instantly share code, notes, and snippets.

@RCowles
Forked from Gearbottle/gist:da21c4e65d293f091484
Last active August 29, 2015 14:10
Show Gist options
  • Save RCowles/cdf2bd155e83169bb6d4 to your computer and use it in GitHub Desktop.
Save RCowles/cdf2bd155e83169bb6d4 to your computer and use it in GitHub Desktop.
<!-- Map Support Scripts --><div id="ajax_map" class="inline-scripts">
<?php
$settings = return_settings();
$center_single_company = return_single_company();
$item_adrs_sng_lat = return_item_adrs_sng_lat();
$item_adrs_sng_lng = return_item_adrs_sng_lng();
$item_first_cat = return_item_first_cat();
// Get variables metrodir_Options
//Site options
$glocal_map_type = get_option('opt_glocal_map_type');
$glocal_draggable_map = get_option('opt_glocal_map_drag');
$glocal_scrollwheel_map = get_option('opt_glocal_map_scroll');
$glocal_map_zoom = get_option('opt_glocal_map_zoom');
$glocal_markers_type = 'image';
$glocal_map_clusters = get_option('opt_glocal_map_clusters');
$glocal_map_clusters_grid = get_option('opt_glocal_map_clusters_grid');
$glocal_map_clusters_min = get_option('opt_glocal_map_clusters_min');
$centre_map = get_option('opt_glocal_map_centermap');
if(get_option('opt_glocal_map_allmarkers') == "true") {
$centre_map = 'center_all';
}
$centre_addr_lat = get_option('opt_glocal_company_cntr_address_lat');
$centre_addr_lng = get_option('opt_glocal_company_cntr_address_lng');
global $wp_query;
query_posts(array(
'post_type' => array('company'),
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'glocal_address_lat',
'compare' => 'EXISTS'
),
array(
'key' => 'glocal_address_lng',
'compare' => 'EXISTS'
)
)
));
$index = 0;
?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post();
$index++;
$companus[$index][1] = get_the_title();
$companus[$index][11] = get_the_ID();
$companus[$index][13] = '';
//Get Rating variable
$id = get_the_ID();
$item = new stdClass();
$item->rating = get_post_meta( $id, 'rating', true );
$rating = '';
if ($item->rating) {
for ($i = 1; $i <= $item->rating['max']; $i++) {
$rating .= '<i class="fa ';
if (($item->rating['val'] + 1 - $i) >= 1) $rating .= "fa-star"; else if (($item->rating['val'] + 1 - $i) >= 0.5) $rating .= "fa-star-half-o"; else $rating .= 'fa-star-o';
$rating .= ' fa-lg"></i> ';
}
} else {
$rating = '';
}
$companus[$index][10] = $rating;
$terms = get_the_terms( $post->ID, 'company_category' );
$item_cats = array();
$item_cats_slugs = array();
$item_cats_term_id = array();
$i = 0;
if(is_array($terms)) {
foreach ($terms as $term ) {
$i++;
$item_cats_slugs[$i] = $term->slug;
$item_cats_term_id[$i] = $term->term_id;
}
} else {
$item_cats_slugs[1] = "default";
$i = 1;
}
if ($i == 1) {
$companus[$index][2] = $item_cats_slugs[1];
$companus[$index][13] = get_option('glocal_category_'.$item_cats_term_id[1].'_marker');
$custom_fields = get_post_custom();
if(isset($custom_fields['glocal_address_country_name'][0]))
$country = $custom_fields['glocal_address_country_name'][0];
else
$country = NULL;
if(isset($custom_fields['glocal_address_region_name'][0]))
$region = $custom_fields['glocal_address_region_name'][0];
else
$region = NULL;
if(isset($custom_fields['glocal_address_name'][0]))
$name = $custom_fields['glocal_address_name'][0];
else
$name = NULL;
if(isset($custom_fields['glocal_address_zip'][0]))
$zip = $custom_fields['glocal_address_zip'][0];
else
$zip = NULL;
if($zip){
$name = $name.' '.$zip;
}
$item_addr_lat = $custom_fields['glocal_address_lat'][0];
$item_addr_lng = $custom_fields['glocal_address_lng'][0];
$places[$index][1] = $country;
$places[$index][2] = $region;
$places[$index][3] = $name;
$address = "";
if (($country) AND ($region) AND ($name)) {
$address = $country.', '.$region.', '.$name;
} else if (($country) AND ($region)) {
$address = $country.', '.$region;
} else if (($country) AND ($name)) {
$address = $country.', '.$name;
} else if (($region) AND ($name)) {
$address = $region.', '.$name;
} else if ($country) {
$address = $country;
} else if ($region) {
$address = $region;
} else if ($name) {
$address = $name;
}
$companus[$index][3] = $item_addr_lat;
$companus[$index][4] = $address;
$companus[$index][5] = get_permalink();
$companus[$index][6] = get_the_post_thumbnail($id, array(120,120));
$companus[$index][7] = $item_addr_lng;
} else if ($i > 1) {
$companus[$index][2] = $item_cats_slugs[1];
$companus[$index][13] = get_option('glocal_category_'.$item_cats_term_id[1].'_marker');
$custom_fields = get_post_custom();
if (isset($custom_fields['glocal_address_country_name'][0])) {
$country = $custom_fields['glocal_address_country_name'][0];
$places[$index][1] = $country;
}
if (isset($custom_fields['glocal_address_region_name'][0])) {
$region = $custom_fields['glocal_address_region_name'][0];
$places[$index][2] = $region;
}
if (isset($custom_fields['glocal_address_name'][0])) {
$name = $custom_fields['glocal_address_name'][0];
$places[$index][3] = $name;
}
if(isset($custom_fields['glocal_address_zip'][0])){
$name = $name.' '.$custom_fields['glocal_address_zip'][0];
}
$item_addr_lat = $custom_fields['glocal_address_lat'][0];
$item_addr_lng = $custom_fields['glocal_address_lng'][0];
$address = "";
if (isset($country) AND isset($region) AND isset($name)) {
$address = $country.', '.$region.', '.$name;
} else if (isset($country) AND isset($region)) {
$address = $country.', '.$region;
} else if (isset($country) AND isset($name)) {
$address = $country.', '.$name;
} else if (isset($region) AND isset($name)) {
$address = $region.', '.$name;
} else if (isset($country)) {
$address = $country;
} else if (isset($region)) {
$address = $region;
} else if (isset($name)) {
$address = $name;
}
$companus[$index][3] = $item_addr_lat;
$companus[$index][4] = $address;
$companus[$index][5] = get_permalink();
$companus[$index][6] = get_the_post_thumbnail();
$companus[$index][7] = $item_addr_lng;
for ($k = 2; $k <= $i; $k++) {
$index++;
$companus[$index][1] = $companus[$index - 1][1];
$companus[$index][2] = $item_cats_slugs[$k];
$companus[$index][3] = $companus[$index - 1][3];
$companus[$index][4] = $companus[$index - 1][4];
$companus[$index][5] = $companus[$index - 1][5];
$companus[$index][6] = $companus[$index - 1][6];
$companus[$index][7] = $companus[$index - 1][7];
$companus[$index][10] = $companus[$index - 1][10];
$companus[$index][11] = $companus[$index - 1][11];
$companus[$index][13] = get_option('glocal_category_'.$item_cats_term_id[$k].'_marker');
if (isset($places[$index - 1][1]))
$places[$index][1] = $places[$index - 1][1];
if (isset($places[$index - 1][2]))
$places[$index][2] = $places[$index - 1][2];
if (isset($places[$index - 1][3]))
$places[$index][3] = $places[$index - 1][3];
}
}
endwhile;
?>
<?php
// Map load option
$zoom = 10;
if ($glocal_map_zoom) {
$zoom = $glocal_map_zoom;
}
$map_type = "ROADMAP";
if($glocal_map_type){
$map_type = $glocal_map_type;
}
$draggable_map = "true";
if($glocal_draggable_map){
$draggable_map = $glocal_draggable_map;
}
$scrollwheel_map = "false";
if($glocal_scrollwheel_map){
$scrollwheel_map = $glocal_scrollwheel_map;
}
// Get default Map category
$center_def = false;
$center_cat = get_option('opt_glocal_home_defcat');
if(!$center_cat or $center_cat == 'Select a category:'){
$center_cat = "nocat";
} else {
$center_def = true;
}
$term = get_term_by('name', $center_cat, 'company_category');
$center_cat = $term->slug;
// Get center map coordinate and custom category
$center_lat = 0;
$center_lng = 0;
if (isset($companus)) {
if (($center_single_company == "ye") && ($item_adrs_sng_lat)) {
$center_lat = $item_adrs_sng_lat;
$center_lng = $item_adrs_sng_lng;
$center_cat = $item_first_cat;
$zoom = 15;
} else if (($centre_addr_lat) && ($centre_map == "centre_addr")) {
$center_lat = $centre_addr_lat;
$center_lng = $centre_addr_lng;
} else if ($centre_map == "centre_random") {
$index = 0;
if (! $center_def) {
$randomize = rand(1, count($companus));
} else {
do {
$randomize = rand(1, count($companus));
$index++;
} while (($center_cat != $companus[$randomize][2]) OR ($index <= count($companus)));
}
$center_cat = $companus[$randomize][2];
$center_lat = $companus[$randomize][3];
$center_lng = $companus[$randomize][7];
} else if ($centre_map == "centre_last") {
if (! $center_def) {
$center_cat = $companus[1][2];
$center_lat = $companus[1][3];
$center_lng = $companus[1][7];
} else {
for ($index = 1; $index <= count($companus); $index++) {
if ($center_cat == $companus[$index][2]) {
$center_cat = $companus[$index][2];
$center_lat = $companus[$index][3];
$center_lng = $companus[$index][7];
break;
}
}
}
} else if ($centre_map == "centre_geomap") {
require_once(get_template_directory().'/skl/plugin/geoplugin.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
if (isset($geoplugin->latitude) AND isset($geoplugin->longitude)) {
$center_lat = $geoplugin->latitude;
$center_lng = $geoplugin->longitude;
} else {
$center_lat = 10;
$center_lng = 10;
}
}
} else {
require_once(get_template_directory().'/skl/plugin/geoplugin.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
if (isset($geoplugin->latitude) AND isset($geoplugin->longitude)) {
$center_lat = $geoplugin->latitude;
$center_lng = $geoplugin->longitude;
} else {
$center_lat = 10;
$center_lng = 10;
}
}
echo'<div id="map_options" style="display:none">';
echo'<div class="draggable">'.$draggable_map.'</div>';
echo'<div class="scrollwheel">'.$scrollwheel_map.'</div>';
echo'<div class="maptype">'.$map_type.'</div>';
echo'<div class="zoom">'.$zoom.'</div>';
if ($glocal_map_clusters == 'true' AND $glocal_markers_type == 'image') {
echo'<div class="clusters">true</div>';
echo'<div class="clusters-grid">'.$glocal_map_clusters_grid.'</div>';
echo'<div class="clusters-min">'.$glocal_map_clusters_min.'</div>';
echo'<div class="clusters-markers">'.get_template_directory_uri().'/images/clusters/cluster-</div>';
} else {
echo'<div class="clusters">false</div>';
}
echo '<div class="markers-type">'.$glocal_markers_type.'</div>';
if ($center_def) echo '<div class="markers-category-def">true</div>'; else echo '<div class="markers-category-def">false</div>';
echo'</div>';
echo'<div id="markers_container" style="display:none">';
echo'<div id="markers_center"><div class="latitude">'.$center_lat.'</div><div class="longitude">'.$center_lng.'</div><div class="category">'.$center_cat.'</div><div class="option">'.$centre_map.'</div></div>';
if (isset($companus)) {
echo'<div id="markers">';
$markers_counter = 0;
for ($index = 1; $index <= count($companus); $index++) {
if ($companus[$index][3]) { $markers_counter++;
if ($index == 1) {
$marker_load_indikator = 'load';
} else if ($companus[$index][11] == $companus[$index - 1][11]) {
$marker_load_indikator = '000000';
} else {
$marker_load_indikator = 'load';
}
if ($center_def) {
if ($center_cat == $companus[$index][2]) {
$marker_load_indikator .= ' load-def';
} else {
$marker_load_indikator .= '';
}
}
echo'<div id="marker-'.$markers_counter.'" class="'.$marker_load_indikator.'">';
echo '<div class="lat">'.$companus[$index][3].'</div>';
echo '<div class="lan">'.$companus[$index][7].'</div>';
echo '<div class="group">'.$companus[$index][2].'</div>';
echo '<div class="name">'.$companus[$index][1].'</div>';
echo '<div class="where">'.$companus[$index][4].'</div>';
echo '<div class="id">marker-id-'.$index.'</div>';
if ($companus[$index][13]) {
echo '<div class="icon">'.$companus[$index][13].'</div>';
} else {
echo '<div class="icon">'.get_template_directory_uri().'/images/markers/'.$companus[$index][2].'.png</div>';
}
if($companus[$index][10])
echo '<div class="html"><div style="height: 120px; width: 320px; overflow: hidden; position: relative;"><div class="map-image" style="float: left; width: 120px; height: 120px; background: #000000;"><a href="'.$companus[$index][5].'">'.$companus[$index][6].'</a></div><div style="float: left; width: 190px; height: 120px; padding: 0 0 0 10px;"><div><a style="display: block; font-size: 14px; font-weight: bold; line-height: 20px; overflow: hidden; max-height: 40px;" class="map-title" href="'.$companus[$index][5].'">'.$companus[$index][1].'</a></div><div style="height: 16px">'.$companus[$index][10].'</div><div style="font-size: 12px; color: #CCCCCC; margin: 0 0 2px 0; overflow: hidden; max-height: 32px;">'.addcslashes($companus[$index][4] , '\'').'</div><div style="height: 30px;"><a class="map-more-button" style="display: block; height: 27px; width: 188px; text-align: center; background: #A6C12A; color: #FFFFFF; font-weight: bold; line-height: 27px; border: 1px solid #E6E6E6; position: absolute; bottom: 1px; right: 0;" href="'.$companus[$index][5].'">'.__('Read More','glocal_site').'</a></div></div></div></div></div>';
else
echo '<div class="html"><div style="height: 120px; width: 320px; overflow: hidden; position: relative;"><div class="map-image" style="float: left; width: 120px; height: 120px; background: #000000;"><a href="'.$companus[$index][5].'">'.$companus[$index][6].'</a></div><div style="float: left; width: 190px; height: 120px; padding: 0 0 0 10px;"><div><a style="display: block; font-size: 14px; font-weight: bold; line-height: 20px; overflow: hidden; max-height: 40px;" class="map-title" href="'.$companus[$index][5].'">'.$companus[$index][1].'</a></div><div style="font-size: 12px; color: #CCCCCC; margin: 0 0 2px 0; overflow: hidden; max-height: 48px;">'.addcslashes($companus[$index][4] , '\'').'</div><div style="height: 30px;"><a class="map-more-button" style="display: block; height: 27px; width: 188px; text-align: center; background: #A6C12A; color: #FFFFFF; font-weight: bold; line-height: 27px; border: 1px solid #E6E6E6; position: absolute; bottom: 1px; right: 0;" href="'.$companus[$index][5].'">'.__('Read More','glocal_site').'</a></div></div></div></div></div>';
}
}
echo'</div>';
echo'<div id="markers_count">'.$markers_counter.'</div>';
echo'</div>';
}
if (isset($places)) {
$places_count = 1;
for ($index = 1; $index <= count($places); $index++) {
for ($index_inner = 1; $index_inner <= 2; $index_inner++) {
if ($places[$index][$index_inner]) {
$counter = 0;
if(isset($places_filtered)){
for ($i = 1; $i <= count($places_filtered); $i++ ) {
if ($places_filtered[$i] == $places[$index][$index_inner]) {
$counter++;
}
}
}
if ($counter == 0) {
$places_filtered[$places_count] = $places[$index][$index_inner];
$places_count++;
}
}
}
}
if($places_filtered){
asort($places_filtered);
}
if (isset($places_filtered)) {
echo'<script type="text/javascript">'."\n";
echo'var $ = jQuery.noConflict();'."\n";
echo'jQuery(document).ready(function(){'."\n";
echo'var places = ['."\n";
$index = 0;
foreach($places_filtered as $places) {
$index++;
$places = preg_replace('/([^\pL\pN\pP\pS\pZ])|([\xC2\xA0])/u', ' ', $places);
$places = str_replace(' ',' ', $places);
$places = trim($places);
echo'{ value: "'.$places.'"}'; if ($index != count($places_filtered)) {echo ','."\n";}
}
echo'];'."\n";
echo'jQuery("#search-where").autocomplete({'."\n";
echo'maxItemsToShow : 10,'."\n";
echo'source : places,'."\n";
echo'select : function( event, ui ) { jQuery("#search-where").val( ui.item.value ); if (jQuery("#map").length) { ajaxGetMarkers(); } return false; },'."\n";
echo'minLength : 0,});'."\n";
echo'});'."\n";
echo'jQuery("#search-where").click(function(){$(this).autocomplete( "search", "" );});'."\n";
echo'</script>'."\n";
}
}
?>
<?php wp_reset_query(); wp_reset_postdata(); ?>
</div><!-- /Map Support Scripts -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment