This repository has been archived by the owner on Dec 11, 2017. It is now read-only.
forked from Codeinwp/intergeo-maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
1295 lines (1217 loc) · 51 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: Intergeo Lite - Google Maps Plugin
Plugin URI: http://themeisle.com/plugins/intergeo-maps-lite/
Description: A simple, easy and quite powerful Google Map tool to create, manage and embed custom Google Maps into your WordPress posts and pages. The plugin allows you to deeply customize look and feel of a map, add overlays like markers, rectangles, circles, polylines and polygons to your map. It could even be integraded with your Google Adsense account and show ad on your maps.
Version: 1.1.5
Author: Themeisle
Author URI: http://themeisle.com
License: GPL v2.0 or later
License URI: http://www.opensource.org/licenses/gpl-license.php
Text Domain: intergeo
Domain Path: /languages
*/
// <editor-fold defaultstate="collapsed" desc="constants">
define( 'INTERGEO_PLUGIN_NAME', 'intergeo' ); // don't change it whatever
define( 'INTERGEO_VERSION', '1.1.5' );
define( 'INTERGEO_ABSPATH', dirname( __FILE__ ) );
define( 'INTERGEO_ABSURL', plugins_url( '/', __FILE__ ) );
define( 'INTERGEO_PRO_URL', "http://themeisle.com/plugins/intergeo-maps-pro/" );
// Added by Ash/Upwork
defined( 'WPLANG' ) || define( 'WPLANG', '' );
// Added by Ash/Upwork
// Added by Ash/Upwork
if ( class_exists( 'IntergeoMaps_Pro', false ) ) {
define( 'IntergeoMaps_Pro', true );
}
// Added by Ash/Upwork
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="plugin init">
function im_fs() {
global $im_fs;
if ( ! isset( $im_fs ) ) {
// Include Freemius SDK.
require_once dirname( __FILE__ ) . '/freemius/start.php';
$im_fs = fs_dynamic_init( array(
'id' => '239',
'slug' => 'intergeo-maps',
'public_key' => 'pk_35c86b731f06c8d4ba25b490af632',
'is_premium' => false,
'has_addons' => false,
'has_paid_plans' => false,
'anonymous_mode' => true,
'menu' => array(
'slug' => 'intergeo',
'account' => false,
'support' => false,
'contact' => false,
'parent' => array(
'slug' => 'upload.php',
),
),
) );
}
return $im_fs;
}
// Init Freemius.
im_fs();
add_filter( 'plugin_action_links', 'intergeo_action_links', 10, 2 );
function intergeo_action_links( $links, $file ) {
if ( $file == plugin_basename( __FILE__ ) ) {
array_unshift(
$links,
sprintf( '<a href="%s">%s</a>', add_query_arg( 'page', INTERGEO_PLUGIN_NAME, admin_url( 'upload.php' ) ), __( "Maps", INTERGEO_PLUGIN_NAME ) ),
sprintf( '<a href="%s">%s</a>', admin_url( 'options-media.php' ), __( "Settings", INTERGEO_PLUGIN_NAME ) )
);
}
return $links;
}
add_action( 'admin_init', 'intergeo_admin_init' );
function intergeo_admin_init() {
load_plugin_textdomain( INTERGEO_PLUGIN_NAME, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
register_post_type( INTERGEO_PLUGIN_NAME );
}
add_action( 'wp_enqueue_scripts', 'intergeo_frontend_enqueue_scripts' );
function intergeo_frontend_enqueue_scripts() {
wp_register_style( 'intergeo-frontend', INTERGEO_ABSURL . 'css/frontend.css', array(), INTERGEO_VERSION );
}
add_action( "plugins_loaded", 'intergeo_i18n' );
function intergeo_i18n() {
$pluginDirName = dirname( plugin_basename( __FILE__ ) );
$domain = INTERGEO_PLUGIN_NAME;
$locale = apply_filters( "plugin_locale", get_locale(), $domain );
load_textdomain( $domain, WP_LANG_DIR . "/" . $pluginDirName . "/" . $domain . "-" . $locale . ".mo" );
load_plugin_textdomain( $domain, "", $pluginDirName . "/languages/" );
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="settings">
function intergeo_settings_init() {
if ( isset( $_POST["sb-intergeo"] ) && wp_verify_nonce( $_POST["intergeo-nonce"], "intergeo-settings" ) ) {
update_option( 'intergeo_map_api_key', sanitize_text_field( $_POST['intergeo_map_api_key'] ) );
update_option( 'intergeo_adsense_publisher_id', sanitize_text_field( $_POST['intergeo_adsense_publisher_id'] ) );
}
echo "<form method='post' action=''>";
register_setting( 'intergeo', 'intergeo-settings-map-api-key', 'trim' );
add_settings_section( 'intergeo-settings-maps', __( 'Intergeo Google Maps', INTERGEO_PLUGIN_NAME ), 'intergeo_settings_init_map', INTERGEO_PLUGIN_NAME );
add_settings_field( 'intergeo_map_api_key', __( 'Maps API Key', INTERGEO_PLUGIN_NAME ), 'intergeo_settings_print_field', INTERGEO_PLUGIN_NAME, 'intergeo-settings-maps', array(
'<input type="text" name="%s" value="%s" class="regular-text">',
'intergeo_map_api_key',
esc_attr( get_option( 'intergeo_map_api_key' ) ),
) );
register_setting( 'intergeo', 'intergeo_adsense_publisher_id', 'trim' );
add_settings_section( 'intergeo-settings-adsense', __( 'Intergeo Google Maps AdSense Integration', INTERGEO_PLUGIN_NAME ), 'intergeo_settings_init_adsense', INTERGEO_PLUGIN_NAME );
add_settings_field( 'intergeo_adsense_publisher_id', __( 'AdSense Publisher Id', INTERGEO_PLUGIN_NAME ), 'intergeo_settings_print_field', INTERGEO_PLUGIN_NAME, 'intergeo-settings-adsense', array(
'<input type="text" name="%s" value="%s" class="regular-text">',
'intergeo_adsense_publisher_id',
esc_attr( get_option( 'intergeo_adsense_publisher_id' ) ),
) );
do_settings_sections( INTERGEO_PLUGIN_NAME );
submit_button( __( "Save Changes", INTERGEO_PLUGIN_NAME ), "primary", "sb-intergeo" );
wp_nonce_field( "intergeo-settings", "intergeo-nonce" );
echo "</form>";
}
function intergeo_settings_init_map() {
?><p><?php
printf( esc_html__( ' Below shows how to find your API Key, after retrieving your key add it to the "Maps API Key" input box.', INTERGEO_PLUGIN_NAME ) );
?></p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/gbFDMBGPCcs" frameborder="0"
allowfullscreen></iframe>
<?php
}
function intergeo_settings_init_adsense() {
?><p><?php
printf( esc_html__( "Adding display ads to your map requires that you have an AdSense account enabled for AdSense for Content. If you don't yet have an AdSense account, %1\$ssign up%3\$s for one. Once you have done so (or if you already have an account) make sure you've also enabled the account with %2\$sAdSense for Content%3\$s.", INTERGEO_PLUGIN_NAME ), '<a href="https://www.google.com/adsense/support/bin/answer.py?answer=10162" target="_blank">', '<a href="https://www.google.com/adsense/support/bin/answer.py?hl=en&answer=17470" target="_blank">', '</a>' )
?></p><p><?php
esc_html_e( 'Once you have an Adsense for Content account, you will have received an AdSense for Content (AFC) publisher ID. This publisher ID is used to link any advertising shown to your AdSense account, allowing you to share in advertising revenue when a user clicks on one of the ads shown on your maps.', INTERGEO_PLUGIN_NAME )
?></p><?php
}
function intergeo_settings_print_field( array $args ) {
vprintf( array_shift( $args ), $args );
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="common">
function intergeo_enqueue_google_maps_script( $libraries = false ) {
global $wp_scripts;
if ( is_array( $libraries ) ) {
$libraries = implode( ',', $libraries );
}
if ( wp_script_is( 'google-maps-v3' ) ) {
$params = array();
$arr = explode( '?', $wp_scripts->registered['google-maps-v3']->src );
parse_str( end( $arr ), $params );
$params['libraries'] = implode( ',', array_unique( array_merge( isset( $params['libraries'] ) ? explode( ',', $params['libraries'] ) : array(), explode( ',', $libraries ) ) ) );
$wp_scripts->registered['google-maps-v3']->src = '//maps.googleapis.com/maps/api/js?' . http_build_query( $params );
} else {
$lang = explode( '_', WPLANG ? WPLANG : 'en_US' );
$params = array(
'region' => isset( $lang[1] ) ? $lang[1] : 'US',
'language' => $lang[0],
);
if ( ! empty( $libraries ) ) {
$params['libraries'] = $libraries;
}
$api_key = get_option( 'intergeo_map_api_key' );
if ( ! empty( $api_key ) ) {
$params['key'] = $api_key;
}
if ( wp_script_is( "google-maps" ) ) {
wp_dequeue_script( "google-maps" );
}
wp_enqueue_script( 'google-maps-v3', '//maps.googleapis.com/maps/api/js?' . http_build_query( $params ), array(), null );
}
}
function intergeo_check_libraries( $json, $libraries = array() ) {
if ( isset( $json['layer']['adsense'] ) && $json['layer']['adsense'] && ! in_array( 'adsense', $libraries ) ) {
$libraries[] = 'adsense';
}
if ( isset( $json['layer']['panoramio'] ) && $json['layer']['panoramio'] && ! in_array( 'panoramio', $libraries ) ) {
$libraries[] = 'panoramio';
}
if ( ( isset( $json['layer']['weather'] ) && $json['layer']['weather'] ) || ( isset( $json['layer']['cloud'] ) && $json['layer']['cloud'] ) ) {
if ( ! in_array( 'weather', $libraries ) ) {
$libraries[] = 'weather';
}
}
return $libraries;
}
function intergeo_encode( $id ) {
return strrev( rtrim( call_user_func( 'base64_' . 'encode', $id ), '=' ) );
}
function intergeo_decode( $code ) {
return intval( call_user_func( 'base64' . '_decode', strrev( $code ) ) );
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="iframe">
// <editor-fold defaultstate="collapsed" desc="rendering">
add_filter( 'media_upload_tabs', 'intergeo_media_upload_tabs' );
function intergeo_media_upload_tabs( $tabs ) {
$tabs['intergeo_map'] = __( 'Intergeo Maps', INTERGEO_PLUGIN_NAME );
return $tabs;
}
add_action( 'media_upload_intergeo_map', 'intergeo_map_popup_init' );
function intergeo_map_popup_init() {
$post_id = filter_input( INPUT_GET, 'post_id', FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) );
$map_id = filter_input( INPUT_GET, 'map' );
$send_to_editor = false;
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$shortcode = intergeo_save_map( $map_id, $post_id );
if ( $post_id ) {
$send_to_editor = $shortcode;
} else {
$args = array(
'page' => INTERGEO_PLUGIN_NAME,
'updated' => date( 'YmdHis' ),
);
wp_redirect( add_query_arg( $args, admin_url( 'upload.php' ) ) );
exit;
}
}
intergeo_enqueue_google_maps_script( 'adsense,panoramio,weather,drawing,places' );
wp_enqueue_script( 'jquery-ddslick', INTERGEO_ABSURL . 'js/jquery.ddslick.min.js', array( 'jquery' ) );
wp_enqueue_script( 'intergeo-editor', INTERGEO_ABSURL . 'js/editor.js', array(
'jquery-ddslick',
'wp-color-picker',
'google-maps-v3'
), INTERGEO_VERSION );
wp_localize_script( 'intergeo-editor', 'intergeo_options', array(
'send_to_editor' => $send_to_editor,
'adsense' => array( 'publisher_id' => get_option( 'intergeo_adsense_publisher_id' ) ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'editor_popup' . filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP ) ),
'l10n' => array(
'marker' => __( 'marker', INTERGEO_PLUGIN_NAME ),
'error' => array(
'style' => __( 'Styles are broken. Please, fix it and try again.', INTERGEO_PLUGIN_NAME ),
'directions' => __( 'Direction was not found.', INTERGEO_PLUGIN_NAME ),
),
),
) );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style( 'intergeo-editor', INTERGEO_ABSURL . 'css/editor.css', array(), INTERGEO_VERSION );
// Added by Ash/Upwork
if ( defined( 'IntergeoMaps_Pro' ) ) {
global $IntergeoMaps_Pro;
$IntergeoMaps_Pro->enqueueScriptsAndStyles( array( 'intergeo-editor' ), array( "mapID" => $map_id ) );
}
// Added by Ash/Upwork
wp_iframe( 'intergeo_iframe', $post_id, $map_id );
}
function intergeo_iframe( $post_id = false, $map_id = false ) {
$publisher_id = trim( get_option( 'intergeo_adsense_publisher_id' ) );
$show_map_center = get_option( 'intergeo_show_map_center', true );
$submit_text = __( 'Insert into post', INTERGEO_PLUGIN_NAME );
if ( ! $post_id ) {
$submit_text = __( 'Create the map', INTERGEO_PLUGIN_NAME );
}
$copy = false;
if ( ! $map_id ) {
$copy = true;
$map_id = filter_input( INPUT_GET, 'copy' );
}
$json = array();
if ( $map_id ) {
$map = get_post( intergeo_decode( $map_id ) );
if ( $map->post_type == INTERGEO_PLUGIN_NAME ) {
$json = json_decode( $map->post_content, true );
if ( ! $copy ) {
$submit_text = __( 'Update the map', INTERGEO_PLUGIN_NAME );
}
}
}
require INTERGEO_ABSPATH . '/templates/iframe/form.php';
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="filtering">
function intergeo_filter_value( $value, $array ) {
$value = strtoupper( $value );
return ! in_array( $value, $array ) ? null : $value;
}
function intergeo_filter_position( $position ) {
return intergeo_filter_value( $position, array(
'TOP_LEFT',
'TOP_CENTER',
'TOP_RIGHT',
'RIGHT_TOP',
'RIGHT_CENTER',
'RIGHT_BOTTOM',
'BOTTOM_RIGHT',
'BOTTOM_CENTER',
'BOTTOM_LEFT',
'LEFT_BOTTOM',
'LEFT_CENTER',
'LEFT_TOP'
) );
}
function intergeo_filter_map_type( $type ) {
return intergeo_filter_value( $type, array( 'ROADMAP', 'TERRAIN', 'SATELLITE', 'HYBRID' ) );
}
function intergeo_filter_map_type_style( $style ) {
return intergeo_filter_value( $style, array( 'DEFAULT', 'DROPDOWN_MENU', 'HORIZONTAL_BAR' ) );
}
function intergeo_filter_zoom_style( $style ) {
return intergeo_filter_value( $style, array( 'DEFAULT', 'SMALL', 'LARGE' ) );
}
function intergeo_filter_wind_speed_units( $unit ) {
return intergeo_filter_value( $unit, array( 'KILOMETERS_PER_HOUR', 'METERS_PER_SECOND', 'MILES_PER_HOUR' ) );
}
function intergeo_filter_temperature_units( $unit ) {
return intergeo_filter_value( $unit, array( 'CELSIUS', 'FAHRENHEIT' ) );
}
function intergeo_filter_adsense_format( $format ) {
return intergeo_filter_value( $format, array(
'BANNER',
'BUTTON',
'HALF_BANNER',
'LARGE_HORIZONTAL_LINK_UNIT',
'LARGE_RECTANGLE',
'LARGE_VERTICAL_LINK_UNIT',
'LEADERBOARD',
'MEDIUM_RECTANGLE',
'MEDIUM_VERTICAL_LINK_UNIT',
'SKYSCRAPER',
'SMALL_HORIZONTAL_LINK_UNIT',
'SMALL_RECTANGLE',
'SMALL_SQUARE',
'SMALL_VERTICAL_LINK_UNIT',
'SQUARE',
'VERTICAL_BANNER',
'WIDE_SKYSCRAPER',
'X_LARGE_VERTICAL_LINK_UNIT',
) );
}
function intergeo_filter_custom_style( $style ) {
$style = trim( $style );
$json = @json_decode( $style, true );
return empty( $json ) ? null : $json;
}
function intergeo_filter_overlays_marker( $marker ) {
if ( ! isset( $marker['position'] ) || ! preg_match( '/^-?\d+\.?\d*,-?\d+\.?\d*$/', $marker['position'] ) ) {
return false;
}
return array(
'position' => explode( ',', $marker['position'] ),
'icon' => isset( $marker['icon'] ) ? filter_var( $marker['icon'], FILTER_VALIDATE_URL ) : '',
'info' => isset( $marker['info'] ) ? trim( preg_replace( '/\<\/?script.*?\>/is', '', $marker['info'] ) ) : '',
'title' => isset( $marker['title'] ) ? strip_tags( trim( $marker['title'] ) ) : '',
'loc' => isset( $marker['loc'] ) ? strip_tags( trim( $marker['loc'] ) ) : '',
);
}
function intergeo_filter_overlays_polyline( $polyline ) {
if ( ! isset( $polyline['path'] ) ) {
return false;
}
$path = array();
foreach ( explode( ';', $polyline['path'] ) as $point ) {
if ( preg_match( '/^-?\d+\.?\d*,-?\d+\.?\d*$/', $point ) ) {
$path[] = explode( ',', $point );
}
}
if ( count( $path ) < 2 ) {
return false;
}
return array(
'path' => $path,
'weight' => isset( $polyline['weight'] )
? filter_var( $polyline['weight'], FILTER_VALIDATE_INT, array(
'options' => array(
'min_range' => 1,
'default' => ''
)
) )
: '',
'opacity' => isset( $polyline['opacity'] )
? filter_var( $polyline['opacity'], FILTER_VALIDATE_FLOAT, array(
'options' => array(
'min_range' => 0,
'max_range' => 1,
'default' => ''
)
) )
: '',
'color' => isset( $polyline['color'] )
? filter_var( $polyline['color'], FILTER_VALIDATE_REGEXP, array(
'options' => array(
'regexp' => '/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/',
'default' => '#000000'
)
) )
: '#000000',
);
}
function intergeo_filter_overlays_polyoverlay( $polygon ) {
if ( ! isset( $polygon['path'] ) ) {
return false;
}
$path = array();
foreach ( explode( ';', $polygon['path'] ) as $point ) {
if ( preg_match( '/^-?\d+\.?\d*,-?\d+\.?\d*$/', $point ) ) {
$path[] = explode( ',', $point );
}
}
if ( count( $path ) < 2 ) {
return false;
}
$position = isset( $polygon['position'] ) ? strtoupper( trim( $polygon['position'] ) ) : 'CENTER';
return array(
'path' => $path,
'position' => in_array( $position, array( 'CENTER', 'INSIDE', 'OUTSIDE' ) ) ? $position : 'CENTER',
'weight' => isset( $polygon['weight'] ) ? filter_var( $polygon['weight'], FILTER_VALIDATE_INT, array(
'options' => array(
'min_range' => 1,
'default' => ''
)
) ) : '',
'stroke_opacity' => isset( $polygon['stroke_opacity'] ) ? filter_var( $polygon['stroke_opacity'], FILTER_VALIDATE_FLOAT, array(
'options' => array(
'min_range' => 0,
'max_range' => 1,
'default' => ''
)
) ) : '',
'stroke_color' => isset( $polygon['stroke_color'] ) ? filter_var( $polygon['stroke_color'], FILTER_VALIDATE_REGEXP, array(
'options' => array(
'regexp' => '/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/',
'default' => '#000000'
)
) ) : '#000000',
'fill_opacity' => isset( $polygon['fill_opacity'] ) ? filter_var( $polygon['fill_opacity'], FILTER_VALIDATE_FLOAT, array(
'options' => array(
'min_range' => 0,
'max_range' => 1,
'default' => ''
)
) ) : '',
'fill_color' => isset( $polygon['fill_color'] ) ? filter_var( $polygon['fill_color'], FILTER_VALIDATE_REGEXP, array(
'options' => array(
'regexp' => '/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/',
'default' => '#000000'
)
) ) : '#000000',
);
}
function intergeo_filter_directions( $direction ) {
$to = isset( $direction['to'] ) ? trim( $direction['to'] ) : '';
$from = isset( $direction['from'] ) ? trim( $direction['from'] ) : '';
if ( empty( $to ) || empty( $from ) ) {
return false;
}
$mode = isset( $direction['mode'] ) ? strtoupper( trim( $direction['mode'] ) ) : 'DRIVING';
return array(
'mode' => in_array( $mode, array( 'BICYCLING', 'DRIVING', 'TRANSIT', 'WALKING' ) ) ? $mode : 'DRIVING',
'from' => $from,
'to' => $to,
);
}
function intergeo_filter_input() {
$color_regexp = '/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/';
$postion_filter = array( 'filter' => FILTER_CALLBACK, 'options' => 'intergeo_filter_position' );
$validationArray = array(
'lat' => array(
'filter' => FILTER_VALIDATE_FLOAT,
'flags' => FILTER_REQUIRE_SCALAR,
'options' => array( 'min_range' => - 90, 'max_range' => 90, 'default' => 48.1366069 )
),
'lng' => array(
'filter' => FILTER_VALIDATE_FLOAT,
'flags' => FILTER_REQUIRE_SCALAR,
'options' => array( 'min_range' => - 180, 'max_range' => 180, 'default' => 11.577085099999977 )
),
'zoom' => array(
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_REQUIRE_SCALAR,
'options' => array( 'min_range' => 0, 'max_range' => 19, 'default' => 5 )
),
'address' => FILTER_SANITIZE_STRING,
'map_mapTypeId' => array(
'filter' => FILTER_CALLBACK,
'options' => 'intergeo_filter_map_type'
),
'map_draggable' => FILTER_VALIDATE_BOOLEAN,
'map_minZoom' => array(
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_REQUIRE_SCALAR,
'options' => array( 'min_range' => 0, 'max_range' => 19, 'default' => 0 )
),
'map_maxZoom' => array(
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_REQUIRE_SCALAR,
'options' => array( 'min_range' => 0, 'max_range' => 19, 'default' => 19 )
),
'map_scrollwheel' => FILTER_VALIDATE_BOOLEAN,
'map_zoomControl' => FILTER_VALIDATE_BOOLEAN,
'map_zoomControlOptions_position' => $postion_filter,
'map_zoomControlOptions_style' => array(
'filter' => FILTER_CALLBACK,
'options' => 'intergeo_filter_zoom_style'
),
'map_panControl' => FILTER_VALIDATE_BOOLEAN,
'map_panControlOptions_position' => $postion_filter,
'map_scaleControl' => FILTER_VALIDATE_BOOLEAN,
'map_scaleControlOptions_position' => $postion_filter,
'map_mapTypeControl' => FILTER_VALIDATE_BOOLEAN,
'map_mapTypeControlOptions_position' => $postion_filter,
'map_mapTypeControlOptions_style' => array(
'filter' => FILTER_CALLBACK,
'options' => 'intergeo_filter_map_type_style'
),
'map_mapTypeControlOptions_mapTypeIds' => array(
'filter' => FILTER_CALLBACK,
'flags' => FILTER_REQUIRE_ARRAY,
'options' => 'intergeo_filter_map_type'
),
'map_streetViewControl' => FILTER_VALIDATE_BOOLEAN,
'map_streetViewControlOptions_position' => $postion_filter,
'map_rotateControl' => FILTER_VALIDATE_BOOLEAN,
'map_rotateControlOptions_position' => $postion_filter,
'map_overviewMapControl' => FILTER_VALIDATE_BOOLEAN,
'map_overviewMapControlOptions_opened' => FILTER_VALIDATE_BOOLEAN,
'layer_traffic' => FILTER_VALIDATE_BOOLEAN,
'layer_bicycling' => FILTER_VALIDATE_BOOLEAN,
'layer_cloud' => FILTER_VALIDATE_BOOLEAN,
'layer_weather' => FILTER_VALIDATE_BOOLEAN,
'weather_temperatureUnits' => array(
'filter' => FILTER_CALLBACK,
'options' => 'intergeo_filter_temperature_units'
),
'weather_windSpeedUnits' => array(
'filter' => FILTER_CALLBACK,
'options' => 'intergeo_filter_wind_speed_units'
),
'layer_panoramio' => FILTER_VALIDATE_BOOLEAN,
'panoramio_tag' => FILTER_SANITIZE_STRING,
'panoramio_userId' => FILTER_SANITIZE_STRING,
'layer_adsense' => FILTER_VALIDATE_BOOLEAN,
'adsense_format' => array(
'filter' => FILTER_CALLBACK,
'options' => 'intergeo_filter_adsense_format'
),
'adsense_position' => $postion_filter,
'adsense_backgroundColor' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array(
'regexp' => $color_regexp,
'default' => '#c4d4f3'
)
),
'adsense_borderColor' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array(
'regexp' => $color_regexp,
'default' => '#e5ecf9'
)
),
'adsense_titleColor' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array(
'regexp' => $color_regexp,
'default' => '#0000cc'
)
),
'adsense_textColor' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array(
'regexp' => $color_regexp,
'default' => '#000000'
)
),
'adsense_urlColor' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array(
'regexp' => $color_regexp,
'default' => '#009900'
)
),
'container_width' => FILTER_SANITIZE_STRING,
'container_height' => FILTER_SANITIZE_STRING,
'container_styles' => FILTER_SANITIZE_STRING,
'styles_type' => FILTER_SANITIZE_STRING,
'styles_custom' => array(
'filter' => FILTER_CALLBACK,
'options' => 'intergeo_filter_custom_style'
),
'overlays_marker' => array( 'filter' => FILTER_DEFAULT, 'flags' => FILTER_REQUIRE_ARRAY ),
'overlays_polyline' => array( 'filter' => FILTER_DEFAULT, 'flags' => FILTER_REQUIRE_ARRAY ),
'overlays_polygon' => array( 'filter' => FILTER_DEFAULT, 'flags' => FILTER_REQUIRE_ARRAY ),
'overlays_rectangle' => array( 'filter' => FILTER_DEFAULT, 'flags' => FILTER_REQUIRE_ARRAY ),
'overlays_circle' => array( 'filter' => FILTER_DEFAULT, 'flags' => FILTER_REQUIRE_ARRAY ),
'directions' => array( 'filter' => FILTER_DEFAULT, 'flags' => FILTER_REQUIRE_ARRAY ),
);
$defaults = array(
'lat' => 48.1366069,
'lng' => 11.577085099999977,
'zoom' => 5,
'address' => '',
'map_mapTypeId' => 'ROADMAP',
'map_draggable' => true,
'map_minZoom' => 0,
'map_maxZoom' => 19,
'map_scrollwheel' => true,
'map_zoomControl' => true,
'map_zoomControlOptions_position' => null,
'map_zoomControlOptions_style' => 'DEFAULT',
'map_panControl' => true,
'map_panControlOptions_position' => null,
'map_scaleControl' => false,
'map_scaleControlOptions_position' => null,
'map_mapTypeControl' => true,
'map_mapTypeControlOptions_position' => null,
'map_mapTypeControlOptions_style' => 'DEFAULT',
'map_mapTypeControlOptions_mapTypeIds' => array( 'ROADMAP', 'TERRAIN', 'SATELLITE', 'HYBRID' ),
'map_streetViewControl' => true,
'map_streetViewControlOptions_position' => null,
'map_rotateControl' => true,
'map_rotateControlOptions_position' => null,
'map_overviewMapControl' => false,
'map_overviewMapControlOptions_opened' => false,
'layer_traffic' => false,
'layer_bicycling' => false,
'layer_cloud' => false,
'layer_weather' => false,
'weather_temperatureUnits' => null,
'weather_windSpeedUnits' => null,
'layer_panoramio' => false,
'panoramio_tag' => '',
'panoramio_userId' => '',
'layer_adsense' => false,
'adsense_format' => null,
'adsense_position' => null,
'adsense_backgroundColor' => '#c4d4f3',
'adsense_borderColor' => '#e5ecf9',
'adsense_titleColor' => '#0000cc',
'adsense_textColor' => '#000000',
'adsense_urlColor' => '#009900',
'container_width' => '',
'container_height' => '',
'container_styles' => '',
'styles_type' => 'DEFAULT',
'styles_custom' => null,
'overlays_marker' => array(),
'overlays_polyline' => array(),
'overlays_polygon' => array(),
'overlays_rectangle' => array(),
'overlays_circle' => array(),
'directions' => array(),
);
// Added by Ash/Upwork
if ( defined( 'IntergeoMaps_Pro' ) ) {
global $IntergeoMaps_Pro;
$IntergeoMaps_Pro->addValidations( $validationArray, $defaults );
}
// Added by Ash/Upwork
$options = filter_input_array( INPUT_POST, $validationArray );
$results = array();
foreach ( $options as $key => $value ) {
if ( array_key_exists( $key, $defaults ) ) {
$equals = $defaults[ $key ] == $value;
if ( is_array( $value ) ) {
$equals = ( count( $value ) == count( $defaults[ $key ] ) ) && ( count( array_diff( (array) $defaults[ $key ], $value ) ) == 0 );
}
if ( ! $equals ) {
$results[ $key ] = $value;
}
}
}
if ( ! empty( $results['overlays_marker'] ) ) {
$results['overlays_marker'] = array_filter( array_map( 'intergeo_filter_overlays_marker', $results['overlays_marker'] ) );
}
if ( ! empty( $results['overlays_polyline'] ) ) {
$results['overlays_polyline'] = array_filter( array_map( 'intergeo_filter_overlays_polyline', $results['overlays_polyline'] ) );
}
if ( ! empty( $results['directions'] ) ) {
$results['directions'] = array_filter( array_map( 'intergeo_filter_directions', $results['directions'] ) );
}
foreach ( array( 'polygon', 'rectangle', 'circle' ) as $overlay ) {
$overlay = 'overlays_' . $overlay;
if ( ! empty( $results[ $overlay ] ) ) {
$results[ $overlay ] = array_filter( array_map( 'intergeo_filter_overlays_polyoverlay', $results[ $overlay ] ) );
}
}
// Added by Ash/Upwork
if ( defined( 'IntergeoMaps_Pro' ) ) {
global $IntergeoMaps_Pro;
$IntergeoMaps_Pro->processResults( $results );
}
// Added by Ash/Upwork
return $results;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="saving">
function intergeo_save_map( $map_id = false, $post_id = false ) {
$options = array();
$array_ptr = &$options;
foreach ( intergeo_filter_input() as $key => $value ) {
if ( ! is_null( $value ) ) {
$keys = explode( '_', $key );
$last_key = array_pop( $keys );
while ( $arr_key = array_shift( $keys ) ) {
if ( ! array_key_exists( $arr_key, $array_ptr ) ) {
$array_ptr[ $arr_key ] = array();
}
$array_ptr = &$array_ptr[ $arr_key ];
}
$array_ptr[ $last_key ] = $value;
$array_ptr = &$options;
}
}
$address = '';
if ( ! empty( $options['address'] ) ) {
$address = $options['address'] = trim( $options['address'] );
}
$args = array(
'post_type' => INTERGEO_PLUGIN_NAME,
'post_content' => addcslashes( json_encode( $options ), '\\' ),
'post_status' => 'private',
);
$update = false;
if ( $map_id ) {
$post = get_post( intergeo_decode( $map_id ) );
if ( $post && $post->post_type == INTERGEO_PLUGIN_NAME ) {
$update = true;
$args['ID'] = $post->ID;
}
}
$id = wp_insert_post( $args );
if ( ! empty( $id ) && ! is_wp_error( $id ) ) {
if ( ! $post_id ) {
intergeo_set_info( $update
? __( 'The map has been updated successfully.', INTERGEO_PLUGIN_NAME )
: __( 'The map has been created successfully.', INTERGEO_PLUGIN_NAME )
);
}
return sprintf( '[intergeo id="%s"]%s[/intergeo]', intergeo_encode( $id ), $address );
}
if ( ! $post_id ) {
intergeo_set_error( $update
? __( 'The map updating failed.', INTERGEO_PLUGIN_NAME )
: __( 'The map creation failed.', INTERGEO_PLUGIN_NAME )
);
}
return false;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="ajax stuff">
add_action( 'wp_ajax_intergeo_show_map_center', 'intergeo_show_map_center_changed' );
function intergeo_show_map_center_changed() {
$nonce = filter_input( INPUT_POST, 'nonce' );
if ( wp_verify_nonce( $nonce, 'editor_popup' . filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP ) ) ) {
update_option( 'intergeo_show_map_center', (int) filter_input( INPUT_POST, 'status', FILTER_VALIDATE_BOOLEAN ) );
}
}
// </editor-fold>
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="shortcode">
add_filter( 'widget_text', 'do_shortcode' );
add_filter( 'term_description', 'do_shortcode' );
add_shortcode( INTERGEO_PLUGIN_NAME, 'intergeo_shortcode' );
function intergeo_shortcode( $attrs, $address = '' ) {
do_action( "intergeo_shortcode_render_before", $attrs );
$args = shortcode_atts( array(
'id' => false,
'hook' => false,
'width' => false,
'height' => false,
'style' => false,
'zoom' => false,
), $attrs );
$address = trim( $address );
if ( empty( $args['id'] ) && empty( $address ) ) {
return '';
}
$json = array();
if ( ! empty( $args['id'] ) ) {
$post = get_post( intergeo_decode( $args['id'] ) );
if ( ! $post || $post->post_type != INTERGEO_PLUGIN_NAME ) {
return '';
}
$json = json_decode( $post->post_content, true );
} else {
$args['id'] = intergeo_encode( rand( 0, 100 ) . rand( 0, 10000 ) );
$json['zoom'] = intval( $args['zoom'] ) ? intval( $args['zoom'] ) : 15;
}
if ( ! empty( $address ) ) {
$json['address'] = $address;
}
if ( trim( $args['hook'] ) != '' ) {
$json = apply_filters( $args['hook'], $json );
}
wp_enqueue_style( 'intergeo-frontend' );
intergeo_enqueue_google_maps_script( intergeo_check_libraries( $json ) );
if ( ! wp_script_is( 'intergeo-rendering' ) ) {
wp_enqueue_script( 'intergeo-rendering', INTERGEO_ABSURL . 'js/rendering.js', array(
'jquery',
'google-maps-v3'
), INTERGEO_VERSION );
wp_localize_script( 'intergeo-rendering', 'intergeo_options', array(
'adsense' => array( 'publisher_id' => get_option( 'intergeo_adsense_publisher_id' ) )
) );
}
$container = array();
if ( isset( $json['container'] ) ) {
$container = $json['container'];
unset( $json['container'] );
}
$width = ! empty( $container['width'] ) ? esc_attr( $container['width'] ) : '100%';
if ( trim( $args['width'] ) != '' ) {
$width = $args['width'];
}
if ( is_numeric( $width ) ) {
$width .= 'px';
}
$height = ! empty( $container['height'] ) ? esc_attr( $container['height'] ) : '300px';
if ( trim( $args['height'] ) != '' ) {
$height = $args['height'];
}
if ( is_numeric( $height ) ) {
$height .= 'px';
}
$styles = ! empty( $container['styles'] ) ? esc_attr( $container['styles'] ) : '';
if ( trim( $args['style'] ) != '' ) {
$styles = $args['style'];
}
return sprintf( '
<div id="intergeo_map%1$s" class="intergeo_map_canvas" style="width:100%%;height:300px;width:%2$s;height:%3$s;%4$s"></div>
<script type="text/javascript">
/* <![CDATA[ */
if (!window.intergeo_maps) window.intergeo_maps = [];
window.intergeo_maps.push( { container: \'intergeo_map%1$s\', options: %5$s } );
if (!window.intergeo_maps_current) window.intergeo_maps_current = null;
/* ]]> */
</script>
',
$args['id'],
$width,
$height,
$styles,
json_encode( $json )
);
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="library">
add_action( 'admin_menu', 'intergeo_admin_menu' );
function intergeo_admin_menu() {
add_options_page( __( 'Intergeo Maps Library', INTERGEO_PLUGIN_NAME ), __( 'Intergeo Maps', INTERGEO_PLUGIN_NAME ), 'edit_posts', INTERGEO_PLUGIN_NAME, 'intergeo_settings_init' );
$page = add_submenu_page( 'upload.php', __( 'Intergeo Maps Library', INTERGEO_PLUGIN_NAME ), __( 'Intergeo Maps', INTERGEO_PLUGIN_NAME ), 'edit_posts', INTERGEO_PLUGIN_NAME, 'intergeo_library' );
if ( $page ) {
add_action( "load-{$page}", 'intergeo_library_init' );
}
}
function intergeo_library_init() {
wp_enqueue_style( 'intergeo_library', INTERGEO_ABSURL . 'css/library.css', array(), INTERGEO_VERSION );
wp_enqueue_media();
$screen = get_current_screen();
$screen->add_help_tab( array(
'title' => esc_html__( 'Overview', INTERGEO_PLUGIN_NAME ),
'id' => 'overview',
'content' => sprintf( '<p>%s</p>', implode( '</p><p>', array(
esc_html__( "The library is a list to view all maps you have created in your system. The library is showing you 3x3 grid of maps' previews. You will see the same maps embedded into your posts at front end, as you see here. The library is paginated and if you have more than 9 maps, you will see pagination links under maps grid.", INTERGEO_PLUGIN_NAME ),
esc_html__( 'To create a new map, click on "Add New" button next to the page title and map editor popup will appear. In case you want to edit a map, you can click on pencil icon in the right bottom corner of map preview box and edit popup window will appear.', INTERGEO_PLUGIN_NAME ),
esc_html__( "If you want to delete a map, click on the trash icon in the right bottom corner of a map and confirm your action. Pay attention that whole information about the map will be removed from the system, but all shortcodes will be left where you embed it. However these deprecated shortcodes won't be rendered anymore, so you don't have to worry about it while the plugin is enabled.", INTERGEO_PLUGIN_NAME ),
) ) ),
) );
$screen->add_help_tab( array(
'title' => esc_html__( 'Shortcodes', INTERGEO_PLUGIN_NAME ),
'id' => 'shortcodes',
'content' => sprintf( '<p>%s</p>', implode( '</p><p>', array(
esc_html__( 'You can easily embed a map into your posts, pages, categories or tags descriptions and text widgets by copying shortcode which you can find in the input field of a map preview box.', INTERGEO_PLUGIN_NAME ),
esc_html__( 'To specify a certain address just type it inside a shortcode, and a map will be automatically centered at this place. Also each shortcode could be extended with custom attributes like width, height, style, zoom and hook. Use standard CSS values for such attributes as width, height and style. Type an integer between 0 and 19 for zoom attribute. You can use hook attribute to set up a filter hook which you can use in your custom plugin or theme to configure all options of a map.', INTERGEO_PLUGIN_NAME ),
) ) ),
) );
}
function intergeo_library() {
if ( filter_input( INPUT_GET, 'do' ) == 'delete' ) {
intergeo_library_delete();
}
$query = new WP_Query( array(
'orderby' => 'ID',
'order' => 'DESC',
'post_type' => INTERGEO_PLUGIN_NAME,
'posts_per_page' => 9,
'paged' => filter_input( INPUT_GET, 'pagenum', FILTER_VALIDATE_INT, array(
'options' => array(
'min_range' => 1,
'default' => 1,
)
) ),
) );
$libraries = array();
$pagination = paginate_links( array(
'base' => add_query_arg( array(
'pagenum' => '%#%',
'updated' => false,
) ),
'format' => '',
'current' => max( 1, $query->get( 'paged' ) ),
'total' => $query->max_num_pages,
'type' => 'array',
) );
require INTERGEO_ABSPATH . '/templates/library/list.php';
intergeo_enqueue_google_maps_script( $libraries );
wp_enqueue_script( 'intergeo-rendering', INTERGEO_ABSURL . 'js/rendering.js', array(
'jquery',
'google-maps-v3'
), INTERGEO_VERSION );
wp_enqueue_script( 'intergeo-library', INTERGEO_ABSURL . 'js/library.js', array(
'intergeo-rendering',
'media-views'
), INTERGEO_VERSION );
wp_localize_script( 'intergeo-rendering', 'intergeo_options', array(
'adsense' => array( 'publisher_id' => get_option( 'intergeo_adsense_publisher_id' ) )
) );
// Added by Ash/Upwork
if ( defined( 'IntergeoMaps_Pro' ) ) {
global $IntergeoMaps_Pro;
$IntergeoMaps_Pro->enqueueScriptsAndStyles( array( 'intergeo-rendering' ) );
}
// Added by Ash/Upwork
}
function intergeo_library_delete() {
if ( ! current_user_can( 'delete_posts' ) ) {
return;
}
$id = intergeo_decode( trim( filter_input( INPUT_GET, 'map' ) ) );
if ( ! $id ) {
return;
}
$post = get_post( $id );
if ( wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), $id . filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP ) ) && $post->post_type == INTERGEO_PLUGIN_NAME ) {
if ( wp_delete_post( $id, true ) ) {
intergeo_set_info( __( 'The map was deleted successfully.', INTERGEO_PLUGIN_NAME ) );
}
}
if ( filter_input( INPUT_GET, 'noheader', FILTER_VALIDATE_BOOLEAN ) ) {
wp_redirect( add_query_arg( 'page', INTERGEO_PLUGIN_NAME, admin_url( 'upload.php' ) ) );
exit;
}
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="messaging functions">
function intergeo_set_message( $message, $is_normal, $user_id = false ) {
$messages = get_option( 'intergeo_messages', array() );
if ( $user_id === false ) {
$user_id = get_current_user_id();
}
if ( ! isset( $messages[ $user_id ] ) ) {
$messages[ $user_id ] = array();
}
$messages[ $user_id ][] = array( $message, $is_normal );
update_option( 'intergeo_messages', $messages );
}
function intergeo_set_info( $message, $user_id = false ) {
intergeo_set_message( $message, 1, $user_id );
}
function intergeo_set_error( $message, $user_id = false ) {
intergeo_set_message( $message, 0, $user_id );
}