PluginProbe
CBX Map for Google Map & OpenStreetMap / 1.1.10
CBX Map for Google Map & OpenStreetMap v1.1.10
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 / admin / class-cbxgooglemap-admin.php

class-cbxgooglemap-admin.php in CBX Map for Google Map & OpenStreetMap 1.1.10, at admin/class-cbxgooglemap-admin.php

1,059 lines 36.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The admin-specific functionality of the plugin.
5 *
6 * @link https://codeboxr.com
7 * @since 1.0.0
8 *
9 * @package Cbxgooglemap
10 * @subpackage Cbxgooglemap/admin
11 */
12
13 /**
14 * The admin-specific functionality of the plugin.
15 *
16 * Defines the plugin name, version, and two examples hooks for how to
17 * enqueue the admin-specific stylesheet and JavaScript.
18 *
19 * @package Cbxgooglemap
20 * @subpackage Cbxgooglemap/admin
21 * @author Codeboxr <info@codeboxr.com>
22 */
23 class CBXGoogleMap_Admin {
24
25 /**
26 * The ID of this plugin.
27 *
28 * @since 1.0.0
29 * @access private
30 * @var string $plugin_name The ID of this plugin.
31 */
32 private $plugin_name;
33
34 /**
35 * The version of this plugin.
36 *
37 * @since 1.0.0
38 * @access private
39 * @var string $version The current version of this plugin.
40 */
41 private $version;
42
43 /**
44 * Initialize the class and set its properties.
45 *
46 * @since 1.0.0
47 * @param string $plugin_name The name of this plugin.
48 * @param string $version The version of this plugin.
49 */
50 public function __construct( $plugin_name, $version ) {
51 $this->plugin_name = $plugin_name;
52 $this->version = $version;
53
54 $this->plugin_basename = plugin_basename(plugin_dir_path(__DIR__) . $plugin_name . '.php');
55 //get instance of setting api
56 $this->settings_api = new CBXGooglemapSettings();
57 }//end of construtor
58
59 /**
60 * Initialize setting
61 */
62 public function setting_init() {
63 //set the settings
64 $this->settings_api->set_sections($this->get_settings_sections());
65 $this->settings_api->set_fields($this->get_settings_fields());
66 //initialize settings
67 $this->settings_api->admin_init();
68 }//end setting_init
69
70 /**
71 * Global Setting Sections
72 *
73 *
74 * @return type
75 */
76 public function get_settings_sections(){
77 return apply_filters(
78 'cbxgooglemap_setting_sections', array(
79 array(
80 'id' => 'cbxgooglemap_general',
81 'title' => esc_html__( 'Default Config', 'cbxgooglemap' )
82 ),
83 array(
84 'id' => 'cbxgooglemap_demo',
85 'title' => esc_html__( 'Demo & Shortcodes', 'cbxgooglemap' )
86 )
87 )
88 );
89 }//end get_settings_sections
90
91 /**
92 * Returns all the settings fields
93 *
94 * @return array settings fields
95 */
96 public function get_settings_fields() {
97 $all_post_types = CBXGooglemapHelper::post_types();
98 $general_settings = get_option( 'cbxgooglemap_general', array() );
99
100 $settings_builtin_fields = array(
101 'cbxgooglemap_general' => array(
102 'mapsource' => array(
103 'name' => 'mapsource',
104 'label' => esc_html__('Map Source', 'cbxgooglemap'),
105 'type' => 'radio',
106 'default' => '1',
107 'options' => array(
108 '1' => esc_html__('Google Map', 'cbxgooglemap' ),
109 '0' => esc_html__('Openstreet Map(leafletjs)', 'cbxgooglemap' )
110 )
111 ),
112 'apikey' => array(
113 'name' => 'apikey',
114 'label' => esc_html__('Api Key', 'cbxgooglemap'),
115 'desc' => esc_html__('Google map api key', 'cbxgooglemap'),
116 'type' => 'text'
117
118 ),
119 'maptype' => array(
120 'name' => 'maptype',
121 'label' => esc_html__('Map Type', 'cbxgooglemap'),
122 'type' => 'select',
123 'default' => 'roadmap',
124 'options' => array(
125 'roadmap' => esc_html__('Road Map', 'cbxgooglemap' ),
126 'satellite' => esc_html__('Satellite Map', 'cbxgooglemap' ),
127 'hybrid' => esc_html__('Hybrid Map', 'cbxgooglemap' ),
128 'terrain' => esc_html__('Terrain Map', 'cbxgooglemap' ),
129 ),
130 'desc' => esc_html__('Google Map only', 'cbxgooglemap')
131 ),
132 'zoom' => array(
133 'name' => 'zoom',
134 'label' => esc_html__('Zoom Level', 'cbxgooglemap'),
135 'desc' => esc_html__('Default Zoom Level', 'cbxgooglemap'),
136 'type' => 'text',
137 'default' => 8
138
139 ),
140 /*'radius' => array(
141 'name' => 'radius',
142 'label' => esc_html__('Radius Display Distance', 'cbxgooglemap'),
143 'desc' => esc_html__('Put zero to hide radius ', 'cbxgooglemap'),
144 'type' => 'text',
145 'default' => 0
146 ),*/
147 'width' => array(
148 'name' => 'with',
149 'label' => esc_html__('Width', 'cbxgooglemap'),
150 'desc' => esc_html__('Default is 100% to make the map responsive, if you want any fixed width then don\'t put, % or just put numeric value, don\'t px with numeric value', 'cbxgooglemap'),
151 'type' => 'text',
152 'default' => '100%'
153
154 ),
155 'height' => array(
156 'name' => 'height',
157 'label' => esc_html__('Height', 'cbxgooglemap'),
158 'desc' => esc_html__('Default height 300 as px, put any numeric value.', 'cbxgooglemap'),
159 'type' => 'number',
160 'default' => '300'
161 ),
162 'scrollwheel' => array(
163 'name' => 'scrollwheel',
164 'label' => esc_html__('Mouse Scroll Wheel', 'cbxgooglemap'),
165 'desc' => esc_html__('Enable/disable mouse scroll whell', 'cbxgooglemap'),
166 'type' => 'radio',
167 'default' => '1',
168 'options' => array(
169 '1' => esc_html__('Enable', 'cbxgooglemap' ),
170 '0' => esc_html__('Disable', 'cbxgooglemap' ),
171 )
172 ),
173 'showinfo' => array(
174 'name' => 'showinfo',
175 'label' => esc_html__('Show Info window', 'cbxgooglemap'),
176 'desc' => esc_html__('Show information on click of marker', 'cbxgooglemap'),
177 'type' => 'radio',
178 'default' => '1',
179 'desc_tip' => true,
180 'options' => array(
181 '1' => esc_html__('Enable', 'cbxgooglemap' ),
182 '0' => esc_html__('Disable', 'cbxgooglemap' ),
183 )
184 ),
185 'infow_open' => array(
186 'name' => 'infow_open',
187 'label' => esc_html__('Info/Popup Window', 'cbxgooglemap'),
188 //'desc' => esc_html__('If disabled then popup or info window will show on click', 'cbxgooglemap'),
189 'type' => 'radio',
190 'default' => '1',
191 'desc_tip' => true,
192 'options' => array(
193 '1' => esc_html__('Open(Default)', 'cbxgooglemap' ),
194 '0' => esc_html__('On Click', 'cbxgooglemap' ),
195 )
196 ),
197 'mapicon' => array(
198 'name' => 'mapicon',
199 'label' => esc_html__( 'Map Icon', 'cbxgooglemap' ),
200 //'desc' => esc_html__( 'Map marker custom icon', 'cbxgooglemap' ),
201 'type' => 'file',
202 'default' => '',
203 'desc_tip' => true
204 ),
205
206 ),
207 'cbxgooglemap_demo' => array(
208 'shortcode_demo' => array(
209 'name' => 'shortcode_demo',
210 'label' => esc_html__( 'Shortcode & Demo', 'cbxgooglemap' ),
211 'desc' => esc_html__( 'Shortcode and demo based on default setting, please save once to check change.', 'cbxgooglemap' ),
212 'type' => 'shortcode',
213 'class' => 'cbcurrencyconverter_demo_copy',
214 'default' => CBXGooglemapHelper::shortcode_builder( $general_settings),
215 )
216
217 )
218 );
219
220
221
222 $settings_fields = array(); //final setting array that will be passed to different filters
223 $sections = $this->get_settings_sections();
224
225 foreach ($sections as $section) {
226 if (!isset($settings_builtin_fields[$section['id']])) {
227 $settings_builtin_fields[$section['id']] = array();
228 }
229 }
230
231
232 foreach ($sections as $section) {
233 $settings_fields[$section['id']] = apply_filters('cbxgooglemap_global_' . $section['id'] . '_fields', $settings_builtin_fields[$section['id']]);
234 }
235
236 $settings_fields = apply_filters('cbxgooglemap_global_fields', $settings_fields); //final filter if need
237 return $settings_fields;
238 }//end get_settings_fields
239
240 /**
241 * Register Custom Post Type cbxgooglemap
242 *
243 * @since 3.7.0
244 */
245 public function create_post_type(){
246 CBXGooglemapHelper::create_googlemap_post_type();
247
248 // Check the option we set on activation.
249 if (get_option('cbxgooglemap_flush_rewrite_rules') == 'true') {
250 flush_rewrite_rules();
251 delete_option('cbxgooglemap_flush_rewrite_rules');
252 }
253 }//end create_post_type
254
255
256 /**
257 * Show menu page
258 */
259 public function admin_overview_menu_page(){
260 //setting page
261 $this->settingpage_hook = add_submenu_page(
262 'edit.php?post_type=cbxgooglemap', esc_html__('CBX WP Map Settings', 'cbxgooglemap'), esc_html__('Setting', 'cbxgooglemap'), 'manage_options', 'cbxgooglemapsettings', array($this, 'display_plugin_admin_settings'));
263
264 $hook = add_submenu_page( 'edit.php?post_type=cbxgooglemap', esc_html__( 'Helps & Updates', 'cbxgooglemap' ), esc_html__( 'Helps & Updates', 'cbxgooglemap' ), 'manage_options', 'cbxgooglemap-help-support', array(
265 $this, 'cbxgooglemap_helps_updates_display'
266 ) );
267 }//end admin_overview_menu_page
268
269 /**
270 * Show cbxeventz Setting page
271 */
272 public function display_plugin_admin_settings() {
273 echo cbxgooglemap_get_template_html('admin/settings-display.php', array('ref' => $this));
274 }//end display_plugin_admin_settings
275
276 /**
277 * Render the help & support page for this plugin.
278 *
279 * @since 1.0.0
280 */
281 public function cbxgooglemap_helps_updates_display() {
282 echo cbxgooglemap_get_template_html('admin/dashboard.php');
283 }//end method cbxgooglemap_helps_updates_display
284
285 /**
286 * Add metabox for custom post type cbxfeedbackform && cbxfeedbackbtn
287 *
288 * @since 1.0.0
289 */
290 public function add_meta_boxes_form()
291 {
292 $screen = get_current_screen();
293
294 add_meta_box(
295 'cbxgooglemap_metabox', esc_html__('Map Parameter', 'cbxgooglemap'), array($this, 'parameter_metabox_display'), 'cbxgooglemap', 'normal', 'high'
296 );
297
298
299 add_meta_box(
300 'cbxgooglemap_shortcode', esc_html__('Shortcode', 'cbxgooglemap'), array($this, 'shortcode_metabox_display'), 'cbxgooglemap', 'side', 'low'
301 );
302
303 }//end add_meta_boxes_form
304
305 /**
306 * Show Shortcode display metabox
307 *
308 * @param $post
309 */
310 public function shortcode_metabox_display($post){
311 if (isset($post->ID) && $post->ID > 0) {
312 $post_id = $post->ID;
313 $post_type = $post->post_type;
314
315 echo cbxgooglemap_get_template_html('admin/metabox_shortcode.php', array('post_id' => $post_id, 'post_type' => $post_type));
316 }
317 }//end shortcode_metabox_display
318
319 /**
320 * Render change logs metabox
321 *
322 * @param $post
323 *
324 * since v1.0.0
325 */
326 public function parameter_metabox_display($post) {
327 global $post;
328 $post_type = $post->post_type;
329
330
331 $meta_fields = CBXGooglemapHelper::cbxgooglemap_meta_fields();
332
333 $combined_field = '_' . $post_type . '_combined'; //field name for non sortable fields
334 $meta_prefix = '_' . $post_type; //field prefix for sortable fields
335
336
337 CBXGooglemapHelper::render_meta_fields( $post, $meta_fields, $combined_field, $meta_prefix, true ); //
338 }//end parameter_metabox_display
339
340 /**
341 * Save meta box for cbxeventz
342 *
343 * @param $post_id
344 */
345 public function metabox_save($post_id, $post, $update){
346
347 $post_type = $post->post_type;
348
349 // Check if our nonce is set.
350 if (!isset($_POST['cbxmetahelper_'.$post_type.'_meta_box_nonce'])) {
351 return;
352 }
353
354 // Verify that the nonce is valid.
355 if (!wp_verify_nonce($_POST['cbxmetahelper_'.$post_type.'_meta_box_nonce'], 'cbxmetahelper_'.$post_type.'_meta_box')) {
356 return;
357 }
358
359 // If this is an autosave, our form has not been submitted, so we don't want to do anything.
360 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
361
362 // Check the user's permissions.
363 if (isset($_POST['post_type']) && $post_type == $_POST['post_type']) {
364
365 if (!current_user_can('edit_post', $post_id)) {
366 return;
367 }
368 }
369
370 if(method_exists('CBXGooglemapHelper', $post_type.'_meta_fields')){
371 $meta_fields = call_user_func('CBXGooglemapHelper::'.$post_type.'_meta_fields', array($post_id, $post_type));
372 }
373 else return;
374
375
376 $combined_field = '_'.$post_type.'_combined'; //field name for non sortable fields
377 $meta_prefix = '_'.$post_type; //field prefix for sortable fields
378
379 $meta_combined = get_post_meta($post_id, $combined_field, true); //meta fields not sortable
380
381 $meta_combined = !is_array($meta_combined)? array(): $meta_combined;
382
383
384
385
386
387 $combined_arr = array();
388 foreach($meta_fields as $section_id => $fields){
389 foreach($fields as $id => $field){
390 if(isset($_POST[$meta_prefix.$id])){
391
392 if(isset($_POST[$meta_prefix.$id])){
393 $updated_value = $_POST[$meta_prefix.$id];
394
395 $is_sortable = isset($field['sortable'])? $field['sortable']: false;
396
397 if($is_sortable){
398 $ret = update_post_meta($post_id, $meta_prefix.$id, $updated_value); //update the combined meta
399 }
400 else{
401 //save as combined meta
402 $meta_combined[$meta_prefix.$id] = $updated_value;
403 }
404 }
405
406 }
407
408 }
409 }
410
411 update_post_meta($post_id, $combined_field, $meta_combined); //update the combined meta
412
413 }//end metabox_save
414
415 /**
416 * Add or adjust col for cbxgooglemap post type
417 *
418 * @param $cbxpoll_columns
419 *
420 * @return array
421 *
422 */
423 public function cbxgooglemap_add_new_columns($columns)
424 {
425 unset($columns['date']);
426 unset($columns['comments']);
427
428 $columns['lat'] = esc_html__('Latitude', 'cbxgooglemap');
429 $columns['lng'] = esc_html__('Longitude', 'cbxgooglemap');
430 $columns['zoom'] = esc_html__('Zoom', 'cbxgooglemap');
431 $columns['shortcode'] = esc_html__('Shortcode', 'cbxgooglemap');
432 //$columns['taxonomy-cbxgooglemapcat'] = esc_html__('Categories', 'cbxgooglemap');
433
434 return $columns;
435 }//end cbxgooglemap_add_new_columns
436
437 /**
438 * Add extra cols information for cbxgooglemap post type
439 *
440 * @param $column_name
441 *
442 *
443 * show data to poll table custom column
444 */
445 public function cbxgooglemap_manage_columns($column_name){
446 global $wpdb, $post;
447 $post_id = $post->ID;
448 $post_type = $post->post_type;
449
450 $combined_field = '_cbxgooglemap_combined'; //field name for non sortable fields
451 $meta_prefix = '_cbxgooglemap'; //field prefix for sortable fields
452
453 $meta_combined = get_post_meta($post_id, $combined_field, true);
454
455 $lat = get_post_meta($post_id, $meta_prefix.'lat', true);
456 $lat = ($lat !== false) ? $lat: '';
457
458 $lng = get_post_meta($post_id, $meta_prefix.'lng', true);
459 $lng = ($lng !== false) ? $lng: '';
460
461 $zoom = (isset($meta_combined[$meta_prefix.'zoom']) && intval($meta_combined[$meta_prefix.'zoom']) > 0 ) ? intval($meta_combined[$meta_prefix.'zoom']): '';
462
463
464 switch ($column_name) {
465 case 'shortcode':
466 echo '<span id="cbxgooglemapshortcode-' . $post_id . '" class="cbxgooglemapshortcode cbxgooglemapshortcode-' . $post_id . '">[cbxgooglemap id="' . $post_id . '"]</span>';
467 echo '<span class="cbxgooglemapshortcodetrigger" data-clipboard-text=\'[cbxgooglemap id="'.$post_id.'"]\' title="' . esc_html__("Copy to clipboard", 'cbxgooglemap') . '">
468 </span>';
469 break;
470 case 'lat':
471 echo $lat;
472 break;
473 case 'lng':
474 echo $lng;
475 break;
476 case 'zoom':
477 echo $zoom;
478 break;
479 default:
480 break;
481 } // end switch
482 }//end cbxgooglemap_manage_columns
483
484 /**
485 * Register the stylesheets for the admin area.
486 *
487 * @since 1.0.0
488 */
489 public function enqueue_styles($hook) {
490
491 $current_page = isset( $_GET['page'] ) ? esc_attr( wp_unslash($_GET['page']) ) : '';
492 global $post_type, $post;
493
494 $googlemap_api_key = $this->settings_api->get_option('apikey', 'cbxgooglemap_general', '');
495 $mapsource = intval( $this->settings_api->get_option( 'mapsource', 'cbxgooglemap_general', 1 ) );
496
497
498 wp_register_style( 'select2',
499 plugin_dir_url( __FILE__ ) . '../assets/select2/css/select2.min.css',
500 array(),
501 $this->version );
502
503 wp_register_style('jquery-ui.min', plugin_dir_url( __FILE__ ).'../assets/css/ui-lightness/jquery-ui.min.css', array(), $this->version);
504
505
506 if($mapsource == 0){
507 wp_register_style( 'leaflet', '//unpkg.com/leaflet@1.3.4/dist/leaflet.css', array(), $this->version, 'all' );
508 wp_register_style( 'leaflet-control-geocoder', '//unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.css', array(), $this->version, 'all' );
509 }
510
511 wp_register_style( 'cbxgooglemap-admin', plugin_dir_url( __FILE__ ) . '../assets/css/cbxgooglemap-admin.css', array(), $this->version );
512 wp_register_style( 'cbxgooglemap-setting', plugin_dir_url( __FILE__ ) . '../assets/css/cbxgooglemap-setting.css', array(), $this->version );
513
514
515 //listing mode
516 if(($hook == 'edit.php') && $post_type == 'cbxgooglemap'){
517 wp_enqueue_style('cbxgooglemap-admin');
518 }
519
520 //add new, edit mode
521 if(($hook == 'post.php' || $hook == 'post-new.php') && $post_type == 'cbxgooglemap'){
522 wp_enqueue_style( 'wp-color-picker' );
523 wp_enqueue_style('select2');
524 wp_enqueue_style('jquery-ui.min');
525
526 if($mapsource == 0){
527 wp_enqueue_style( 'leaflet');
528 wp_enqueue_style( 'leaflet-control-geocoder');
529 }
530 wp_enqueue_style('cbxgooglemap-admin');
531 }
532
533 if($current_page == 'cbxgooglemapsettings'){
534 wp_enqueue_style( 'wp-color-picker' );
535
536 wp_enqueue_style('select2');
537 wp_enqueue_style('jquery-ui.min');
538 wp_enqueue_style('cbxgooglemap-setting');
539
540
541 //for demo css
542 if ( $mapsource == 0 ) {
543 //wp_register_style( 'leaflet', '//unpkg.com/leaflet@1.3.4/dist/leaflet.css', array(), $this->version, 'all' );
544
545 wp_register_style( 'cbxgooglemap-public', plugin_dir_url( __FILE__ ) . '../assets/css/cbxgooglemap-public.css', array( 'leaflet' ), $this->version, 'all' );
546 wp_enqueue_style( 'leaflet' );
547
548 } else {
549 wp_register_style( 'cbxgooglemap-public', plugin_dir_url( __FILE__ ) . '../assets/css/cbxgooglemap-public.css', array(), $this->version, 'all' );
550 }
551 wp_enqueue_style( 'cbxgooglemap-public' );
552 //end for demo css
553
554
555 }//end setting
556
557 if ( ( $hook == 'post.php' || $hook == 'post-new.php' || $hook == 'edit.php' ) && $post_type == 'cbxgooglemap' || $current_page =='cbxgooglemapsettings' || $current_page == 'cbxgooglemap-help-support' ) {
558 wp_register_style( 'cbxgooglemap-branding', plugin_dir_url( __FILE__ ) . '../assets/css/cbxgooglemap-branding.css',
559 array( ),
560 $this->version );
561 wp_enqueue_style( 'cbxgooglemap-branding' );
562 }
563 }//end enqueue_styles
564
565 /**
566 * Register the JavaScript for the admin area.
567 *
568 * @since 1.0.0
569 */
570 public function enqueue_scripts($hook) {
571
572 $current_page = isset( $_GET['page'] ) ? esc_attr( wp_unslash($_GET['page']) ) : '';
573 global $post_type, $post;
574
575 $googlemap_api_key = $this->settings_api->get_option('apikey', 'cbxgooglemap_general', '');
576 $mapsource = intval( $this->settings_api->get_option( 'mapsource', 'cbxgooglemap_general', 1 ) );
577
578 $zoom_level_default = $this->settings_api->get_option('zoom', 'cbxgooglemap_general', '8');
579 if($zoom_level_default == 0) $zoom_level_default = 8;
580
581
582 $meta_js_dep = array('jquery', 'select2');
583
584
585 if($mapsource == 1 && $googlemap_api_key != ''){
586 wp_register_script('coregooglemapapi', '//maps.googleapis.com/maps/api/js?key=' . $googlemap_api_key.'&libraries=places', array(), $this->version);
587 wp_register_script('locationpicker-jquery', plugin_dir_url( __FILE__ ).'../assets/js/locationpicker.jquery.js', array('coregooglemapapi', 'jquery'), $this->version);
588
589 $meta_js_dep[] = 'coregooglemapapi';
590 $meta_js_dep[] = 'locationpicker-jquery';
591 }
592 else if($mapsource == 0){
593 wp_register_script('coregooglemapapi', '//unpkg.com/leaflet@1.3.4/dist/leaflet.js', array(), $this->version);
594 wp_register_script('leaflet-control-geocoder', '//unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.js', array('coregooglemapapi'), $this->version);
595
596 $meta_js_dep[] = 'coregooglemapapi';
597 $meta_js_dep[] = 'leaflet-control-geocoder';
598 }
599
600 wp_register_script( 'select2', plugin_dir_url( __FILE__ ) . '../assets/select2/js/select2.min.js', array('jquery'),$this->version, true );
601
602
603 //listing mode
604 if(($hook == 'edit.php') && $post_type == 'cbxgooglemap'){
605 wp_register_script( 'cbxgooglemap-admin', plugin_dir_url( __FILE__ ) . '../assets/js/cbxgooglemap-admin.js', array( 'jquery'), $this->version, true );
606
607 wp_enqueue_script( 'jquery' );
608 wp_enqueue_script('cbxgooglemap-admin');
609
610 }
611
612 //add new or edit mode
613 if(($hook == 'post.php' || $hook == 'post-new.php') && $post_type == 'cbxgooglemap'){
614
615 wp_enqueue_media();
616 wp_enqueue_script('jquery' );
617 wp_enqueue_script('wp-color-picker' );
618
619 wp_enqueue_script('select2');
620 wp_enqueue_style('jquery-ui-core');
621
622
623 wp_register_script( 'cbxgooglemap-meta', plugin_dir_url( __FILE__ ) . '../assets/js/cbxgooglemap-meta.js', $meta_js_dep, $this->version, true );
624 $cbxgooglemap_meta_js_vars = apply_filters( 'cbxgooglemap_meta_js_vars',
625 array(
626 'please_select' => esc_html__( 'Please Select', 'cbxgooglemap' ),
627 'upload_title' => esc_html__( 'Window Title', 'cbxgooglemap' ),
628 'copy_success' => esc_html__( 'Shortcode copied to clipboard', 'cbxgooglemap' ),
629 'copy_fail' => esc_html__( 'Oops, unable to copy', 'cbxgooglemap' ),
630 'search_address' => esc_html__( 'Search Address', 'cbxgooglemap' )
631 ) );
632
633 wp_localize_script( 'cbxgooglemap-meta', 'cbxgooglemap_meta', $cbxgooglemap_meta_js_vars );
634
635
636 wp_enqueue_script('coregooglemapapi');
637 if($mapsource == 0){
638 wp_enqueue_script('leaflet-control-geocoder');
639 }
640
641 if($mapsource == 1 && $googlemap_api_key != ''){
642 wp_enqueue_script('locationpicker-jquery');
643 }
644
645 wp_enqueue_script('cbxgooglemap-meta');
646 }
647
648 if($current_page == 'cbxgooglemapsettings'){
649 wp_register_script( 'cbxgooglemap-setting', plugin_dir_url( __FILE__ ) . '../assets/js/cbxgooglemap-setting.js', array('jquery', 'wp-color-picker', 'select2'), $this->version, true );
650
651 $cbxgooglemap_setting_js_vars = apply_filters( 'cbxgooglemap_setting_js_vars',
652 array(
653 'please_select' => esc_html__( 'Please Select', 'cbxgooglemap' ),
654 'upload_title' => esc_html__( 'Window Title', 'cbxgooglemap' )
655 ) );
656 wp_localize_script( 'cbxgooglemap-setting', 'cbxgooglemap_setting', $cbxgooglemap_setting_js_vars );
657
658 wp_enqueue_media();
659 wp_enqueue_script( 'jquery' );
660 wp_enqueue_script( 'wp-color-picker' );
661
662 wp_enqueue_script( 'select2');
663 wp_enqueue_script( 'cbxgooglemap-setting');
664
665 //for demo js
666 if ( ( $mapsource == 1 && ! empty( $googlemap_api_key ) ) || $mapsource == 0 ) {
667 //wp_enqueue_script( 'jquery' );
668
669 if ( $mapsource == 1 ) {
670 wp_register_script( 'jqcbxgooglemap', plugin_dir_url( __FILE__ ) . '../assets/js/jqcbxgooglemap.js', array(
671 'jquery',
672 'coregooglemapapi'
673 ), $this->version, true );
674 wp_register_script( 'cbxgooglemap-public', plugin_dir_url( __FILE__ ) . '../assets/js/cbxgooglemap-public.js', array(
675 'jquery',
676 'coregooglemapapi',
677 'jqcbxgooglemap'
678 ), $this->version, true );
679
680 wp_enqueue_script( 'coregooglemapapi' );
681 wp_enqueue_script( 'jqcbxgooglemap' );
682 } else {
683 wp_register_script( 'cbxgooglemap-public', plugin_dir_url( __FILE__ ) . '../assets/js/cbxgooglemap-public.js', array('jquery','coregooglemapapi', 'leaflet-control-geocoder'), $this->version, true );
684 wp_enqueue_script( 'coregooglemapapi' );
685 wp_enqueue_script( 'leaflet-control-geocoder' );
686 }
687
688 wp_enqueue_script( 'cbxgooglemap-public' );
689 }//end for demo js
690
691 }//end js for setting page
692
693 //header scroll
694 wp_register_script( 'cbxgooglemap-scroll', plugins_url( '../assets/js/cbxgooglemap-scroll.js', __FILE__ ), array( 'jquery' ), $this->version );
695 if ( $current_page == 'cbxgooglemapsettings' || $current_page == 'cbxgooglemap-help-support' ) {
696 wp_enqueue_script( 'jquery' );
697 wp_enqueue_script( 'cbxgooglemap-scroll' );
698 }
699 }//end enqueue_scripts
700
701 /**
702 * Add settings action link to the plugins page.
703 *
704 * @since 1.0.0
705 */
706 public function plugin_listing_setting_link( $links ) {
707 return array_merge( array(
708 'settings' => '<a style="color:#39A96B; font-weight: bold;" target="_blank" href="' . admin_url( 'edit.php?post_type=cbxgooglemap&page=cbxgooglemapsettings' ) . '">' . esc_html__( 'Settings', 'cbxgooglemap' ) . '</a>'
709 ), $links );
710
711 }//end plugin_listing_setting_link
712
713 /**
714 * Add Pro product link in plugin listing
715 *
716 * @param $links
717 * @param $file
718 *
719 * @return array
720 */
721 public function custom_plugin_row_meta( $links, $file ) {
722 if ( strpos( $file, 'cbxgooglemap.php' ) !== false ) {
723 $new_links = array(
724 'free_support' => '<a style="color:#39A96B; font-weight: bold;" href="https://wordpress.org/support/plugin/cbxgooglemap/" target="_blank">' . esc_html__( 'Free Support', 'cbxgooglemap' ) . '</a>',
725 'reviews' => '<a style="color:#39A96B; font-weight: bold;" href="https://wordpress.org/plugins/cbxgooglemap/#reviews" target="_blank">' . esc_html__( 'Reviews', 'cbxgooglemap' ) . '</a>',
726 'pro' => '<a style="color:#39A96B; font-weight: bold;" href="https://codeboxr.com/product/cbx-google-map-for-wordpress/" target="_blank">' . esc_html__( 'Try Pro', 'cbxgooglemap' ) . '</a>',
727 'pro_support' => '<a style="color:#39A96B; font-weight: bold;" href="https://codeboxr.com/contact-us/" target="_blank">' . esc_html__( 'Pro Support', 'cbxgooglemap' ) . '</a>',
728
729 );
730
731 $links = array_merge( $links, $new_links );
732 }
733
734 return $links;
735 }//end custom_plugin_row_meta
736
737
738
739 /**
740 * Init all gutenberg blocks
741 */
742 public function gutenberg_blocks() {
743 if(!function_exists('register_block_type')){
744 return ;
745 }
746
747 $settings = new CBXGooglemapSettings();
748 $general_settings = get_option( 'cbxgooglemap_general', array() );
749
750 //default field values
751 $zoom_default = $settings->get_field( 'zoom', $general_settings, '8' );
752 if ( $zoom_default == 0 ) {
753 $zoom_default = 8;
754 }
755
756
757 $width_default = $settings->get_field( 'width', $general_settings, '100%' );
758 if ( $width_default == '' || $width_default == 0 ) {
759 $width_default = '100%';
760 }
761
762 $height_default = intval( $settings->get_field( 'height', $general_settings, '300' ) );
763 if ( $height_default == 0 ) {
764 $height_default = 300;
765 }
766
767
768 $scrollwheel_default = intval( $settings->get_field( 'scrollwheel', $general_settings, 1 ) );
769 $showinfo_default = intval( $settings->get_field( 'showinfo', $general_settings, 1 ) );
770 $infow_open_default = intval( $settings->get_field( 'infow_open', $general_settings, 1 ) );
771 $maptype_default = $settings->get_field( 'maptype', $general_settings, 'roadmap' );
772
773 $query = get_posts( array(
774 'post_type' => 'cbxgooglemap',
775 'orderby' => 'date',
776 'posts_per_page' => - 1,
777 'post_status' => 'publish'
778 ) );
779
780 $googleMap_posts = array();
781
782 $googleMap_posts[] = array(
783 'label' => esc_html__('Select Map', 'cbxgooglemap'),
784 'value' => '0'
785 );
786
787 foreach ( $query as $key => $data ) {
788 $googleMap_posts[] = array(
789 'label' => esc_html($data->post_title),
790 'value' => intval($data->ID)
791 );
792 }
793
794
795
796 wp_register_script( 'cbxgooglemap-block', plugin_dir_url( __FILE__ ) . '../assets/js/cbxgooglemap-block.js', array(
797 'wp-blocks',
798 'wp-element',
799 'wp-components',
800 'wp-editor',
801 //'jquery',
802 //'codeboxrflexiblecountdown-public'
803 ), filemtime(plugin_dir_path( __FILE__ ) . '../assets/js/cbxgooglemap-block.js') );
804
805 wp_register_style( 'cbxgooglemap-block', plugin_dir_url( __FILE__ ) . '../assets/css/cbxgooglemap-block.css', array(), filemtime(plugin_dir_path( __FILE__ ) . '../assets/css/cbxgooglemap-block.css') );
806
807 $js_vars = apply_filters( 'cbxgooglemap_block_js_vars',
808 array(
809 'block_title' => esc_html__( 'CBX Maps', 'cbxgooglemap' ),
810 'block_category' => 'codeboxr',
811 'block_icon' => 'universal-access-alt',
812 'general_settings' => array(
813 'title' => esc_html__( 'CBX Map Settings', 'cbxgooglemap' ),
814 'id' => esc_html__( 'Select Map', 'cbxgooglemap' ),
815 'id_default' => '',
816 'id_options' => $googleMap_posts,
817 'id_note' => esc_html__( 'Choose saved map or create from custom attributes below', 'cbxgooglemap' ),
818 'custom_attribute_note' => esc_html__( 'Custom Map Attributes', 'cbxgooglemap' ),
819 'maptype' => esc_html__( 'Map Type(Google Map Only)', 'cbxgooglemap' ),
820 'maptype_options' => CBXGooglemapHelper::maptype_block_options(),
821 'lat' => esc_html__( 'Latitude', 'cbxgooglemap' ),
822 'lng' => esc_html__( 'Longitude', 'cbxgooglemap' ),
823 'width' => esc_html__( 'Width(Numeric, % allowed)', 'cbxgooglemap' ),
824 'height' => esc_html__( 'Height(only Numeric)', 'cbxgooglemap' ),
825 'zoom' => esc_html__( 'zoom', 'cbxgooglemap' ),
826 'scrollwheel' => esc_html__( 'Mouse Scroll Wheel', 'cbxgooglemap' ),
827 'showinfo' => esc_html__( 'Show Popup', 'cbxgooglemap' ),
828 'infow_open' => esc_html__( 'Popup Auto Display ', 'cbxgooglemap' ),
829 'heading' => esc_html__( 'Popup Heading', 'cbxgooglemap' ),
830 'address' => esc_html__( 'Location Address', 'cbxgooglemap' ),
831 'website' => esc_html__( 'Website url', 'cbxgooglemap' ),
832 'mapicon' => esc_html__( 'Map Icon', 'cbxgooglemap' ),
833 'mapicon_select' => esc_html__( 'Select image', 'cbxgooglemap' ),
834 ),
835 ) );
836
837 wp_localize_script( 'cbxgooglemap-block', 'cbxgooglemap_block', $js_vars );
838
839 register_block_type( 'codeboxr/cbxgooglemap', array(
840 'editor_script' => 'cbxgooglemap-block',
841 'editor_style' => 'cbxgooglemap-block',
842 'attributes' => apply_filters('cbxgooglemap_block_attributes', array(
843 //general
844 'id' => array(
845 'type' => 'integer',
846 'default' => '0',
847 ),
848 'maptype' => array(
849 'type' => 'string',
850 'default' => $maptype_default
851 ),
852 'lat' => array(
853 'type' => 'string',
854 'default' => ''
855 ),
856 'lng' => array(
857 'type' => 'string',
858 'default' => ''
859 ),
860 'width' => array(
861 'type' => 'string',
862 'default' => $width_default,
863 ),
864
865 'height' => array(
866 'type' => 'integer',
867 'default' => $height_default
868 ),
869 'zoom' => array(
870 'type' => 'string',
871 'default' => $zoom_default
872 ),
873 'scrollwheel' => array(
874 'type' => 'boolean',
875 'default' => ($scrollwheel_default)? true: false
876 ),
877 'showinfo' => array(
878 'type' => 'boolean',
879 'default' => ($showinfo_default)? true: false
880 ),
881 'infow_open' => array(
882 'type' => 'boolean',
883 'default' => ($infow_open_default)? true: false
884 ),
885 'heading' => array(
886 'type' => 'string',
887 'default' => ''
888 ),
889 'address' => array(
890 'type' => 'string',
891 'default' => ''
892 ),
893 'website' => array(
894 'type' => 'string',
895 'default' => ''
896 ),
897 'mapicon' => array(
898 'type' => 'string',
899 /*'source' => 'attribute',
900 'selector' => 'img',
901 'attribute' => 'src',*/
902 'default' => '',
903 ),
904 /*'icon_id' => array(
905 'type' => 'integer',
906 //'default' => '',
907 ),*/
908 )),
909 'render_callback' => array($this, 'cbxgooglemap_block_render')
910 ) );
911
912 }//end gutenberg_blocks
913
914 /**
915 * Getenberg server side render
916 *
917 * @param $settings
918 *
919 * @return string
920 */
921 public function cbxgooglemap_block_render($attributes){
922 $settings_api = new CBXGooglemapSettings();
923 $general_settings = get_option( 'cbxgooglemap_general', array() );
924
925 $googlemap_api_key = $settings_api->get_field( 'apikey', $general_settings, '' );
926 $mapsource = intval( $settings_api->get_field( 'mapsource', $general_settings, 1 ) );
927
928 if ( $mapsource == 1 && $googlemap_api_key == '' ) {
929 echo '<p style="text-align: center;">' . esc_html__( 'Google Map Api Key is invalid!', 'cbxgooglemap' ) . '</p>';
930 }
931 else {
932 $id = isset($attributes['id'])? intval( $attributes['id'] ): 0;
933
934 if ( $id > 0 ) {
935 //render map from saved map
936 return '[cbxgooglemap id="' . $id . '"]' ;
937 }
938 else {
939 $attr = array();
940 if(isset($attributes['lat'])) $attr['lat'] = sanitize_text_field( $attributes['lat'] );
941 if(isset($attributes['lng'])) $attr['lng'] = sanitize_text_field( $attributes['lng'] );
942 if(isset($attributes['width'])) $attr['width'] = sanitize_text_field( $attributes['width'] );
943 if(isset($attributes['height'])) $attr['height'] = intval( $attributes['height'] );
944 if(isset($attributes['zoom'])) $attr['zoom'] = sanitize_text_field( $attributes['zoom'] );
945
946 $attr['scrollwheel'] = isset($attributes['scrollwheel'])? $attributes['scrollwheel'] : 'true';
947 $attr['infow_open'] = isset($attributes['infow_open'])? $attributes['infow_open']: 'true';
948 $attr['showinfo'] = isset($attributes['showinfo'])? $attributes['showinfo']: 'true';
949
950 $attr['scrollwheel'] = ($attr['scrollwheel'] == 'true')? 1: 0;
951 $attr['infow_open'] = ($attr['infow_open'] == 'true')? 1: 0;
952 $attr['showinfo'] = ($attr['showinfo'] == 'true')? 1: 0;
953
954 if(isset($attributes['heading'])) $attr['heading'] = sanitize_text_field( $attributes['heading'] );
955 if(isset($attributes['address'])) $attr['address'] = sanitize_text_field( $attributes['address'] );
956 if(isset($attributes['website'])) $attr['website'] = sanitize_text_field( $attributes['website'] );
957 if(isset($attributes['maptype'])) $attr['maptype'] = sanitize_text_field( $attributes['maptype'] );
958 if(isset($attributes['mapicon'])) $attr['mapicon'] = sanitize_text_field( $attributes['mapicon'] );
959
960 $attr = apply_filters( 'cbxgooglemap_block_shortcode_builder_attr', $attr, $attributes );
961
962 $attr_html = '';
963
964 foreach ( $attr as $key => $value ) {
965 $attr_html .= ' ' . $key . '="' . $value . '" ';
966 }
967
968 //return do_shortcode( '[cbxgooglemap ' . $attr_html . ']' );
969 return '[cbxgooglemap ' . $attr_html . ']' ;
970 }
971 }//end if api keys are ok
972
973 }//end codeboxrflexiblecountdown_block_render
974
975 /**
976 * Register New Gutenberg block Category if need
977 *
978 * @param $categories
979 * @param $post
980 *
981 * @return mixed
982 */
983 public function gutenberg_block_categories( $categories, $post ) {
984 $found = false;
985 foreach ($categories as $category){
986 if($category['slug'] == 'codeboxr'){
987 $found = true;
988 break;
989 }
990 }
991
992 if(!$found){
993 return array_merge(
994 $categories,
995 array(
996 array(
997 'slug' => 'codeboxr',
998 'title' => esc_html__('CBX Blocks', 'cbxgooglemap'),
999 ),
1000 )
1001 );
1002 }
1003
1004 return $categories;
1005 }//end gutenberg_block_categories
1006
1007
1008 /**
1009 * Enqueue style for block editor
1010 */
1011 public function enqueue_block_editor_assets(){
1012 /*$mapsource = intval( $this->settings_api->get_option( 'mapsource', 'cbxgooglemap_general', 1 ) );
1013 if ( $mapsource == 0 ) {
1014 wp_register_style( 'leaflet', '//unpkg.com/leaflet@1.3.4/dist/leaflet.css', array(), $this->version, 'all' );
1015 wp_register_style( 'cbxgooglemap-public', plugin_dir_url( __FILE__ ) . '../assets/css/cbxgooglemap-public.css', array( 'leaflet' ), $this->version, 'all' );
1016 wp_enqueue_style( 'leaflet' );
1017 } else {
1018 wp_register_style( 'cbxgooglemap-public', plugin_dir_url( __FILE__ ) . '../assets/css/cbxgooglemap-public.css', array(), $this->version, 'all' );
1019 }
1020
1021 wp_enqueue_style( 'cbxgooglemap-public' );
1022
1023
1024 $googlemap_api_key = $this->settings_api->get_option( 'apikey', 'cbxgooglemap_general', '' );
1025 $mapsource = intval( $this->settings_api->get_option( 'mapsource', 'cbxgooglemap_general', 1 ) );
1026
1027 if ( ( $mapsource == 1 && ! empty( $googlemap_api_key ) ) || $mapsource == 0 ) {
1028 wp_enqueue_script( 'jquery' );
1029
1030 if ( $mapsource == 1 ) {
1031 wp_register_script( 'coregooglemapapi', '//maps.googleapis.com/maps/api/js?key=' . $googlemap_api_key . '&libraries=places', array(), $this->version );
1032 wp_register_script( 'jqcbxgooglemap', plugin_dir_url( __FILE__ ) . '../assets/js/jqcbxgooglemap.js', array(
1033 'jquery',
1034 'coregooglemapapi'
1035 ), $this->version, true );
1036 wp_register_script( 'cbxgooglemap-public', plugin_dir_url( __FILE__ ) . '../assets/js/cbxgooglemap-public.js', array(
1037 'jquery',
1038 'jqcbxgooglemap',
1039 'cbxgooglemap-block'
1040 ), $this->version, true );
1041
1042 wp_enqueue_script( 'coregooglemapapi' );
1043 wp_enqueue_script( 'jqcbxgooglemap' );
1044 } else {
1045 wp_register_script( 'coregooglemapapi', '//unpkg.com/leaflet@1.3.4/dist/leaflet.js', array(), $this->version );
1046 wp_register_script( 'cbxgooglemap-public', plugin_dir_url( __FILE__ ) . '../assets/js/cbxgooglemap-public.js', array(
1047 'jquery',
1048 'coregooglemapapi'
1049 ), $this->version, true );
1050 wp_enqueue_script( 'coregooglemapapi' );
1051 }
1052
1053 wp_enqueue_script( 'cbxgooglemap-public' );
1054 }*/
1055
1056 }//end enqueue_block_editor_assets
1057
1058 }//end class CBXGoogleMap_Admin
1059