Version Description
- Added the option to open a link in a new window
- Added the option to show a reset button that will reset the map back to how it was on page load
- Added the option to load all stores on page load
- Fixed a problem with the shortcode output
Download this release
Release Info
Developer | tijmensmit |
Plugin | WP Store Locator |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0.1 to 1.1
- admin/class-admin.php +10 -4
- admin/templates/map-settings.php +20 -7
- css/styles.css +25 -1
- frontend/class-frontend.php +34 -3
- frontend/templates/default.php +50 -39
- frontend/wpsl-ajax-functions.php +29 -15
- js/wpsl-gmap.js +186 -47
- readme.txt +8 -2
- wp-store-locator.php +4 -1
admin/class-admin.php
CHANGED
@@ -373,6 +373,9 @@ if ( !class_exists( 'WPSL_Admin' ) ) {
|
|
373 |
case 'label_missing':
|
374 |
$error_msg = __( 'One of the label fields was left empty, the default value for that field has been restored.', 'wpsl' );
|
375 |
break;
|
|
|
|
|
|
|
376 |
}
|
377 |
|
378 |
add_settings_error ( 'setting-errors', esc_attr( 'settings_fail' ), $error_msg, 'error' );
|
@@ -440,7 +443,8 @@ if ( !class_exists( 'WPSL_Admin' ) ) {
|
|
440 |
|
441 |
/* If no location name is set to zoom to we also empty the latlng values from the hidden input field */
|
442 |
if ( empty( $output['zoom_name'] ) ) {
|
443 |
-
$
|
|
|
444 |
} else {
|
445 |
$output['zoom_latlng'] = sanitize_text_field( $_POST['wpsl_map']['zoom_latlng'] );
|
446 |
}
|
@@ -451,12 +455,13 @@ if ( !class_exists( 'WPSL_Admin' ) ) {
|
|
451 |
} else {
|
452 |
$output['map_type'] = $this->get_default_setting( 'map_type' );
|
453 |
}
|
454 |
-
|
|
|
|
|
455 |
$output['streetview'] = isset( $_POST['wpsl_map']['streetview'] ) ? 1 : 0;
|
456 |
$output['pan_controls'] = isset( $_POST['wpsl_map']['pan_controls'] ) ? 1 : 0;
|
457 |
$output['control_position'] = ( $_POST['wpsl_map']['control_position'] == 'left' ) ? 'left' : 'right';
|
458 |
$output['control_style'] = ( $_POST['wpsl_map']['control_style'] == 'small' ) ? 'small' : 'large';
|
459 |
-
$output['auto_locate'] = isset( $_POST['wpsl_map']['auto_locate'] ) ? 1 : 0;
|
460 |
|
461 |
/* Check the height value of the map */
|
462 |
if ( absint( $_POST['wpsl_design']['height_value'] ) ) {
|
@@ -487,7 +492,8 @@ if ( !class_exists( 'WPSL_Admin' ) ) {
|
|
487 |
}
|
488 |
|
489 |
$output['results_dropdown'] = isset( $_POST['wpsl_design']['design_results'] ) ? 1 : 0;
|
490 |
-
|
|
|
491 |
$output['start_marker'] = wp_filter_nohtml_kses( $_POST['wpsl_map']['start_marker'] );
|
492 |
$output['store_marker'] = wp_filter_nohtml_kses( $_POST['wpsl_map']['store_marker'] );
|
493 |
|
373 |
case 'label_missing':
|
374 |
$error_msg = __( 'One of the label fields was left empty, the default value for that field has been restored.', 'wpsl' );
|
375 |
break;
|
376 |
+
case 'start_point':
|
377 |
+
$error_msg = __( 'Please provide the name of a city or country that can be used as a starting point under "Map Settings". This will only be used if auto-locating the user fails, or the option itself is disabled.', 'wpsl' );
|
378 |
+
break;
|
379 |
}
|
380 |
|
381 |
add_settings_error ( 'setting-errors', esc_attr( 'settings_fail' ), $error_msg, 'error' );
|
443 |
|
444 |
/* If no location name is set to zoom to we also empty the latlng values from the hidden input field */
|
445 |
if ( empty( $output['zoom_name'] ) ) {
|
446 |
+
$this->settings_error( 'start_point' );
|
447 |
+
$output['zoom_latlng'] = '';
|
448 |
} else {
|
449 |
$output['zoom_latlng'] = sanitize_text_field( $_POST['wpsl_map']['zoom_latlng'] );
|
450 |
}
|
455 |
} else {
|
456 |
$output['map_type'] = $this->get_default_setting( 'map_type' );
|
457 |
}
|
458 |
+
|
459 |
+
$output['auto_locate'] = isset( $_POST['wpsl_map']['auto_locate'] ) ? 1 : 0;
|
460 |
+
$output['auto_load'] = isset( $_POST['wpsl_map']['auto_load'] ) ? 1 : 0;
|
461 |
$output['streetview'] = isset( $_POST['wpsl_map']['streetview'] ) ? 1 : 0;
|
462 |
$output['pan_controls'] = isset( $_POST['wpsl_map']['pan_controls'] ) ? 1 : 0;
|
463 |
$output['control_position'] = ( $_POST['wpsl_map']['control_position'] == 'left' ) ? 'left' : 'right';
|
464 |
$output['control_style'] = ( $_POST['wpsl_map']['control_style'] == 'small' ) ? 'small' : 'large';
|
|
|
465 |
|
466 |
/* Check the height value of the map */
|
467 |
if ( absint( $_POST['wpsl_design']['height_value'] ) ) {
|
492 |
}
|
493 |
|
494 |
$output['results_dropdown'] = isset( $_POST['wpsl_design']['design_results'] ) ? 1 : 0;
|
495 |
+
$output['new_window'] = isset( $_POST['wpsl_design']['new_window'] ) ? 1 : 0;
|
496 |
+
$output['reset_map'] = isset( $_POST['wpsl_design']['reset_map'] ) ? 1 : 0;
|
497 |
$output['start_marker'] = wp_filter_nohtml_kses( $_POST['wpsl_map']['start_marker'] );
|
498 |
$output['store_marker'] = wp_filter_nohtml_kses( $_POST['wpsl_map']['store_marker'] );
|
499 |
|
admin/templates/map-settings.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<h2>WP Store Locator: <?php _e( 'Settings', 'wpsl' ); ?></h2>
|
3 |
|
4 |
<?php global $wpdb; ?>
|
5 |
-
|
6 |
<?php settings_errors(); ?>
|
7 |
<ul id="wpsl-mainnav" class="nav-tab-wrapper">
|
8 |
<li><a class="nav-tab" href="<?php echo admin_url( 'admin.php?page=wpsl_store_editor' ); ?>"><?php _e( 'Current Stores', 'wpsl' ); ?></a></li>
|
@@ -77,16 +77,20 @@
|
|
77 |
<p>
|
78 |
<label for="wpsl-auto-locate"><?php _e( 'Attempt to auto-locate the user:', 'wpsl' ); ?></label>
|
79 |
<input type="checkbox" value="" <?php checked( $this->settings['auto_locate'] == '1', true ); ?> name="wpsl_map[auto_locate]" id="wpsl-auto-locate">
|
80 |
-
</p>
|
81 |
-
<p>
|
82 |
-
<label for="wpsl-zoom-level"><?php _e( 'Zoom level:', 'wpsl' ); ?></label>
|
83 |
-
<?php echo $this->show_zoom_levels(); ?>
|
84 |
</p>
|
85 |
<p>
|
86 |
-
|
|
|
|
|
|
|
|
|
87 |
<input type="text" value="<?php echo esc_attr( $this->settings['zoom_name'] ); ?>" name="wpsl_map[zoom_name]" class="textinput" id="wpsl-zoom-name">
|
88 |
<input type="hidden" value="<?php echo esc_attr( $this->settings['zoom_latlng'] ); ?>" name="wpsl_map[zoom_latlng]" id="wpsl-latlng" />
|
89 |
</p>
|
|
|
|
|
|
|
|
|
90 |
<p>
|
91 |
<label for="wpsl-map-type"><?php _e( 'Map type:', 'wpsl' ); ?></label>
|
92 |
<?php echo $this->show_map_types(); ?>
|
@@ -116,7 +120,8 @@
|
|
116 |
<input type="radio" value="large" <?php checked( 'large', $this->settings['control_style'], true ); ?> name="wpsl_map[control_style]" id="wpsl-large-style">
|
117 |
<label for="wpsl-large-style"><?php _e( 'Large', 'wpsl' ); ?></label>
|
118 |
</span>
|
119 |
-
</p>
|
|
|
120 |
</div>
|
121 |
</div>
|
122 |
</div>
|
@@ -147,6 +152,14 @@
|
|
147 |
<label for="wpsl-design-results"><?php _e( 'Show the limit results dropdown?', 'wpsl' ); ?></label>
|
148 |
<input type="checkbox" value="" <?php checked( $this->settings['results_dropdown'] == '1', true ); ?> name="wpsl_design[design_results]">
|
149 |
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
<em><?php _e( '* This is the text that is placed before the search input and radius dropdown', 'wpsl' ); ?></em>
|
151 |
</div>
|
152 |
</div>
|
2 |
<h2>WP Store Locator: <?php _e( 'Settings', 'wpsl' ); ?></h2>
|
3 |
|
4 |
<?php global $wpdb; ?>
|
5 |
+
|
6 |
<?php settings_errors(); ?>
|
7 |
<ul id="wpsl-mainnav" class="nav-tab-wrapper">
|
8 |
<li><a class="nav-tab" href="<?php echo admin_url( 'admin.php?page=wpsl_store_editor' ); ?>"><?php _e( 'Current Stores', 'wpsl' ); ?></a></li>
|
77 |
<p>
|
78 |
<label for="wpsl-auto-locate"><?php _e( 'Attempt to auto-locate the user:', 'wpsl' ); ?></label>
|
79 |
<input type="checkbox" value="" <?php checked( $this->settings['auto_locate'] == '1', true ); ?> name="wpsl_map[auto_locate]" id="wpsl-auto-locate">
|
|
|
|
|
|
|
|
|
80 |
</p>
|
81 |
<p>
|
82 |
+
<label for="wpsl-auto-load"><?php _e( 'Load all stores on page load:', 'wpsl' ); ?></label>
|
83 |
+
<input type="checkbox" value="" <?php checked( $this->settings['auto_load'] == '1', true ); ?> name="wpsl_map[auto_load]" id="wpsl-auto-locate">
|
84 |
+
</p>
|
85 |
+
<p>
|
86 |
+
<label for="wpsl-zoom-name"><?php _e( 'Start point: *', 'wpsl' ); ?></label>
|
87 |
<input type="text" value="<?php echo esc_attr( $this->settings['zoom_name'] ); ?>" name="wpsl_map[zoom_name]" class="textinput" id="wpsl-zoom-name">
|
88 |
<input type="hidden" value="<?php echo esc_attr( $this->settings['zoom_latlng'] ); ?>" name="wpsl_map[zoom_latlng]" id="wpsl-latlng" />
|
89 |
</p>
|
90 |
+
<p>
|
91 |
+
<label for="wpsl-zoom-level"><?php _e( 'Zoom level:', 'wpsl' ); ?></label>
|
92 |
+
<?php echo $this->show_zoom_levels(); ?>
|
93 |
+
</p>
|
94 |
<p>
|
95 |
<label for="wpsl-map-type"><?php _e( 'Map type:', 'wpsl' ); ?></label>
|
96 |
<?php echo $this->show_map_types(); ?>
|
120 |
<input type="radio" value="large" <?php checked( 'large', $this->settings['control_style'], true ); ?> name="wpsl_map[control_style]" id="wpsl-large-style">
|
121 |
<label for="wpsl-large-style"><?php _e( 'Large', 'wpsl' ); ?></label>
|
122 |
</span>
|
123 |
+
</p>
|
124 |
+
<em><?php _e( '* Required field. If auto-locating the user is disabled or fails, the center of the provided city or country will be used as the initial starting point for the user.', 'wpsl' ); ?></em>
|
125 |
</div>
|
126 |
</div>
|
127 |
</div>
|
152 |
<label for="wpsl-design-results"><?php _e( 'Show the limit results dropdown?', 'wpsl' ); ?></label>
|
153 |
<input type="checkbox" value="" <?php checked( $this->settings['results_dropdown'] == '1', true ); ?> name="wpsl_design[design_results]">
|
154 |
</p>
|
155 |
+
<p>
|
156 |
+
<label for="wpsl-new-window"><?php _e( 'Open links in a new window?', 'wpsl' ); ?></label>
|
157 |
+
<input type="checkbox" value="" <?php checked( $this->settings['new_window'] == '1', true ); ?> name="wpsl_design[new_window]" id="wpsl-new-window">
|
158 |
+
</p>
|
159 |
+
<p>
|
160 |
+
<label for="wpsl-reset-map"><?php _e( 'Show a reset map button?', 'wpsl' ); ?></label>
|
161 |
+
<input type="checkbox" value="" <?php checked( $this->settings['reset_map'] == '1', true ); ?> name="wpsl_design[reset_map]" id="wpsl-reset-map">
|
162 |
+
</p>
|
163 |
<em><?php _e( '* This is the text that is placed before the search input and radius dropdown', 'wpsl' ); ?></em>
|
164 |
</div>
|
165 |
</div>
|
css/styles.css
CHANGED
@@ -1,10 +1,28 @@
|
|
1 |
/* The map container */
|
|
|
|
|
|
|
2 |
#wpsl-gmap {
|
3 |
float:left;
|
4 |
width:66.5%;
|
5 |
height:350px;
|
6 |
}
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
/*
|
9 |
Some themes set a box-shadow or max-width for all image /
|
10 |
div elements, we disable it to prevent it from messing up the map
|
@@ -51,7 +69,9 @@ div elements, we disable it to prevent it from messing up the map
|
|
51 |
box-shadow: 0 1px 2px rgba(64, 64, 64, 0.1);
|
52 |
text-transform: none !important;
|
53 |
}
|
54 |
-
|
|
|
|
|
55 |
.wpsl-search {
|
56 |
margin-bottom:12px;
|
57 |
padding:12px 12px 0 12px;
|
@@ -491,8 +511,12 @@ wpsl-search-input.focus,
|
|
491 |
}
|
492 |
#wpsl-result-list,
|
493 |
#wpsl-gmap {
|
|
|
494 |
width:100%;
|
495 |
}
|
|
|
|
|
|
|
496 |
#wpsl-gmap {
|
497 |
margin-top:10px;
|
498 |
}
|
1 |
/* The map container */
|
2 |
+
.wpsl-gmap-wrap {
|
3 |
+
position:relative;
|
4 |
+
}
|
5 |
#wpsl-gmap {
|
6 |
float:left;
|
7 |
width:66.5%;
|
8 |
height:350px;
|
9 |
}
|
10 |
|
11 |
+
/* Map reset button */
|
12 |
+
#wpsl-reset-map {
|
13 |
+
position:absolute;
|
14 |
+
right:15px;
|
15 |
+
top:15px;
|
16 |
+
padding:6px 14px;
|
17 |
+
background:#fff;
|
18 |
+
box-shadow:0 1px 2px rgba(64, 64, 64, 0.3);
|
19 |
+
border-radius: 3px;
|
20 |
+
z-index:9999;
|
21 |
+
display:none;
|
22 |
+
}
|
23 |
+
#wpsl-reset-map:hover {
|
24 |
+
cursor: pointer;
|
25 |
+
}
|
26 |
/*
|
27 |
Some themes set a box-shadow or max-width for all image /
|
28 |
div elements, we disable it to prevent it from messing up the map
|
69 |
box-shadow: 0 1px 2px rgba(64, 64, 64, 0.1);
|
70 |
text-transform: none !important;
|
71 |
}
|
72 |
+
#wpsl-search-input.wpsl-error {
|
73 |
+
border:1px solid #bd0028 !important;
|
74 |
+
}
|
75 |
.wpsl-search {
|
76 |
margin-bottom:12px;
|
77 |
padding:12px 12px 0 12px;
|
511 |
}
|
512 |
#wpsl-result-list,
|
513 |
#wpsl-gmap {
|
514 |
+
float:none;
|
515 |
width:100%;
|
516 |
}
|
517 |
+
#wpsl-reset-map {
|
518 |
+
top:25px;
|
519 |
+
}
|
520 |
#wpsl-gmap {
|
521 |
margin-top:10px;
|
522 |
}
|
frontend/class-frontend.php
CHANGED
@@ -34,8 +34,10 @@ if ( !class_exists( 'WPSL_Frontend' ) ) {
|
|
34 |
* @return void
|
35 |
*/
|
36 |
public function render_store_locator() {
|
37 |
-
require_once( WPSL_PLUGIN_DIR . 'frontend/templates/default.php' );
|
38 |
$this->add_frontend_scripts();
|
|
|
|
|
39 |
}
|
40 |
|
41 |
/**
|
@@ -126,7 +128,29 @@ if ( !class_exists( 'WPSL_Frontend' ) ) {
|
|
126 |
|
127 |
return $filename;
|
128 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
|
|
|
|
|
|
130 |
/**
|
131 |
* Load the front-end scripts and localize the required js data
|
132 |
*
|
@@ -138,11 +162,14 @@ if ( !class_exists( 'WPSL_Frontend' ) ) {
|
|
138 |
wp_enqueue_script( 'wpsl-dropdown', WPSL_URL.'js/jquery.easydropdown.min.js', array( 'jquery' ) ); //not minified version is in the js folder
|
139 |
wp_enqueue_script( 'wpsl-gmap', ( "//maps.google.com/maps/api/js?sensor=false".$this->get_gmap_api_attributes() ),'' ,'' ,true );
|
140 |
wp_enqueue_script( 'wpsl-js', WPSL_URL.'js/wpsl-gmap.js', array( 'jquery' ) );
|
141 |
-
|
|
|
|
|
142 |
$settings = array(
|
143 |
'startMarker' => $this->create_retina_filename( $this->settings['start_marker'] ),
|
144 |
'storeMarker' => $this->create_retina_filename( $this->settings['store_marker'] ),
|
145 |
'autoLocate' => $this->settings['auto_locate'],
|
|
|
146 |
'mapType' => $this->settings['map_type'],
|
147 |
'zoomLevel' => $this->settings['zoom_level'],
|
148 |
'zoomLatlng' => $this->settings['zoom_latlng'],
|
@@ -151,7 +178,11 @@ if ( !class_exists( 'WPSL_Frontend' ) ) {
|
|
151 |
'controlPosition' => $this->settings['control_position'],
|
152 |
'controlStyle' => $this->settings['control_style'],
|
153 |
'markerBounce' => $this->settings['marker_bounce'],
|
154 |
-
|
|
|
|
|
|
|
|
|
155 |
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
156 |
'path' => WPSL_URL,
|
157 |
);
|
34 |
* @return void
|
35 |
*/
|
36 |
public function render_store_locator() {
|
37 |
+
$output = require_once( WPSL_PLUGIN_DIR . 'frontend/templates/default.php' );
|
38 |
$this->add_frontend_scripts();
|
39 |
+
|
40 |
+
return $output;
|
41 |
}
|
42 |
|
43 |
/**
|
128 |
|
129 |
return $filename;
|
130 |
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Get the default values for the max_results and the search_radius dropdown
|
134 |
+
*
|
135 |
+
* @since 1.0.2
|
136 |
+
* @return array $output The default dropdown values
|
137 |
+
*/
|
138 |
+
public function get_dropdown_defaults() {
|
139 |
+
|
140 |
+
$required_defaults = array(
|
141 |
+
"max_results",
|
142 |
+
"search_radius"
|
143 |
+
);
|
144 |
+
|
145 |
+
/* Strip out the default values that are wrapped in ( ) */
|
146 |
+
foreach ( $required_defaults as $required_default ) {
|
147 |
+
preg_match_all('/\(([0-9]+?)\)/', $this->settings[$required_default], $match, PREG_PATTERN_ORDER );
|
148 |
+
$output[$required_default] = $match[1][0];
|
149 |
+
}
|
150 |
|
151 |
+
return $output;
|
152 |
+
}
|
153 |
+
|
154 |
/**
|
155 |
* Load the front-end scripts and localize the required js data
|
156 |
*
|
162 |
wp_enqueue_script( 'wpsl-dropdown', WPSL_URL.'js/jquery.easydropdown.min.js', array( 'jquery' ) ); //not minified version is in the js folder
|
163 |
wp_enqueue_script( 'wpsl-gmap', ( "//maps.google.com/maps/api/js?sensor=false".$this->get_gmap_api_attributes() ),'' ,'' ,true );
|
164 |
wp_enqueue_script( 'wpsl-js', WPSL_URL.'js/wpsl-gmap.js', array( 'jquery' ) );
|
165 |
+
|
166 |
+
$dropdown_defaults = $this->get_dropdown_defaults();
|
167 |
+
|
168 |
$settings = array(
|
169 |
'startMarker' => $this->create_retina_filename( $this->settings['start_marker'] ),
|
170 |
'storeMarker' => $this->create_retina_filename( $this->settings['store_marker'] ),
|
171 |
'autoLocate' => $this->settings['auto_locate'],
|
172 |
+
'autoLoad' => $this->settings['auto_load'],
|
173 |
'mapType' => $this->settings['map_type'],
|
174 |
'zoomLevel' => $this->settings['zoom_level'],
|
175 |
'zoomLatlng' => $this->settings['zoom_latlng'],
|
178 |
'controlPosition' => $this->settings['control_position'],
|
179 |
'controlStyle' => $this->settings['control_style'],
|
180 |
'markerBounce' => $this->settings['marker_bounce'],
|
181 |
+
'newWindow' => $this->settings['new_window'],
|
182 |
+
'resetMap' => $this->settings['reset_map'],
|
183 |
+
'maxResults' => $dropdown_defaults['max_results'],
|
184 |
+
'searchRadius' => $dropdown_defaults['search_radius'],
|
185 |
+
'distanceUnit' => $this->settings['distance_unit'],
|
186 |
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
187 |
'path' => WPSL_URL,
|
188 |
);
|
frontend/templates/default.php
CHANGED
@@ -1,45 +1,56 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
|
4 |
$show_results_filter = $this->settings['results_dropdown'];
|
5 |
$results_filter_class = ( $show_results_filter ) ? '' : 'wpsl-no-results';
|
6 |
-
?>
|
7 |
|
8 |
-
<div id="wpsl-wrap">
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
<div id="wpsl-stores">
|
37 |
-
<ul></ul>
|
38 |
-
</div>
|
39 |
-
<div id="wpsl-direction-details">
|
40 |
-
<ul></ul>
|
41 |
-
</div>
|
42 |
-
</div>
|
43 |
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
+
$output = $this->get_custom_css();
|
3 |
|
4 |
$show_results_filter = $this->settings['results_dropdown'];
|
5 |
$results_filter_class = ( $show_results_filter ) ? '' : 'wpsl-no-results';
|
|
|
6 |
|
7 |
+
$output .= '<div id="wpsl-wrap">' . "\r\n";
|
8 |
+
$output .= '<div class="wpsl-search clearfix' . $results_filter_class . '">' . "\r\n";
|
9 |
+
$output .= '<div id="wpsl-search-wrap">' . "\r\n";
|
10 |
+
$output .= '<div class="wpsl-input">' . "\r\n";
|
11 |
+
$output .= '<label for="wpsl-search-input">' . esc_attr( $this->settings['search_label'] ) . '</label>' . "\r\n";
|
12 |
+
$output .= '<input autocomplete="off" id="wpsl-search-input" type="text" value="" name="wpsl-search-input" />' . "\r\n";
|
13 |
+
$output .= '</div>' . "\r\n";
|
14 |
+
$output .= '<div class="wpsl-select-wrap">' . "\r\n";
|
15 |
+
$output .= '<div id="wpsl-radius">' . "\r\n";
|
16 |
+
$output .= '<label for="wpsl-radius-label">' . esc_attr( $this->settings['radius_label'] ).'</label>' . "\r\n";
|
17 |
+
$output .= '<select autocomplete="off" id="wpsl-radius-label" class="wpsl-dropdown" name="wpsl-radius">' . "\r\n";
|
18 |
+
$output .= $this->get_dropdown_list( 'search_radius' );
|
19 |
+
$output .= '</select>' . "\r\n";
|
20 |
+
$output .= '</div>' . "\r\n";
|
21 |
+
|
22 |
+
if ( $show_results_filter ) {
|
23 |
+
$output .= '<div id="wpsl-results">' . "\r\n";
|
24 |
+
$output .= '<label for="wpsl-results-label">' . esc_attr( $this->settings['results_label'] ) . '</label>' . "\r\n";
|
25 |
+
$output .= '<select autocomplete="off" id="wpsl-results-label" class="wpsl-dropdown" name="wpsl-results">' . "\r\n";
|
26 |
+
$output .= $this->get_dropdown_list( 'max_results' );
|
27 |
+
$output .= '</select>' . "\r\n";
|
28 |
+
$output .= '</div>' . "\r\n";
|
29 |
+
}
|
30 |
+
|
31 |
+
$output .= '<input id="wpsl-search-btn" type="submit" value='. esc_attr( $this->settings['search_btn_label'] ) . '>' . "\r\n";
|
32 |
+
$output .= '</div>' . "\r\n";
|
33 |
+
$output .= '</div>' . "\r\n";
|
34 |
+
$output .= '</div>' . "\r\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
$output .= '<div id="wpsl-result-list">' . "\r\n";
|
37 |
+
$output .= '<div id="wpsl-stores">' . "\r\n";
|
38 |
+
$output .= '<ul></ul>' . "\r\n";
|
39 |
+
$output .= '</div>' . "\r\n";
|
40 |
+
$output .= '<div id="wpsl-direction-details">' . "\r\n";
|
41 |
+
$output .= '<ul></ul>' . "\r\n";
|
42 |
+
$output .= '</div>' . "\r\n";
|
43 |
+
$output .= '</div>' . "\r\n";
|
44 |
+
|
45 |
+
if ( $this->settings['reset_map'] ) {
|
46 |
+
$output .= '<div class="wpsl-gmap-wrap">' . "\r\n";
|
47 |
+
$output .= '<div id="wpsl-reset-map">Reset</div>' . "\r\n";
|
48 |
+
$output .= '<div id="wpsl-gmap"></div>' . "\r\n";
|
49 |
+
$output .= '</div>' . "\r\n";
|
50 |
+
} else {
|
51 |
+
$output .= '<div id="wpsl-gmap"></div>' . "\r\n";
|
52 |
+
}
|
53 |
+
|
54 |
+
$output .= '</div>' . "\r\n";
|
55 |
+
|
56 |
+
return $output;
|
frontend/wpsl-ajax-functions.php
CHANGED
@@ -19,7 +19,7 @@ function wpsl_store_search() {
|
|
19 |
$options = get_option( 'wpsl_settings' );
|
20 |
$distance_unit = ( $options['distance_unit'] == 'km' ) ? '6371' : '3959';
|
21 |
$allowed_html = '';
|
22 |
-
|
23 |
/* If no max results is set, we get the default value from the settings.
|
24 |
* The only situation when it can be empty, is when the "Show the limit results dropdown"
|
25 |
* checkbox is unchecked on the settings page.
|
@@ -30,21 +30,35 @@ function wpsl_store_search() {
|
|
30 |
$max_results = $_GET['max_results'];
|
31 |
}
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
$result = $wpdb->get_results(
|
34 |
-
$wpdb->prepare(
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
",
|
42 |
-
$_GET['lat'],
|
43 |
-
$_GET['lng'],
|
44 |
-
$_GET['lat'],
|
45 |
-
$_GET['radius'],
|
46 |
-
$max_results
|
47 |
-
)
|
48 |
);
|
49 |
|
50 |
if ( $result === false ) {
|
19 |
$options = get_option( 'wpsl_settings' );
|
20 |
$distance_unit = ( $options['distance_unit'] == 'km' ) ? '6371' : '3959';
|
21 |
$allowed_html = '';
|
22 |
+
|
23 |
/* If no max results is set, we get the default value from the settings.
|
24 |
* The only situation when it can be empty, is when the "Show the limit results dropdown"
|
25 |
* checkbox is unchecked on the settings page.
|
30 |
$max_results = $_GET['max_results'];
|
31 |
}
|
32 |
|
33 |
+
/* Check if we need to include the distance and radius limit in the sql query.
|
34 |
+
* If autoload is enabled we load all stores, so no limits required.
|
35 |
+
*/
|
36 |
+
if ( !$_GET['autoload'] ) {
|
37 |
+
$sql_part = ' HAVING distance < %d ORDER BY distance LIMIT 0, %d';
|
38 |
+
$placeholders = array(
|
39 |
+
$_GET["lat"],
|
40 |
+
$_GET["lng"],
|
41 |
+
$_GET["lat"],
|
42 |
+
$_GET["radius"],
|
43 |
+
$max_results
|
44 |
+
);
|
45 |
+
} else {
|
46 |
+
$sql_part = '';
|
47 |
+
$placeholders = array(
|
48 |
+
$_GET["lat"],
|
49 |
+
$_GET["lng"],
|
50 |
+
$_GET["lat"]
|
51 |
+
);
|
52 |
+
}
|
53 |
+
|
54 |
$result = $wpdb->get_results(
|
55 |
+
$wpdb->prepare( "
|
56 |
+
SELECT *, ( $distance_unit * acos( cos( radians( %s ) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians( %s ) ) + sin( radians( %s ) ) * sin( radians( lat ) ) ) )
|
57 |
+
AS distance FROM $wpdb->wpsl_stores WHERE active = 1
|
58 |
+
$sql_part
|
59 |
+
",
|
60 |
+
$placeholders
|
61 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
);
|
63 |
|
64 |
if ( $result === false ) {
|
js/wpsl-gmap.js
CHANGED
@@ -1,12 +1,16 @@
|
|
1 |
jQuery( document ).ready( function( $ ) {
|
2 |
-
var geocoder, map, infowindow, directionsDisplay, directionsService,
|
3 |
markersArray = [],
|
|
|
|
|
|
|
4 |
$selects = $( "#wpsl-search-wrap select" );
|
5 |
|
6 |
/* Load Google Maps */
|
7 |
function initializeGmap() {
|
8 |
var myOptions, zoomControlPosition, zoomControlStyle,
|
9 |
latLng, zoomTo, zoomLevel, mapType,
|
|
|
10 |
streetViewVisible = ( wpslSettings.streetView == 1 ) ? true : false;
|
11 |
|
12 |
/* If no zoom location is defined, we show the entire world */
|
@@ -43,25 +47,26 @@ function initializeGmap() {
|
|
43 |
/* Set the selected map type */
|
44 |
switch ( wpslSettings.mapType ) {
|
45 |
case "roadmap":
|
46 |
-
|
47 |
-
|
48 |
case "satellite":
|
49 |
-
|
50 |
-
|
51 |
case "hybrid":
|
52 |
-
|
53 |
-
|
54 |
case "terrain":
|
55 |
-
|
56 |
-
|
57 |
default:
|
58 |
-
|
59 |
}
|
60 |
|
61 |
myOptions = {
|
62 |
zoom: zoomLevel,
|
63 |
center: zoomTo,
|
64 |
mapTypeId: mapType,
|
|
|
65 |
panControl: false,
|
66 |
streetViewControl: streetViewVisible,
|
67 |
zoomControlOptions: {
|
@@ -75,7 +80,12 @@ function initializeGmap() {
|
|
75 |
/* Check if we need to try and autolocate the user */
|
76 |
if ( wpslSettings.autoLocate == 1 ) {
|
77 |
checkGeolocation();
|
78 |
-
}
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
/* Style the dropdown menu */
|
81 |
$selects.easyDropDown({
|
@@ -84,35 +94,127 @@ function initializeGmap() {
|
|
84 |
});
|
85 |
}
|
86 |
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
function checkGeolocation() {
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
};
|
93 |
|
94 |
-
function handleGeolocationQuery( position ) {
|
95 |
-
var storeId = 0,
|
96 |
-
storeName = "",
|
97 |
-
draggable = true,
|
98 |
-
latLng = new google.maps.LatLng( position.coords.latitude, position.coords.longitude );
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
};
|
105 |
|
106 |
/* Handle clicks on the search button */
|
107 |
$( "#wpsl-search-btn" ).on( "click", function() {
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
-
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
/* Handle the click on the back button when the route directions are displayed */
|
118 |
$( "#wpsl-result-list" ).on( "click", ".wpsl-back", function() {
|
@@ -247,7 +349,8 @@ function calcRoute( start, end ) {
|
|
247 |
|
248 |
/* Geocode the user input */
|
249 |
function codeAddress() {
|
250 |
-
var latLng,
|
|
|
251 |
address = $( "#wpsl-search-input" ).val();
|
252 |
|
253 |
geocoder.geocode( { 'address': address}, function( response, status ) {
|
@@ -256,10 +359,10 @@ function codeAddress() {
|
|
256 |
|
257 |
/* Remove any previous markers and add a new one */
|
258 |
deleteOverlays();
|
259 |
-
addMarker( latLng, storeId
|
260 |
|
261 |
/* Try to find stores that match the radius, location criteria */
|
262 |
-
findStoreLocations( latLng );
|
263 |
} else {
|
264 |
geocodeNotification( status );
|
265 |
}
|
@@ -292,7 +395,7 @@ function filterApiResponse( response ) {
|
|
292 |
for ( i = 0; i < addressLength; i++ ){
|
293 |
responseType = response[0].address_components[i].types;
|
294 |
|
295 |
-
/* filter out the
|
296 |
if ( ( /^postal_code$/.test( responseType ) ) || ( /^postal_code_prefix,postal_code$/.test( responseType ) ) ) {
|
297 |
zipcode = response[0].address_components[i].long_name;
|
298 |
}
|
@@ -301,7 +404,7 @@ function filterApiResponse( response ) {
|
|
301 |
return zipcode;
|
302 |
}
|
303 |
|
304 |
-
function findStoreLocations( startLatLng ) {
|
305 |
var location,
|
306 |
center = map.getCenter(),
|
307 |
infoWindowData = {},
|
@@ -312,11 +415,26 @@ function findStoreLocations( startLatLng ) {
|
|
312 |
ajaxData = {
|
313 |
action: "store_search",
|
314 |
lat: startLatLng.lat(),
|
315 |
-
lng: startLatLng.lng()
|
316 |
-
max_results: $( "#wpsl-results select" ).val(),
|
317 |
-
radius: $( "#wpsl-radius select" ).val()
|
318 |
};
|
319 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
320 |
/* Add the preloader */
|
321 |
$storeList.empty().append( "<li class='wpsl-preloader'><img src='" + preloader + "'/><span>" + wpslLabels.preloader + "</span></li>" );
|
322 |
|
@@ -345,9 +463,10 @@ function findStoreLocations( startLatLng ) {
|
|
345 |
|
346 |
location = new google.maps.LatLng( response[index].lat, response[index].lng );
|
347 |
addMarker( location, response[index].id, infoWindowData, draggable );
|
348 |
-
storeData = storeData + storeHtml( response[index] );
|
|
|
349 |
});
|
350 |
-
|
351 |
$( "#wpsl-result-list" ).off( "click", ".wpsl-directions" );
|
352 |
$storeList.append( storeData );
|
353 |
|
@@ -364,6 +483,21 @@ function findStoreLocations( startLatLng ) {
|
|
364 |
} else {
|
365 |
alert( wpslLabels.generalError );
|
366 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
});
|
368 |
}
|
369 |
|
@@ -401,12 +535,10 @@ function addMarker( location, storeId, infoWindowData, draggable ) {
|
|
401 |
infoWindowContent = createInfoWindowHtml( infoWindowData, storeId );
|
402 |
infowindow.setContent( infoWindowContent );
|
403 |
} else {
|
404 |
-
infowindow.setContent( wpslLabels.startPoint );
|
405 |
}
|
406 |
infowindow.open( map, marker );
|
407 |
|
408 |
-
//pixelOffset: new google.maps.Size(0, 60)
|
409 |
-
|
410 |
$( ".wpsl-info-window" ).on( "click", ".wpsl-directions", function() {
|
411 |
renderDirections( $(this) );
|
412 |
return false;
|
@@ -418,21 +550,27 @@ function addMarker( location, storeId, infoWindowData, draggable ) {
|
|
418 |
|
419 |
if ( draggable ) {
|
420 |
google.maps.event.addListener( marker, "dragend", function( event ) {
|
|
|
421 |
map.setCenter( event.latLng );
|
422 |
reverseGeocode( event.latLng );
|
423 |
-
findStoreLocations( event.latLng );
|
424 |
});
|
425 |
}
|
426 |
}
|
427 |
|
428 |
/* Create the data for the infowindows on Google Maps */
|
429 |
function createInfoWindowHtml( infoWindowData, storeId ) {
|
430 |
-
var storeHeader,
|
|
|
431 |
windowContent = "<div data-store-id='" + storeId + "' class='wpsl-info-window'>";
|
432 |
|
433 |
/* Check if we need to turn the store name into a link or not */
|
434 |
if ( ( typeof( infoWindowData.url ) !== "undefined" ) && ( infoWindowData.url !== "" ) ) {
|
435 |
-
|
|
|
|
|
|
|
|
|
436 |
} else {
|
437 |
storeHeader = "<strong>" + infoWindowData.store + "</strong>";
|
438 |
}
|
@@ -509,6 +647,7 @@ function fitBounds() {
|
|
509 |
|
510 |
/* Remove all existing markers and route lines from the map */
|
511 |
function deleteOverlays() {
|
|
|
512 |
directionsDisplay.setMap( null );
|
513 |
|
514 |
/* Remove all the markers from the map, and empty the array */
|
1 |
jQuery( document ).ready( function( $ ) {
|
2 |
+
var geocoder, map, infowindow, directionsDisplay, directionsService, geolocationLatlng,
|
3 |
markersArray = [],
|
4 |
+
mapDefaults = {},
|
5 |
+
resetMap = false,
|
6 |
+
autoLoad = wpslSettings.autoLoad,
|
7 |
$selects = $( "#wpsl-search-wrap select" );
|
8 |
|
9 |
/* Load Google Maps */
|
10 |
function initializeGmap() {
|
11 |
var myOptions, zoomControlPosition, zoomControlStyle,
|
12 |
latLng, zoomTo, zoomLevel, mapType,
|
13 |
+
startMarker = {},
|
14 |
streetViewVisible = ( wpslSettings.streetView == 1 ) ? true : false;
|
15 |
|
16 |
/* If no zoom location is defined, we show the entire world */
|
47 |
/* Set the selected map type */
|
48 |
switch ( wpslSettings.mapType ) {
|
49 |
case "roadmap":
|
50 |
+
mapType = google.maps.MapTypeId.ROADMAP
|
51 |
+
break;
|
52 |
case "satellite":
|
53 |
+
mapType = google.maps.MapTypeId.SATELLITE
|
54 |
+
break;
|
55 |
case "hybrid":
|
56 |
+
mapType = google.maps.MapTypeId.HYBRID
|
57 |
+
break;
|
58 |
case "terrain":
|
59 |
+
mapType = google.maps.MapTypeId.TERRAIN
|
60 |
+
break;
|
61 |
default:
|
62 |
+
mapType = google.maps.MapTypeId.ROADMAP
|
63 |
}
|
64 |
|
65 |
myOptions = {
|
66 |
zoom: zoomLevel,
|
67 |
center: zoomTo,
|
68 |
mapTypeId: mapType,
|
69 |
+
mapTypeControl: false,
|
70 |
panControl: false,
|
71 |
streetViewControl: streetViewVisible,
|
72 |
zoomControlOptions: {
|
80 |
/* Check if we need to try and autolocate the user */
|
81 |
if ( wpslSettings.autoLocate == 1 ) {
|
82 |
checkGeolocation();
|
83 |
+
} else {
|
84 |
+
showStores();
|
85 |
+
|
86 |
+
/* Put the mousecursor in the store search field */
|
87 |
+
$("#wpsl-search-input").focus();
|
88 |
+
}
|
89 |
|
90 |
/* Style the dropdown menu */
|
91 |
$selects.easyDropDown({
|
94 |
});
|
95 |
}
|
96 |
|
97 |
+
function showStores() {
|
98 |
+
var latLng = wpslSettings.zoomLatlng.split( ',' ),
|
99 |
+
zoomTo = new google.maps.LatLng( latLng[0], latLng[1] ),
|
100 |
+
startMarker = {
|
101 |
+
store: wpslLabels.startPoint
|
102 |
+
};
|
103 |
+
|
104 |
+
addMarker( zoomTo, 0, startMarker, true ); // This marker is the 'start location' marker. With a storeId of 0, no name and is draggable
|
105 |
+
findStoreLocations( zoomTo, resetMap, autoLoad );
|
106 |
+
}
|
107 |
+
|
108 |
+
/* Check if Geolocation detection is supported. If there is an error / timeout with determining the users
|
109 |
+
* location we use the 'start point' value from the settings as the start location through the showStores function.
|
110 |
+
*/
|
111 |
function checkGeolocation() {
|
112 |
+
if ( navigator.geolocation ) {
|
113 |
+
var locationTimeout = setTimeout( showStores, 3000 );
|
114 |
+
|
115 |
+
navigator.geolocation.getCurrentPosition( function( position ) {
|
116 |
+
clearTimeout( locationTimeout );
|
117 |
+
|
118 |
+
/* If the timeout is triggerd, and the user later decides to enable the gelocation detection,
|
119 |
+
* it gets messy with multiple start markers. So we first clear the map before adding new ones.
|
120 |
+
*/
|
121 |
+
deleteOverlays();
|
122 |
+
handleGeolocationQuery( position, resetMap );
|
123 |
+
}, function( error ) {
|
124 |
+
clearTimeout( locationTimeout );
|
125 |
+
showStores();
|
126 |
+
});
|
127 |
+
} else {
|
128 |
+
showStores();
|
129 |
+
}
|
130 |
};
|
131 |
|
132 |
+
function handleGeolocationQuery( position, resetMap ) {
|
|
|
|
|
|
|
|
|
133 |
|
134 |
+
if ( typeof( position ) === "undefined" ) {
|
135 |
+
showStores();
|
136 |
+
} else {
|
137 |
+
var latLng = new google.maps.LatLng( position.coords.latitude, position.coords.longitude );
|
138 |
+
|
139 |
+
/* Store the latlng from the geolocation for when the user hits "reset" again
|
140 |
+
* without having to ask for permission again
|
141 |
+
*/
|
142 |
+
geolocationLatlng = position;
|
143 |
+
|
144 |
+
reverseGeocode( latLng ); // Set the zipcode that belongs to the latlng in the input field
|
145 |
+
map.setCenter( latLng );
|
146 |
+
addMarker( latLng, 0, '', true ); // This marker is the 'start location' marker. With a storeId of 0, no name and is draggable
|
147 |
+
findStoreLocations( latLng, resetMap, autoLoad );
|
148 |
+
}
|
149 |
};
|
150 |
|
151 |
/* Handle clicks on the search button */
|
152 |
$( "#wpsl-search-btn" ).on( "click", function() {
|
153 |
+
|
154 |
+
$( "#wpsl-search-input" ).removeClass();
|
155 |
+
|
156 |
+
if ( !$( "#wpsl-search-input" ).val() ) {
|
157 |
+
$( "#wpsl-search-input" ).addClass( 'wpsl-error' ).focus();
|
158 |
+
} else {
|
159 |
+
$( "#wpsl-result-list ul" ).empty();
|
160 |
+
$( "#wpsl-stores" ).show();
|
161 |
+
$( ".wpsl-direction-before, .wpsl-direction-after" ).remove();
|
162 |
+
$( "#wpsl-direction-details" ).hide();
|
163 |
+
resetMap = false;
|
164 |
+
deleteOverlays();
|
165 |
+
codeAddress();
|
166 |
+
}
|
167 |
+
});
|
168 |
|
169 |
+
/* Reset the map */
|
170 |
+
$( "#wpsl-reset-map" ).on( "click", function() {
|
171 |
+
var latLng;
|
172 |
+
resetMap = true;
|
173 |
+
|
174 |
+
/* When the start marker is dragged the autoload value is set to false.
|
175 |
+
* So we need to check the correct value when the reset btn is pushed before reloading the stores.
|
176 |
+
*/
|
177 |
+
if ( wpslSettings.autoLoad == 1) {
|
178 |
+
autoLoad = 1;
|
179 |
+
}
|
180 |
+
|
181 |
+
/* Check if the latlng or zoom has changed since pageload, if so there is something to reset */
|
182 |
+
if ( ( ( ( map.getCenter().lat() !== mapDefaults.centerLatlng.lat() ) || ( map.getCenter().lng() !== mapDefaults.centerLatlng.lng() ) || ( map.getZoom() !== mapDefaults.zoomLevel ) ) ) ) {
|
183 |
+
deleteOverlays();
|
184 |
+
$( "#wpsl-search-input" ).val('').removeClass();
|
185 |
+
|
186 |
+
/* Reset the dropdown values */
|
187 |
+
resetDropdowns();
|
188 |
+
|
189 |
+
if ( wpslSettings.autoLocate == 1 ) {
|
190 |
+
handleGeolocationQuery( geolocationLatlng, resetMap );
|
191 |
+
} else {
|
192 |
+
showStores();
|
193 |
+
$("#wpsl-search-input").focus();
|
194 |
+
}
|
195 |
+
}
|
196 |
+
|
197 |
+
$( "#wpsl-stores" ).show();
|
198 |
+
$( "#wpsl-direction-details" ).hide();
|
199 |
});
|
200 |
+
|
201 |
+
/* Reset the dropdown values after the "reset" button is triggerd */
|
202 |
+
function resetDropdowns() {
|
203 |
+
var i, arrayLength,
|
204 |
+
defaultValues = [wpslSettings.searchRadius + ' ' + wpslSettings.distanceUnit, wpslSettings.maxResults],
|
205 |
+
dropdowns = ["wpsl-radius", "wpsl-results"];
|
206 |
+
|
207 |
+
for ( i = 0, arrayLength = dropdowns.length; i < arrayLength; i++ ) {
|
208 |
+
$( "#" + dropdowns[i] + " .selected" ).html( defaultValues[i] );
|
209 |
+
$( "#" + dropdowns[i] + " li" ).removeClass();
|
210 |
+
|
211 |
+
$( "#" + dropdowns[i] + " li" ).each( function () {
|
212 |
+
if ( $(this).text() === defaultValues[i] ) {
|
213 |
+
$(this).addClass('active');
|
214 |
+
}
|
215 |
+
});
|
216 |
+
}
|
217 |
+
}
|
218 |
|
219 |
/* Handle the click on the back button when the route directions are displayed */
|
220 |
$( "#wpsl-result-list" ).on( "click", ".wpsl-back", function() {
|
349 |
|
350 |
/* Geocode the user input */
|
351 |
function codeAddress() {
|
352 |
+
var latLng,
|
353 |
+
autoLoad = false,
|
354 |
address = $( "#wpsl-search-input" ).val();
|
355 |
|
356 |
geocoder.geocode( { 'address': address}, function( response, status ) {
|
359 |
|
360 |
/* Remove any previous markers and add a new one */
|
361 |
deleteOverlays();
|
362 |
+
addMarker( latLng, 0, '', true ); // This marker is the 'start location' marker. With a storeId of 0, no name and is draggable
|
363 |
|
364 |
/* Try to find stores that match the radius, location criteria */
|
365 |
+
findStoreLocations( latLng, resetMap, autoLoad );
|
366 |
} else {
|
367 |
geocodeNotification( status );
|
368 |
}
|
395 |
for ( i = 0; i < addressLength; i++ ){
|
396 |
responseType = response[0].address_components[i].types;
|
397 |
|
398 |
+
/* filter out the postal code */
|
399 |
if ( ( /^postal_code$/.test( responseType ) ) || ( /^postal_code_prefix,postal_code$/.test( responseType ) ) ) {
|
400 |
zipcode = response[0].address_components[i].long_name;
|
401 |
}
|
404 |
return zipcode;
|
405 |
}
|
406 |
|
407 |
+
function findStoreLocations( startLatLng, resetMap, autoLoad ) {
|
408 |
var location,
|
409 |
center = map.getCenter(),
|
410 |
infoWindowData = {},
|
415 |
ajaxData = {
|
416 |
action: "store_search",
|
417 |
lat: startLatLng.lat(),
|
418 |
+
lng: startLatLng.lng()
|
|
|
|
|
419 |
};
|
420 |
+
|
421 |
+
/*
|
422 |
+
* If we reset the map we use the default dropdown
|
423 |
+
* values instead of the selected values
|
424 |
+
*/
|
425 |
+
if ( resetMap ) {
|
426 |
+
ajaxData.max_results = wpslSettings.maxResults;
|
427 |
+
ajaxData.radius = wpslSettings.searchRadius;
|
428 |
+
} else {
|
429 |
+
ajaxData.max_results = $( "#wpsl-results select" ).val();
|
430 |
+
ajaxData.radius = $( "#wpsl-radius select" ).val();
|
431 |
+
}
|
432 |
+
|
433 |
+
/* Check if autoload all stores is enabled */
|
434 |
+
if ( autoLoad == 1 ) {
|
435 |
+
ajaxData.autoload = 1 ;
|
436 |
+
}
|
437 |
+
|
438 |
/* Add the preloader */
|
439 |
$storeList.empty().append( "<li class='wpsl-preloader'><img src='" + preloader + "'/><span>" + wpslLabels.preloader + "</span></li>" );
|
440 |
|
463 |
|
464 |
location = new google.maps.LatLng( response[index].lat, response[index].lng );
|
465 |
addMarker( location, response[index].id, infoWindowData, draggable );
|
466 |
+
storeData = storeData + storeHtml( response[index] );
|
467 |
+
$("#wpsl-reset-map").show();
|
468 |
});
|
469 |
+
|
470 |
$( "#wpsl-result-list" ).off( "click", ".wpsl-directions" );
|
471 |
$storeList.append( storeData );
|
472 |
|
483 |
} else {
|
484 |
alert( wpslLabels.generalError );
|
485 |
}
|
486 |
+
|
487 |
+
/* If a reset button exists, store the default zoom and latlng values.
|
488 |
+
* This way when a user clicks the reset button we can check if the zoom/latlng values have changed,
|
489 |
+
* and if we actually have to reload the map.
|
490 |
+
*
|
491 |
+
*/
|
492 |
+
if ( $("#wpsl-reset-map").length > 0 ) {
|
493 |
+
if ( $.isEmptyObject( mapDefaults ) ) {
|
494 |
+
mapDefaults = {
|
495 |
+
centerLatlng : map.getCenter(),
|
496 |
+
zoomLevel : map.getZoom()
|
497 |
+
};
|
498 |
+
}
|
499 |
+
}
|
500 |
+
|
501 |
});
|
502 |
}
|
503 |
|
535 |
infoWindowContent = createInfoWindowHtml( infoWindowData, storeId );
|
536 |
infowindow.setContent( infoWindowContent );
|
537 |
} else {
|
538 |
+
infowindow.setContent( wpslLabels.startPoint );
|
539 |
}
|
540 |
infowindow.open( map, marker );
|
541 |
|
|
|
|
|
542 |
$( ".wpsl-info-window" ).on( "click", ".wpsl-directions", function() {
|
543 |
renderDirections( $(this) );
|
544 |
return false;
|
550 |
|
551 |
if ( draggable ) {
|
552 |
google.maps.event.addListener( marker, "dragend", function( event ) {
|
553 |
+
//deleteOverlays();
|
554 |
map.setCenter( event.latLng );
|
555 |
reverseGeocode( event.latLng );
|
556 |
+
findStoreLocations( event.latLng, resetMap, autoLoad = false );
|
557 |
});
|
558 |
}
|
559 |
}
|
560 |
|
561 |
/* Create the data for the infowindows on Google Maps */
|
562 |
function createInfoWindowHtml( infoWindowData, storeId ) {
|
563 |
+
var storeHeader,
|
564 |
+
newWindow = '',
|
565 |
windowContent = "<div data-store-id='" + storeId + "' class='wpsl-info-window'>";
|
566 |
|
567 |
/* Check if we need to turn the store name into a link or not */
|
568 |
if ( ( typeof( infoWindowData.url ) !== "undefined" ) && ( infoWindowData.url !== "" ) ) {
|
569 |
+
if ( wpslSettings.newWindow == 1 ) {
|
570 |
+
newWindow = "target='_blank'";
|
571 |
+
}
|
572 |
+
|
573 |
+
storeHeader = "<a " + newWindow + " href='" + infoWindowData.url + "'><strong>" + infoWindowData.store + "</strong></a>";
|
574 |
} else {
|
575 |
storeHeader = "<strong>" + infoWindowData.store + "</strong>";
|
576 |
}
|
647 |
|
648 |
/* Remove all existing markers and route lines from the map */
|
649 |
function deleteOverlays() {
|
650 |
+
var markerLen, i;
|
651 |
directionsDisplay.setMap( null );
|
652 |
|
653 |
/* Remove all the markers from the map, and empty the array */
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: tijmensmit
|
|
3 |
Tags: google maps, store locator, business locations, geocoding, stores, geo
|
4 |
Requires at least: 3.5
|
5 |
Tested up to: 3.8
|
6 |
-
Stable tag: 1.
|
7 |
License: GPLv3
|
8 |
License URI: http://www.gnu.org/licenses/gpl.html
|
9 |
|
@@ -55,8 +55,14 @@ Add this shortcode [wpsl] to the page where you want to display the store locato
|
|
55 |
|
56 |
== Changelog ==
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
= 1.0.1 =
|
59 |
-
* Fixed the styling for the
|
60 |
* Fixed a problem with slashes in store titles
|
61 |
|
62 |
= 1.0 =
|
3 |
Tags: google maps, store locator, business locations, geocoding, stores, geo
|
4 |
Requires at least: 3.5
|
5 |
Tested up to: 3.8
|
6 |
+
Stable tag: 1.1
|
7 |
License: GPLv3
|
8 |
License URI: http://www.gnu.org/licenses/gpl.html
|
9 |
|
55 |
|
56 |
== Changelog ==
|
57 |
|
58 |
+
= 1.1 =
|
59 |
+
* Added the option to open a link in a new window
|
60 |
+
* Added the option to show a reset button that will reset the map back to how it was on page load
|
61 |
+
* Added the option to load all stores on page load
|
62 |
+
* Fixed a problem with the shortcode output
|
63 |
+
|
64 |
= 1.0.1 =
|
65 |
+
* Fixed the styling for the store locator dropdowns being applied site wide
|
66 |
* Fixed a problem with slashes in store titles
|
67 |
|
68 |
= 1.0 =
|
wp-store-locator.php
CHANGED
@@ -5,7 +5,7 @@ Plugin URI:
|
|
5 |
Description: An easy to use location management system that enables users to search for nearby physical stores
|
6 |
Author: Tijmen Smit
|
7 |
Author URI: http://tijmensmit.com/
|
8 |
-
Version: 1.
|
9 |
Text Domain: wpsl
|
10 |
Domain Path: /languages/
|
11 |
License: GPLv3
|
@@ -57,6 +57,7 @@ if ( !class_exists( 'WP_Store_locator' ) ) {
|
|
57 |
'search_radius' => '10,25,(50),100,200,500',
|
58 |
'marker_bounce' => '1',
|
59 |
'auto_locate' => '1',
|
|
|
60 |
'zoom_level' => '3',
|
61 |
'zoom_name' => '',
|
62 |
'zoom_latlng' => '',
|
@@ -70,6 +71,8 @@ if ( !class_exists( 'WP_Store_locator' ) ) {
|
|
70 |
'label_width' => '95',
|
71 |
'control_position' => 'left',
|
72 |
'control_style' => 'small',
|
|
|
|
|
73 |
'start_marker' => 'red.png',
|
74 |
'store_marker' => 'blue.png',
|
75 |
'start_label' => 'Start location',
|
5 |
Description: An easy to use location management system that enables users to search for nearby physical stores
|
6 |
Author: Tijmen Smit
|
7 |
Author URI: http://tijmensmit.com/
|
8 |
+
Version: 1.1
|
9 |
Text Domain: wpsl
|
10 |
Domain Path: /languages/
|
11 |
License: GPLv3
|
57 |
'search_radius' => '10,25,(50),100,200,500',
|
58 |
'marker_bounce' => '1',
|
59 |
'auto_locate' => '1',
|
60 |
+
'auto_load' => '1',
|
61 |
'zoom_level' => '3',
|
62 |
'zoom_name' => '',
|
63 |
'zoom_latlng' => '',
|
71 |
'label_width' => '95',
|
72 |
'control_position' => 'left',
|
73 |
'control_style' => 'small',
|
74 |
+
'new_window' => '0',
|
75 |
+
'reset_option' => '0',
|
76 |
'start_marker' => 'red.png',
|
77 |
'store_marker' => 'blue.png',
|
78 |
'start_label' => 'Start location',
|