PluginProbe
CBX Map for Google Map & OpenStreetMap / trunk
CBX Map for Google Map & OpenStreetMap vtrunk
trunk 1.1.10 1.1.11 1.1.12 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5
cbxgooglemap / includes / Helpers / CBXGooglemapMetaHelper.php

CBXGooglemapMetaHelper.php in CBX Map for Google Map & OpenStreetMap trunk, at includes/Helpers/CBXGooglemapMetaHelper.php

575 lines 26.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Cbx\Googlemap\Helpers;
3
4 // If this file is called directly, abort.
5 if ( ! defined( 'WPINC' ) ) {
6 die;
7 }
8
9 use Cbx\Googlemap\CBXGooglemapSettings;
10
11
12 class CBXGooglemapMetaHelper {
13 /**
14 * Session field sections
15 *
16 * @param int $post_id
17 *
18 * @return array
19 */
20 public static function meta_field_sections( $post_id = 0, $post_type = 'cbxgooglemap' ) {
21 $sections = [
22 'mapsettings' => esc_html__( 'Map Settings', 'cbxgooglemap' ),
23 'maplocation' => esc_html__( 'Primary Marker', 'cbxgooglemap' ),
24 ];
25
26 return apply_filters( 'cbxgooglemap_sections', $sections );
27 }//end method meta_field_sections
28
29 /**
30 * Meta fields for sessions
31 *
32 * @param int $post_id
33 *
34 * @return array
35 */
36 public static function cbxgooglemap_meta_fields( $post_id = 0 ) {
37 $meta_fields = [];
38 $settings = new CBXGooglemapSettings();
39 $general_settings = get_option( 'cbxgooglemap_general', [] );
40
41 $zoom_level = intval( $settings->get_field( 'zoom', 'cbxgooglemap_general', '8' ) );
42 if ( $zoom_level == 0 ) {
43 $zoom_level = 8;
44 }
45
46
47 $width_default = $settings->get_field( 'width', 'cbxgooglemap_general', '100%' );
48 if ( $width_default == '' || $width_default == 0 ) {
49 $width_default = '100%';
50 }
51
52
53 $height_default = intval( $settings->get_field( 'height', 'cbxgooglemap_general', '300' ) );
54 if ( $height_default == 0 ) {
55 $height_default = 300;
56 }
57
58 $scrollwheel = intval( $settings->get_field( 'scrollwheel', 'cbxgooglemap_general', 1 ) );
59 $showinfo = intval( $settings->get_field( 'showinfo', 'cbxgooglemap_general', 1 ) );
60 $infow_open = intval( $settings->get_field( 'infow_open', 'cbxgooglemap_general', 1 ) );
61 $maptype = $settings->get_field( 'maptype', 'cbxgooglemap_general', 'roadmap' );
62
63
64 $meta_fields['mapsettings'] = apply_filters( 'cbxgooglemap_mapsettings_fields', [
65 'maptype' => [
66 'label' => esc_html__( 'Map Type', 'cbxgooglemap' ),
67 'type' => 'select',
68 'default' => $maptype,
69 'options' => [
70 'roadmap' => esc_html__( 'Road Map', 'cbxgooglemap' ),
71 'satellite' => esc_html__( 'Satellite Map', 'cbxgooglemap' ),
72 'hybrid' => esc_html__( 'Hybrid Map', 'cbxgooglemap' ),
73 'terrain' => esc_html__( 'Terrain Map', 'cbxgooglemap' ),
74 ],
75 'desc' => esc_html__( 'Google Map only', 'cbxgooglemap' ),
76 'sanitize_callback' => 'sanitize_text_field'
77 ],
78 'zoom' => [
79 'label' => esc_html__( 'Zoom Level', 'cbxgooglemap' ),
80 'desc' => esc_html__( 'Plain address with road no etc', 'cbxgooglemap' ),
81 'type' => 'text',
82 'default' => $zoom_level,
83 'sanitize_callback' => 'sanitize_text_field'
84 ],
85 'width' => [
86 'label' => esc_html__( 'Width', 'cbxgooglemap' ),
87 'desc' => esc_html__( 'Map width, use % if need, don\'t use px as it will be automatically if no % used.', 'cbxgooglemap' ),
88 'type' => 'text',
89 'default' => $width_default,
90 'sanitize_callback' => 'sanitize_text_field'
91 ],
92 'height' => [
93 'label' => esc_html__( 'Height', 'cbxgooglemap' ),
94 'desc' => esc_html__( 'Map height, don\'t use px', 'cbxgooglemap' ),
95 'type' => 'text',
96 'default' => $height_default,
97 'sanitize_callback' => 'sanitize_text_field'
98 ],
99 'scrollwheel' => [
100 'label' => esc_html__( 'Mouse Scroll Wheel', 'cbxgooglemap' ),
101 'desc' => esc_html__( 'Enable/disable mouse scroll whell', 'cbxgooglemap' ),
102 'type' => 'radio',
103 'default' => $scrollwheel,
104 'desc_tip' => true,
105 'options' => [
106 '1' => esc_html__( 'Enable', 'cbxgooglemap' ),
107 '0' => esc_html__( 'Disable', 'cbxgooglemap' ),
108 ],
109 'inline' => true,
110 'sanitize_callback' => 'absint'
111 ],
112 'showinfo' => [
113 'label' => esc_html__( 'Show Info window', 'cbxgooglemap' ),
114 'desc' => esc_html__( 'Show information on click of marker', 'cbxgooglemap' ),
115 'type' => 'radio',
116 'default' => $showinfo,
117 'desc_tip' => true,
118 'options' => [
119 '1' => esc_html__( 'Enable', 'cbxgooglemap' ),
120 '0' => esc_html__( 'Disable', 'cbxgooglemap' ),
121 ],
122 'inline' => true,
123 'sanitize_callback' => 'absint'
124 ],
125 'infow_open' => [
126 'label' => esc_html__( 'Info/Popup Window', 'cbxgooglemap' ),
127 'type' => 'radio',
128 'default' => $infow_open,
129 'desc_tip' => true,
130 'options' => [
131 '1' => esc_html__( 'Open(Default)', 'cbxgooglemap' ),
132 '0' => esc_html__( 'On Click', 'cbxgooglemap' ),
133 ],
134 'inline' => true,
135 'sanitize_callback' => 'absint'
136 ],
137 ] );
138
139 $meta_fields['maplocation'] = apply_filters( 'cbxgooglemap_maplocation_fields', [
140 'title' => [
141 'label' => esc_html__( 'Marker Heading', 'cbxgooglemap' ),
142 'desc' => esc_html__( 'Heading title will be used for marker pop info', 'cbxgooglemap' ),
143 'type' => 'text',
144 'default' => esc_html__('Default Title', 'cbxgooglemap'),
145 'sanitize_callback' => 'sanitize_text_field'
146 ],
147 'address' => [
148 'label' => esc_html__( 'Address', 'cbxgooglemap' ),
149 'desc' => esc_html__( 'Plain address with road no etc', 'cbxgooglemap' ),
150 'type' => 'text',
151 'default' => '',
152 'sanitize_callback' => 'sanitize_text_field'
153 ],
154 'website' => [
155 'label' => esc_html__( 'Website Link', 'cbxgooglemap' ),
156 'desc' => esc_html__( 'If website link is given then market popup will show the Title as linked with this address', 'cbxgooglemap' ),
157 'type' => 'text',
158 'default' => '',
159 'sanitize_callback' => 'sanitize_text_field'
160 ],
161 'location' => [
162 'label' => esc_html__( 'Map Location', 'cbxgooglemap' ),
163 'desc' => esc_html__( 'Type location and select from google map auto suggest.', 'cbxgooglemap' ),
164 'type' => 'location',
165 'default' => '',
166 'sanitize_callback' => 'sanitize_text_field'
167 ],
168 'lat' => [
169 'label' => esc_html__( 'Latitude', 'cbxgooglemap' ),
170 'desc' => esc_html__( 'If you select location from google map then latitude will be picked automatically but still you can put manually', 'cbxgooglemap' ),
171 'type' => 'lat',
172 'default' => '',
173 'sortable' => true,
174 'sanitize_callback' => 'sanitize_text_field'
175 ],
176 'lng' => [
177 'label' => esc_html__( 'Longitude', 'cbxgooglemap' ),
178 'desc' => esc_html__( 'If you select location from google map then longitude will be picked automatically but still you can put manually', 'cbxgooglemap' ),
179 'type' => 'lng',
180 'default' => '',
181 'sortable' => true,
182 'sanitize_callback' => 'sanitize_text_field'
183 ],
184
185 'mapicon' => [
186 'label' => esc_html__( 'Map Icon', 'cbxgooglemap' ),
187 'desc' => esc_html__( 'Map marker custom icon', 'cbxgooglemap' ),
188 'type' => 'file',
189 'default' => '',
190 'desc_tip' => true,
191 'sanitize_callback' => 'sanitize_text_field'
192 ],
193
194 ] );
195
196 return apply_filters( 'cbxgooglemap_fields', $meta_fields );
197 }//end method cbxgooglemap_meta_fields
198
199 /**
200 * Render the meta fields html
201 *
202 * @param $post
203 * @param $meta_fields
204 * @param $combined_field
205 * @param $meta_prefix
206 * @param $sectionable
207 *
208 * @return void\
209 */
210 public static function render_meta_fields( $post, $meta_fields, $combined_field, $meta_prefix, $sectionable = false ) {
211 $settings = new CBXGooglemapSettings();
212
213 $general_settings = get_option( 'cbxgooglemap_general', [] );
214
215 $api_key = esc_attr( $settings->get_field( 'apikey', 'cbxgooglemap_general', '' ) );
216 $map_source = absint( $settings->get_field( 'mapsource', 'cbxgooglemap_general', 1 ) );
217 $scrollwheel_default = absint( $settings->get_field( 'scrollwheel', 'cbxgooglemap_general', 1 ) );
218 $showinfo_default = absint( $settings->get_field( 'showinfo', 'cbxgooglemap_general', 1 ) );
219
220 $mapicon_default = esc_url( $settings->get_field( 'mapicon', 'cbxgooglemap_general', '' ) );
221
222 if ( isset( $post->ID ) && $post->ID > 0 ) {
223 $post_id = $post->ID;
224 $post_type = $post->post_type;
225
226
227 wp_nonce_field( 'cbxmetahelper_' . $post_type . '_meta_box', 'cbxmetahelper_' . $post_type . '_meta_box_nonce' );
228
229 $meta_combined = get_post_meta( $post_id, $combined_field, true ); //meta fields not sortable
230
231 $mapicon = isset( $meta_combined['_cbxgooglemapmapicon'] ) ? esc_url( $meta_combined['_cbxgooglemapmapicon'] ) : $mapicon_default;
232
233 $sections_found = false;
234 $sections = [];
235
236 $sections = CBXGooglemapMetaHelper::meta_field_sections( $post_id, $post_type );
237
238 echo '<div class="metabox-holder-wrapper">';
239
240 //print the sections
241 if ( $sectionable ) {
242
243 $sections_html = '<h2 class="nav-tab-wrapper" id="cbxgooglemap_meta_tabs">';
244 foreach ( $meta_fields as $section_id => $fields ) {
245 $sections_html .= '<a id="metabox-content' . esc_attr( $section_id ) . '-tab" class="nav-tab" href="#metabox-content' . esc_attr( $section_id ) . '">' . ( isset( $sections[ $section_id ] ) ? $sections[ $section_id ] : ucfirst( $section_id ) ) . '</a>';
246 }
247
248 $sections_html .= '</h2>';
249 echo $sections_html;//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
250 }
251
252 echo '<div class="metabox-holder metabox-holder-cbxgooglemap metabox-holder-cbxgooglemap-' . esc_attr( $post_type ) . '">';
253
254 foreach ( $meta_fields as $section_id => $fields ) {
255 echo '<div id="metabox-content' . esc_attr( $section_id ) . '" class="metabox-content metabox-content-cbxgooglemap metabox-content-cbxgooglemap-' . esc_attr( $post_type ) . '">';
256 echo '<table class="form-table">';
257
258 foreach ( $fields as $id => $field ) {
259
260 $is_sortable = isset( $field['sortable'] ) ? ( $field['sortable'] ) : false;
261 $multiple_select = ( isset( $field['multiple'] ) ) ? $field['multiple'] : false;
262
263 if ( $is_sortable ) {
264 $meta = get_post_meta( $post_id, $meta_prefix . $id, true );
265 } else {
266 //for combined field
267 $meta = isset( $meta_combined[ $meta_prefix . $id ] ) ? $meta_combined[ $meta_prefix . $id ] : '';
268 }
269
270
271 if ( $meta == '' && isset( $field['default'] ) ) {
272 $meta = $field['default'];
273 }
274
275 $label = isset( $field['label'] ) ? $field['label'] : '';
276
277 echo '<tr>';
278 $colspan = 1;
279 if ( $label == '' ) {
280 $colspan = 2;
281 }
282 echo ( $label != '' ) ? '<th><label for="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '">' . esc_attr( $label ) . '</label></th>' : '';
283
284 echo '<td colspan="' . esc_attr( $colspan ) . '">';
285
286 switch ( $field['type'] ) {
287 case 'text':
288 echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_text cbxgooglemapmeta_input_' . esc_attr( $id ) . '" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-text-' . esc_attr( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
289 if ( isset( $field['desc'] ) ) {
290 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
291 }
292 break;
293
294 case 'location':
295
296 if ( $map_source == 1 && $api_key == '' ) {
297 echo '<input type="text" class="cbxeventzmeta_input cbxeventzmeta_input_location" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-location-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
298
299 echo '<div class="notification notification-warning" style="margin-top: 10px;">
300 <div class="notification-icon">
301 <svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 256 256"><path fill="#f59e0b" d="M235.07 189.09L147.61 37.22a22.75 22.75 0 0 0-39.22 0L20.93 189.09a21.53 21.53 0 0 0 0 21.72A22.35 22.35 0 0 0 40.55 222h174.9a22.35 22.35 0 0 0 19.6-11.19a21.53 21.53 0 0 0 .02-21.72Zm-10.41 15.71a10.46 10.46 0 0 1-9.21 5.2H40.55a10.46 10.46 0 0 1-9.21-5.2a9.51 9.51 0 0 1 0-9.72l87.45-151.87a10.75 10.75 0 0 1 18.42 0l87.46 151.87a9.51 9.51 0 0 1-.01 9.72ZM122 144v-40a6 6 0 0 1 12 0v40a6 6 0 0 1-12 0Zm16 36a10 10 0 1 1-10-10a10 10 0 0 1 10 10Z"/></svg>
302 </div>
303 <div class="notification-content">';
304 echo '<div class="notification-title">'.esc_html__('Googlemap Api Key Missing', 'cbxgooglemap').'</div>';
305 /* translators: %s: Admin URL */
306 echo '<div class="notification-message"><p>' . wp_kses(sprintf( __( 'Google map api key missing, alternative openstreet map can be enabled from <a href="%s" target="_blank">global setting</a>', 'cbxgooglemap' ), esc_url( admin_url( 'edit.php?post_type=cbxgooglemap&page=cbxgooglemap_settings' ) ) ), ['a' => ['href' => [], 'target' => []]]) . '</p></div>';
307 echo '</div></div>';
308
309 //echo $map_api_key_missing;//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
310
311 } elseif (
312 $map_source == 1 ) {
313 $data_custom_attrs = [];
314
315 $data_custom_attrs = apply_filters( 'cbxgooglemap_data_custom_attrs', $data_custom_attrs, $post_id, [] );
316 $data_custom_attrs_html = ' ';
317 foreach ( $data_custom_attrs as $custom_attr_key => $custom_attr_value ) {
318 $data_custom_attrs_html .= ' ' . $custom_attr_key . '="' . $custom_attr_value . '" ';
319 }
320
321 echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_location" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-location-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" /><div ' . esc_html( $data_custom_attrs_html ) . ' data-apikey="' . esc_attr( $api_key ) . '" data-mapsource="1" class="map_canvas"></div>';
322
323 if ( isset( $field['desc'] ) ) {
324 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
325 }
326 } else {
327 $data_custom_attrs = [];
328
329 $data_custom_attrs = apply_filters( 'cbxgooglemap_data_custom_attrs', $data_custom_attrs, $post_id, [] );
330 $data_custom_attrs_html = ' ';
331 foreach ( $data_custom_attrs as $custom_attr_key => $custom_attr_value ) {
332 $data_custom_attrs_html .= ' ' . $custom_attr_key . '="' . $custom_attr_value . '" ';
333 }
334
335 echo '<input style="width:100%;" type="hidden" placeholder="' . esc_html__( 'Type full address and enter to find the lat, lon of the location', 'cbxgooglemap' ) . '" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_location" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-location-' . esc_attr( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" /><div ' . esc_html( $data_custom_attrs_html ) . ' data-mapsource="0" class="map_canvas"></div>';
336 if ( isset( $field['desc'] ) ) {
337 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
338 }
339 }
340
341 break;
342 case 'lat':
343 echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_lat" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-lat-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
344 if ( isset( $field['desc'] ) ) {
345 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
346 }
347 break;
348 case 'lng':
349 echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_lng" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-lng-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
350 if ( isset( $field['desc'] ) ) {
351 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
352 }
353 break;
354 case 'number':
355 echo '<input type="number" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_number" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-text-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />
356 <p class="description">' . esc_html( $field['desc'] ) . '</p>';
357 break;
358
359 case 'url':
360 echo '<input type="url" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_url" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-url-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
361 if ( isset( $field['desc'] ) ) {
362 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
363 }
364 break;
365
366 case 'file':
367 echo '<div class="cbxgooglemapmeta_input_file_wrap">';
368 echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_file cbxgooglemapmeta_filepicker" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-file-' . intval( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
369
370 $icon_extra_class = '';
371 $marker_icon = '';
372 $trash_extra_class = '';
373
374 if ( $meta == '' ) {
375 $icon_extra_class = 'cbxgooglemapmeta_marker_hide';
376 $file_picked_class = 'cbxgooglemapmeta_left_space';
377 $trash_extra_class = 'cbxgooglemapmeta_trash_hide';
378 } else {
379 $marker_icon = ' background-image: url(\'' . esc_url( $meta ) . '\') ;';
380 $file_picked_class = 'cbxgooglemapmeta_filepicked';
381 }
382
383 echo '<span style="' . esc_attr( $marker_icon ) . '" class="cbxgooglemapmeta_marker ' . esc_attr( $icon_extra_class ) . '"></span>';
384
385 echo '<input type="button" class="button cbxgooglemapmeta_filepicker_btn ' . esc_attr( $file_picked_class ) . '" value="' . esc_attr( $label ) . '" />';
386 echo '<span class="cbxgooglemapmeta_trash dashicons dashicons-no-alt ' . esc_attr( $trash_extra_class ) . '"></span>';
387 echo '</div>';
388 if ( isset( $field['desc'] ) ) {
389 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
390 }
391 break;
392
393 case 'color':
394
395 echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_color cbxgooglemapmeta_colorpicker" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-color-' . esc_attr( $post_id ) . '" value="' . esc_attr( $meta ) . '" size="30" />';
396 if ( isset( $field['desc'] ) ) {
397 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
398 }
399 break;
400
401 case 'select':
402 echo '<select name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-select-' . intval( $post_id ) . '" class="selecttwo-select">';
403
404 if ( isset( $field['optgroup'] ) && intval( $field['optgroup'] ) ) {
405
406 foreach ( $field['options'] as $optlabel => $data ) {
407 echo '<optgroup label="' . esc_attr( $optlabel ) . '">';
408 foreach ( $data as $index => $option ) {
409 echo '<option ' . ( ( $meta == $index ) ? ' selected="selected"' : '' ) . ' value="' . esc_attr( $index ) . '">' . esc_attr( $option ) . '</option>';
410 }
411
412 }
413 } else {
414 foreach ( $field['options'] as $index => $option ) {
415 echo '<option ' . ( ( $meta == $index ) ? ' selected="selected"' : '' ) . ' value="' . esc_attr( $index ) . '">' . esc_attr( $option ) . '</option>';
416 }
417 }
418 echo '</select><br/>';
419 if ( isset( $field['desc'] ) ) {
420 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
421 }
422 break;
423 case 'multiselect':
424
425 echo '<select name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '[]" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-multiselect-' . esc_attr( $post_id ) . '" class="selecttwo-select" multiple>';
426 if ( isset( $field['optgroup'] ) && intval( $field['optgroup'] ) ) {
427
428 foreach ( $field['options'] as $optlabel => $data ) {
429 echo '<optgroup label="' . esc_attr( $optlabel ) . '">';
430 foreach ( $data as $key => $val ) {
431 echo '<option value="' . $key . '"', is_array( $meta ) && in_array( $key, $meta ) ? ' selected="selected"' : '', ' >' . esc_html( $val ) . '</option>';
432 }
433 echo '<optgroup>';
434 }
435
436 } else {
437 foreach ( $field['options'] as $key => $val ) {
438 echo '<option value="' . $key . '"', is_array( $meta ) && in_array( $key, $meta ) ? ' selected="selected"' : '', ' >' . esc_html( $val ) . '</option>';
439 }
440 }
441
442 echo '</select>';
443 if ( isset( $field['desc'] ) ) {
444 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
445 }
446 break;
447
448 case 'radio':
449 if ( in_array( 'inline', $field ) ) {
450 $inline = isset( $field['inline'] ) ? intval( $field['inline'] ) : 0;
451 $inline_class = ( $inline ) ? 'cbxgooglemap-metabox-label-radio-inline' : '';
452 $br_html = ( ! $inline ) ? '<br/>' : '';
453 $last_class = '';
454 }
455 $last_element = array_key_last( $field['options'] );
456 echo '<fieldset>
457 <legend class="screen-reader-text"><span>input type="radio"</span></legend>';
458 foreach ( $field['options'] as $key => $value ) {
459 if ( $key === $last_element ) {
460 $last_class = 'label-margin-none';
461 }
462 echo '<label title="g:i a" for="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-radio-' . esc_attr( $post_id ) . '-' . esc_attr( $key ) . '" class="' . esc_attr( $inline_class ) . ' ' . esc_attr( $last_class ) . '">
463 <input id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-radio-' . esc_attr( $post_id ) . '-' . esc_attr( $key ) . '" type="radio" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" value="' . esc_attr( $key ) . '" ' . ( ( $meta == $key ) ? ' checked="checked" ' : '' ) . ' />
464 <span>' . esc_html( $value ) . '</span>
465 </label>' . esc_html( $br_html );
466
467
468 }
469 echo '</fieldset>';
470 echo esc_html( $br_html );
471 if ( isset( $field['desc'] ) ) {
472 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
473 }
474 break;
475
476 case 'checkbox':
477 echo '<input type="checkbox" name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-checkbox-' . esc_attr( $post_id ) . '" class="cb-checkbox checkbox-' . esc_attr( $post_id ) . '" ' . ( $meta ? ' checked="checked"' : '' ) . '/>';
478 if ( isset( $field['desc'] ) ) {
479 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
480 }
481 break;
482 // checkbox_group
483 case 'multicheck':
484 if ( $meta == '' ) {
485 $meta = [];
486 foreach ( $field['options'] as $option ) {
487 array_push( $meta, $option['value'] );
488 }
489 }
490
491 foreach ( $field['options'] as $option ) {
492 echo '<input type="checkbox" value="' . $option['value'] . '" name="' . esc_attr( $meta_prefix ) . $id . '[]" id="' . $option['value'] . '-mult-chk-' . $post_id . '-field-' . esc_attr( $meta_prefix ) . $id . '" class="cb-multi-check mult-check-' . $post_id . '"', $meta && in_array( $option['value'], $meta ) ? ' checked="checked"' : '', ' />
493 <label for="' . esc_attr( $option['value'] ) . '">' . esc_html( $option['label'] ) . '</label><br/>';
494 }
495
496 if ( isset( $field['desc'] ) ) {
497 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
498 }
499 break;
500
501 case 'post_type':
502 $post_type_ = ( isset( $field['post_type'] ) ) ? $field['post_type'] : [ 'post' ];
503 $post_order_ = ( isset( $field['post_order'] ) ) ? $field['post_order'] : 'DESC';
504 $post_orderby_ = ( isset( $field['post_orderby'] ) ) ? $field['post_orderby'] : 'ID';
505
506 if ( ! is_array( $post_type_ ) ) {
507 $post_type_ = (array) $post_type_;
508 }
509
510 // WP_Query arguments
511
512 $args = [
513 'post_type' => $post_type_,
514 'post_status' => [ 'publish' ],
515 'order' => $post_order_,
516 'orderby ' => $post_orderby_,
517 'posts_per_page' => '-1',
518 ];
519
520 // The Query
521 $query_post_types = get_posts( $args );
522
523 // The Loop
524
525 $posts_found = [];
526 foreach ( $query_post_types as $post ) : CBXGooglemapHelper::setup_admin_postdata( $post );
527
528 $post_id_ = get_the_ID();
529 $post_title_ = get_the_title( $post_id_ );
530 $posts_found[ $post_id_ ] = $post_title_;
531
532 endforeach;
533 CBXGooglemapHelper::wp_reset_admin_postdata();
534
535
536 if ( $multiple_select ) {
537 echo '<select name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '[]" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-post_type-' . intval( $post_id ) . '" class="selecttwo-select" multiple >';
538 foreach ( $posts_found as $key => $val ) {
539 echo '<option value="' . esc_attr( $key ) . '"', is_array( $meta ) && in_array( $key, $meta ) ? ' selected="selected"' : '', ' >' . esc_attr( $val ) . '</option>';
540 }
541 echo '</select>';
542 } else {
543 echo '<select name="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '" id="' . esc_attr( $meta_prefix ) . esc_attr( $id ) . '-post_type-' . intval( $post_id ) . '" class="selecttwo-select" >';
544 foreach ( $posts_found as $index => $option ) {
545 echo '<option ' . ( ( $meta == $index ) ? ' selected="selected"' : '' ) . ' value="' . esc_attr( $index ) . '">' . esc_attr( $option ) . '</option>';
546 }
547 echo '</select>';
548 }
549
550 if ( isset( $field['desc'] ) ) {
551 echo '<p class="description">' . esc_html( $field['desc'] ) . '</p>';
552 }
553 break;
554 }
555
556 do_action( 'cbxgooglemap_meta_fields_render', $field['type'], $field, $post, $meta_combined );
557
558 echo '</td>';
559
560 echo '</tr>';
561 }
562 echo '</table>';
563
564 echo '</div>';
565 }
566
567 echo '</div>';
568 echo '</div>';
569
570 } else {
571 echo esc_html__( 'Please save first to add extra information.', 'cbxgooglemap' );
572 }
573 }//end method render_meta_fields
574
575 }//end class CBXGooglemapHelper