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

1,448 lines 45.5 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.3
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 $operation = sanitize_text_field( wp_unslash( $_POST['operation'] ) );
609 $value = wp_unslash( $_POST );
610 if ( isset( $operation ) ) {
611 $this->$operation( $value );
612 }
613 exit;
614 }
615
616 /**
617 * Process slug and display view in the backend.
618 */
619 function wpgmp_processor() {
620
621 $return = '';
622 $page = ( isset( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : 'wpgmp_view_overview';
623 $pageData = explode( '_', $page );
624 $obj_type = $pageData[2];
625 $obj_operation = $pageData[1];
626
627 if ( count( $pageData ) < 3 ) { die( 'Cheating!' ); }
628
629 try {
630
631 if ( count( $pageData ) > 3 ) {
632 $obj_type = $pageData[2] . '_' . $pageData[3];
633 }
634 $factoryObject = new WPGMP_Controller();
635 $viewObject = $factoryObject->create_object( $obj_type , $factoryObject);
636 $viewObject->display( $obj_operation );
637
638 } catch ( Exception $e ) {
639 echo wp_kses_post( WPGMP_Template::show_message( array( 'error' => $e->getMessage() ) ) );
640
641 }
642
643 }
644
645 public function wpgmp_add_plugin_row_custom_link( $links, $file ){
646
647 if ( strpos( $file, basename(__FILE__) ) ) {
648
649 $links[] = '<a href="https://www.wpmapspro.com/tutorials/" target="_blank" title="WP Maps Docs">'.esc_html__('Docs','wp-google-map-plugin').'</a>';
650 $links[] = '<a href="https://www.wpmapspro.com/map-hooks/" target="_blank" title="WP Maps Developer Hooks">'.esc_html__('Hooks','wp-google-map-plugin').'</a>';
651 $links[] = '<a href="https://weplugins.com/support/" target="_blank" title="WP Maps Support">'.esc_html__('Support','wp-google-map-plugin').'</a>';
652 $links[] = '<a href="https://weplugins.com/contact/" target="_blank" title="WP Maps Customisation">'.esc_html__('Customisation','wp-google-map-plugin').'</a>';
653 $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>';
654
655 }
656 return $links;
657 }
658
659 function wpgmp_plugin_settings_link($actions) {
660
661 $actions['settings'] = '<a href="' . admin_url( 'admin.php?page=wpgmp_manage_settings' ) . '">'.esc_html__( 'Settings', 'wp-google-map-plugin' ).'</a>';
662
663 return $actions;
664 }
665
666 /**
667 * Create backend navigation.
668 */
669 function wpgmp_create_menu() {
670
671 global $navigations;
672
673 $pagehook1 = add_menu_page(
674 esc_html__( 'WP MAPS', 'wp-google-map-plugin' ),
675 esc_html__( 'WP MAPS', 'wp-google-map-plugin' ),
676 'wpgmp_admin_overview',
677 WPGMP_SLUG,
678 array( $this, 'wpgmp_processor' ),
679 WPGMP_IMAGES . '/fc-small-logo.png'
680 );
681
682 if ( current_user_can( 'manage_options' ) ) {
683 $role = get_role( 'administrator' );
684 $role->add_cap( 'wpgmp_admin_overview' );
685 }
686
687 $this->wpgmp_load_modules_menu();
688 add_action( 'load-' . $pagehook1, array( $this, 'wpgmp_backend_scripts' ) );
689
690 }
691 /**
692 * Read models and create backend navigation.
693 */
694 function wpgmp_load_modules_menu() {
695
696 $modules = $this->modules;
697 $pagehooks = array();
698 if ( is_array( $modules ) ) {
699 foreach ( $modules as $module ) {
700
701 $object = new $module();
702
703 if ( method_exists( $object, 'navigation' ) ) {
704
705 if ( ! is_array( $object->navigation() ) ) {
706 continue;
707 }
708
709 foreach ( $object->navigation() as $nav => $title ) {
710
711 if ( current_user_can( 'manage_options' ) && is_admin() ) {
712 $role = get_role( 'administrator' );
713 $role->add_cap( $nav );
714
715 }
716
717 $pagehooks[] = add_submenu_page(
718 WPGMP_SLUG,
719 $title,
720 $title,
721 $nav,
722 $nav,
723 array( $this, 'wpgmp_processor' ),
724 100
725 );
726
727 }
728 }
729 }
730 }
731
732 if ( is_array( $pagehooks ) ) {
733
734 foreach ( $pagehooks as $key => $pagehook ) {
735 add_action( 'load-' . $pagehooks[ $key ], array( $this, 'wpgmp_backend_scripts' ) );
736 }
737 }
738
739 }
740 /**
741 * Eneque scripts in the backend.
742 */
743 function wpgmp_backend_scripts() {
744
745 WPGMP_Helper::wpgmp_register_map_backend_resources();
746 }
747
748 /**
749 * Load plugin language file.
750 */
751 function wpgmp_load_plugin_languages() {
752
753 $this->modules = apply_filters( 'wpgmp_extensions', $this->modules );
754 load_plugin_textdomain( 'wp-google-map-plugin', false, WPGMP_FOLDER . '/lang/' );
755 }
756 /**
757 * Call hook on plugin activation for both multi-site and single-site.
758 */
759 function wpgmp_plugin_activation( $network_wide ) {
760
761 if ( is_multisite() && $network_wide ) {
762 global $wpdb;
763 $currentblog = $wpdb->blogid;
764 $activated = array();
765 $blog_ids = $wpdb->get_col(
766 $wpdb->prepare( "SELECT blog_id FROM {$wpdb->blogs}" )
767 );
768
769 foreach ( $blog_ids as $blog_id ) {
770 switch_to_blog( $blog_id );
771 $this->wpgmp_activation();
772 $activated[] = $blog_id;
773 }
774
775 switch_to_blog( $currentblog );
776 update_site_option( 'op_activated', $activated );
777
778 } else {
779 $this->wpgmp_activation();
780 }
781
782 if (class_exists('WePlugins_Notification')) {
783 WePlugins_Notification::schedule_cron();
784 }
785 }
786 /**
787 * Call hook on plugin deactivation for both multi-site and single-site.
788 */
789 function wpgmp_plugin_deactivation() {
790
791 if ( is_multisite() && $network_wide ) {
792 global $wpdb;
793 $currentblog = $wpdb->blogid;
794 $activated = array();
795 $blog_ids = $wpdb->get_col(
796 $wpdb->prepare( "SELECT blog_id FROM {$wpdb->blogs}" )
797 );
798
799 foreach ( $blog_ids as $blog_id ) {
800 switch_to_blog( $blog_id );
801 $this->wpgmp_deactivation();
802 $activated[] = $blog_id;
803 }
804
805 switch_to_blog( $currentblog );
806 update_site_option( 'op_activated', $activated );
807
808 } else {
809 $this->wpgmp_deactivation();
810 }
811
812 if (class_exists('WePlugins_Notification')) {
813 WePlugins_Notification::deactivate_cron();
814 }
815 }
816
817 /**
818 * Perform tasks on new blog create and table install.
819 */
820
821 function wpgmp_on_blog_new_generate( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
822
823 if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
824 switch_to_blog( $blog_id );
825 $this->wpgmp_activation();
826 restore_current_blog();
827 }
828
829 }
830
831 /**
832 * Perform tasks on when blog deleted and remove plugin tables.
833 */
834
835 function wpgmp_on_blog_delete( $tables ) {
836 global $wpdb;
837 $tables[] = str_replace( $wpdb->base_prefix, $wpdb->prefix, TBL_LOCATION );
838 $tables[] = str_replace( $wpdb->base_prefix, $wpdb->prefix, TBL_GROUPMAP );
839 $tables[] = str_replace( $wpdb->base_prefix, $wpdb->prefix, TBL_MAP );
840 $tables[] = str_replace( $wpdb->base_prefix, $wpdb->prefix, TBL_ROUTES );
841 return $tables;
842 }
843 /**
844 * Create choose icon tab in media manager.
845 *
846 * @param array $tabs Current Tabs.
847 * @return array New Tabs.
848 */
849 function wpgmp_google_map_tabs_filter( $tabs ) {
850
851 $newtab = array( 'ell_insert_gmap_tab' => esc_html__( 'Choose Icons', 'wp-google-map-plugin' ),
852 'ell_insert_gmap_svg_tab' => esc_html__( 'SVG Icons', 'wp-google-map-plugin' ) );
853
854 return array_merge( $tabs, $newtab );
855 }
856 /**
857 * Intialize wp_iframe for icons tab
858 *
859 * @return [type] [description]
860 */
861 function wpgmp_google_map_media_upload_tab() {
862
863 return wp_iframe( array( $this, 'media_wpgmp_google_map_icon' ), array() );
864 }
865
866 /**
867 * Intialize wp_iframe for svg icons tab
868 *
869 * @return [type] [description]
870 */
871 function wpgmp_google_map_media_upload_svg_tab() {
872
873 return wp_iframe( array( $this, 'media_wpgmp_google_map_svg_icon' ), array() );
874 }
875 /**
876 * Read images/icons folder.
877 */
878 function media_wpgmp_google_map_icon() {
879
880 wp_enqueue_style( 'media' );
881 media_upload_header();
882 $form_action_url = site_url( "wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=ell_insert_gmap_tab", 'admin' );
883 ?>
884
885 <style type="text/css">
886 #select_icons .read_icons {width: 32px;height: 32px;}
887 #select_icons .active img {border: 3px solid #000;width: 26px;}
888 </style>
889
890 <script type="text/javascript">
891
892 jQuery(document).ready(function($) {
893
894 $(".read_icons").click(function () {
895 $(".read_icons").removeClass('active');
896 $(this).addClass('active');
897 });
898
899 $('input[name="wpgmp_search_icon"]').keyup(function() {
900 if($(this).val() == '')
901 $('.read_icons').show();
902 else {
903 $('.read_icons').hide();
904 $('img[title^="' + $(this).val() + '"]').parent().show();
905 }
906
907 });
908
909 });
910
911
912
913 function wpgmp_add_icon_to_images(target) {
914
915 if(jQuery('.read_icons').hasClass('active')) {
916 imgsrc = jQuery('.active').find('img').attr('src');
917 var win = window.dialogArguments || opener || parent || top;
918 win.send_icon_to_map(imgsrc,target);
919 }else{
920 alert('<?php esc_html_e( 'Choose marker icon', 'wp-google-map-plugin' ); ?>');
921 }
922 }
923 </script>
924 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr( $form_action_url ); ?>" class="media-upload-form" id="library-form">
925 <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' ); ?>" />
926 </h3>
927 <div style="margin-bottom:20px; float:left; width:100%;">
928 <ul style="float:left; width:100%;" id="select_icons">
929 <?php
930 $dir = WPGMP_ICONS_DIR;
931 $file_display = array( 'jpg', 'jpeg', 'png', 'gif' );
932
933 if ( file_exists( $dir ) == false ) {
934 echo 'Directory \'', esc_html( $dir ), '\' not found!';
935
936 } else {
937 $dir_contents = scandir( $dir );
938 foreach ( $dir_contents as $file ) {
939 $image_data = explode( '.', $file );
940 $file_type = strtolower( end( $image_data ) );
941 if ( '.' !== $file && '..' !== $file && true == in_array( $file_type, $file_display ) ) {
942 ?>
943 <li class="read_icons" style="float:left;">
944 <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;" />
945 </li>
946 <?php
947 }
948 }
949 }
950
951 if ( isset( $_GET['target'] ) ) {
952 $target = esc_js( $_GET['target'] );
953 } else {
954 $target = '';
955 }
956
957 ?>
958 </ul>
959 <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>
960 </div>
961 </form>
962 <?php
963 }
964
965 function media_wpgmp_google_map_svg_icon() {
966 wp_enqueue_style( 'media' );
967 media_upload_header();
968 $form_action_url = site_url( "wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=ell_insert_gmap_svg_tab", 'admin' );
969 ?>
970
971 <style type="text/css">
972 #wpgmp-icon-customizer {
973 display: flex;
974 gap: 20px;
975 padding-block: 20px;
976 }
977 #wpgmp-icon-controls {
978 flex: 1;
979 }
980 #svg_preview_panel {
981 display: flex;
982 flex-direction: column;
983 align-items: center;
984 justify-content: center;
985 flex-shrink: 0;
986 border: 1px solid #ddd;
987 padding: 15px;
988 background: #f9f9f9;
989 text-align: center;
990 width: 200px;
991 margin-right:20px;
992 }
993 #svg_preview_panel svg {
994 width: auto;
995 height: 120px;
996 }
997 #select_icons .read_icons {
998 width: 75px;
999 height: 75px;
1000 border: 1px solid #ccc;
1001 border-radius: 4px;
1002 padding: 5px;
1003 margin: 5px;
1004 display: flex;
1005 align-items: center;
1006 justify-content: center;
1007 cursor: pointer;
1008 transition: border 0.3s;
1009 }
1010 #select_icons .read_icons.active {
1011 border: 1px solid #007cba;
1012 }
1013 #select_icons .read_icons svg {
1014 width: 65px;
1015 }
1016
1017 #wpgmp-icon-controls .wpgmp-icon-control-list {
1018 display: flex;
1019 flex-direction: column;
1020 gap: 15px;
1021 }
1022 #wpgmp-icon-controls .wpgmp-icon-control-item {
1023 display: flex;
1024 align-items: center;
1025 gap: 20px;
1026 }
1027
1028 #wpgmp-icon-controls .wpgmp-icon-control-item label {
1029 font-weight: bold;
1030 min-width: 80px;
1031 }
1032
1033 .fc-quick-filter {
1034 display: flex;
1035 flex-wrap: wrap;
1036 align-items: center;
1037 gap: 10px;
1038 margin-bottom: 20px;
1039 }
1040
1041 .fc-quick-filter > label {
1042 display: inline-block;
1043 font-size: 14px;
1044 font-weight: 600;
1045 }
1046 .fc-quick-filter > .fc-filter-menu {
1047 background-color: color-mix(in srgb, #4390ff 15%, transparent);
1048 color: #4390ff;
1049 padding: 4px 12px 6px;
1050 font-size: 12px;
1051 font-weight: 500;
1052 border-radius: 6px;
1053 cursor: pointer;
1054 transition: all 0.2s ease;
1055 }
1056
1057 .fc-quick-filter > .fc-filter-menu:is(:hover, :focus, .active) {
1058 background-color: #4390ff;
1059 color: #fff;
1060 }
1061
1062 </style>
1063
1064 <script type="text/javascript">
1065 jQuery(document).ready(function($) {
1066 let selectedSVG = '';
1067
1068 $(document).on("click", ".read_icons", function () {
1069 $(".read_icons").removeClass('active');
1070 $(this).addClass('active');
1071 //selectedSVG = $(this).find('svg').prop('outerHTML');
1072 selectedSVG = $(this).find('svg').clone();
1073 updatePreview();
1074 });
1075
1076 $('#icon_fill_color, #icon_stroke_color, #icon_stroke_width').on('input', updatePreview);
1077
1078 function updatePreview() {
1079 if (!selectedSVG) return;
1080
1081 const fillColor = $('#icon_fill_color').val();
1082 const strokeColor = $('#icon_stroke_color').val();
1083 const strokeWidth = $('#icon_stroke_width').val();
1084
1085 // Clone fresh copy each time
1086 const $svgClone = selectedSVG.clone();
1087 // Generate a unique ID to prefix class names
1088 const uniqueId = 'svg_' + Math.random().toString(36).substr(2, 6);
1089
1090 // Prefix all class names in the SVG
1091 $svgClone.find('[class]').each(function () {
1092 const classList = $(this).attr('class').split(/\s+/).map(cls => `${uniqueId}-${cls}`);
1093 $(this).attr('class', classList.join(' '));
1094 });
1095
1096 // Update <style> block: prefix selectors and apply fill/stroke
1097 const $styleTag = $svgClone.find('style');
1098 if ($styleTag.length) {
1099 let css = $styleTag.html();
1100
1101 // Prefix all class selectors like `.st0` => `.svg_xyz-st0`
1102 css = css.replace(/\.(\w[\w-]*)/g, `.${uniqueId}-$1`);
1103
1104 // Then update fill, stroke, and stroke-width inside CSS
1105 css = css
1106 .replace(/fill\s*:\s*[^;]+/gi, `fill: ${fillColor}`)
1107 .replace(/stroke\s*:\s*[^;]+/gi, `stroke: ${strokeColor}`)
1108 .replace(/stroke-width\s*:\s*[^;]+/gi, `stroke-width: ${strokeWidth}`);
1109
1110 $styleTag.html(css);
1111 }
1112
1113 // Also update inline attributes just in case
1114 $svgClone.find('[fill]').attr('fill', fillColor);
1115 $svgClone.find('[stroke]').attr('stroke', strokeColor);
1116 $svgClone.find('[stroke-width]').attr('stroke-width', strokeWidth);
1117
1118 // Render to preview
1119 $('#svg_preview').html($svgClone);
1120 }
1121
1122 $('.fc-filter-menu').on('click', function () {
1123 const filter = $(this).text().trim().toLowerCase();
1124
1125 $('.fc-filter-menu').removeClass('active');
1126 $(this).addClass('active');
1127
1128 $('#select_icons .read_icons').each(function () {
1129 const title = $(this).data('title').toLowerCase();
1130
1131 if (filter === 'all') {
1132 $(this).show();
1133 } else if (title.includes('alpha') && filter === 'alphabets') {
1134 $(this).show();
1135 } else if (title.includes('digit') && filter === 'digits') {
1136 $(this).show();
1137 } else if (title.includes('shape') && filter === 'shapes') {
1138 $(this).show();
1139 } else {
1140 $(this).hide();
1141 }
1142 });
1143 });
1144
1145 });
1146
1147 function wpgmp_add_icon_to_images(target) {
1148 const svg = jQuery('#svg_preview').html();
1149 if (svg) {
1150 const win = window.dialogArguments || opener || parent || top;
1151 win.send_icon_to_map(svg, target);
1152 } else {
1153 alert('<?php esc_html_e( 'Choose an SVG marker icon.', 'wp-google-map-plugin' ); ?>');
1154 }
1155 }
1156 </script>
1157
1158 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr( $form_action_url ); ?>" class="media-upload-form" id="library-form">
1159 <!-- <div style="display: flex; flex-wrap: wrap; align-items: center; gap: 15px;">
1160 <h3 style="margin: 0;"><?php esc_html_e( 'Choose SVG Icon', 'wp-google-map-plugin' ); ?></h3>
1161 <input name="wpgmp_search_icon" id="wpgmp_search_icon" type='text' placeholder="<?php esc_html_e( 'Search icons', 'wp-google-map-plugin' ); ?>" />
1162 </div> -->
1163
1164 <div class="fc-quick-filter">
1165 <label><?php esc_html_e('Quick Filter:', 'wp-google-map-plugin'); ?></label>
1166 <span class="fc-filter-menu active"><?php esc_html_e('All', 'wp-google-map-plugin'); ?></span>
1167 <span class="fc-filter-menu"><?php esc_html_e('Alphabets', 'wp-google-map-plugin'); ?></span>
1168 <span class="fc-filter-menu"><?php esc_html_e('Digits', 'wp-google-map-plugin'); ?></span>
1169 <span class="fc-filter-menu"><?php esc_html_e('Shapes', 'wp-google-map-plugin'); ?></span>
1170 </div>
1171
1172
1173 <ul style="display: flex; flex-wrap: wrap;" id="select_icons">
1174 <?php
1175 $dir = WPGMP_ICONS_DIR;
1176 $file_display = array('svg');
1177
1178 if (!file_exists($dir)) {
1179 echo '<li>' . esc_html__('Directory not found:', 'wp-google-map-plugin') . ' ' . esc_html($dir) . '</li>';
1180 } else {
1181 $dir_contents = scandir($dir);
1182 foreach ($dir_contents as $file) {
1183 $image_data = explode('.', $file);
1184 $file_type = strtolower(end($image_data));
1185 if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display)) {
1186 $svg_content = file_get_contents($dir . '/' . $file);
1187 echo "<li class='read_icons' data-title='" . esc_attr($image_data[0]) . "'>" . $svg_content . "</li>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1188 }
1189 }
1190 }
1191 $target = isset($_GET['target']) ? esc_js($_GET['target']) : '';
1192 ?>
1193 </ul>
1194
1195 <div id="wpgmp-icon-customizer">
1196 <div id="wpgmp-icon-controls">
1197 <h3><?php esc_html_e('Customize Icon', 'wp-google-map-plugin'); ?></h3>
1198 <div class="wpgmp-icon-control-list">
1199 <div class="wpgmp-icon-control-item">
1200 <label><?php esc_html_e('Fill Color:', 'wp-google-map-plugin'); ?></label>
1201 <input type="color" id="icon_fill_color" value="#D14B4B" />
1202 </div>
1203
1204 <div class="wpgmp-icon-control-item">
1205 <label><?php esc_html_e('Stroke Color:', 'wp-google-map-plugin'); ?></label>
1206 <input type="color" id="icon_stroke_color" value="#000000" />
1207 </div>
1208
1209 <div class="wpgmp-icon-control-item">
1210 <label><?php esc_html_e('Stroke Width:', 'wp-google-map-plugin'); ?></label>
1211 <input type="number" id="icon_stroke_width" style="width:100px" value="0" />
1212 </div>
1213
1214 <div class="wpgmp-icon-control-item">
1215 <button type="button" class="button" onclick="wpgmp_add_icon_to_images('<?php echo esc_attr($target); ?>');">
1216 <?php esc_html_e('Insert into Post', 'wp-google-map-plugin'); ?>
1217 </button>
1218 </div>
1219 </div>
1220 </div>
1221
1222 <div id="svg_preview_panel">
1223 <div id="svg_preview"></div>
1224 </div>
1225 </div>
1226 </form>
1227 <?php
1228 }
1229
1230 /**
1231 * Perform tasks on plugin deactivation.
1232 */
1233 function wpgmp_deactivation() {}
1234
1235 /**
1236 * Perform tasks on plugin deactivation.
1237 */
1238 function wpgmp_activation() {
1239
1240 global $wpdb;
1241
1242 // migrate options data from previous version.
1243 if ( ! get_option( 'wpgmp_settings' ) && get_option( 'wpgmp_language' ) ) {
1244 $wpgmp_settings['wpgmp_language'] = get_option( 'wpgmp_language', 'en' );
1245 $wpgmp_settings['wpgmp_api_key'] = get_option( 'wpgmp_api_key', '' );
1246 $wpgmp_settings['wpgmp_scripts_place'] = get_option( 'wpgmp_scripts_place', true );
1247 $wpgmp_settings['wpgmp_allow_meta'] = get_option( 'wpgmp_allow_meta', true );
1248 $wpgmp_settings['wpgmp_scripts_minify'] = get_option( 'wpgmp_scripts_minify', true );
1249 $wpgmp_settings['wpgmp_version'] = get_option( 'wpgmp_version', WPGMP_VERSION );
1250
1251 update_option( 'wpgmp_settings', $wpgmp_settings );
1252 }else if(! get_option( 'wpgmp_settings' ) && ! get_option( 'wpgmp_language' )){
1253 $wpgmp_settings['wpgmp_language'] = 'en';
1254 $wpgmp_settings['wpgmp_api_key'] = '';
1255 $wpgmp_settings['wpgmp_version'] = WPGMP_VERSION;
1256
1257 update_option( 'wpgmp_settings', $wpgmp_settings );
1258 }
1259
1260
1261 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
1262
1263 $modules = $this->modules;
1264 $pagehooks = array();
1265 $tables = array();
1266 if ( is_array( $modules ) ) {
1267 foreach ( $modules as $module ) {
1268 $object = new $module();
1269 if ( method_exists( $object, 'install' ) ) {
1270 $tables[] = $object->install();
1271 }
1272 }
1273 }
1274
1275 $tables = array_filter($tables);
1276 if ( is_array( $tables ) ) {
1277 foreach ( $tables as $i => $sql ) {
1278 dbDelta( $sql );
1279 }
1280 }
1281
1282 $this->wpgmp_set_extrafields();
1283 }
1284
1285 /**
1286 * Eneque scripts at backend overview page only.
1287 */
1288 function wpgmp_overview_page_styles( $hook ) {
1289 if($hook == 'plugins.php'){
1290 wp_enqueue_style('wpgmp-modal-css', plugin_dir_url(__FILE__) . 'assets/css/modal.css');
1291 if(function_exists('wpgmp_add_feedback_form')){
1292 wpgmp_add_feedback_form();
1293 }
1294 }
1295
1296 }
1297
1298 public static function wpgmp_set_extrafields(){
1299
1300 $extra_field_val = get_option( 'wpgmp_settings', true );
1301
1302 if(!isset($extra_field_val['wpgmp_extrafield_val'])){
1303 $modelFactory = new WPGMP_Model();
1304 $location_obj = $modelFactory->create_object( 'location' );
1305 $map_locations = $location_obj->fetch();
1306 if( !empty( $map_locations ) ){
1307 $extra_field_val['wpgmp_extrafield_val'] = array();
1308 foreach($map_locations as $loc_val){
1309 if(isset($loc_val->location_extrafields) && !empty($loc_val->location_extrafields)){
1310 foreach($loc_val->location_extrafields as $ex_key => $ex_val){
1311 if(!isset($extra_field_val['wpgmp_extrafield_val'][$ex_key])){
1312 $extra_field_val['wpgmp_extrafield_val'][$ex_key] = array();
1313 if(!empty($ex_val)){
1314 $extra_val_impolode = array_map('trim',explode(',', $ex_val));
1315 $extra_field_val['wpgmp_extrafield_val'][$ex_key] = $extra_val_impolode;
1316 }
1317 }else{
1318
1319 if(empty($extra_field_val['wpgmp_extrafield_val'][$ex_key])){
1320 if(!empty($ex_val)){
1321 $extra_val_impolode = array_map('trim',explode(',', $ex_val));
1322 $extra_field_val['wpgmp_extrafield_val'][$ex_key] = $extra_val_impolode;
1323 }
1324 }else{
1325 if(!empty($ex_val)){
1326 $extra_val_impolode = array_map('trim',explode(',', $ex_val));
1327 $temp_store = $extra_field_val['wpgmp_extrafield_val'][$ex_key];
1328 foreach($extra_val_impolode as $ev_val){
1329 if (!in_array(strtolower($ev_val), array_map('strtolower', $temp_store))) {
1330 $extra_field_val['wpgmp_extrafield_val'][$ex_key][] = $ev_val;
1331 }
1332 }
1333 }
1334
1335 }
1336
1337 }
1338 }
1339
1340 }
1341
1342 }
1343 }
1344
1345 update_option( 'wpgmp_settings', $extra_field_val );
1346 }
1347
1348 }
1349
1350 /**
1351 * Define all plugin constants.
1352 */
1353 private function wpgmp_define( $name, $value ) {
1354 if ( ! defined( $name ) ) {
1355 define( $name, $value );
1356 }
1357 }
1358
1359 /**
1360 * Function calls to define constants.
1361 */
1362 private function wpgmp_define_constants() {
1363
1364 global $wpdb;
1365
1366 if ( is_admin() )
1367 $this->wpgmp_define( 'WPGMP_SLUG', 'wpgmp_view_overview' );
1368 $this->wpgmp_define( 'WPGMP_VERSION', '4.9.3' );
1369 $this->wpgmp_define( 'WPGMP_FOLDER', basename( dirname( __FILE__ ) ) );
1370 $this->wpgmp_define( 'WPGMP_DIR', plugin_dir_path( __FILE__ ) );
1371 $this->wpgmp_define( 'WPGMP_ICONS_DIR', WPGMP_DIR . '/assets/images/icons/' );
1372 $this->wpgmp_define( 'WPGMP_CORE_CLASSES', WPGMP_DIR . 'core/' );
1373 $this->wpgmp_define( 'WPGMP_PLUGIN_CLASSES', WPGMP_DIR . 'classes/' );
1374 $this->wpgmp_define( 'WPGMP_TEMPLATES', WPGMP_DIR . 'templates/' );
1375 $this->wpgmp_define( 'WPGMP_MODEL', WPGMP_DIR . 'modules/' );
1376 $this->wpgmp_define( 'WPGMP_CONTROLLER', WPGMP_CORE_CLASSES );
1377 $this->wpgmp_define( 'WPGMP_URL', plugin_dir_url( WPGMP_FOLDER ) . WPGMP_FOLDER . '/' );
1378 $this->wpgmp_define( 'WPGMP_TEMPLATES_URL', WPGMP_URL . 'templates/' );
1379 $this->wpgmp_define( 'WPGMP_CSS', WPGMP_URL . 'assets/css/' );
1380 $this->wpgmp_define( 'WPGMP_JS', WPGMP_URL . 'assets/js/' );
1381 $this->wpgmp_define( 'WPGMP_IMAGES', WPGMP_URL . 'assets/images/' );
1382 $this->wpgmp_define( 'WPGMP_ICONS', WPGMP_URL . 'assets/images/icons/' );
1383 $this->wpgmp_define( 'TBL_LOCATION', $wpdb->prefix . 'map_locations' );
1384 $this->wpgmp_define( 'TBL_GROUPMAP', $wpdb->prefix . 'group_map' );
1385 $this->wpgmp_define( 'TBL_MAP', $wpdb->prefix . 'create_map' );
1386 $this->wpgmp_define( 'TBL_ROUTES', $wpdb->prefix . 'map_routes' );
1387
1388 }
1389
1390 public static function wpgmp_get_version_number(){ return WPGMP_VERSION; }
1391
1392
1393 /**
1394 * Load all required core classes.
1395 */
1396 private function wpgmp_load_files() {
1397
1398 $coreInitialisationFile = plugin_dir_path( __FILE__ ) . 'core/class.initiate-core.php';
1399 if ( file_exists( $coreInitialisationFile ) ) {
1400 require_once $coreInitialisationFile;
1401 }
1402
1403 // Load Plugin Files
1404 $plugin_files_to_include = array(
1405 'wpgmp-security.php',
1406 'wpgmp-pro-feature-ui.php',
1407 'wpgmp-integration-form.php',
1408 'wpgmp-helper.php',
1409 'wpgmp-template.php',
1410 'wpgmp-controller.php',
1411 'wpgmp-model.php',
1412 'wpgmp-map-widget.php',
1413 'wpgmp-check-cookies.php',
1414 'wpgmp-temp-access.php',
1415 'wpgmp-feedback-form.php'
1416 );
1417
1418 foreach ( $plugin_files_to_include as $file ) {
1419
1420 if ( file_exists( WPGMP_PLUGIN_CLASSES . $file ) ) {
1421 require_once WPGMP_PLUGIN_CLASSES . $file;
1422 }
1423 }
1424 // Load all modules.
1425 $core_modules = array( 'overview', 'group_map','location', 'map', 'route', 'drawing', 'permissions', 'settings', 'tools', 'post', 'extentions','integration' );
1426
1427 $core_modules = apply_filters('wpgmp_modules_to_load',$core_modules);
1428
1429 if ( is_array( $core_modules ) ) {
1430 foreach ( $core_modules as $module ) {
1431
1432 $file = WPGMP_MODEL . $module . '/model.' . $module . '.php';
1433 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
1434 $file = apply_filters('fc_backend_module_path_load', $file ,$module );
1435
1436 if ( file_exists( $file ) ) {
1437 include_once $file;
1438 $class_name = 'WPGMP_Model_' . ucwords( $module );
1439 array_push( $this->modules, $class_name );
1440 }
1441 }
1442 }
1443
1444 }
1445 }
1446 }
1447
1448 new WPGMP_Google_Maps_Lite();