-
Notifications
You must be signed in to change notification settings - Fork 40
/
functions.php
2860 lines (2494 loc) · 77.9 KB
/
functions.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
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
require_once plugin_dir_path(__FILE__) . 'functions-legacy.php';
global $cmplz_banner;
if ( !function_exists('cmplz_get_cookiebanner')) {
function cmplz_get_cookiebanner($ID = false, $set_defaults = true, $load_wysiwyg_options = false){
global $cmplz_banner;
//try cached data if defaults are used
if ( $ID && $set_defaults && !$load_wysiwyg_options ) {
$banner = $cmplz_banner[ $ID ] ?? false;
if (!$banner){
$banner = new CMPLZ_COOKIEBANNER($ID, $set_defaults, $load_wysiwyg_options);
$cmplz_banner[ $ID ] = $banner;
}
} else {
$banner = new CMPLZ_COOKIEBANNER($ID, $set_defaults, $load_wysiwyg_options);
}
return $banner;
}
}
if ( ! function_exists( 'cmplz_get_option' ) ) {
/**
* Get a Really Simple SSL option by name
*
* @param string $name
* @param bool $default
*
* @return mixed
*/
function cmplz_get_option( string $id, bool $load_default=true ) {
$id = cmplz_sanitize_title_preserve_uppercase($id);
//to ensure the fields function only runs once, we store it here, and check if it's filled in the next request.
$fields = false;
$options = get_option( 'cmplz_options', [] );
$value = $options[ $id ] ?? false;
if ( $value===false && $load_default && class_exists('COMPLIANZ') ) {
$fields = COMPLIANZ::$config->fields ?? [];
$keys = array_keys( array_column( $fields, 'id' ), $id );
$key = reset( $keys );
if (isset($fields[$key]) ) {
$default = $fields[ $key ]['default'] ?? false;
$value = apply_filters( 'cmplz_default_value', $default, $id, $fields[$key] );
}
}
/*
* Translate output
*
* */
if ( function_exists('pll__') || function_exists('icl_translate') || defined("WPML_PLUGIN_BASENAME" ) ) {
//check if Complianz::$config has property fields
if (class_exists('COMPLIANZ')) {
$config_fields = COMPLIANZ::$config->fields ?? [];
} else {
$config_fields = [];
}
$fields = $fields ?: $config_fields;
$keys = array_keys( array_column( $fields, 'id' ), $id );
$key = reset( $keys );
if ( $key !== false ) {
$type = $fields[ $key ]['type'] ?? false;
$translatable = $fields[ $key ]['translatable'] ?? false;
if ( $translatable ) {
if ( is_array( $value ) && ( $type === 'thirdparties' || $type === 'processors' ) ) {
foreach ( $value as $item_key => $item ) {
//contains the values of an item
foreach ( $item as $key => $key_value ) {
if ( function_exists( 'pll__' ) ) {
$value[ $item_key ][ $key ] = pll__( $item_key . '_' . $id . "_" . $key );
}
if ( function_exists( 'icl_translate' ) ) {
$value[ $item_key ][ $key ] = icl_translate( 'complianz', $item_key . '_' . $id . "_" . $key, $key_value );
}
$value[ $item_key ][ $key ] = apply_filters( 'wpml_translate_single_string', $key_value, 'complianz', $item_key . '_' . $id . "_" . $key );
}
}
} else {
if ( function_exists( 'pll__' ) ) {
$value = pll__( $value );
}
if ( function_exists( 'icl_translate' ) ) {
$value = icl_translate( 'complianz', $id, $value );
}
$value = apply_filters( 'wpml_translate_single_string', $value, 'complianz', $id );
}
}
}
}
return apply_filters("cmplz_option_$id", $value, $id);
}
}
if (!function_exists('cmplz_get_field')) {
function cmplz_get_field($id){
$fields = COMPLIANZ::$config->fields;
foreach ($fields as $field) {
if (isset($field['id']) && $field['id'] === $id) {
return $field;
}
}
return false;
}
}
if (!function_exists('cmplz_get_field_index')) {
function cmplz_get_field_index($id, $fields){
foreach ($fields as $index => $field) {
if (isset($field['id']) && $field['id'] === $id) {
return $index;
}
}
return false;
}
}
if ( !function_exists('cmplz_remove_field') ) {
/**
* @param array $fields
* @param $ids
*
* @return array
*/
function cmplz_remove_field( array $fields, $ids): array {
if (!is_array($ids)) {
$ids = array($ids);
}
$field_ids = array_column($fields, 'id');
foreach ($ids as $id){
$drop_index = array_search( $id, $field_ids, true );
if ($drop_index!==false) {
unset($fields[$drop_index]);
}
}
return $fields;
}
}
if ( !function_exists('cmplz_sanitize_title_preserve_uppercase')) {
/**
* @param string $title
*
* @return string
*/
function cmplz_sanitize_title_preserve_uppercase($title) {
if (empty($title)) {
return '';
}
$title = preg_replace( '/&.+?;/', '', $title );
$title = str_replace( '.', '-', $title );
$title = preg_replace( '/[^%a-zA-Z0-9 _-]/', '', $title );
$title = preg_replace( '/\s+/', '-', $title );
$title = preg_replace( '|-+|', '-', $title );
return str_replace(' ', '-', sanitize_text_field(remove_accents($title)));
}
}
if ( ! function_exists( 'cmplz_uses_google_analytics' ) ) {
/**
* Check if site uses google analytics
* @return bool
*/
function cmplz_uses_google_analytics() {
return COMPLIANZ::$banner_loader->uses_google_analytics();
}
}
if ( ! function_exists( 'cmplz_consent_mode' ) ) {
/**
* Check if site uses google analytics
* @return bool
*/
function cmplz_consent_mode() {
return cmplz_get_option( 'consent-mode' ) === 'yes';
}
}
if ( ! function_exists('cmplz_upload_dir')) {
/**
* Get the upload dir
*
* @param string $path
*
* @return string
*/
function cmplz_upload_dir( string $path=''): string {
$uploads = wp_upload_dir();
$upload_dir = trailingslashit( apply_filters( 'cmplz_upload_dir', $uploads['basedir'] ) ).'complianz/'.$path;
if ( !is_dir( $upload_dir) ) {
cmplz_create_missing_directories_recursively($upload_dir);
}
return trailingslashit( $upload_dir );
}
}
/**
* Create directories recursively
*
* @param string $path
*/
if ( !function_exists('cmplz_create_missing_directories_recursively') ) {
function cmplz_create_missing_directories_recursively( string $path ) {
if ( ! cmplz_user_can_manage() ) {
return;
}
$parts = explode( '/', $path );
$dir = '';
foreach ( $parts as $part ) {
$dir .= $part . '/';
if (cmplz_has_open_basedir_restriction($dir)) {
continue;
}
if ( ! is_dir( $dir ) && strlen( $dir ) > 0 && is_writable( dirname( $dir, 1 ) ) ) {
if ( ! mkdir( $dir ) && ! is_dir( $dir ) ) {
throw new \RuntimeException( sprintf( 'Directory "%s" was not created', $dir ) );
}
}
}
}
}
if (!function_exists('cmplz_has_open_basedir_restriction')) {
function cmplz_has_open_basedir_restriction($path) {
// Default error handler is required
set_error_handler(null);
// Clean last error info.
error_clear_last();
// Testing...
@file_exists($path);
// Restore previous error handler
restore_error_handler();
// Return `true` if error has occurred
return ($error = error_get_last()) && $error['message'] !== '__clean_error_info';
}
}
if ( ! function_exists('cmplz_upload_url')) {
/**
* Get the upload url
*
* @param string $path
*
* @return string
*/
function cmplz_upload_url( string $path=''): string {
$uploads = wp_upload_dir();
$upload_url = $uploads['baseurl'];
$upload_url = trailingslashit( apply_filters('cmplz_upload_url', $upload_url) );
return trailingslashit($upload_url.'complianz/'.$path);
}
}
if ( ! function_exists( 'cmplz_uses_social_media' ) ) {
/**
* Check if site uses social media
* @return bool
*/
function cmplz_uses_social_media() {
$socialmedia_list = cmplz_get_option( 'socialmedia_on_site' );
return is_array( $socialmedia_list ) && count( array_filter( $socialmedia_list ) ) > 0;
}
}
if ( !function_exists('cmplz_upgraded_to_current_version')){
/**
* Check if the user has upgraded to the current version, or if this is a fresh install with this version.
*/
function cmplz_upgraded_to_current_version() {
$first_version = get_option( 'cmplz_first_version' );
//if there's no first version yet, we assume it's not upgraded
if ( !$first_version ) {
return false;
}
//if the first version is below current, we just upgraded.
if ( version_compare($first_version,cmplz_version ,'<') ){
return true;
}
return false;
}
}
if ( ! function_exists( 'cmplz_get_template' ) ) {
/**
* Get a template based on filename, overridable in theme dir
* @param string $filename
* @param array $args
* @param string $path
* @return string
*/
function cmplz_get_template( $filename , $args = array(), $path = false ) {
$path = $path ? trailingslashit($path) : trailingslashit( cmplz_path ) . 'templates/';
$file = apply_filters('cmplz_template_file', $path . $filename, $filename);
$theme_file = trailingslashit( get_stylesheet_directory() )
. trailingslashit( basename( cmplz_path ) )
. 'templates/' . $filename;
if ( !file_exists( $file ) ) {
return false;
}
if ( file_exists( $theme_file ) ) {
$file = $theme_file;
}
if ( strpos( $file, '.php' ) !== false ) {
ob_start();
require $file;
$contents = ob_get_clean();
} else {
$contents = file_get_contents( $file );
}
if ( !empty($args) && is_array($args) ) {
foreach($args as $fieldname => $value ) {
$contents = str_replace( '{'.$fieldname.'}', $value, $contents );
}
}
return $contents;
}
}
if ( ! function_exists( 'cmplz_uses_google_tagmanager_or_analytics' ) ) {
function cmplz_uses_google_tagmanager_or_analytics(){
return COMPLIANZ::$banner_loader->uses_google_analytics() || COMPLIANZ::$banner_loader->uses_google_tagmanager();
}
}
if ( ! function_exists( 'cmplz_tagmanager_conditional_helptext' ) ) {
function cmplz_tagmanager_conditional_helptext() {
if ( !COMPLIANZ::$banner_loader->consent_required_for_anonymous_stats() ) {
$text = __( "Based on your Analytics configuration you should fire Analytics on event cmplz_functional.", 'complianz-gdpr' );
} else {
$text = __( "Based on your Analytics configuration you should fire Analytics on event cmplz_statistics.", 'complianz-gdpr' );
}
return $text;
}
}
if ( ! function_exists( 'cmplz_statistics_privacy_friendly' ) ) {
/**
* Checks if statistics are configured privacy friendly
*
* @return bool
*/
function cmplz_statistics_privacy_friendly()
{
return COMPLIANZ::$banner_loader->statistics_privacy_friendly();
}
}
if ( ! function_exists( 'cmplz_manual_stats_config_possible' ) ) {
/**
* Checks if the statistics are configured so no consent is need for statistics
*
* @return bool
*/
function cmplz_manual_stats_config_possible() {
$stats = cmplz_get_option( 'compile_statistics' );
if ( $stats === 'matomo' && cmplz_no_ip_addresses() ) {
return true;
}
//Google Tag Manager should also be possible to embed yourself if you haven't integrated it anonymously
if ( $stats === 'google-tag-manager' ) {
return true;
}
if ( $stats === 'google-analytics' ) {
if ( !COMPLIANZ::$banner_loader->consent_required_for_anonymous_stats()
) {
return true;
}
}
return false;
}
}
if ( ! function_exists( 'cmplz_get_stats_tool_nice' ) ) {
function cmplz_get_stats_tool_nice() {
//if the user just changed the setting, we use the posted data. The data is not saved yet, so would yield the previous setting
if ( isset($_POST['cmplz_compile_statistics'])) {
$stats = sanitize_text_field($_POST['cmplz_compile_statistics']);
} else {
$stats = cmplz_get_option( 'compile_statistics' );
}
switch ( $stats ){
case 'google-analytics':
return "Google Analytics";
case 'matomo':
return "Matomo";
case 'clicky':
return "Clicky";
case 'yandex':
return "Yandex";
case 'google-tag-manager':
return "Google Tag Manager";
case 'matomo-tag-manager':
return "Matomo Tag Manager";
case 'clarity':
return "Clarity";
default:
return __("Not found","complianz-gdpr");
}
}
}
if ( !function_exists('cmplz_detected_cookie_plugin')) {
function cmplz_detected_cookie_plugin( $return_name = false ){
$plugin = false;
if (defined('CLI_LATEST_VERSION_NUMBER')){
$plugin = "GDPR Cookie Consent";
} elseif(defined('MOOVE_GDPR_VERSION')) {
$plugin = "GDPR Cookie Compliance";
}elseif(defined('CTCC_PLUGIN_URL')) {
$plugin = "GDPR Cookie Consent Banner";
}elseif(defined('RCB_FILE')) {
$plugin = "Real Cookie Banner";
}elseif(class_exists('Cookiebot_WP')) {
$plugin = "Cookiebot";
}elseif(function_exists('bst_plugin_install')) {
$plugin = "BST DSGVO Cookie";
}elseif(function_exists('jlplg_lovecoding_set_cookie')) {
$plugin = "Simple Cookie Notice";
}elseif(class_exists('SCCBPP_WpCookie_Save')) {
$plugin = "Seers Cookie Consent Banner Privacy Policy";
}elseif(function_exists('daextlwcnf_customize_action_links')) {
$plugin = "Lightweight Cookie Notice Free";
}elseif(defined('GDPRCN_VERSION')) {
$plugin = "GDPR Cookie Notice";
}elseif(function_exists('wp_gdpr_cookie_notice_check_requirements')) {
$plugin = "WP GDPR Cookie Notice";
}elseif(defined('SURBMA_GPGA_PLUGIN_VERSION_NUMBER')) {
$plugin = "Surbma | GDPR Proof Cookie Consent & Notice Bar";
}elseif(class_exists('dsdvo_wp_backend')) {
$plugin = "DSGVO All in one for WP";
}elseif(class_exists('Cookie_Notice')) {
$plugin = "Cookie Notice & Compliance";
}elseif(defined('CNCB_VERSION')) {
$plugin = "Cookie Notice and Consent Banner";
}elseif(function_exists('add_cookie_notice')) {
$plugin = "Cookie Notice Lite";
}elseif(function_exists('fhw_dsgvo_cookie_insert')) {
$plugin = "GDPR tools: cookie notice + privacy";
}elseif(defined('GDPR_COOKIE_CONSENT_PLUGIN_URL')) {
$plugin = "GDPR Cookie Consent";
}elseif(defined('WP_GDPR_C_SLUG')) {
$plugin = "WP GDPR Compliance";
}elseif(defined('TERMLY_VERSION')) {
$plugin = "Termly | GDPR/CCPA Cookie Consent Banner";
}
if ( $plugin !== false && !$return_name ) {
return true;
} else {
return $plugin;
}
}
}
if ( ! function_exists( 'cmplz_revoke_link' ) ) {
/**
* Output a revoke button
* @param bool $text
*
* @return string
*/
function cmplz_revoke_link( $text = false ) {
$text = sanitize_text_field($text) ? : __( 'Revoke', 'complianz-gdpr' );
$text = apply_filters( 'cmplz_revoke_button_text', $text );
$css
= "<style>.cmplz-status-accepted,.cmplz-status-denied {display: none;}</style>
<script>
document.addEventListener('cmplz_before_cookiebanner', function(){
if (cmplz_has_consent('marketing')) {
document.querySelector('.cmplz-status-accepted').style.display = 'block';
document.querySelector('.cmplz-status-denied').style.display = 'none';
} else {
document.querySelector('.cmplz-status-accepted').style.display = 'none';
document.querySelector('.cmplz-status-denied').style.display = 'block';
document.querySelector('.cmplz-revoke-custom').setAttribute('disabled', true);
}
document.addEventListener('click', e => {
if ( e.target.closest('.cmplz-revoke-custom') ) {
document.querySelector('.cmplz-revoke-custom').setAttribute('disabled', true);
cmplz_set_banner_status('dismissed');
}
});
document.addEventListener('click', e => {
if ( e.target.closest('.cmplz-accept') ) {
document.querySelector('.cmplz-status-accepted').style.display = 'block';
document.querySelector('.cmplz-status-denied').style.display = 'none';
document.querySelector('.cmplz-revoke-custom').removeAttribute('disabled');
}
});
});
</script>";
$html = $css . '<button class="cmplz-deny cmplz-revoke-custom">' . esc_html($text)
. '</button> <span class="cmplz-status-accepted">'
. cmplz_sprintf( __( 'Current status: %s', 'complianz-gdpr' ),
__( "Accepted", 'complianz-gdpr' ) )
. '</span><span class="cmplz-status-denied">'
. cmplz_sprintf( __( 'Current status: %s', 'complianz-gdpr' ),
__( "Denied", 'complianz-gdpr' ) ) . '</span>';
return apply_filters( 'cmplz_revoke_link', $html );
}
}
if ( ! function_exists( 'cmplz_sells_personal_data' ) ) {
function cmplz_sells_personal_data() {
$purposes = cmplz_get_option( 'purpose_personaldata');
if ( isset( $purposes['selling-data-thirdparty'] )
&& $purposes['selling-data-thirdparty']
) {
return true;
}
return false;
}
}
if ( ! function_exists( 'cmplz_sold_data_12months' ) ) {
function cmplz_sold_data_12months() {
return COMPLIANZ::$company->sold_data_12months();
}
}
if ( ! function_exists( 'cmplz_disclosed_data_12months' ) ) {
function cmplz_disclosed_data_12months() {
return COMPLIANZ::$company->disclosed_data_12months();
}
}
if ( ! function_exists( 'cmplz_site_needs_cookie_warning' ) ) {
/**
* Check if site needs a cookie warning
*
* @return bool
*/
function cmplz_site_needs_cookie_warning() {
return COMPLIANZ::$banner_loader->site_needs_cookie_warning();
}
}
if ( ! function_exists( 'cmplz_eu_site_needs_cookie_warning' ) ) {
/**
* Check if EU targeted site needs a cookie warning
*
* @return bool
*/
function cmplz_eu_site_needs_cookie_warning() {
return COMPLIANZ::$banner_loader->site_needs_cookie_warning( 'eu' );
}
}
if ( ! function_exists( 'cmplz_za_site_needs_cookie_warning' ) ) {
/**
* Check if ZA targeted site needs a cookie warning
*
* @return bool
*/
function cmplz_za_site_needs_cookie_warning() {
return COMPLIANZ::$banner_loader->site_needs_cookie_warning( 'za' );
}
}
if ( ! function_exists( 'cmplz_uk_site_needs_cookie_warning' ) ) {
/**
* Check if EU targeted site needs a cookie warning
*
* @return bool
*/
function cmplz_uk_site_needs_cookie_warning() {
return COMPLIANZ::$banner_loader->site_needs_cookie_warning( 'uk' );
}
}
if ( ! function_exists( 'cmplz_site_uses_cookie_warning_cats' ) ) {
/**
* Check if optin site needs cookie warning with categories
* @return bool
*/
function cmplz_site_uses_cookie_warning_cats() {
$cookiebanner = cmplz_get_cookiebanner( apply_filters( 'cmplz_user_banner_id', cmplz_get_default_banner_id() ) );
if ( $cookiebanner->use_categories !== 'no'
) {
return true;
}
return false;
}
}
if ( ! function_exists( 'cmplz_company_located_in_region' ) ) {
/**
* Check if this company is located in a certain region
*
* @param $region
*
* @return bool
*/
function cmplz_company_located_in_region( $region ) {
$country_code = cmplz_get_option( 'country_company' );
return ( cmplz_get_region_for_country( $country_code ) === $region );
}
}
if ( ! function_exists( 'cmplz_has_region' ) ) {
/**
* Check if this website targets a specific region.
*
* @param string $code
*
* @return bool
*/
function cmplz_has_region( $code ) {
$regions = cmplz_get_regions(true);
if ( in_array( $code, $regions ) ) {
return true;
}
return false;
}
}
if ( ! function_exists( 'cmplz_has_state' ) ) {
/**
* Check if this website targest a specific state
*
* @param string $code
*
* @return bool
*/
function cmplz_has_state( $code ) {
$regions = cmplz_get_regions(true);
if ( !isset( $regions[ 'us' ] ) ) {
return false;
}
$states = cmplz_get_option('us_states');
if ( isset( $states[ $code ] ) ) {
return true;
}
return false;
}
}
if ( ! function_exists( 'cmplz_get_region_from_legacy_type' ) ) {
function cmplz_get_region_from_legacy_type( $type ) {
$region = false;
if ( strpos( $type, 'disclaimer' ) !== false || strpos( $type, 'all' ) !== false ) {
$region = 'all';
}
//get last three chars of string. if not contains -, it's eu or disclaimer.
if ( substr( $type, - 3, 1 ) === '-' ) {
$region = substr( $type, - 2 );
}
if ( ! $region ) {
$region = 'eu';
}
return $region;
}
}
if (!function_exists('cmplz_format_as_javascript_array')) {
function cmplz_format_as_javascript_array($array) {
$out = [];
foreach ($array as $key => $label){
$out[] = [
'id' => $key,
'label' => $label,
];
}
return $out;
}
}
if ( ! function_exists( 'cmplz_get_regions' ) ) {
function cmplz_get_regions( $ad_all_category = false, $label_type = false ) {
$regions = cmplz_get_option( 'regions' );
if ( ! is_array( $regions ) ) {
$regions = !empty( $regions ) ? array( $regions ) : [];
}
if ( $label_type && ! empty( $regions ) ) {
$output = array();
foreach ( $regions as $region ) {
if ($label_type==='full') {
$label = isset( COMPLIANZ::$config->regions[ $region ] ) ? COMPLIANZ::$config->regions[ $region ]['label_full'] : '';
} else {
$label = isset( COMPLIANZ::$config->regions[ $region ] ) ? COMPLIANZ::$config->regions[ $region ]['label'] : '';
}
$output[ $region ] = $label;
}
} else {
$output = $regions;
}
if ( $ad_all_category ) {
if ($label_type) {
$output['all'] = __( 'General', 'complianz-gdpr' );
} else {
$output[] = 'all';
}
}
return array_filter($output);
}
}
if ( ! function_exists( 'cmplz_multiple_regions' ) ) {
function cmplz_multiple_regions() {
//if geo ip is not enabled, return false anyway
if ( ! cmplz_geoip_enabled() ) {
return false;
}
$regions = cmplz_get_regions();
return count( $regions ) > 1;
}
}
if ( ! function_exists( 'cmplz_get_region_for_country' ) ) {
function cmplz_get_region_for_country( $country_code ) {
$region = false;
$regions = COMPLIANZ::$config->regions;
foreach ( $regions as $region_code => $region_data ) {
if ( in_array( $country_code, $region_data['countries'] ) ) {
$region = $region_code;
break;
}
}
return apply_filters( "cmplz_region_for_country", $region, $country_code );
}
}
if ( ! function_exists( 'cmplz_get_consenttype_for_country' ) ) {
function cmplz_get_consenttype_for_country( $country_code ) {
$regions = COMPLIANZ::$config->regions;
$used_regions = cmplz_get_regions();
//do not unset a not used region if it's a manual override.
if ( !isset($_GET['cmplz_user_region']) ) {
foreach ( $regions as $region => $region_data ) {
if ( empty($used_regions) || !in_array( $region, $used_regions )) {
unset($regions[$region]);
}
}
}
$actual_region = apply_filters('cmplz_user_region', cmplz_get_region_for_country( $country_code ));
if ( isset( $regions[ $actual_region ]) && isset( $regions[ $actual_region ]['type'] ) ) {
$consenttype = apply_filters( 'cmplz_consenttype', $regions[ $actual_region ]['type'], $actual_region );
return $consenttype;
}
return false;
}
}
if ( ! function_exists( 'cmplz_targeting_multiple_regions' ) ) {
function cmplz_targeting_multiple_regions(){
if ( defined("POLYLANG_VERSION" ) ) return true;
if ( defined("WPML_PLUGIN_BASENAME" ) ) return true;
return false;
}
}
/**
* Check if the scan detected social media on the site.
*
*
* */
if ( ! function_exists( 'cmplz_scan_detected_social_media' ) ) {
function cmplz_scan_detected_social_media() {
$social_media = get_option( 'cmplz_detected_social_media', array() );
if ( ! is_array( $social_media ) ) {
$social_media = array( $social_media );
}
$social_media = array_filter( $social_media );
$social_media = apply_filters( 'cmplz_detected_social_media',
$social_media );
//nothing scanned yet, or nothing found
if ( ! $social_media || ( count( $social_media ) == 0 ) ) {
$social_media = false;
}
return $social_media;
}
}
if ( ! function_exists( 'cmplz_scan_detected_thirdparty_services' ) ) {
function cmplz_scan_detected_thirdparty_services() {
$thirdparty = get_option( 'cmplz_detected_thirdparty_services', array() );
if ( ! is_array( $thirdparty ) ) {
$thirdparty = array( $thirdparty );
}
$thirdparty = array_filter( $thirdparty );
$thirdparty = apply_filters( 'cmplz_detected_services', $thirdparty );
//nothing scanned yet, or nothing found
if ( ! $thirdparty || ( count( $thirdparty ) == 0 ) ) {
$thirdparty = false;
}
return $thirdparty;
}
}
if ( ! function_exists( 'cmplz_scan_detected_stats' ) ) {
function cmplz_scan_detected_stats() {
$stats = get_option( 'cmplz_detected_stats', array() );
if ( ! is_array( $stats ) ) {
$stats = array( $stats );
}
$stats = array_filter( $stats );
//nothing scanned yet, or nothing found
if ( ! $stats || ( count( $stats ) == 0 ) ) {
$stats = false;
}
$stats = apply_filters( 'cmplz_detected_stats', $stats );
return $stats;
}
}
if ( ! function_exists( 'cmplz_page_is_of_type' ) ) {
/**
* Save a complianz option
* @param string $type
* @return bool
*/
function cmplz_page_is_of_type( $type ) {
$regions = cmplz_get_regions();
global $post;
if ( !$post ) return false;
$post_id = $post->ID;
foreach ( $regions as $region ) {
$policy_id = COMPLIANZ::$document->get_shortcode_page_id( $type, $region );
if ( $policy_id === $post_id ) {
return true;
}
}
return false;
}
}
if ( ! function_exists( 'cmplz_uses_statistics' ) ) {
function cmplz_uses_statistics() {
$stats = cmplz_get_option( 'compile_statistics' );
if ( $stats !== 'no' ) {
return true;
}
return false;
}
}
if ( ! function_exists( 'cmplz_show_install_burst_warning' ) ) {
function cmplz_show_install_burst_warning() {
if ( cmplz_get_option('consent_for_anonymous_stats') === 'yes' && !defined( 'burst_version' ) ) {
return true;
}
return false;
}
}
if ( ! function_exists( 'cmplz_uses_only_functional_cookies' ) ) {
function cmplz_uses_only_functional_cookies() {
return COMPLIANZ::$banner_loader->uses_only_functional_cookies();
}
}
if ( !function_exists('cmplz_scan_in_progress')) {
function cmplz_scan_in_progress(){
return isset( $_GET['complianz_scan_token'] ) && wp_verify_nonce( $_GET['complianz_scan_token'], 'complianz_scan_token');
}
}
if ( ! function_exists( 'cmplz_ecommerce_legal' ) ) {
function cmplz_ecommerce_legal() {
//check Woo and EDD constants
$ecommerce_enabled = defined('WC_PLUGIN_FILE') || defined('EDD_VERSION');
return $ecommerce_enabled;
}
}
if ( ! function_exists( 'cmplz_site_shares_data' ) ) {
/**
* Function to check if site shares data. Used in canada cookie policy
* @return bool
*/
function cmplz_site_shares_data() {
return COMPLIANZ::$banner_loader->site_shares_data();
}
}
if ( ! function_exists( 'cmplz_strip_spaces' ) ) {
function cmplz_strip_spaces( $string ) {
return preg_replace( '/\s*/m', '', $string );
}
}
if ( ! function_exists( 'cmplz_localize_date' ) ) {
function cmplz_localize_date( $unix_time ) {
$formatted_date = date( get_option( 'date_format' ), $unix_time );
$month = date( 'F', $unix_time ); //june
$month_localized = __( $month ); //juni
$date = str_replace( $month, $month_localized, $formatted_date );
$weekday = date( 'l', $unix_time ); //wednesday
$weekday_localized = __( $weekday ); //woensdag
$date = str_replace( $weekday, $weekday_localized, $date );
return $date;
}
}
if (!function_exists('cmplz_strpos_arr')) {
/**
* check if there is a partial match between a key of the array and the haystack
* We cannot use array_search, as this would not allow partial matches.
*
* @param string $haystack
* @param array $needle
*
* @return bool|string
*/
function cmplz_strpos_arr( $haystack, $needle ) {
if ( empty( $haystack ) ) {
return false;
}
if ( ! is_array( $needle ) ) {
$needle = array( $needle );
}
foreach ( $needle as $key => $value ) {
if ( strlen($value) === 0 ) continue;
if ( ( strpos( $haystack, $value ) ) !== false ) {
return ( is_numeric( $key ) ) ? $value : $key;
}
}
return false;
}
}
/**
* callback for privacy document Check if there is a text entered in the custom privacy statement text
*
* */
if ( ! function_exists( 'cmplz_has_custom_privacy_policy' ) ) {
function cmplz_has_custom_privacy_policy() {
$policy = cmplz_get_option( 'custom_privacy_policy_text' );
if ( empty( $policy ) ) {
return false;
}
return true;
}
}