1 | <?php |
||
9 | class Google_Maps { |
||
10 | |||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | protected static $_version = '0.1.6'; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected static $_api_key = ''; |
||
20 | |||
21 | /** |
||
22 | * @var Geocoder |
||
23 | */ |
||
24 | protected static $_geocoder; |
||
25 | |||
26 | /** |
||
27 | * These conditions will be used to determine whether to enqueue the Google Maps JS. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected static $_script_conditions = array(); |
||
32 | |||
33 | /** |
||
34 | * The path to this library's directory |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected static $_source_dir; |
||
39 | |||
40 | /** |
||
41 | * The url to this module's directory |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected static $_source_url; |
||
46 | |||
47 | /** |
||
48 | * |
||
49 | */ |
||
50 | static function initialize() { |
||
57 | |||
58 | /** |
||
59 | * @return string |
||
60 | */ |
||
61 | 1 | static function api_key() { |
|
62 | |||
63 | 1 | return static::$_api_key; |
|
64 | |||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @return Geocoder |
||
69 | */ |
||
70 | 1 | static function geocoder() { |
|
71 | |||
72 | 1 | if ( ! isset( static::$_geocoder ) ) { |
|
73 | 1 | static::$_geocoder = new Geocoder( ['api_key' => self::api_key() ] ); |
|
74 | } |
||
75 | |||
76 | 1 | return static::$_geocoder; |
|
77 | |||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param array $args |
||
82 | * @return Map |
||
83 | */ |
||
84 | 1 | static function make_new_map( $args = array() ) { |
|
85 | |||
86 | 1 | $class = __NAMESPACE__ . '\Map'; |
|
87 | 1 | return new $class( $args ); |
|
88 | |||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @param string $key |
||
93 | */ |
||
94 | 1 | static function register_api_key( $key ) { |
|
95 | |||
96 | 1 | static::$_api_key = filter_var( $key, FILTER_SANITIZE_STRING ); |
|
97 | |||
98 | 1 | } |
|
99 | |||
100 | /** |
||
101 | * @param callable $condition |
||
102 | */ |
||
103 | 1 | static function register_script_condition( $condition ) { |
|
104 | |||
105 | 1 | static::$_script_conditions[] = $condition; |
|
106 | |||
107 | 1 | } |
|
108 | |||
109 | static function _wp_enqueue_scripts_9() { |
||
135 | |||
136 | 1 | static function script_conditions() { |
|
137 | |||
138 | 1 | return static::$_script_conditions; |
|
139 | |||
140 | } |
||
141 | |||
142 | /** |
||
143 | * @param string $address |
||
144 | * @param array $args |
||
145 | * @return Marker |
||
146 | */ |
||
147 | 1 | static function make_marker_by_address( $address, $args = array() ) { |
|
148 | |||
149 | 1 | $args = wp_parse_args( $args, array( |
|
150 | 1 | 'address' => $address, |
|
151 | 1 | 'geocoder' => self::geocoder(), |
|
152 | ) ); |
||
153 | |||
154 | 1 | return new Marker( $args ); |
|
155 | |||
156 | } |
||
157 | |||
158 | /** |
||
159 | * @param string $destination |
||
160 | * @param array $args |
||
161 | * @return string |
||
162 | */ |
||
163 | 1 | static function driving_directions_href($destination, $args = array() ) { |
|
164 | |||
165 | 1 | $args = wp_parse_args( $args, array( |
|
166 | 1 | 'start' => 'My Location', |
|
167 | ) ); |
||
168 | |||
169 | 1 | return sprintf( 'https://maps.google.com/maps?saddr=%1$s&daddr=%2$s', urlencode( $args['start'] ), urlencode( $destination ) ); |
|
170 | } |
||
171 | |||
172 | /** |
||
173 | * @return string |
||
174 | */ |
||
175 | 1 | static function source_dir() { |
|
176 | |||
177 | 1 | return self::$_source_dir; |
|
178 | |||
179 | } |
||
180 | |||
181 | /** |
||
182 | * @return string |
||
183 | */ |
||
184 | static function source_url() { |
||
197 | |||
198 | 1 | static function version() { |
|
199 | |||
200 | 1 | return self::$_version; |
|
201 | |||
202 | } |
||
203 | |||
204 | } |
||
205 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.