55 */
66class Stellar_Places_Google_Map {
77
8- // HTML Attributes
9- public $ id = '' ;
10- public $ class = '' ;
11- public $ width = '100% ' ;
8+ /**
9+ * HTML ID.
10+ *
11+ * @var string
12+ */
13+ public $ id = '' ;
14+
15+ /**
16+ * HTML class.
17+ *
18+ * @var string
19+ */
20+ public $ class = '' ;
21+
22+ /**
23+ * HTML element width.
24+ *
25+ * @var string
26+ */
27+ public $ width = '100% ' ;
28+
29+ /**
30+ * HTML element height.
31+ *
32+ * @var string
33+ */
1234 public $ height = '350px ' ;
1335
14- // Map Center
15- public $ latitude = 0 ;
36+ /**
37+ * Map center - latitude.
38+ *
39+ * @var int
40+ */
41+ public $ latitude = 0 ;
42+
43+ /**
44+ * Map center - longitude.
45+ *
46+ * @var int
47+ */
1648 public $ longitude = 0 ;
1749
18- // Custom Map Options
19- public $ autoZoom = true ;
50+ /**
51+ * Map option: autoZoom
52+ *
53+ * @var bool
54+ */
55+ public $ autoZoom = true ;
56+
57+ /**
58+ * Map option: infoWindows
59+ *
60+ * @var bool
61+ */
2062 public $ infoWindows = true ;
2163
22- // Google Map Options
64+ /**
65+ * Google Map Options
66+ *
67+ * @var array
68+ */
2369 public $ mapOptions = array (
2470 'backgroundColor ' => null ,
2571 'disableDefaultUI ' => null ,
@@ -55,13 +101,17 @@ class Stellar_Places_Google_Map {
55101 'zoomControlOptions ' => null ,
56102 );
57103
58- // Locations
59- protected $ _locations = array ();
104+ /**
105+ * Locations
106+ *
107+ * @var array
108+ */
109+ protected $ locations = array ();
60110
61111 /**
62112 * Instantiate class
63113 *
64- * @param mixed $args
114+ * @param mixed $args Arguments.
65115 */
66116 public function __construct ( $ args = null ) {
67117 if ( is_object ( $ args ) ) {
@@ -81,20 +131,20 @@ public function __construct( $args = null ) {
81131 /**
82132 * Add a location
83133 *
84- * @param Stellar_Places_Place_Model $place
134+ * @param Stellar_Places_Place_Model $place Place model.
85135 */
86136 public function add_location ( Stellar_Places_Place_Model $ place ) {
87- $ this ->_locations [] = $ place ;
137+ $ this ->locations [] = $ place ;
88138 }
89139
90140 /**
91141 * Add a location
92142 *
93- * @param WP_Post $post
143+ * @param WP_Post $post The post object.
94144 */
95145 public function set_location ( WP_Post $ post ) {
96- $ this ->_locations = array ();
97- $ place = Stellar_Places::get_place_object ( $ post );
146+ $ this ->locations = array ();
147+ $ place = Stellar_Places::get_place_object ( $ post );
98148 if ( $ place ) {
99149 $ this ->add_location ( $ place );
100150 }
@@ -103,11 +153,11 @@ public function set_location( WP_Post $post ) {
103153 /**
104154 * Set all locations at once
105155 *
106- * @param WP_Query $query
156+ * @param WP_Query $query The query object.
107157 */
108158 public function set_locations ( WP_Query $ query ) {
109- $ this ->_locations = array ();
110- $ posts = $ query ->get_posts ();
159+ $ this ->locations = array ();
160+ $ posts = $ query ->get_posts ();
111161 foreach ( $ posts as $ post ) {
112162 $ place = Stellar_Places::get_place_object ( $ post );
113163 if ( $ place ) {
@@ -133,7 +183,7 @@ public function get_html() {
133183 $ style = "width: {$ this ->width }; height: {$ this ->height }; " ;
134184 $ autoZoom = filter_var ( $ this ->autoZoom , FILTER_VALIDATE_BOOLEAN ) ? 'true ' : 'false ' ;
135185 $ infoWindows = filter_var ( $ this ->infoWindows , FILTER_VALIDATE_BOOLEAN ) ? 'true ' : 'false ' ;
136- $ mapOptions = array_filter ( $ this ->mapOptions , array ( $ this , '_is_not_null ' ) );
186+ $ mapOptions = array_filter ( $ this ->mapOptions , array ( $ this , 'is_not_null ' ) );
137187
138188 // Load JS and CSS
139189 wp_enqueue_script ( 'stellar-places-map ' );
@@ -148,15 +198,17 @@ public function get_html() {
148198
149199 ob_start ();
150200 ?>
151- <div id="<?php echo esc_attr ( $ this ->id ); ?> "
152- class="<?php echo esc_attr ( $ class ); ?> "
153- style="<?php echo esc_attr ( $ style ); ?> "
154- data-stellar-places-map-auto-zoom="<?php echo esc_attr ( $ autoZoom ); ?> "
155- data-stellar-places-map-info-windows="<?php echo esc_attr ( $ infoWindows ); ?> "
156- data-stellar-places-map-lat="<?php echo esc_attr ( $ this ->latitude ); ?> "
157- data-stellar-places-map-lng="<?php echo esc_attr ( $ this ->longitude ); ?> "
158- data-stellar-places-map-locations="<?php echo esc_attr ( json_encode ( $ this ->_locations ) ); ?> "
159- data-stellar-places-map-options="<?php echo esc_attr ( json_encode ( $ mapOptions ) ); ?> "></div>
201+ <div
202+ id="<?php echo esc_attr ( $ this ->id ); ?> "
203+ class="<?php echo esc_attr ( $ class ); ?> "
204+ style="<?php echo esc_attr ( $ style ); ?> "
205+ data-stellar-places-map-auto-zoom="<?php echo esc_attr ( $ autoZoom ); ?> "
206+ data-stellar-places-map-info-windows="<?php echo esc_attr ( $ infoWindows ); ?> "
207+ data-stellar-places-map-lat="<?php echo esc_attr ( $ this ->latitude ); ?> "
208+ data-stellar-places-map-lng="<?php echo esc_attr ( $ this ->longitude ); ?> "
209+ data-stellar-places-map-locations="<?php echo esc_attr ( wp_json_encode ( $ this ->locations ) ); ?> "
210+ data-stellar-places-map-options="<?php echo esc_attr ( wp_json_encode ( $ mapOptions ) ); ?> "
211+ ></div>
160212 <?php
161213 return ob_get_clean ();
162214 }
@@ -165,7 +217,7 @@ class="<?php echo esc_attr( $class ); ?>"
165217 * Render map
166218 */
167219 public function render () {
168- echo $ this ->get_html ();
220+ echo $ this ->get_html (); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
169221 }
170222
171223 /**
@@ -177,17 +229,18 @@ public static function wp_print_footer_scripts() {
177229 $ template = dirname ( STELLAR_PLACES_FILE ) . '/includes/templates/info-window.html ' ;
178230 }
179231 echo '<script type="text/template" id="stellar-places-info-window-template"> ' ;
180- echo file_get_contents ( $ template );
232+ echo file_get_contents ( $ template ); // phpcs:ignore
181233 echo '</script> ' ;
182234 }
183235
184236 /**
185237 * Helper function to check if a value is not null
186238 *
187- * @param mixed $value
239+ * @param mixed $value The value.
240+ *
188241 * @return bool
189242 */
190- protected function _is_not_null ( $ value ) {
243+ protected function is_not_null ( $ value ) {
191244 return ! is_null ( $ value );
192245 }
193246
0 commit comments