PluginProbe
WP Maps – Google Maps,OpenStreetMap,Mapbox,Store Locator,Listing,Directory & Filters / trunk
WP Maps – Google Maps,OpenStreetMap,Mapbox,Store Locator,Listing,Directory & Filters vtrunk
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 trunk, at wp-google-map-plugin.php

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