| 1 |
<?php |
| 2 |
|
| 3 |
// If this file is called directly, abort. |
| 4 |
if ( ! defined( 'WPINC' ) ) { |
| 5 |
die; |
| 6 |
} |
| 7 |
|
| 8 |
class CBXGooglemapHelper { |
| 9 |
/** |
| 10 |
* Is gutenberg edit page |
| 11 |
* |
| 12 |
* @return bool |
| 13 |
* |
| 14 |
* @since 1.1.5 |
| 15 |
*/ |
| 16 |
public static function is_gutenberg_page() { |
| 17 |
//if(!is_admin()) return false; |
| 18 |
if ( function_exists( 'is_gutenberg_page' ) && |
| 19 |
is_gutenberg_page() |
| 20 |
) { |
| 21 |
// The Gutenberg plugin is on. |
| 22 |
return true; |
| 23 |
} |
| 24 |
|
| 25 |
$current_screen = get_current_screen(); |
| 26 |
if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor()) { |
| 27 |
// Gutenberg page on 5+. |
| 28 |
return true; |
| 29 |
} |
| 30 |
return false; |
| 31 |
}//end is_gutenberg_page |
| 32 |
|
| 33 |
|
| 34 |
/** |
| 35 |
* Enqueue css and js when needed |
| 36 |
* |
| 37 |
* @param bool $enqueue_js |
| 38 |
* @param bool $enqueue_css |
| 39 |
* |
| 40 |
* @since 1.1.5 |
| 41 |
*/ |
| 42 |
public static function enqueue_js_css($enqueue_js = true, $enqueue_css = true){ |
| 43 |
$settings = new CBXGooglemapSettings();; |
| 44 |
$googlemap_api_key = $settings->get_option( 'apikey', 'cbxgooglemap_general', '' ); |
| 45 |
$mapsource = intval( $settings->get_option( 'mapsource', 'cbxgooglemap_general', 1 ) ); |
| 46 |
|
| 47 |
if($enqueue_js){ |
| 48 |
//handle enqueue js |
| 49 |
if ( ( $mapsource == 1 && ! empty( $googlemap_api_key ) ) || $mapsource == 0 ) { |
| 50 |
if ( $mapsource == 1 ) { |
| 51 |
wp_enqueue_script( 'coregooglemapapi' ); |
| 52 |
wp_enqueue_script( 'jqcbxgooglemap' ); |
| 53 |
} |
| 54 |
else{ |
| 55 |
wp_enqueue_script( 'coregooglemapapi' ); |
| 56 |
} |
| 57 |
|
| 58 |
wp_enqueue_script( 'cbxgooglemap-public' ); |
| 59 |
} |
| 60 |
//end handle enqueue js |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
if($enqueue_css){ |
| 65 |
//handle enqueue css |
| 66 |
if ( $mapsource == 0 ) { |
| 67 |
wp_enqueue_style( 'leaflet' ); |
| 68 |
} |
| 69 |
else{ |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
wp_enqueue_style( 'cbxgooglemap-public' ); |
| 74 |
//end handle enqueue css |
| 75 |
} |
| 76 |
|
| 77 |
}//end enqueue_js_css |
| 78 |
|
| 79 |
/** |
| 80 |
* Register Custom Post Type cbxgooglemap |
| 81 |
* |
| 82 |
* @since 3.7.0 |
| 83 |
*/ |
| 84 |
public static function create_googlemap_post_type() { |
| 85 |
$labels = array( |
| 86 |
'name' => _x( 'Maps', 'Post Type General Name', 'cbxgooglemap' ), |
| 87 |
'singular_name' => _x( 'Map', 'Post Type Singular Name', 'cbxgooglemap' ), |
| 88 |
'menu_name' => esc_html__( 'CBX Maps', 'cbxgooglemap' ), |
| 89 |
'parent_item_colon' => esc_html__( 'Parent Item:', 'cbxgooglemap' ), |
| 90 |
'all_items' => esc_html__( 'Maps', 'cbxgooglemap' ), |
| 91 |
'view_item' => esc_html__( 'View Map', 'cbxgooglemap' ), |
| 92 |
'add_new_item' => esc_html__( 'Add New map', 'cbxgooglemap' ), |
| 93 |
'add_new' => esc_html__( 'Add New', 'cbxgooglemap' ), |
| 94 |
'edit_item' => esc_html__( 'Edit map', 'cbxgooglemap' ), |
| 95 |
'update_item' => esc_html__( 'Update map', 'cbxgooglemap' ), |
| 96 |
'search_items' => esc_html__( 'Search map', 'cbxgooglemap' ), |
| 97 |
'not_found' => esc_html__( 'Not found', 'cbxgooglemap' ), |
| 98 |
'not_found_in_trash' => esc_html__( 'Not found in Trash', 'cbxgooglemap' ), |
| 99 |
); |
| 100 |
|
| 101 |
$args = array( |
| 102 |
'label' => esc_html__( 'Maps', 'cbxgooglemap' ), |
| 103 |
'description' => esc_html__( 'Simple map using google map and openstreet map.', 'cbxgooglemap' ), |
| 104 |
'labels' => apply_filters( 'cbxgooglemap_post_type_labels', $labels ), |
| 105 |
'supports' => apply_filters( 'cbxgooglemap_post_type_supports', array( 'title' ) ), |
| 106 |
'hierarchical' => false, |
| 107 |
'public' => apply_filters( 'cbxgooglemap_post_type_public', false ), |
| 108 |
'show_ui' => true, |
| 109 |
'show_in_menu' => true, |
| 110 |
'show_in_nav_menus' => true, |
| 111 |
'show_in_admin_bar' => true, |
| 112 |
//'menu_icon' => 'dashicons-list-view', |
| 113 |
'menu_icon' => apply_filters('cbxgooglemap_menu_icon', CBXGOOGLEMAP_ROOT_URL.'assets/img/menu_icon2.png'), |
| 114 |
'can_export' => true, |
| 115 |
'has_archive' => apply_filters( 'cbxgooglemap_post_type_has_archive', false ), |
| 116 |
'exclude_from_search' => apply_filters( 'cbxgooglemap_post_type_exclude_from_search', true ), |
| 117 |
'publicly_queryable' => apply_filters( 'cbxgooglemap_post_type_publicly_queryable', false ), |
| 118 |
'capability_type' => 'post', |
| 119 |
); |
| 120 |
register_post_type( 'cbxgooglemap', apply_filters( 'cbxgooglemap_post_type_args', $args ) ); |
| 121 |
|
| 122 |
|
| 123 |
}//end create_googlemap_post_type |
| 124 |
|
| 125 |
/** |
| 126 |
* Session field sections |
| 127 |
* |
| 128 |
* @param int $post_id |
| 129 |
* |
| 130 |
* @return array |
| 131 |
*/ |
| 132 |
public static function cbxgooglemap_meta_field_sections( $post_id = 0, $post_type = 'cbxgooglemap' ) { |
| 133 |
$sections = array( |
| 134 |
'maplocation' => esc_html__( 'Map Location', 'cbxgooglemap' ), |
| 135 |
); |
| 136 |
|
| 137 |
return apply_filters( 'cbxgooglemap_sections', $sections ); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
/** |
| 142 |
* Meta fields for sessions |
| 143 |
* |
| 144 |
* @param int $post_id |
| 145 |
* |
| 146 |
* @return array |
| 147 |
*/ |
| 148 |
public static function cbxgooglemap_meta_fields( $post_id = 0 ) { |
| 149 |
|
| 150 |
$meta_fields = array(); |
| 151 |
$settings_api = new CBXGooglemapSettings(); |
| 152 |
$general_settings = get_option( 'cbxgooglemap_general', array() ); |
| 153 |
|
| 154 |
$zoom_level = intval( $settings_api->get_field( 'zoom', $general_settings, '8' ) ); |
| 155 |
if ( $zoom_level == 0 ) { |
| 156 |
$zoom_level = 8; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
$width_default = $settings_api->get_field( 'width', $general_settings, '100%' ); |
| 161 |
if ( $width_default == '' || $width_default == 0 ) { |
| 162 |
$width_default = '100%'; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
$height_default = intval( $settings_api->get_field( 'height', $general_settings, '300' ) ); |
| 167 |
if ( $height_default == 0 ) { |
| 168 |
$height_default = 300; |
| 169 |
} |
| 170 |
|
| 171 |
$scrollwheel = intval( $settings_api->get_field( 'scrollwheel', $general_settings, 1 ) ); |
| 172 |
|
| 173 |
$showinfo = intval( $settings_api->get_field( 'showinfo', $general_settings, 1 ) ); |
| 174 |
|
| 175 |
$infow_open = intval( $settings_api->get_field( 'infow_open', $general_settings, 1 ) ); |
| 176 |
$maptype = $settings_api->get_field( 'maptype', $general_settings, 'roadmap' ); |
| 177 |
|
| 178 |
|
| 179 |
$meta_fields['maplocation'] = apply_filters( 'cbxgooglemap_maplocation_fields', array( |
| 180 |
|
| 181 |
'maptype' => array( |
| 182 |
'label' => esc_html__( 'Map Type', 'cbxgooglemap' ), |
| 183 |
'type' => 'select', |
| 184 |
'default' => $maptype, |
| 185 |
'options' => array( |
| 186 |
'roadmap' => esc_html__( 'Road Map', 'cbxgooglemap' ), |
| 187 |
'satellite' => esc_html__( 'Satellite Map', 'cbxgooglemap' ), |
| 188 |
'hybrid' => esc_html__( 'Hybrid Map', 'cbxgooglemap' ), |
| 189 |
'terrain' => esc_html__( 'Terrain Map', 'cbxgooglemap' ), |
| 190 |
), |
| 191 |
'desc' => esc_html__( 'Google Map only', 'cbxgooglemap' ) |
| 192 |
), |
| 193 |
'address' => array( |
| 194 |
'label' => esc_html__( 'Addresss', 'cbxgooglemap' ), |
| 195 |
'desc' => esc_html__( 'Plain address with road no etc', 'cbxgooglemap' ), |
| 196 |
'type' => 'text', |
| 197 |
'default' => '', |
| 198 |
), |
| 199 |
'website' => array( |
| 200 |
'label' => esc_html__( 'Website Link', 'cbxgooglemap' ), |
| 201 |
'desc' => esc_html__( 'If website link is given then market popup will show the Title as linked with this address', 'cbxgooglemap' ), |
| 202 |
'type' => 'text', |
| 203 |
'default' => '', |
| 204 |
), |
| 205 |
'location' => array( |
| 206 |
'label' => esc_html__( 'Map Location', 'cbxgooglemap' ), |
| 207 |
'desc' => esc_html__( 'Type location and select from google map auto suggest.', 'cbxgooglemap' ), |
| 208 |
'type' => 'location', |
| 209 |
'default' => '' |
| 210 |
), |
| 211 |
'lat' => array( |
| 212 |
'label' => esc_html__( 'Latitude', 'cbxgooglemap' ), |
| 213 |
'desc' => esc_html__( 'If you select location from google map then latitude will be picked automatically but still you can put manually', 'cbxgooglemap' ), |
| 214 |
'type' => 'lat', |
| 215 |
'default' => '', |
| 216 |
'sortable' => true |
| 217 |
), |
| 218 |
'lng' => array( |
| 219 |
'label' => esc_html__( 'Longitude', 'cbxgooglemap' ), |
| 220 |
'desc' => esc_html__( 'If you select location from google map then longitude will be picked automatically but still you can put manually', 'cbxgooglemap' ), |
| 221 |
'type' => 'lng', |
| 222 |
'default' => '', |
| 223 |
'sortable' => true |
| 224 |
), |
| 225 |
'zoom' => array( |
| 226 |
'label' => esc_html__( 'Zoom Level', 'cbxgooglemap' ), |
| 227 |
'desc' => esc_html__( 'Plain addresss with road no etc', 'cbxgooglemap' ), |
| 228 |
'type' => 'text', |
| 229 |
'default' => $zoom_level, |
| 230 |
), |
| 231 |
'width' => array( |
| 232 |
'label' => esc_html__( 'Width', 'cbxgooglemap' ), |
| 233 |
'desc' => esc_html__( 'Map width, use % if need, don\'t use px as it will be automatically if no % used.', 'cbxgooglemap' ), |
| 234 |
'type' => 'text', |
| 235 |
'default' => $width_default, |
| 236 |
), |
| 237 |
'height' => array( |
| 238 |
'label' => esc_html__( 'Height', 'cbxgooglemap' ), |
| 239 |
'desc' => esc_html__( 'Map height, don\'t use px', 'cbxgooglemap' ), |
| 240 |
'type' => 'text', |
| 241 |
'default' => $height_default, |
| 242 |
), |
| 243 |
'scrollwheel' => array( |
| 244 |
'label' => esc_html__( 'Mouse Scroll Wheel', 'cbxgooglemap' ), |
| 245 |
'desc' => esc_html__( 'Enable/disable mouse scroll whell', 'cbxgooglemap' ), |
| 246 |
'type' => 'radio', |
| 247 |
'default' => $scrollwheel, |
| 248 |
'desc_tip' => true, |
| 249 |
'options' => array( |
| 250 |
'1' => esc_html__( 'Enable', 'cbxgooglemap' ), |
| 251 |
'0' => esc_html__( 'Disable', 'cbxgooglemap' ), |
| 252 |
) |
| 253 |
), |
| 254 |
'showinfo' => array( |
| 255 |
'label' => esc_html__( 'Show Info window', 'cbxgooglemap' ), |
| 256 |
'desc' => esc_html__( 'Show information on click of marker', 'cbxgooglemap' ), |
| 257 |
'type' => 'radio', |
| 258 |
'default' => $showinfo, |
| 259 |
'desc_tip' => true, |
| 260 |
'options' => array( |
| 261 |
'1' => esc_html__( 'Enable', 'cbxgooglemap' ), |
| 262 |
'0' => esc_html__( 'Disable', 'cbxgooglemap' ), |
| 263 |
) |
| 264 |
), |
| 265 |
'infow_open' => array( |
| 266 |
//'name' => 'infow_open', |
| 267 |
'label' => esc_html__( 'Info/Popup Window', 'cbxgooglemap' ), |
| 268 |
//'desc' => esc_html__('If disabled then popup or info window will show on click', 'cbxgooglemap'), |
| 269 |
'type' => 'radio', |
| 270 |
'default' => $infow_open, |
| 271 |
'desc_tip' => true, |
| 272 |
'options' => array( |
| 273 |
'1' => esc_html__( 'Open(Default)', 'cbxgooglemap' ), |
| 274 |
'0' => esc_html__( 'On Click', 'cbxgooglemap' ), |
| 275 |
) |
| 276 |
), |
| 277 |
'mapicon' => array( |
| 278 |
'label' => esc_html__( 'Map Icon', 'cbxgooglemap' ), |
| 279 |
'desc' => esc_html__( 'Map marker custom icon', 'cbxgooglemap' ), |
| 280 |
'type' => 'file', |
| 281 |
'default' => '', |
| 282 |
'desc_tip' => true |
| 283 |
), |
| 284 |
|
| 285 |
) ); |
| 286 |
|
| 287 |
|
| 288 |
return apply_filters( 'cbxgooglemap_fields', $meta_fields ); |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
public static function render_meta_fields( $post, $meta_fields, $combined_field, $meta_prefix, $sectionable = false ) { |
| 293 |
|
| 294 |
$settings_api = new CBXGooglemapSettings(); |
| 295 |
$general_settings = get_option( 'cbxgooglemap_general', array() ); |
| 296 |
$googlemap_api_key = $settings_api->get_field( 'apikey', $general_settings, '' ); |
| 297 |
$mapsource = intval( $settings_api->get_field( 'mapsource', $general_settings, 1 ) ); |
| 298 |
$scrollwheel_default = intval( $settings_api->get_field( 'scrollwheel', $general_settings, 1 ) ); |
| 299 |
$showinfo_default = intval( $settings_api->get_field( 'showinfo', $general_settings, 1 ) ); |
| 300 |
|
| 301 |
|
| 302 |
if ( isset( $post->ID ) && $post->ID > 0 ) { |
| 303 |
$post_id = $post->ID; |
| 304 |
$post_type = $post->post_type; |
| 305 |
|
| 306 |
|
| 307 |
wp_nonce_field( 'cbxmetahelper_' . $post_type . '_meta_box', 'cbxmetahelper_' . $post_type . '_meta_box_nonce' ); |
| 308 |
|
| 309 |
$meta_combined = get_post_meta( $post_id, $combined_field, true ); //meta fields not sortable |
| 310 |
|
| 311 |
|
| 312 |
$sections_found = false; |
| 313 |
|
| 314 |
$sections = array(); |
| 315 |
if ( method_exists( 'CBXGooglemapHelper', $post_type . '_meta_field_sections' ) ) { |
| 316 |
$sections_found = true; |
| 317 |
$sections = call_user_func( 'CBXGooglemapHelper::' . $post_type . '_meta_field_sections', array( |
| 318 |
$post_id, |
| 319 |
$post_type |
| 320 |
) ); |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
echo '<div class="metabox-holder-wrapper">'; |
| 325 |
|
| 326 |
if ( $sectionable && $sections_found ) { |
| 327 |
$sections_html = '<h2 class="nav-tab-wrapper">'; |
| 328 |
foreach ( $meta_fields as $section_id => $fields ) { |
| 329 |
|
| 330 |
$sections_html .= '<a id="metabox-content' . $section_id . '-tab" class="nav-tab" href="#metabox-content' . $section_id . '">' . ( isset( $sections[ $section_id ] ) ? $sections[ $section_id ] : ucfirst( $section_id ) ) . '</a>'; |
| 331 |
} |
| 332 |
$sections_html .= '</h2>'; |
| 333 |
|
| 334 |
echo $sections_html; |
| 335 |
} |
| 336 |
|
| 337 |
echo '<div class="metabox-holder metabox-holder-cbxgooglemap metabox-holder-cbxgooglemap-' . $post_type . '">'; |
| 338 |
|
| 339 |
foreach ( $meta_fields as $section_id => $fields ) { |
| 340 |
echo '<div id="metabox-content' . $section_id . '" class="metabox-content metabox-content-cbxgooglemap metabox-content-cbxgooglemap-' . $post_type . '">'; |
| 341 |
echo '<table class="form-table">'; |
| 342 |
|
| 343 |
foreach ( $fields as $id => $field ) { |
| 344 |
|
| 345 |
$is_sortable = isset( $field['sortable'] ) ? ( $field['sortable'] ) : false; |
| 346 |
$multiple_select = ( isset( $field['multiple'] ) ) ? $field['multiple'] : false; |
| 347 |
|
| 348 |
if ( $is_sortable ) { |
| 349 |
|
| 350 |
$meta = get_post_meta( $post_id, $meta_prefix . $id, true ); |
| 351 |
} else { |
| 352 |
//for combined field |
| 353 |
$meta = isset( $meta_combined[ $meta_prefix . $id ] ) ? $meta_combined[ $meta_prefix . $id ] : ''; |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
if ( $meta == '' && isset( $field['default'] ) ) { |
| 358 |
$meta = $field['default']; |
| 359 |
} |
| 360 |
|
| 361 |
$label = isset( $field['label'] ) ? $field['label'] : ''; |
| 362 |
|
| 363 |
echo '<tr>'; |
| 364 |
$colspan = 1; |
| 365 |
if ( $label == '' ) { |
| 366 |
$colspan = 2; |
| 367 |
} |
| 368 |
echo ( $label != '' ) ? '<th><label for="' . $meta_prefix . $id . '">' . $label . '</label></th>' : ''; |
| 369 |
|
| 370 |
echo '<td colspan="' . $colspan . '">'; |
| 371 |
|
| 372 |
|
| 373 |
switch ( $field['type'] ) { |
| 374 |
|
| 375 |
case 'text': |
| 376 |
echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_text cbxgooglemapmeta_input_' . $id . '" name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-text-' . $post_id . '" value="' . $meta . '" size="30" />'; |
| 377 |
if ( isset( $field['desc'] ) ) { |
| 378 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 379 |
} |
| 380 |
break; |
| 381 |
case 'location': |
| 382 |
if ( $mapsource == 1 && $googlemap_api_key == '' ) { |
| 383 |
echo '<input type="text" class="cbxeventzmeta_input cbxeventzmeta_input_location" name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-location-' . $post_id . '" value="' . $meta . '" size="30" />'; |
| 384 |
echo '<p>' . sprintf( __( 'Google map api key missing, alternative openstreet map can be enabled from <a href="%s" target="_blank">global setting</a>', 'cbxgooglemap' ), admin_url( 'edit.php?post_type=cbxgooglemap&page=cbxgooglemapsettings' ) ) . '</p>'; |
| 385 |
} else if ( $mapsource == 1 ) { |
| 386 |
echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_location" name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-location-' . $post_id . '" value="' . $meta . '" size="30" /><div data-apikey="' . $googlemap_api_key . '" data-mapsource="1" class="map_canvas"></div>'; |
| 387 |
if ( isset( $field['desc'] ) ) { |
| 388 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 389 |
} |
| 390 |
} else { |
| 391 |
echo '<p><strong>' . esc_html__( 'For Openstreet map automatic location picker is not available yet, please set lat, lon and save once to get started', 'cbxgooglemap' ) . '</strong></p>'; |
| 392 |
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="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-location-' . $post_id . '" value="' . $meta . '" size="30" /><div data-mapsource="0" class="map_canvas"></div>'; |
| 393 |
if ( isset( $field['desc'] ) ) { |
| 394 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 395 |
} |
| 396 |
} |
| 397 |
//echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_location" name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-location-' . $post_id . '" value="' . $meta . '" size="30" /><div class="map_canvas"></div>'; |
| 398 |
|
| 399 |
break; |
| 400 |
case 'lat': |
| 401 |
echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_lat" name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-lat-' . $post_id . '" value="' . $meta . '" size="30" />'; |
| 402 |
if ( isset( $field['desc'] ) ) { |
| 403 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 404 |
} |
| 405 |
break; |
| 406 |
case 'lng': |
| 407 |
echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_lng" name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-lng-' . $post_id . '" value="' . $meta . '" size="30" />'; |
| 408 |
if ( isset( $field['desc'] ) ) { |
| 409 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 410 |
} |
| 411 |
break; |
| 412 |
case 'number': |
| 413 |
echo '<input type="number" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_number" name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-text-' . $post_id . '" value="' . $meta . '" size="30" /> |
| 414 |
<span class="description">' . $field['desc'] . '</span>'; |
| 415 |
break; |
| 416 |
|
| 417 |
case 'url': |
| 418 |
echo '<input type="url" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_url" name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-url-' . $post_id . '" value="' . $meta . '" size="30" />'; |
| 419 |
if ( isset( $field['desc'] ) ) { |
| 420 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 421 |
} |
| 422 |
break; |
| 423 |
|
| 424 |
case 'file': |
| 425 |
echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_file cbxgooglemapmeta_filepicker" name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-file-' . $post_id . '" value="' . $meta . '" size="30" /> |
| 426 |
<input type="button" class="button cbxgooglemapmeta_filepicker_btn" value="' . __( 'Choose File', 'cbxgooglemap' ) . '" />'; |
| 427 |
if ( isset( $field['desc'] ) ) { |
| 428 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 429 |
} |
| 430 |
break; |
| 431 |
|
| 432 |
/*case 'date': |
| 433 |
echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_date cbxgooglemapmeta_datepicker" name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-date-' . $post_id . '" value="' . $meta . '" size="30" />'; |
| 434 |
if ( isset( $field['desc'] ) ) { |
| 435 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 436 |
} |
| 437 |
break;*/ |
| 438 |
|
| 439 |
|
| 440 |
case 'color': |
| 441 |
|
| 442 |
echo '<input type="text" class="cbxgooglemapmeta_input cbxgooglemapmeta_input_color cbxgooglemapmeta_colorpicker" name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-color-' . $post_id . '" value="' . $meta . '" size="30" />'; |
| 443 |
if ( isset( $field['desc'] ) ) { |
| 444 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 445 |
} |
| 446 |
break; |
| 447 |
|
| 448 |
case 'select': |
| 449 |
echo '<select name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-select-' . $post_id . '" class="selecttwo-select">'; |
| 450 |
|
| 451 |
if ( isset( $field['optgroup'] ) && intval( $field['optgroup'] ) ) { |
| 452 |
|
| 453 |
foreach ( $field['options'] as $optlabel => $data ) { |
| 454 |
echo '<optgroup label="' . $optlabel . '">'; |
| 455 |
foreach ( $data as $index => $option ) { |
| 456 |
echo '<option ' . ( ( $meta == $index ) ? ' selected="selected"' : '' ) . ' value="' . $index . '">' . $option . '</option>'; |
| 457 |
} |
| 458 |
|
| 459 |
} |
| 460 |
} else { |
| 461 |
foreach ( $field['options'] as $index => $option ) { |
| 462 |
echo '<option ' . ( ( $meta == $index ) ? ' selected="selected"' : '' ) . ' value="' . $index . '">' . $option . '</option>'; |
| 463 |
} |
| 464 |
} |
| 465 |
echo '</select><br/>'; |
| 466 |
if ( isset( $field['desc'] ) ) { |
| 467 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 468 |
} |
| 469 |
break; |
| 470 |
case 'multiselect': |
| 471 |
|
| 472 |
echo '<select name="' . $meta_prefix . $id . '[]" id="' . $meta_prefix . $id . '-multiselect-' . $post_id . '" class="selecttwo-select" multiple>'; |
| 473 |
if ( isset( $field['optgroup'] ) && intval( $field['optgroup'] ) ) { |
| 474 |
|
| 475 |
foreach ( $field['options'] as $optlabel => $data ) { |
| 476 |
echo '<optgroup label="' . $optlabel . '">'; |
| 477 |
foreach ( $data as $key => $val ) { |
| 478 |
echo '<option value="' . $key . '"', is_array( $meta ) && in_array( $key, $meta ) ? ' selected="selected"' : '', ' >' . $val . '</option>'; |
| 479 |
} |
| 480 |
echo '<optgroup>'; |
| 481 |
} |
| 482 |
|
| 483 |
} else { |
| 484 |
foreach ( $field['options'] as $key => $val ) { |
| 485 |
echo '<option value="' . $key . '"', is_array( $meta ) && in_array( $key, $meta ) ? ' selected="selected"' : '', ' >' . $val . '</option>'; |
| 486 |
} |
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
echo '</select>'; |
| 491 |
if ( isset( $field['desc'] ) ) { |
| 492 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 493 |
} |
| 494 |
break; |
| 495 |
|
| 496 |
|
| 497 |
case 'radio': |
| 498 |
|
| 499 |
echo '<fieldset> |
| 500 |
<legend class="screen-reader-text"><span>input type="radio"</span></legend>'; |
| 501 |
foreach ( $field['options'] as $key => $value ) { |
| 502 |
echo '<label title="g:i a" for="' . $meta_prefix . $id . '-radio-' . $post_id . '-' . $key . '"> |
| 503 |
<input id="' . $meta_prefix . $id . '-radio-' . $post_id . '-' . $key . '" type="radio" name="' . $meta_prefix . $id . '" value="' . $key . '" ' . ( ( $meta == $key ) ? ' checked="checked" ' : '' ) . ' /> |
| 504 |
<span>' . $value . '</span> |
| 505 |
</label><br>'; |
| 506 |
|
| 507 |
|
| 508 |
} |
| 509 |
echo '</fieldset><br/>'; |
| 510 |
if ( isset( $field['desc'] ) ) { |
| 511 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 512 |
} |
| 513 |
break; |
| 514 |
|
| 515 |
case 'checkbox': |
| 516 |
echo '<input type="checkbox" name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-checkbox-' . $post_id . '" class="cb-checkbox checkbox-' . $post_id . '" ' . ( $meta ? ' checked="checked"' : '' ) . '/>'; |
| 517 |
if ( isset( $field['desc'] ) ) { |
| 518 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 519 |
} |
| 520 |
break; |
| 521 |
// checkbox_group |
| 522 |
case 'multicheck': |
| 523 |
if ( $meta == '' ) { |
| 524 |
$meta = array(); |
| 525 |
foreach ( $field['options'] as $option ) { |
| 526 |
array_push( $meta, $option['value'] ); |
| 527 |
} |
| 528 |
} |
| 529 |
|
| 530 |
foreach ( $field['options'] as $option ) { |
| 531 |
echo '<input type="checkbox" value="' . $option['value'] . '" name="' . $meta_prefix . $id . '[]" id="' . $option['value'] . '-mult-chk-' . $post_id . '-field-' . $meta_prefix . $id . '" class="cb-multi-check mult-check-' . $post_id . '"', $meta && in_array( $option['value'], $meta ) ? ' checked="checked"' : '', ' /> |
| 532 |
<label for="' . $option['value'] . '">' . $option['label'] . '</label><br/>'; |
| 533 |
} |
| 534 |
|
| 535 |
if ( isset( $field['desc'] ) ) { |
| 536 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 537 |
} |
| 538 |
break; |
| 539 |
|
| 540 |
case 'post_type': |
| 541 |
|
| 542 |
//$multiple_attr = ($multiple_select) ? ' multiple ': ''; |
| 543 |
|
| 544 |
$post_type_ = ( isset( $field['post_type'] ) ) ? $field['post_type'] : array( 'post' ); |
| 545 |
$post_order_ = ( isset( $field['post_order'] ) ) ? $field['post_order'] : 'DESC'; |
| 546 |
$post_orderby_ = ( isset( $field['post_orderby'] ) ) ? $field['post_orderby'] : 'ID'; |
| 547 |
|
| 548 |
if ( ! is_array( $post_type_ ) ) { |
| 549 |
$post_type_ = (array) $post_type_; |
| 550 |
} |
| 551 |
|
| 552 |
// WP_Query arguments |
| 553 |
|
| 554 |
$args = array( |
| 555 |
'post_type' => $post_type_, |
| 556 |
'post_status' => array( 'publish' ), |
| 557 |
'order' => $post_order_, |
| 558 |
'orderby ' => $post_orderby_, |
| 559 |
'posts_per_page' => '-1', |
| 560 |
); |
| 561 |
|
| 562 |
|
| 563 |
// The Query |
| 564 |
$query_post_types = get_posts( $args ); |
| 565 |
|
| 566 |
// The Loop |
| 567 |
|
| 568 |
$posts_found = array(); |
| 569 |
foreach ( $query_post_types as $post ) : self::setup_admin_postdata( $post ); |
| 570 |
|
| 571 |
//$query_post_types->the_post(); |
| 572 |
$post_id_ = get_the_ID(); |
| 573 |
$post_title_ = get_the_title( $post_id_ ); |
| 574 |
$posts_found[ $post_id_ ] = $post_title_; |
| 575 |
|
| 576 |
endforeach; |
| 577 |
self::wp_reset_admin_postdata(); |
| 578 |
|
| 579 |
|
| 580 |
if ( $multiple_select ) { |
| 581 |
echo '<select name="' . $meta_prefix . $id . '[]" id="' . $meta_prefix . $id . '-post_type-' . $post_id . '" class="selecttwo-select" multiple >'; |
| 582 |
foreach ( $posts_found as $key => $val ) { |
| 583 |
echo '<option value="' . $key . '"', is_array( $meta ) && in_array( $key, $meta ) ? ' selected="selected"' : '', ' >' . $val . '</option>'; |
| 584 |
} |
| 585 |
echo '</select>'; |
| 586 |
} else { |
| 587 |
echo '<select name="' . $meta_prefix . $id . '" id="' . $meta_prefix . $id . '-post_type-' . $post_id . '" class="selecttwo-select" >'; |
| 588 |
foreach ( $posts_found as $index => $option ) { |
| 589 |
echo '<option ' . ( ( $meta == $index ) ? ' selected="selected"' : '' ) . ' value="' . $index . '">' . $option . '</option>'; |
| 590 |
} |
| 591 |
echo '</select>'; |
| 592 |
} |
| 593 |
|
| 594 |
if ( isset( $field['desc'] ) ) { |
| 595 |
echo '<span class="description">' . $field['desc'] . '</span>'; |
| 596 |
} |
| 597 |
break; |
| 598 |
|
| 599 |
} |
| 600 |
echo '</td>'; |
| 601 |
echo '</tr>'; |
| 602 |
} |
| 603 |
echo '</table>'; |
| 604 |
|
| 605 |
echo '</div>'; |
| 606 |
} |
| 607 |
|
| 608 |
echo '</div>'; |
| 609 |
echo '</div>'; |
| 610 |
|
| 611 |
} else { |
| 612 |
|
| 613 |
echo esc_html__( 'Please save first to add extra information.', 'cbxgooglemap' ); |
| 614 |
} |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
/** |
| 619 |
* Setup a post object and store the original loop item so we can reset it later |
| 620 |
* |
| 621 |
* @param obj $post_to_setup The post that we want to use from our custom loop |
| 622 |
*/ |
| 623 |
public static function setup_admin_postdata( $post_to_setup ) { |
| 624 |
|
| 625 |
//only on the admin side |
| 626 |
if ( is_admin() ) { |
| 627 |
|
| 628 |
//get the post for both setup_postdata() and to be cached |
| 629 |
global $post; |
| 630 |
|
| 631 |
//only cache $post the first time through the loop |
| 632 |
if ( ! isset( $GLOBALS['post_cache'] ) ) { |
| 633 |
$GLOBALS['post_cache'] = $post; |
| 634 |
} |
| 635 |
|
| 636 |
//setup the post data as usual |
| 637 |
$post = $post_to_setup; |
| 638 |
setup_postdata( $post ); |
| 639 |
} |
| 640 |
}//end setup_admin_postdata |
| 641 |
|
| 642 |
|
| 643 |
/** |
| 644 |
* Reset $post back to the original item |
| 645 |
* |
| 646 |
*/ |
| 647 |
public static function wp_reset_admin_postdata() { |
| 648 |
|
| 649 |
//only on the admin and if post_cache is set |
| 650 |
if ( is_admin() && ! empty( $GLOBALS['post_cache'] ) ) { |
| 651 |
|
| 652 |
//globalize post as usual |
| 653 |
global $post; |
| 654 |
|
| 655 |
//set $post back to the cached version and set it up |
| 656 |
$post = $GLOBALS['post_cache']; |
| 657 |
setup_postdata( $post ); |
| 658 |
|
| 659 |
//cleanup |
| 660 |
unset( $GLOBALS['post_cache'] ); |
| 661 |
} |
| 662 |
}//end wp_reset_admin_postdata |
| 663 |
|
| 664 |
|
| 665 |
public static function supported_post_types() { |
| 666 |
$allowed_post_types = array( 'cbxgooglemap' ); |
| 667 |
$allowed_post_types = apply_filters( 'cbxgooglemap_post_types_support', $allowed_post_types ); |
| 668 |
|
| 669 |
return $allowed_post_types; |
| 670 |
}//end supported_post_types |
| 671 |
|
| 672 |
|
| 673 |
/** |
| 674 |
* Returns all post types that has public view and visually accessible |
| 675 |
* |
| 676 |
* @return array |
| 677 |
*/ |
| 678 |
public static function post_types() { |
| 679 |
$post_type_args = array( |
| 680 |
'builtin' => array( |
| 681 |
'options' => array( |
| 682 |
'public' => true, |
| 683 |
'_builtin' => true, |
| 684 |
'show_ui' => true, |
| 685 |
), |
| 686 |
'label' => esc_html__( 'Built in post types', 'cbxgooglemap' ), |
| 687 |
) |
| 688 |
|
| 689 |
); |
| 690 |
|
| 691 |
$post_type_args = apply_filters( 'cbxgooglemap_post_types', $post_type_args ); |
| 692 |
|
| 693 |
$output = 'objects'; // names or objects, note names is the default |
| 694 |
$operator = 'and'; // 'and' or 'or' |
| 695 |
$postTypes = array(); |
| 696 |
|
| 697 |
foreach ( $post_type_args as $postArgType => $postArgTypeArr ) { |
| 698 |
$types = get_post_types( $postArgTypeArr['options'], $output, $operator ); |
| 699 |
|
| 700 |
if ( ! empty( $types ) ) { |
| 701 |
foreach ( $types as $type ) { |
| 702 |
$postTypes[ $postArgType ]['label'] = $postArgTypeArr['label']; |
| 703 |
$postTypes[ $postArgType ]['data'][ $type->name ] = $type->labels->name; |
| 704 |
} |
| 705 |
} |
| 706 |
} |
| 707 |
|
| 708 |
return $postTypes; |
| 709 |
|
| 710 |
}//end post_types |
| 711 |
|
| 712 |
/** |
| 713 |
* Shortcode builder for display and copy paste purpose |
| 714 |
* |
| 715 |
* @param array $general_settings |
| 716 |
* @param array $light_settings |
| 717 |
* @param array $circular_settings |
| 718 |
* @param array $kk_settings |
| 719 |
* @param string $type |
| 720 |
* |
| 721 |
* @since 1.1.2 |
| 722 |
* |
| 723 |
* @return string |
| 724 |
*/ |
| 725 |
public static function shortcode_builder( $general_settings = array() ) { |
| 726 |
|
| 727 |
$settings = new CBXGooglemapSettings(); |
| 728 |
$zoom_default = $settings->get_field( 'zoom', $general_settings, '8' ); |
| 729 |
if ( $zoom_default == 0 ) { |
| 730 |
$zoom_default = 8; |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
$width_default = $settings->get_field( 'width', $general_settings, '100%' ); |
| 735 |
if ( $width_default == '' || $width_default == 0 ) { |
| 736 |
$width_default = '100%'; |
| 737 |
} |
| 738 |
|
| 739 |
$height_default = intval( $settings->get_field( 'height', $general_settings, '300' ) ); |
| 740 |
if ( $height_default == 0 ) { |
| 741 |
$height_default = 300; |
| 742 |
} |
| 743 |
|
| 744 |
|
| 745 |
$scrollwheel_default = intval( $settings->get_field( 'scrollwheel', $general_settings, 1 ) ); |
| 746 |
$showinfo_default = intval( $settings->get_field( 'showinfo', $general_settings, 1 ) ); |
| 747 |
$infow_open_default = intval( $settings->get_field( 'infow_open', $general_settings, 1 ) ); |
| 748 |
$maptype_default = $settings->get_field( 'maptype', $general_settings, 'roadmap' ); |
| 749 |
|
| 750 |
|
| 751 |
$attr = array( |
| 752 |
//default setting |
| 753 |
'width' => $width_default, |
| 754 |
'height' => $height_default, |
| 755 |
'zoom' => $zoom_default, |
| 756 |
'scrollwheel' => $scrollwheel_default, |
| 757 |
'showinfo' => $showinfo_default, |
| 758 |
'infow_open' => $infow_open_default, |
| 759 |
'maptype' => $maptype_default, |
| 760 |
'heading' => 'Codeboxr(Sample)', |
| 761 |
'address' => '6H, Dilara Tower, 77 Bir Uttam C.R. Dutta Road, Dhaka 1205(Sample)', |
| 762 |
'website' => 'https://codeboxr.com/', |
| 763 |
'mapicon' => '', |
| 764 |
'maptype' => $maptype_default, |
| 765 |
'lat' => '23.744825100000003', |
| 766 |
'lng' => '90.39219739999999' |
| 767 |
|
| 768 |
); |
| 769 |
|
| 770 |
|
| 771 |
$attr = apply_filters( 'cbxgooglemap_builder_attr', $attr ); |
| 772 |
|
| 773 |
$attr_html = ''; |
| 774 |
|
| 775 |
foreach ( $attr as $key => $value ) { |
| 776 |
$attr_html .= ' ' . $key . '="' . $value . '" '; |
| 777 |
} |
| 778 |
|
| 779 |
return '[cbxgooglemap ' . $attr_html . ']'; |
| 780 |
}//end |
| 781 |
|
| 782 |
/** |
| 783 |
* Map type block compatible options |
| 784 |
* |
| 785 |
* @return mixed|void |
| 786 |
*/ |
| 787 |
public static function maptype_block_options(){ |
| 788 |
$maptypes = array( |
| 789 |
'roadmap' => esc_html__( 'Road Map', 'cbxgooglemap' ), |
| 790 |
'satellite' => esc_html__( 'Satellite Map', 'cbxgooglemap' ), |
| 791 |
'hybrid' => esc_html__( 'Hybrid Map', 'cbxgooglemap' ), |
| 792 |
'terrain' => esc_html__( 'Terrain Map', 'cbxgooglemap' ), |
| 793 |
); |
| 794 |
|
| 795 |
$maptype_arr = array(); |
| 796 |
foreach ($maptypes as $key => $value){ |
| 797 |
$maptype_arr[] = array( |
| 798 |
'label' => $value, |
| 799 |
'value' => $key |
| 800 |
); |
| 801 |
} |
| 802 |
|
| 803 |
return apply_filters( 'cbxgooglemap_maptype_block_options', $maptype_arr); |
| 804 |
}//end maptype_block_options |
| 805 |
|
| 806 |
|
| 807 |
/** |
| 808 |
* @return mixed|void |
| 809 |
*/ |
| 810 |
public static function get_maptype() { |
| 811 |
$maptype = array( |
| 812 |
'roadmap' => esc_html__( 'Road Map', 'cbxgooglemap' ), |
| 813 |
'satellite' => esc_html__( 'Satellite Map', 'cbxgooglemap' ), |
| 814 |
'hybrid' => esc_html__( 'Hybrid Map', 'cbxgooglemap' ), |
| 815 |
'terrain' => esc_html__( 'Terrain Map', 'cbxgooglemap' ), |
| 816 |
); |
| 817 |
|
| 818 |
return apply_filters( 'cbxgooglemap_maptype', $maptype ); |
| 819 |
}// end get_maptype |
| 820 |
|
| 821 |
/** |
| 822 |
* Get available map type reverser |
| 823 |
* |
| 824 |
* @return mixed|void |
| 825 |
*/ |
| 826 |
public static function get_maptype_r() { |
| 827 |
$maptype = CBXGooglemapHelper::get_maptype(); |
| 828 |
$maptype_r = array(); |
| 829 |
|
| 830 |
foreach ( $maptype as $key => $value ) { |
| 831 |
$maptype_r[ $value ] = $key; |
| 832 |
} |
| 833 |
|
| 834 |
return apply_filters( 'cbxgooglemap_maptype_r', $maptype_r ); |
| 835 |
}//end get_maptype_r |
| 836 |
|
| 837 |
}//end class CBXGooglemapHelper |