PluginProbe
WP Maps – Google Maps,OpenStreetMap,Mapbox,Store Locator,Listing,Directory & Filters / 4.9.7
WP Maps – Google Maps,OpenStreetMap,Mapbox,Store Locator,Listing,Directory & Filters v4.9.7
4.9.9 4.9.8 4.9.7 4.9.6 4.9.5 4.8.7 4.8.8 4.8.9 4.9.0 4.9.1 4.9.2 4.9.3 version4.4.8 trunk 3.0.8 3.1.1 4.0.6 4.2.2 4.4.5 4.4.6 4.4.7 4.4.9 4.5.0 4.5.1 4.5.2 All 54 releases
wp-google-map-plugin / wp-google-map-plugin.php

wp-google-map-plugin.php in WP Maps – Google Maps,OpenStreetMap,Mapbox,Store Locator,Listing,Directory & Filters 4.9.7, at wp-google-map-plugin.php

1,479 lines 46.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: WP Maps
4 * Plugin URI: https://weplugins.com/
5 * Description: A fully customizable WordPress Plugin for Google Maps. Create unlimited Google Maps Shortcodes, assign unlimited locations with custom infowindow messages and add to pages, posts and widgets.
6 * Author: WePlugins
7 * Author URI: https://weplugins.com/
8 * License: GPL v2 or later
9 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
10 * Version: 4.9.7
11 * Text Domain: wp-google-map-plugin
12 * Domain Path: /lang
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 die( 'You are not allowed to call this page directly.' );
17 }
18
19 if ( ! class_exists( 'WPGMP_Google_Maps_Lite' ) ) {
20
21 /**
22 * Main plugin class
23 *
24 * @author Flipper Code <hello@flippercode.com>
25 * @package Maps
26 */
27 class WPGMP_Google_Maps_Lite {
28
29 /**
30 * List of Modules.
31 *
32 * @var array
33 */
34 private $modules = array();
35
36 /**
37 * Check if Pro Version Installed.
38 *
39 * @var bool
40 */
41 private $proVersionInstalled = false;
42
43 /**
44 * Intialize variables, files and call actions.
45 *
46 * @var array
47 */
48 public function __construct() {
49
50 $this->wpagm_check_plugin_dependancy();
51
52 if( $this->proVersionInstalled === false)
53 {
54 $this->wpgmp_define_constants();
55 $this->wpgmp_load_files();
56 $this->wpgmp_register_hooks();
57 }
58
59 }
60
61 function wpgmp_register_hooks(){
62
63 register_activation_hook( __FILE__, [ $this, 'wpgmp_plugin_activation'] );
64 register_deactivation_hook( __FILE__, [ $this, 'wpgmp_plugin_deactivation'] );
65
66 if ( is_multisite() ) {
67 add_action( 'wpmu_new_blog', [ $this, 'wpgmp_on_blog_new_generate'], 10, 6 );
68 add_filter( 'wpmu_drop_tables', [ $this, 'wpgmp_on_blog_delete'] );
69 }
70
71 add_action('init', [$this, 'wpgmp_notification'] );
72 add_action( 'plugins_loaded', [ $this, 'wpgmp_load_plugin_languages'] );
73 add_action( 'plugins_loaded', [ $this, 'wpgmp_load_integrations'] );
74 add_action( 'widgets_init', [ $this, 'wpgmp_google_map_widget'] );
75 add_action( 'wp_enqueue_scripts', [ $this, 'wpgmp_frontend_scripts'] );
76 add_action( 'wp_ajax_wpgmp_ajax_call', [ $this, 'wpgmp_ajax_call'] );
77
78 add_filter( 'media_upload_tabs', [ $this, 'wpgmp_google_map_tabs_filter']);
79 add_filter( 'fc-dummy-placeholders', [ $this, 'wpgmp_apply_placeholders'] );
80 add_filter( 'fc_tabular_action_cap', [ $this, 'wpgmp_return_final_capability' ] );
81
82 add_shortcode( 'put_wpgm', [ $this, 'wpgmp_show_location_in_map'] );
83
84 if ( is_admin() ) {
85
86 add_action( 'admin_head', [ $this, 'wpgmp_customizer_font_family']);
87 add_action( 'admin_menu', [ $this, 'wpgmp_create_menu' ] );
88 add_action( 'admin_init', [ $this, 'wpgmp_export_data' ] );
89 add_action( 'admin_init', [ $this, 'wpgmp_sample_csv_download' ] );
90 add_action( 'admin_enqueue_scripts', [ $this, 'wpgmp_enqueue_metabox_assets' ] );
91 add_action( 'media_upload_ell_insert_gmap_tab', [ $this, 'wpgmp_google_map_media_upload_tab' ] );
92 add_action( 'media_upload_ell_insert_gmap_svg_tab', [ $this, 'wpgmp_google_map_media_upload_svg_tab' ] );
93 add_action( 'wp_ajax_wpdfenabledebug', [ $this, 'wpgmp_enable_debug_mode' ] );
94 add_action( 'wp_ajax_nopriv_wpdfenabledebug', [ $this, 'wpgmp_enable_debug_mode' ] );
95 add_action( 'wp_ajax_wpgmp_temp_access_ajax', [ $this, 'wpgmp_temp_access_ajax_callback'] );
96 add_action( 'wp_ajax_nopriv_wpgmp_temp_access_ajax', [ $this, 'wpgmp_temp_access_ajax_callback'] );
97
98 add_filter( 'plugin_row_meta', [ $this,'wpgmp_add_plugin_row_custom_link'], 10, 2 );
99 add_filter( 'wpgmp_form_header_html', [ $this, 'wpgmp_add_custom_loader' ] );
100 add_filter( 'fc_manage_page_basic_query', [ $this, 'wpgmp_display_own_records' ],10,2 );
101 add_filter( 'plugin_action_links_'. plugin_basename(__FILE__), [$this, 'wpgmp_plugin_settings_link'], 10, 1 );
102 add_filter( 'fc_plugin_nav_menu', [$this,'fc_render_plugin_menu'] );
103 $this->wpgmp_create_vc_component();
104 add_action('wp_ajax_wpgmp_submit_uninstall_reason_action', array($this, 'wpgmp_submit_uninstall_reason_action_perform'));
105 add_action('wp_ajax_nopriv_wpgmp_submit_uninstall_reason_action', array($this, 'wpgmp_submit_uninstall_reason_action'));
106 add_action( 'admin_enqueue_scripts', array( $this, 'wpgmp_overview_page_styles') );
107
108 }
109
110 }
111
112 function wpagm_check_plugin_dependancy() {
113
114 if ( ! function_exists( 'is_plugin_active_for_network' ) )
115 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
116
117 //Advance GoogleMaps Pro Dependency
118 $is_google_maps_installed = in_array( 'wp-google-map-gold/wp-google-map-gold.php',get_option('active_plugins' ) ) ;
119 $is_google_maps_active = ( is_plugin_active_for_network( 'wp-google-map-gold/wp-google-map-gold.php' ) ) ? true : false;
120 $this->proVersionInstalled = ($is_google_maps_installed || $is_google_maps_active) ? true : false;
121
122 }
123
124 function fc_render_plugin_menu() {
125
126 $plugin_submenu_info = $this->get_plugin_submenu_info_by_parent('wpgmp_view_overview');
127
128 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading page parameter for navigation display only
129 $page = ( isset( $_GET['page'] ) && ! empty( $_GET['page'] ) ) ? sanitize_key( $_GET['page'] ) : '';
130
131 $grouped = [];
132
133 foreach ($plugin_submenu_info as $menu) {
134 $parts = explode('_', $menu['slug']);
135 $key = $parts[2] ?? 'other';
136
137 if ($key === 'group') $key = 'category';
138 if ($key === 'overview') $key = 'dashboard';
139
140 $grouped[$key][] = $menu;
141 }
142
143 ob_start();
144 ?>
145 <div class="fc-header-secondary">
146 <div class="fc-container">
147 <div class="fc-navbar">
148 <?php foreach ($grouped as $group => $items): ?>
149 <?php
150 $first = $items[0];
151 $split_first = explode('_',$first['slug']);
152 if(isset($split_first[2]))
153 $active = (strpos($page, $split_first[2]) !== false) ? 'active' : '';
154 else
155 $active = '';
156
157 if( strpos($page, 'group_map') !== false && isset($split_first[2]) && $split_first[2] == 'map') {
158 $active = '';
159 }
160
161 ?>
162 <div class="fc-nav-item <?php echo esc_attr( $active ); ?>">
163 <a href="<?php echo esc_url( $first['url'] ); ?>" class="fc-nav-link <?php echo esc_attr( $first['slug'] ); ?>">
164 <?php echo esc_html( ucfirst( $group ) ); ?>
165 </a>
166
167 <?php if (count($items) > 1): ?>
168 <div class="fc-sub-menu">
169 <?php foreach (array_slice($items, 0) as $item): ?>
170 <?php $sub_active = ($page === $item['slug']) ? 'active' : ''; ?>
171 <div class="fc-nav-item <?php echo esc_attr( $sub_active ); ?>">
172 <a href="<?php echo esc_url( $item['url'] ); ?>" class="fc-nav-link <?php echo esc_attr( $item['slug'] ); ?>">
173 <?php echo esc_html( $item['name'] ); ?>
174 </a>
175 </div>
176 <?php endforeach; ?>
177 </div>
178 <?php endif; ?>
179 </div>
180 <?php endforeach; ?>
181 </div>
182 </div>
183 </div>
184 <?php
185 return ob_get_clean();
186 }
187
188
189 function wpgmp_load_integrations() {
190 $integration_files = glob( plugin_dir_path( __FILE__ ) . 'integrations/class-wpgmp-integration-*.php' );
191 if ( $integration_files ) {
192 foreach ( $integration_files as $file ) {
193 require_once $file;
194 }
195 }
196 }
197
198 function get_plugin_submenu_info_by_parent($parent_slug) {
199
200 global $submenu;
201 $plugin_submenu_info = array();
202
203 if (isset($submenu[$parent_slug])) {
204 foreach ($submenu[$parent_slug] as $submenu_item) {
205 $submenu_name = isset($submenu_item[0]) ? $submenu_item[0] : '';
206 $submenu_slug = isset($submenu_item[2]) ? $submenu_item[2] : '';
207 $submenu_url = isset($submenu_item[2]) ? admin_url('admin.php?page=' . $submenu_item[2]) : '';
208
209 $plugin_submenu_info[] = array(
210 'name' => $submenu_name,
211 'slug' => $submenu_slug,
212 'url' => $submenu_url
213 );
214 }
215 }
216
217 return $plugin_submenu_info;
218 }
219
220
221 /**
222 * Enqueue backend scripts and styles only when editing allowed post types
223 */
224 public function wpgmp_enqueue_metabox_assets( $hook ) {
225 if ( ! in_array( $hook, [ 'post.php', 'post-new.php' ], true ) ) {
226 return;
227 }
228
229 global $post;
230 if ( isset( $post ) && in_array( get_post_type( $post ), WPGMP_Helper::wpgmp_get_all_post_types(), true ) ) {
231 WPGMP_Helper::wpgmp_register_map_backend_resources();
232 }
233 }
234
235 function wpgmp_return_final_capability( $cap ) {
236
237 global $wpdb;
238 if ( current_user_can( 'administrator' ) ) {
239 return $cap;
240 }
241
242 // Sanitize GET values
243 $location_id = isset( $_GET['location_id'] ) ? absint( sanitize_text_field( $_GET['location_id'] ) ) : '';
244 $doaction = isset( $_GET['doaction'] ) ? sanitize_text_field( wp_unslash( $_GET['doaction'] ) ) : '';
245 $get_cap = isset( $_GET['cap'] ) ? sanitize_text_field( wp_unslash( $_GET['cap'] ) ) : '';
246 $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
247
248
249 $backend_page = (
250 is_admin() &&
251 ! empty( $location_id ) &&
252 ! empty( $doaction ) &&
253 $page === 'wpgmp_manage_location'
254 ) ? true : false;
255
256 if ( $backend_page ) {
257
258 $location_data = $wpdb->get_results( $wpdb->prepare(
259 "SELECT * FROM {$wpdb->prefix}map_locations WHERE location_id = %d",
260 intval( $location_id )
261 ) );
262
263 if ( ! empty( $location_data ) && isset( $location_data[0]->location_author ) ) {
264 if ( get_current_user_id() !== (int) $location_data[0]->location_author ) {
265 $cap = '';
266 }
267 }
268 }
269
270 return $cap;
271 }
272
273 function wpgmp_submit_uninstall_reason_action_perform(){
274
275
276 global $wp_version, $current_user;
277 wp_verify_nonce($_REQUEST['wpgmp_ajax_nonce'], 'wpgmp_ajax_nonce');
278 $reason_id = isset($_REQUEST['reason_id']) ? stripcslashes(sanitize_text_field($_REQUEST['reason_id'])) : '';
279 $basename = isset($_REQUEST['plugin']) ? stripcslashes(sanitize_text_field($_REQUEST['plugin'])) : '';
280
281 if (empty($reason_id) || empty($basename)) {
282 exit;
283 }
284
285 $reason_info = isset($_REQUEST['reason_info']) ? stripcslashes(sanitize_textarea_field($_REQUEST['reason_info'])) : '';
286 if (!empty($reason_info)) {
287 $reason_info = substr($reason_info, 0, 255);
288 }
289 $is_anonymous = isset($_REQUEST['is_anonymous']) && 1 == $_REQUEST['is_anonymous'];
290
291
292 $options = array(
293 'product' => 'WP Maps Plugin',
294 'reason_id' => $reason_id,
295 'reason_info' => $reason_info,
296 );
297
298 if (!$is_anonymous) {
299 $options['url'] = get_site_url();
300 $options['wp_version'] = $wp_version;
301 $options['plugin_version'] = WPGMP_VERSION;
302 $options['email'] = $current_user->data->user_email;
303 }
304
305 wp_remote_post(
306 "https://weplugins.com/wp-json/weplugins/v1/plugin-deactivate",
307 array(
308 'method' => 'POST',
309 'body' => $options,
310 'timeout' => 15,
311 )
312 );
313 exit;
314
315
316 }
317
318 function wpgmp_display_own_records($query, $page){
319
320 // Check if the user is logged in
321 if (is_user_logged_in()) {
322
323 $current_user = wp_get_current_user();
324 $roles = $current_user->roles;
325
326 // Check if the user has a specific role
327 if (in_array('administrator', $roles)) {
328 return $query;
329 } else {
330
331 $permission = apply_filters( 'wpgmp_location_update_permission', true, $_GET['page'], $current_user );
332
333 if( isset( $_GET['page'] ) && $_GET['page'] == 'wpgmp_manage_location' && $permission){
334
335 $query .= ' where location_author = '.get_current_user_id();
336
337 }
338
339 }
340 }
341
342
343 return $query;
344 }
345
346 function wpgmp_notification(){
347
348 if (class_exists('WePlugins_Notification')) {
349 WePlugins_Notification::init(); // call static init
350 }
351
352 }
353
354
355
356 function wpgmp_temp_access_ajax_callback(){
357 check_ajax_referer( 'fc-call-nonce', 'nonce' );
358 $temp_access = new WPGMP_Temp_Access();
359 $response = $temp_access->wpgmp_temp_access_support();
360
361 wp_send_json($response);
362
363 exit();
364 }
365
366 /**
367 * Display loader in back-end.
368 *
369 * @since 4.0.0
370 */
371 function wpgmp_add_custom_loader( $form_container_html ) {
372
373 if ( isset( $_GET['page'] ) && strpos( $_GET['page'], 'wpgmp' ) !== false ) {
374 $form_container_html = $form_container_html . '<div class="fc-backend-loader" style="display:none;"><img src="' . WPGMP_IMAGES . '\Preloader_3.gif"></div>';
375 }
376
377 return $form_container_html;
378
379 }
380
381 /**
382 * Enable debug module.
383 *
384 * @since 4.0.0
385 */
386 function wpgmp_enable_debug_mode() {
387
388 if ( ! isset( $_POST['nonce'] ) || empty( $_POST['nonce'] ) ) {
389 echo json_encode(
390 array(
391 'error' => true,
392 'error_msg' => 'Nonce security failed',
393 )
394 );
395 wp_die();
396 }
397 if ( isset( $_POST['nonce'] ) && ( ! wp_verify_nonce( $_POST['nonce'], 'fc-call-nonce' ) ) ) {
398 echo json_encode(
399 array(
400 'error' => true,
401 'error_msg' => 'Nonce security was not verified by our system. Please refresh the page and try again.',
402 )
403 );
404 wp_die();
405
406 }
407 if ( ! current_user_can( 'manage_options' ) ) {
408 echo json_encode(
409 array(
410 'error' => true,
411 'error_msg' => 'You are not allowed to perform actions.',
412 )
413 );
414 wp_die();
415
416 }
417
418 $enabled = true;
419 $data = get_option( 'wpgmp_settings' );
420 if(!empty($data)){
421 $data = maybe_unserialize( $data );
422 }
423
424 if ( ! isset( $data ) || ! isset( $data['wpgmp_enabled'] ) ) {
425
426 $data['wpgmp_enabled'] = 'yes';
427 $_POST['purcahse_data']['platform'] = sanitize_text_field( $_POST['platform'] );
428 $_POST['purcahse_data']['verification_mode'] = sanitize_text_field( $_POST['verification_mode'] );
429 $data['wpgmp_debug_info'] = serialize( $_POST['purcahse_data'] );
430 update_option( 'wpgmp_settings', $data );
431
432 }
433 echo json_encode(
434 array(
435 'enabled' => $enabled,
436 'data' => $data,
437 )
438 );
439 wp_die();
440
441 }
442
443 function wpgmp_create_vc_component() {
444
445 if ( defined( 'WPB_VC_VERSION' ) && class_exists('WPGMP_VC_Builder') ) {
446
447 $vcComponent = new WPGMP_VC_Builder();
448 $vcComponent->wpgmp_register_vc_component();
449
450 }
451 }
452
453 function wpgmp_sample_csv_download(){
454
455 if( !empty($_GET['do_action']) && $_GET['do_action'] == 'sample_csv_download' ){
456
457 if ( isset( $_GET['sample_csv_download_nonce'] ) && wp_verify_nonce( $_GET['sample_csv_download_nonce'], 'sample_csv_download_action' ) ) {
458
459 $sample_zip = WPGMP_DIR . 'import_sample_file.zip';
460
461 // Initialize WP_Filesystem
462 global $wp_filesystem;
463 if ( empty( $wp_filesystem ) ) {
464 require_once ABSPATH . 'wp-admin/includes/file.php';
465 WP_Filesystem();
466 }
467
468 if ( $wp_filesystem->exists( $sample_zip ) ) {
469 header("Content-type: application/zip",true,200);
470 header("Content-Disposition: attachment; filename=import_sample_file.zip");
471 header("Pragma: no-cache");
472 header("Expires: 0");
473 header("Content-Length: " . $wp_filesystem->size( $sample_zip ));
474
475 // Use WP_Filesystem to read and output the file
476 $file_content = $wp_filesystem->get_contents( $sample_zip );
477 if ( $file_content !== false ) {
478 echo $file_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
479 exit();
480 } else {
481 wp_die( esc_html__( 'Unable to read sample file.', 'wp-google-map-plugin' ) );
482 }
483 } else {
484 wp_die( esc_html__( 'Sample file not found.', 'wp-google-map-plugin' ) );
485 }
486 } else {
487 wp_die( esc_html__( 'Something went wrong with the requested action. Please refresh page and try again.', 'wp-google-map-plugin' ) );
488 }
489 }
490 }
491
492 /**
493 * Export data into csv,xml,json or excel file
494 */
495 function wpgmp_export_data() {
496
497 if ( isset( $_POST['action'] ) && isset( $_REQUEST['_wpnonce'] ) && $_POST['action'] == 'export_location_csv' ) {
498 $nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) );
499
500 if ( isset( $nonce ) and ! wp_verify_nonce( $nonce, 'wpgmp-nonce' ) ) {
501 die( 'Cheating...' );
502 }
503
504 if ( isset( $_POST['action'] ) and false != strstr( $_POST['action'], 'export_' ) ) {
505 $export_action = explode( '_', sanitize_text_field( $_POST['action'] ) );
506 if ( 3 == count( $export_action ) and 'export' == $export_action[0] ) {
507 $model_class = 'WPGMP_Model_' . ucwords( $export_action[1] );
508 $entity = new $model_class();
509 $entity->export( $export_action[2] );
510 }
511 }
512 }
513
514 }
515
516 function wpgmp_apply_placeholders( $content ) {
517
518 $content = WPGMP_Helper::wpgmp_apply_placeholders( $content );
519 return $content;
520 }
521
522 function wpgmp_customizer_font_family() {
523
524 if ( isset( $_GET['doaction'] ) and 'edit' == $_GET['doaction'] and isset( $_GET['map_id'] ) ) {
525
526 $modelFactory = new WPGMP_Model();
527 $map_obj = $modelFactory->create_object( 'map' );
528 $styles_and_scripts = $map_obj->get_map_customizer_style();
529 $font_families = $styles_and_scripts['font_families'];
530 $fc_skin_styles = $styles_and_scripts['fc_skin_styles'];
531 if ( ! empty( $fc_skin_styles ) ) {
532 echo '<style id="wpgmp-customiser-style">' . esc_html( $fc_skin_styles ) . '</style>';
533 }
534 if ( ! empty( $font_families ) ) {
535 $font_families = array_unique($font_families);
536 ?>
537 <script type="text/javascript">
538 var google_customizer_fonts = <?php echo json_encode($font_families,JSON_FORCE_OBJECT);?>;
539 </script>
540 <?php }
541
542 }
543
544 }
545
546 /**
547 * Register WP Google Map Widget
548 */
549 function wpgmp_google_map_widget() { register_widget( 'WPGMP_Google_Map_Widget_Class' ); }
550
551 /**
552 * Eneque scripts at frontend.
553 */
554
555 function wpgmp_frontend_scripts() { WPGMP_Helper::wpgmp_register_map_frontend_resources(); }
556
557 /**
558 * Display map at the frontend using put_wpgmp shortcode.
559 *
560 * @param array $atts Map Options.
561 * @param string $content Content.
562 */
563
564 function wpgmp_show_location_in_map( $atts, $content = null ) {
565
566 // Sanitise all the shortcode attributes if provided by site administrator manually.
567 $sanitized_atts = WPGMP_Security::wpgmp_sanitize_shortcode_atts( $atts );
568
569 try {
570
571 $factoryObject = new WPGMP_Controller();
572 $viewObject = $factoryObject->create_object( 'shortcode' );
573 $output = $viewObject->display( 'put-wpgmp', $sanitized_atts );
574
575 // My custom html for rendering google maps has below tags with their attributes that are needed for functionality.
576 $allowed_tags = [
577 'div' => [
578 'id' => true,
579 'class' => true,
580 'rel' => true,
581 'style' => true,
582 'data-*' => true,
583 ],
584 'style' => [
585 'type' => true,
586 ],
587
588 'script' => [
589 'type' => true,
590 ],
591 ];
592
593 // Escape the final output HTML requried for rendering google maps on browser using WordPress standard escaping function. Escape the final HTML output as late as possible, just before returning it from the shortcode for rendering in the browser.
594
595 return wp_kses( $output, $allowed_tags );
596
597 } catch ( Exception $e ) {
598 return wp_kses_post( WPGMP_Template::show_message( array( 'error' => $e->getMessage() ) ) );
599 }
600 }
601
602 /**
603 * Ajax Call
604 */
605 function wpgmp_ajax_call() {
606
607 check_ajax_referer( 'fc-call-nonce', 'nonce' );
608
609 // Only administrators should be able to perform these operations.
610 if ( ! current_user_can( 'manage_options' ) ) {
611 wp_send_json_error(
612 array(
613 'message' => esc_html__( 'Unauthorized request.', 'wp-google-map-plugin' ),
614 ),
615 403
616 );
617 }
618
619 $operation = isset( $_POST['operation'] )
620 ? sanitize_key( wp_unslash( $_POST['operation'] ) )
621 : '';
622
623 $value = wp_unslash( $_POST );
624
625 $allowed_operations = array(
626 'clean_database',
627 'upload_sampledata',
628 'save',
629 'map_fields',
630 'cancel_import',
631 );
632
633 if ( ! in_array( $operation, $allowed_operations, true ) ) {
634 wp_send_json_error(
635 array(
636 'message' => esc_html__( 'Invalid operation.', 'wp-google-map-plugin' ),
637 ),
638 400
639 );
640 }
641
642 $this->{$operation}( $value );
643
644 wp_die();
645 }
646
647 /**
648 * Process slug and display view in the backend.
649 */
650 function wpgmp_processor() {
651
652 $return = '';
653 $page = ( isset( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : 'wpgmp_view_overview';
654 $pageData = explode( '_', $page );
655 $obj_type = $pageData[2];
656 $obj_operation = $pageData[1];
657
658 if ( count( $pageData ) < 3 ) { die( 'Cheating!' ); }
659
660 try {
661
662 if ( count( $pageData ) > 3 ) {
663 $obj_type = $pageData[2] . '_' . $pageData[3];
664 }
665 $factoryObject = new WPGMP_Controller();
666 $viewObject = $factoryObject->create_object( $obj_type , $factoryObject);
667 $viewObject->display( $obj_operation );
668
669 } catch ( Exception $e ) {
670 echo wp_kses_post( WPGMP_Template::show_message( array( 'error' => $e->getMessage() ) ) );
671
672 }
673
674 }
675
676 public function wpgmp_add_plugin_row_custom_link( $links, $file ){
677
678 if ( strpos( $file, basename(__FILE__) ) ) {
679
680 $links[] = '<a href="https://www.wpmapspro.com/tutorials/" target="_blank" title="WP Maps Docs">'.esc_html__('Docs','wp-google-map-plugin').'</a>';
681 $links[] = '<a href="https://www.wpmapspro.com/map-hooks/" target="_blank" title="WP Maps Developer Hooks">'.esc_html__('Hooks','wp-google-map-plugin').'</a>';
682 $links[] = '<a href="https://weplugins.com/support/" target="_blank" title="WP Maps Support">'.esc_html__('Support','wp-google-map-plugin').'</a>';
683 $links[] = '<a href="https://weplugins.com/contact/" target="_blank" title="WP Maps Customisation">'.esc_html__('Customisation','wp-google-map-plugin').'</a>';
684 $links[] = '<a href="https://www.wpmapspro.com/pricing/" class="wpgmp-pro-link" target="_blank" title="WP Maps Pro">'.esc_html__('Upgrade to Pro','wp-google-map-plugin').'</a>';
685
686 }
687 return $links;
688 }
689
690 function wpgmp_plugin_settings_link($actions) {
691
692 $actions['settings'] = '<a href="' . admin_url( 'admin.php?page=wpgmp_manage_settings' ) . '">'.esc_html__( 'Settings', 'wp-google-map-plugin' ).'</a>';
693
694 return $actions;
695 }
696
697 /**
698 * Create backend navigation.
699 */
700 function wpgmp_create_menu() {
701
702 global $navigations;
703
704 $pagehook1 = add_menu_page(
705 esc_html__( 'WP MAPS', 'wp-google-map-plugin' ),
706 esc_html__( 'WP MAPS', 'wp-google-map-plugin' ),
707 'wpgmp_admin_overview',
708 WPGMP_SLUG,
709 array( $this, 'wpgmp_processor' ),
710 WPGMP_IMAGES . '/fc-small-logo.png'
711 );
712
713 if ( current_user_can( 'manage_options' ) ) {
714 $role = get_role( 'administrator' );
715 $role->add_cap( 'wpgmp_admin_overview' );
716 }
717
718 $this->wpgmp_load_modules_menu();
719 add_action( 'load-' . $pagehook1, array( $this, 'wpgmp_backend_scripts' ) );
720
721 }
722 /**
723 * Read models and create backend navigation.
724 */
725 function wpgmp_load_modules_menu() {
726
727 $modules = $this->modules;
728 $pagehooks = array();
729 if ( is_array( $modules ) ) {
730 foreach ( $modules as $module ) {
731
732 $object = new $module();
733
734 if ( method_exists( $object, 'navigation' ) ) {
735
736 if ( ! is_array( $object->navigation() ) ) {
737 continue;
738 }
739
740 foreach ( $object->navigation() as $nav => $title ) {
741
742 if ( current_user_can( 'manage_options' ) && is_admin() ) {
743 $role = get_role( 'administrator' );
744 $role->add_cap( $nav );
745
746 }
747
748 $pagehooks[] = add_submenu_page(
749 WPGMP_SLUG,
750 $title,
751 $title,
752 $nav,
753 $nav,
754 array( $this, 'wpgmp_processor' ),
755 100
756 );
757
758 }
759 }
760 }
761 }
762
763 if ( is_array( $pagehooks ) ) {
764
765 foreach ( $pagehooks as $key => $pagehook ) {
766 add_action( 'load-' . $pagehooks[ $key ], array( $this, 'wpgmp_backend_scripts' ) );
767 }
768 }
769
770 }
771 /**
772 * Eneque scripts in the backend.
773 */
774 function wpgmp_backend_scripts() {
775
776 WPGMP_Helper::wpgmp_register_map_backend_resources();
777 }
778
779 /**
780 * Load plugin language file.
781 */
782 function wpgmp_load_plugin_languages() {
783
784 $this->modules = apply_filters( 'wpgmp_extensions', $this->modules );
785 load_plugin_textdomain( 'wp-google-map-plugin', false, WPGMP_FOLDER . '/lang/' );
786 }
787 /**
788 * Call hook on plugin activation for both multi-site and single-site.
789 */
790 function wpgmp_plugin_activation( $network_wide ) {
791
792 if ( is_multisite() && $network_wide ) {
793 global $wpdb;
794 $currentblog = $wpdb->blogid;
795 $activated = array();
796 $blog_ids = $wpdb->get_col(
797 $wpdb->prepare( "SELECT blog_id FROM {$wpdb->blogs}" )
798 );
799
800 foreach ( $blog_ids as $blog_id ) {
801 switch_to_blog( $blog_id );
802 $this->wpgmp_activation();
803 $activated[] = $blog_id;
804 }
805
806 switch_to_blog( $currentblog );
807 update_site_option( 'op_activated', $activated );
808
809 } else {
810 $this->wpgmp_activation();
811 }
812
813 if (class_exists('WePlugins_Notification')) {
814 WePlugins_Notification::schedule_cron();
815 }
816 }
817 /**
818 * Call hook on plugin deactivation for both multi-site and single-site.
819 */
820 function wpgmp_plugin_deactivation() {
821
822 if ( is_multisite() && $network_wide ) {
823 global $wpdb;
824 $currentblog = $wpdb->blogid;
825 $activated = array();
826 $blog_ids = $wpdb->get_col(
827 $wpdb->prepare( "SELECT blog_id FROM {$wpdb->blogs}" )
828 );
829
830 foreach ( $blog_ids as $blog_id ) {
831 switch_to_blog( $blog_id );
832 $this->wpgmp_deactivation();
833 $activated[] = $blog_id;
834 }
835
836 switch_to_blog( $currentblog );
837 update_site_option( 'op_activated', $activated );
838
839 } else {
840 $this->wpgmp_deactivation();
841 }
842
843 if (class_exists('WePlugins_Notification')) {
844 WePlugins_Notification::deactivate_cron();
845 }
846 }
847
848 /**
849 * Perform tasks on new blog create and table install.
850 */
851
852 function wpgmp_on_blog_new_generate( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
853
854 if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
855 switch_to_blog( $blog_id );
856 $this->wpgmp_activation();
857 restore_current_blog();
858 }
859
860 }
861
862 /**
863 * Perform tasks on when blog deleted and remove plugin tables.
864 */
865
866 function wpgmp_on_blog_delete( $tables ) {
867 global $wpdb;
868 $tables[] = str_replace( $wpdb->base_prefix, $wpdb->prefix, TBL_LOCATION );
869 $tables[] = str_replace( $wpdb->base_prefix, $wpdb->prefix, TBL_GROUPMAP );
870 $tables[] = str_replace( $wpdb->base_prefix, $wpdb->prefix, TBL_MAP );
871 $tables[] = str_replace( $wpdb->base_prefix, $wpdb->prefix, TBL_ROUTES );
872 return $tables;
873 }
874 /**
875 * Create choose icon tab in media manager.
876 *
877 * @param array $tabs Current Tabs.
878 * @return array New Tabs.
879 */
880 function wpgmp_google_map_tabs_filter( $tabs ) {
881
882 $newtab = array( 'ell_insert_gmap_tab' => esc_html__( 'Choose Icons', 'wp-google-map-plugin' ),
883 'ell_insert_gmap_svg_tab' => esc_html__( 'SVG Icons', 'wp-google-map-plugin' ) );
884
885 return array_merge( $tabs, $newtab );
886 }
887 /**
888 * Intialize wp_iframe for icons tab
889 *
890 * @return [type] [description]
891 */
892 function wpgmp_google_map_media_upload_tab() {
893
894 return wp_iframe( array( $this, 'media_wpgmp_google_map_icon' ), array() );
895 }
896
897 /**
898 * Intialize wp_iframe for svg icons tab
899 *
900 * @return [type] [description]
901 */
902 function wpgmp_google_map_media_upload_svg_tab() {
903
904 return wp_iframe( array( $this, 'media_wpgmp_google_map_svg_icon' ), array() );
905 }
906 /**
907 * Read images/icons folder.
908 */
909 function media_wpgmp_google_map_icon() {
910
911 wp_enqueue_style( 'media' );
912 media_upload_header();
913 $form_action_url = site_url( "wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=ell_insert_gmap_tab", 'admin' );
914 ?>
915
916 <style type="text/css">
917 #select_icons .read_icons {width: 32px;height: 32px;}
918 #select_icons .active img {border: 3px solid #000;width: 26px;}
919 </style>
920
921 <script type="text/javascript">
922
923 jQuery(document).ready(function($) {
924
925 $(".read_icons").click(function () {
926 $(".read_icons").removeClass('active');
927 $(this).addClass('active');
928 });
929
930 $('input[name="wpgmp_search_icon"]').keyup(function() {
931 if($(this).val() == '')
932 $('.read_icons').show();
933 else {
934 $('.read_icons').hide();
935 $('img[title^="' + $(this).val() + '"]').parent().show();
936 }
937
938 });
939
940 });
941
942
943
944 function wpgmp_add_icon_to_images(target) {
945
946 if(jQuery('.read_icons').hasClass('active')) {
947 imgsrc = jQuery('.active').find('img').attr('src');
948 var win = window.dialogArguments || opener || parent || top;
949 win.send_icon_to_map(imgsrc,target);
950 }else{
951 alert('<?php esc_html_e( 'Choose marker icon', 'wp-google-map-plugin' ); ?>');
952 }
953 }
954 </script>
955 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr( $form_action_url ); ?>" class="media-upload-form" id="library-form">
956 <h3 class="media-title" style="color: #5A5A5A; font-family: Georgia, 'Times New Roman', Times, serif; font-weight: normal; font-size: 1.6em; margin-left: 10px;"><?php esc_html_e( 'Choose icon', 'wp-google-map-plugin' ); ?> <input name="wpgmp_search_icon" id="wpgmp_search_icon" type='text' value="" placeholder="<?php esc_html_e( 'Search icons', 'wp-google-map-plugin' ); ?>" />
957 </h3>
958 <div style="margin-bottom:20px; float:left; width:100%;">
959 <ul style="float:left; width:100%;" id="select_icons">
960 <?php
961 $dir = WPGMP_ICONS_DIR;
962 $file_display = array( 'jpg', 'jpeg', 'png', 'gif' );
963
964 if ( file_exists( $dir ) == false ) {
965 echo 'Directory \'', esc_html( $dir ), '\' not found!';
966
967 } else {
968 $dir_contents = scandir( $dir );
969 foreach ( $dir_contents as $file ) {
970 $image_data = explode( '.', $file );
971 $file_type = strtolower( end( $image_data ) );
972 if ( '.' !== $file && '..' !== $file && true == in_array( $file_type, $file_display ) ) {
973 ?>
974 <li class="read_icons" style="float:left;">
975 <img alt="<?php echo esc_attr( $image_data[0] ); ?>" title="<?php echo esc_attr( $image_data[0] ); ?>" src="<?php echo esc_url( WPGMP_ICONS . $file ); ?>" style="cursor:pointer;" />
976 </li>
977 <?php
978 }
979 }
980 }
981
982 if ( isset( $_GET['target'] ) ) {
983 $target = esc_js( $_GET['target'] );
984 } else {
985 $target = '';
986 }
987
988 ?>
989 </ul>
990 <button type="button" class="button" style="margin-left:10px;" value="1" onclick="wpgmp_add_icon_to_images('<?php echo esc_attr( $target ); ?>');" name="send[<?php echo esc_attr( $picid ); ?>]"><?php esc_html_e( 'Insert into Post', 'wp-google-map-plugin' ); ?></button>
991 </div>
992 </form>
993 <?php
994 }
995
996 function media_wpgmp_google_map_svg_icon() {
997 wp_enqueue_style( 'media' );
998 media_upload_header();
999 $form_action_url = site_url( "wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=ell_insert_gmap_svg_tab", 'admin' );
1000 ?>
1001
1002 <style type="text/css">
1003 #wpgmp-icon-customizer {
1004 display: flex;
1005 gap: 20px;
1006 padding-block: 20px;
1007 }
1008 #wpgmp-icon-controls {
1009 flex: 1;
1010 }
1011 #svg_preview_panel {
1012 display: flex;
1013 flex-direction: column;
1014 align-items: center;
1015 justify-content: center;
1016 flex-shrink: 0;
1017 border: 1px solid #ddd;
1018 padding: 15px;
1019 background: #f9f9f9;
1020 text-align: center;
1021 width: 200px;
1022 margin-right:20px;
1023 }
1024 #svg_preview_panel svg {
1025 width: auto;
1026 height: 120px;
1027 }
1028 #select_icons .read_icons {
1029 width: 75px;
1030 height: 75px;
1031 border: 1px solid #ccc;
1032 border-radius: 4px;
1033 padding: 5px;
1034 margin: 5px;
1035 display: flex;
1036 align-items: center;
1037 justify-content: center;
1038 cursor: pointer;
1039 transition: border 0.3s;
1040 }
1041 #select_icons .read_icons.active {
1042 border: 1px solid #007cba;
1043 }
1044 #select_icons .read_icons svg {
1045 width: 65px;
1046 }
1047
1048 #wpgmp-icon-controls .wpgmp-icon-control-list {
1049 display: flex;
1050 flex-direction: column;
1051 gap: 15px;
1052 }
1053 #wpgmp-icon-controls .wpgmp-icon-control-item {
1054 display: flex;
1055 align-items: center;
1056 gap: 20px;
1057 }
1058
1059 #wpgmp-icon-controls .wpgmp-icon-control-item label {
1060 font-weight: bold;
1061 min-width: 80px;
1062 }
1063
1064 .fc-quick-filter {
1065 display: flex;
1066 flex-wrap: wrap;
1067 align-items: center;
1068 gap: 10px;
1069 margin-bottom: 20px;
1070 }
1071
1072 .fc-quick-filter > label {
1073 display: inline-block;
1074 font-size: 14px;
1075 font-weight: 600;
1076 }
1077 .fc-quick-filter > .fc-filter-menu {
1078 background-color: color-mix(in srgb, #4390ff 15%, transparent);
1079 color: #4390ff;
1080 padding: 4px 12px 6px;
1081 font-size: 12px;
1082 font-weight: 500;
1083 border-radius: 6px;
1084 cursor: pointer;
1085 transition: all 0.2s ease;
1086 }
1087
1088 .fc-quick-filter > .fc-filter-menu:is(:hover, :focus, .active) {
1089 background-color: #4390ff;
1090 color: #fff;
1091 }
1092
1093 </style>
1094
1095 <script type="text/javascript">
1096 jQuery(document).ready(function($) {
1097 let selectedSVG = '';
1098
1099 $(document).on("click", ".read_icons", function () {
1100 $(".read_icons").removeClass('active');
1101 $(this).addClass('active');
1102 //selectedSVG = $(this).find('svg').prop('outerHTML');
1103 selectedSVG = $(this).find('svg').clone();
1104 updatePreview();
1105 });
1106
1107 $('#icon_fill_color, #icon_stroke_color, #icon_stroke_width').on('input', updatePreview);
1108
1109 function updatePreview() {
1110 if (!selectedSVG) return;
1111
1112 const fillColor = $('#icon_fill_color').val();
1113 const strokeColor = $('#icon_stroke_color').val();
1114 const strokeWidth = $('#icon_stroke_width').val();
1115
1116 // Clone fresh copy each time
1117 const $svgClone = selectedSVG.clone();
1118 // Generate a unique ID to prefix class names
1119 const uniqueId = 'svg_' + Math.random().toString(36).substr(2, 6);
1120
1121 // Prefix all class names in the SVG
1122 $svgClone.find('[class]').each(function () {
1123 const classList = $(this).attr('class').split(/\s+/).map(cls => `${uniqueId}-${cls}`);
1124 $(this).attr('class', classList.join(' '));
1125 });
1126
1127 // Update <style> block: prefix selectors and apply fill/stroke
1128 const $styleTag = $svgClone.find('style');
1129 if ($styleTag.length) {
1130 let css = $styleTag.html();
1131
1132 // Prefix all class selectors like `.st0` => `.svg_xyz-st0`
1133 css = css.replace(/\.(\w[\w-]*)/g, `.${uniqueId}-$1`);
1134
1135 // Then update fill, stroke, and stroke-width inside CSS
1136 css = css
1137 .replace(/fill\s*:\s*[^;]+/gi, `fill: ${fillColor}`)
1138 .replace(/stroke\s*:\s*[^;]+/gi, `stroke: ${strokeColor}`)
1139 .replace(/stroke-width\s*:\s*[^;]+/gi, `stroke-width: ${strokeWidth}`);
1140
1141 $styleTag.html(css);
1142 }
1143
1144 // Also update inline attributes just in case
1145 $svgClone.find('[fill]').attr('fill', fillColor);
1146 $svgClone.find('[stroke]').attr('stroke', strokeColor);
1147 $svgClone.find('[stroke-width]').attr('stroke-width', strokeWidth);
1148
1149 // Render to preview
1150 $('#svg_preview').html($svgClone);
1151 }
1152
1153 $('.fc-filter-menu').on('click', function () {
1154 const filter = $(this).text().trim().toLowerCase();
1155
1156 $('.fc-filter-menu').removeClass('active');
1157 $(this).addClass('active');
1158
1159 $('#select_icons .read_icons').each(function () {
1160 const title = $(this).data('title').toLowerCase();
1161
1162 if (filter === 'all') {
1163 $(this).show();
1164 } else if (title.includes('alpha') && filter === 'alphabets') {
1165 $(this).show();
1166 } else if (title.includes('digit') && filter === 'digits') {
1167 $(this).show();
1168 } else if (title.includes('shape') && filter === 'shapes') {
1169 $(this).show();
1170 } else {
1171 $(this).hide();
1172 }
1173 });
1174 });
1175
1176 });
1177
1178 function wpgmp_add_icon_to_images(target) {
1179 const svg = jQuery('#svg_preview').html();
1180 if (svg) {
1181 const win = window.dialogArguments || opener || parent || top;
1182 win.send_icon_to_map(svg, target);
1183 } else {
1184 alert('<?php esc_html_e( 'Choose an SVG marker icon.', 'wp-google-map-plugin' ); ?>');
1185 }
1186 }
1187 </script>
1188
1189 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr( $form_action_url ); ?>" class="media-upload-form" id="library-form">
1190 <!-- <div style="display: flex; flex-wrap: wrap; align-items: center; gap: 15px;">
1191 <h3 style="margin: 0;"><?php esc_html_e( 'Choose SVG Icon', 'wp-google-map-plugin' ); ?></h3>
1192 <input name="wpgmp_search_icon" id="wpgmp_search_icon" type='text' placeholder="<?php esc_html_e( 'Search icons', 'wp-google-map-plugin' ); ?>" />
1193 </div> -->
1194
1195 <div class="fc-quick-filter">
1196 <label><?php esc_html_e('Quick Filter:', 'wp-google-map-plugin'); ?></label>
1197 <span class="fc-filter-menu active"><?php esc_html_e('All', 'wp-google-map-plugin'); ?></span>
1198 <span class="fc-filter-menu"><?php esc_html_e('Alphabets', 'wp-google-map-plugin'); ?></span>
1199 <span class="fc-filter-menu"><?php esc_html_e('Digits', 'wp-google-map-plugin'); ?></span>
1200 <span class="fc-filter-menu"><?php esc_html_e('Shapes', 'wp-google-map-plugin'); ?></span>
1201 </div>
1202
1203
1204 <ul style="display: flex; flex-wrap: wrap;" id="select_icons">
1205 <?php
1206 $dir = WPGMP_ICONS_DIR;
1207 $file_display = array('svg');
1208
1209 if (!file_exists($dir)) {
1210 echo '<li>' . esc_html__('Directory not found:', 'wp-google-map-plugin') . ' ' . esc_html($dir) . '</li>';
1211 } else {
1212 $dir_contents = scandir($dir);
1213 foreach ($dir_contents as $file) {
1214 $image_data = explode('.', $file);
1215 $file_type = strtolower(end($image_data));
1216 if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display)) {
1217 $svg_content = file_get_contents($dir . '/' . $file);
1218 echo "<li class='read_icons' data-title='" . esc_attr($image_data[0]) . "'>" . $svg_content . "</li>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1219 }
1220 }
1221 }
1222 $target = isset($_GET['target']) ? esc_js($_GET['target']) : '';
1223 ?>
1224 </ul>
1225
1226 <div id="wpgmp-icon-customizer">
1227 <div id="wpgmp-icon-controls">
1228 <h3><?php esc_html_e('Customize Icon', 'wp-google-map-plugin'); ?></h3>
1229 <div class="wpgmp-icon-control-list">
1230 <div class="wpgmp-icon-control-item">
1231 <label><?php esc_html_e('Fill Color:', 'wp-google-map-plugin'); ?></label>
1232 <input type="color" id="icon_fill_color" value="#D14B4B" />
1233 </div>
1234
1235 <div class="wpgmp-icon-control-item">
1236 <label><?php esc_html_e('Stroke Color:', 'wp-google-map-plugin'); ?></label>
1237 <input type="color" id="icon_stroke_color" value="#000000" />
1238 </div>
1239
1240 <div class="wpgmp-icon-control-item">
1241 <label><?php esc_html_e('Stroke Width:', 'wp-google-map-plugin'); ?></label>
1242 <input type="number" id="icon_stroke_width" style="width:100px" value="0" />
1243 </div>
1244
1245 <div class="wpgmp-icon-control-item">
1246 <button type="button" class="button" onclick="wpgmp_add_icon_to_images('<?php echo esc_attr($target); ?>');">
1247 <?php esc_html_e('Insert into Post', 'wp-google-map-plugin'); ?>
1248 </button>
1249 </div>
1250 </div>
1251 </div>
1252
1253 <div id="svg_preview_panel">
1254 <div id="svg_preview"></div>
1255 </div>
1256 </div>
1257 </form>
1258 <?php
1259 }
1260
1261 /**
1262 * Perform tasks on plugin deactivation.
1263 */
1264 function wpgmp_deactivation() {}
1265
1266 /**
1267 * Perform tasks on plugin deactivation.
1268 */
1269 function wpgmp_activation() {
1270
1271 global $wpdb;
1272
1273 // migrate options data from previous version.
1274 if ( ! get_option( 'wpgmp_settings' ) && get_option( 'wpgmp_language' ) ) {
1275 $wpgmp_settings['wpgmp_language'] = get_option( 'wpgmp_language', 'en' );
1276 $wpgmp_settings['wpgmp_api_key'] = get_option( 'wpgmp_api_key', '' );
1277 $wpgmp_settings['wpgmp_scripts_place'] = get_option( 'wpgmp_scripts_place', true );
1278 $wpgmp_settings['wpgmp_allow_meta'] = get_option( 'wpgmp_allow_meta', true );
1279 $wpgmp_settings['wpgmp_scripts_minify'] = get_option( 'wpgmp_scripts_minify', true );
1280 $wpgmp_settings['wpgmp_version'] = get_option( 'wpgmp_version', WPGMP_VERSION );
1281
1282 update_option( 'wpgmp_settings', $wpgmp_settings );
1283 }else if(! get_option( 'wpgmp_settings' ) && ! get_option( 'wpgmp_language' )){
1284 $wpgmp_settings['wpgmp_language'] = 'en';
1285 $wpgmp_settings['wpgmp_api_key'] = '';
1286 $wpgmp_settings['wpgmp_version'] = WPGMP_VERSION;
1287
1288 update_option( 'wpgmp_settings', $wpgmp_settings );
1289 }
1290
1291
1292 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
1293
1294 $modules = $this->modules;
1295 $pagehooks = array();
1296 $tables = array();
1297 if ( is_array( $modules ) ) {
1298 foreach ( $modules as $module ) {
1299 $object = new $module();
1300 if ( method_exists( $object, 'install' ) ) {
1301 $tables[] = $object->install();
1302 }
1303 }
1304 }
1305
1306 $tables = array_filter($tables);
1307 if ( is_array( $tables ) ) {
1308 foreach ( $tables as $i => $sql ) {
1309 dbDelta( $sql );
1310 }
1311 }
1312
1313 $this->wpgmp_set_extrafields();
1314 }
1315
1316 /**
1317 * Eneque scripts at backend overview page only.
1318 */
1319 function wpgmp_overview_page_styles( $hook ) {
1320 if($hook == 'plugins.php'){
1321 wp_enqueue_style('wpgmp-modal-css', plugin_dir_url(__FILE__) . 'assets/css/modal.css');
1322 if(function_exists('wpgmp_add_feedback_form')){
1323 wpgmp_add_feedback_form();
1324 }
1325 }
1326
1327 }
1328
1329 public static function wpgmp_set_extrafields(){
1330
1331 $extra_field_val = get_option( 'wpgmp_settings', true );
1332
1333 if(!isset($extra_field_val['wpgmp_extrafield_val'])){
1334 $modelFactory = new WPGMP_Model();
1335 $location_obj = $modelFactory->create_object( 'location' );
1336 $map_locations = $location_obj->fetch();
1337 if( !empty( $map_locations ) ){
1338 $extra_field_val['wpgmp_extrafield_val'] = array();
1339 foreach($map_locations as $loc_val){
1340 if(isset($loc_val->location_extrafields) && !empty($loc_val->location_extrafields)){
1341 foreach($loc_val->location_extrafields as $ex_key => $ex_val){
1342 if(!isset($extra_field_val['wpgmp_extrafield_val'][$ex_key])){
1343 $extra_field_val['wpgmp_extrafield_val'][$ex_key] = array();
1344 if(!empty($ex_val)){
1345 $extra_val_impolode = array_map('trim',explode(',', $ex_val));
1346 $extra_field_val['wpgmp_extrafield_val'][$ex_key] = $extra_val_impolode;
1347 }
1348 }else{
1349
1350 if(empty($extra_field_val['wpgmp_extrafield_val'][$ex_key])){
1351 if(!empty($ex_val)){
1352 $extra_val_impolode = array_map('trim',explode(',', $ex_val));
1353 $extra_field_val['wpgmp_extrafield_val'][$ex_key] = $extra_val_impolode;
1354 }
1355 }else{
1356 if(!empty($ex_val)){
1357 $extra_val_impolode = array_map('trim',explode(',', $ex_val));
1358 $temp_store = $extra_field_val['wpgmp_extrafield_val'][$ex_key];
1359 foreach($extra_val_impolode as $ev_val){
1360 if (!in_array(strtolower($ev_val), array_map('strtolower', $temp_store))) {
1361 $extra_field_val['wpgmp_extrafield_val'][$ex_key][] = $ev_val;
1362 }
1363 }
1364 }
1365
1366 }
1367
1368 }
1369 }
1370
1371 }
1372
1373 }
1374 }
1375
1376 update_option( 'wpgmp_settings', $extra_field_val );
1377 }
1378
1379 }
1380
1381 /**
1382 * Define all plugin constants.
1383 */
1384 private function wpgmp_define( $name, $value ) {
1385 if ( ! defined( $name ) ) {
1386 define( $name, $value );
1387 }
1388 }
1389
1390 /**
1391 * Function calls to define constants.
1392 */
1393 private function wpgmp_define_constants() {
1394
1395 global $wpdb;
1396
1397 if ( is_admin() )
1398 $this->wpgmp_define( 'WPGMP_SLUG', 'wpgmp_view_overview' );
1399 $this->wpgmp_define( 'WPGMP_VERSION', '4.9.7' );
1400 $this->wpgmp_define( 'WPGMP_FOLDER', basename( dirname( __FILE__ ) ) );
1401 $this->wpgmp_define( 'WPGMP_DIR', plugin_dir_path( __FILE__ ) );
1402 $this->wpgmp_define( 'WPGMP_ICONS_DIR', WPGMP_DIR . '/assets/images/icons/' );
1403 $this->wpgmp_define( 'WPGMP_CORE_CLASSES', WPGMP_DIR . 'core/' );
1404 $this->wpgmp_define( 'WPGMP_PLUGIN_CLASSES', WPGMP_DIR . 'classes/' );
1405 $this->wpgmp_define( 'WPGMP_TEMPLATES', WPGMP_DIR . 'templates/' );
1406 $this->wpgmp_define( 'WPGMP_MODEL', WPGMP_DIR . 'modules/' );
1407 $this->wpgmp_define( 'WPGMP_CONTROLLER', WPGMP_CORE_CLASSES );
1408 $this->wpgmp_define( 'WPGMP_URL', plugin_dir_url( WPGMP_FOLDER ) . WPGMP_FOLDER . '/' );
1409 $this->wpgmp_define( 'WPGMP_TEMPLATES_URL', WPGMP_URL . 'templates/' );
1410 $this->wpgmp_define( 'WPGMP_CSS', WPGMP_URL . 'assets/css/' );
1411 $this->wpgmp_define( 'WPGMP_JS', WPGMP_URL . 'assets/js/' );
1412 $this->wpgmp_define( 'WPGMP_IMAGES', WPGMP_URL . 'assets/images/' );
1413 $this->wpgmp_define( 'WPGMP_ICONS', WPGMP_URL . 'assets/images/icons/' );
1414 $this->wpgmp_define( 'TBL_LOCATION', $wpdb->prefix . 'map_locations' );
1415 $this->wpgmp_define( 'TBL_GROUPMAP', $wpdb->prefix . 'group_map' );
1416 $this->wpgmp_define( 'TBL_MAP', $wpdb->prefix . 'create_map' );
1417 $this->wpgmp_define( 'TBL_ROUTES', $wpdb->prefix . 'map_routes' );
1418
1419 }
1420
1421 public static function wpgmp_get_version_number(){ return WPGMP_VERSION; }
1422
1423
1424 /**
1425 * Load all required core classes.
1426 */
1427 private function wpgmp_load_files() {
1428
1429 $coreInitialisationFile = plugin_dir_path( __FILE__ ) . 'core/class.initiate-core.php';
1430 if ( file_exists( $coreInitialisationFile ) ) {
1431 require_once $coreInitialisationFile;
1432 }
1433
1434 // Load Plugin Files
1435 $plugin_files_to_include = array(
1436 'wpgmp-security.php',
1437 'wpgmp-pro-feature-ui.php',
1438 'wpgmp-integration-form.php',
1439 'wpgmp-helper.php',
1440 'wpgmp-template.php',
1441 'wpgmp-controller.php',
1442 'wpgmp-model.php',
1443 'wpgmp-map-widget.php',
1444 'wpgmp-check-cookies.php',
1445 'wpgmp-temp-access.php',
1446 'wpgmp-feedback-form.php'
1447 );
1448
1449 foreach ( $plugin_files_to_include as $file ) {
1450
1451 if ( file_exists( WPGMP_PLUGIN_CLASSES . $file ) ) {
1452 require_once WPGMP_PLUGIN_CLASSES . $file;
1453 }
1454 }
1455 // Load all modules.
1456 $core_modules = array( 'overview', 'group_map','location', 'map', 'route', 'drawing', 'permissions', 'settings', 'tools', 'post', 'extentions','integration' );
1457
1458 $core_modules = apply_filters('wpgmp_modules_to_load',$core_modules);
1459
1460 if ( is_array( $core_modules ) ) {
1461 foreach ( $core_modules as $module ) {
1462
1463 $file = WPGMP_MODEL . $module . '/model.' . $module . '.php';
1464 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
1465 $file = apply_filters('fc_backend_module_path_load', $file ,$module );
1466
1467 if ( file_exists( $file ) ) {
1468 include_once $file;
1469 $class_name = 'WPGMP_Model_' . ucwords( $module );
1470 array_push( $this->modules, $class_name );
1471 }
1472 }
1473 }
1474
1475 }
1476 }
1477 }
1478
1479 new WPGMP_Google_Maps_Lite();