PluginProbe
CBX Map for Google Map & OpenStreetMap / 1.1.11
CBX Map for Google Map & OpenStreetMap v1.1.11
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.11, at admin/class-cbxgooglemap-admin.php

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