Italy Cookie Choices (for EU Cookie Law) - Version 2.4.2

Version Description

Release Date: December 29th, 2015

Dev time: 1h

  • Fixed PHP7 Fatal error #149
  • Walking to WPCS
Download this release

Release Info

Developer overclokk
Plugin Icon Italy Cookie Choices (for EU Cookie Law)
Version 2.4.2
Comparing to
See all releases

Code changes from version 2.4.1 to 2.4.2

admin/class-italy-cookie-choices-admin.php CHANGED
@@ -4,1625 +4,1625 @@
4
  */
5
  if ( !class_exists( 'Italy_Cookie_Choices_Admin' ) ){
6
 
7
- class Italy_Cookie_Choices_Admin{
8
-
9
- /**
10
- * Definition of variables containing the configuration
11
- * to be applied to the various function calls wordpress
12
- */
13
- protected $capability = 'manage_options';
14
-
15
- /**
16
- * Global variables and default values
17
- * @var array
18
- */
19
- protected $default_options = array();
20
-
21
- /**
22
- * Option
23
- * @var array
24
- */
25
- private $options = array();
26
-
27
- /**
28
- * Default Cookie name
29
- * @var string
30
- */
31
- private $cookieName = 'displayCookieConsent';
32
-
33
- /**
34
- * Default cookie value
35
- * @var string
36
- */
37
- private $cookieVal = 'y';
38
-
39
- /**
40
- * Inizialize banner template to default
41
- * @var string
42
- */
43
- private $js_template = 'default';
44
-
45
- /**
46
- * Array of all posts and pages object
47
- * @var array
48
- */
49
- private $post_and_page_array = array();
50
-
51
- /**
52
- * Array with predefinited vendor iframe
53
- * @var array
54
- */
55
- private $iframe_array = array();
56
- /**
57
- * Array with predefinited vendor script
58
- * @var array
59
- */
60
- private $script_array = array();
61
- /**
62
- * Array with predefinited vendor embed
63
- * @var array
64
- */
65
- private $embed_array = array();
66
-
67
- /**
68
- * [__construct description]
69
- */
70
- public function __construct(){
71
-
72
- /**
73
- * Init vendors array
74
- */
75
- $this->create_third_party_array();
76
-
77
- /**
78
- * Get all posts and pages object and merge for jQuery autocomplete function
79
- */
80
- // $this->get_post_and_page_array();
81
- $this->post_and_page_array = ( is_array( get_pages('numberposts=-1') ) ) ? get_pages('numberposts=-1') : array();
82
-
83
- /**
84
- * Add Admin menù page
85
- */
86
- add_action( 'admin_menu', array( $this, 'addMenuPage') );
87
-
88
- /**
89
- * Init settings
90
- */
91
- add_action( 'admin_init', array( $this, 'italy_cl_settings_init') );
92
-
93
- /**
94
- * Load script only if is Italy Cookie Choices admin panel
95
- */
96
- if ( isset($_GET['page']) && ($_GET['page'] === 'italy-cookie-choices' ) )
97
- add_action('admin_enqueue_scripts', array( $this, 'add_script_and_style' ));
98
-
99
- /**
100
- * Add link in plugin activation panel
101
- */
102
- add_filter( 'plugin_action_links_' . ITALY_COOKIE_CHOICES_BASENAME, array( $this, 'plugin_action_links' ) );
103
-
104
- //Add the export settings method
105
- add_action( 'admin_init', array( $this, 'settings_export' ) );
106
- //Add the import settings method
107
- add_action( 'admin_init', array( $this, 'settings_import' ) );
108
-
109
- }
110
-
111
- /**
112
- * Encode a variable into JSON, with some sanity checks.
113
- *
114
- * @since 4.1.0
115
- *
116
- * @param mixed $data Variable (usually an array or object) to encode as JSON.
117
- * @param int $options Optional. Options to be passed to json_encode(). Default 0.
118
- * @param int $depth Optional. Maximum depth to walk through $data. Must be
119
- * greater than 0. Default 512.
120
- * @return bool|string The JSON encoded string, or false if it cannot be encoded.
121
- */
122
- public function wp_json_encode( $data, $options = 0, $depth = 512 ) {
123
-
124
- /*
125
- * json_encode() has had extra params added over the years.
126
- * $options was added in 5.3, and $depth in 5.5.
127
- * We need to make sure we call it with the correct arguments.
128
- */
129
- if ( version_compare( PHP_VERSION, '5.5', '>=' ) )
130
- $args = array( $data, $options, $depth );
131
- elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) )
132
- $args = array( $data, $options );
133
- else
134
- $args = array( $data );
135
-
136
- $json = call_user_func_array( 'json_encode', $args );
137
-
138
- // If json_encode() was successful, no need to do more sanity checking.
139
- // ... unless we're in an old version of PHP, and json_encode() returned
140
- // a string containing 'null'. Then we need to do more sanity checking.
141
- if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) )
142
- return $json;
143
-
144
- return call_user_func_array( 'json_encode', $args );
145
- }
146
-
147
- /**
148
- * Add page for italy-cookie-choices admin page
149
- */
150
- public function addMenuPage(){
151
-
152
- add_options_page(
153
- __('Italy Cookie Choices Dashboard', 'italy-cookie-choices'),
154
- 'Italy Cookie Choices',
155
- $this->capability,
156
- 'italy-cookie-choices',
157
- array( $this, 'dashboard')
158
- );
159
- }
160
-
161
- /**
162
- * The dashboard callback
163
- */
164
- public function dashboard(){
165
-
166
- if ( !current_user_can( $this->capability ) )
167
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
168
-
169
- include_once( 'template/admin.php' );
170
-
171
- }
172
-
173
- /**
174
- * Initialize plugin
175
- * @return [type] [description]
176
- */
177
- public function italy_cl_settings_init() {
178
-
179
- /**
180
- * Create default options
181
- * @var array
182
- */
183
- $this->default_options = array(
184
-
185
- 'text' => '',
186
- 'url' => '',
187
- 'anchor_text' => '',
188
- 'button_text' => '',
189
- 'cookie_name' => $this->cookieName,
190
- 'cookie_value' => $this->cookieVal,
191
- 'content_message_text' => '',
192
- 'content_message_button_text' => ''
193
-
194
- );
195
-
196
- /**
197
- * All options in array
198
- * @var array
199
- */
200
- $this->options = get_option( 'italy_cookie_choices' );
201
-
202
- /**
203
- * If the theme options don't exist, create them.
204
- */
205
- if( false === $this->options )
206
- add_option( 'italy_cookie_choices', $this->default_options );
207
-
208
- /**
209
- * Section options page
210
- */
211
- add_settings_section(
212
- 'setting_section',
213
- __( 'Italy Cookie Choices options page', 'italy-cookie-choices' ),
214
- array( $this, 'italy_cl_settings_section_callback'),
215
- 'italy_cl_options_group'
216
- );
217
-
218
- /**
219
- * Checkbox for activation
220
- */
221
- add_settings_field(
222
- 'active',
223
- __( 'Activate', 'italy-cookie-choices' ),
224
- array( $this, 'italy_cl_option_active'),
225
- 'italy_cl_options_group',
226
- 'setting_section'
227
- );
228
-
229
- /**
230
- * How to display banner
231
- * Default Bar
232
- */
233
- add_settings_field(
234
- 'banner',
235
- __( 'Where display the banner', 'italy-cookie-choices' ),
236
- array( $this, 'italy_cl_option_banner'),
237
- 'italy_cl_options_group',
238
- 'setting_section'
239
- );
240
-
241
- /**
242
- * Checkbox for scroll event
243
- */
244
- add_settings_field(
245
- 'scroll',
246
- __( 'Mouse scroll event', 'italy-cookie-choices' ),
247
- array( $this, 'italy_cl_option_scroll'),
248
- 'italy_cl_options_group',
249
- 'setting_section'
250
- );
251
-
252
- /**
253
- * Checkbox for open in new page
254
- */
255
- add_settings_field(
256
- 'secondView',
257
- __( 'Accept on second view', 'italy-cookie-choices' ),
258
- array( $this, 'italy_cl_option_secondView'),
259
- 'italy_cl_options_group',
260
- 'setting_section'
261
- );
262
-
263
- /**
264
- * Checkbox for reload page
265
- */
266
- add_settings_field(
267
- 'reload',
268
- __( 'Refresh page', 'italy-cookie-choices' ),
269
- array( $this, 'italy_cl_option_reload'),
270
- 'italy_cl_options_group',
271
- 'setting_section'
272
- );
273
-
274
- /**
275
- * Input for short policy text
276
- */
277
- add_settings_field(
278
- 'text',
279
- __( 'Text to display', 'italy-cookie-choices' ),
280
- array( $this, 'italy_cl_option_text'),
281
- 'italy_cl_options_group',
282
- 'setting_section'
283
- );
284
-
285
- /**
286
- * Input for url policy page
287
- */
288
- add_settings_field(
289
- 'url',
290
- __( 'URL for cookie policy', 'italy-cookie-choices' ),
291
- array( $this, 'italy_cl_option_url'),
292
- 'italy_cl_options_group',
293
- 'setting_section'
294
- );
295
-
296
- /**
297
- * Cookie policy page slug
298
- */
299
- add_settings_field(
300
- 'slug',
301
- __( 'Cookie policy page slug', 'italy-cookie-choices' ),
302
- array( $this, 'italy_cl_option_slug'),
303
- 'italy_cl_options_group',
304
- 'setting_section'
305
- );
306
-
307
- /**
308
- * Input for anchor text
309
- */
310
- add_settings_field(
311
- 'anchor_text',
312
- __( 'Anchor text for URL', 'italy-cookie-choices' ),
313
- array( $this, 'italy_cl_option_anchor_text'),
314
- 'italy_cl_options_group',
315
- 'setting_section'
316
- );
317
-
318
- /**
319
- * Input for button text
320
- */
321
- add_settings_field(
322
- 'button_text',
323
- __( 'Button text', 'italy-cookie-choices' ),
324
- array( $this, 'italy_cl_option_button_text'),
325
- 'italy_cl_options_group',
326
- 'setting_section'
327
- );
328
-
329
- /**
330
- * Settings sections for Style
331
- */
332
- add_settings_section(
333
- 'style_setting_section',
334
- __( 'Style settings', 'italy-cookie-choices' ),
335
- array( $this, 'italy_cl_style_settings_section_callback'),
336
- 'italy_cl_options_group'
337
- );
338
-
339
- /**
340
- * Select box for js_template selection
341
- */
342
- add_settings_field(
343
- 'js_template',
344
- __( 'CookieChoices Template', 'italy-cookie-choices' ),
345
- array( $this, 'italy_cl_option_js_template'),
346
- 'italy_cl_options_group',
347
- 'style_setting_section'
348
- );
349
-
350
- /**
351
- * Checkbox for activation
352
- */
353
- add_settings_field(
354
- 'html_margin',
355
- __( 'HTML top margin', 'italy-cookie-choices' ),
356
- array( $this, 'italy_cl_option_html_margin'),
357
- 'italy_cl_options_group',
358
- 'style_setting_section'
359
- );
360
-
361
- /**
362
- * Background color for banner
363
- */
364
- add_settings_field(
365
- 'banner_bg',
366
- __( 'Banner Background color', 'italy-cookie-choices' ),
367
- array( $this, 'italy_cl_option_banner_bg'),
368
- 'italy_cl_options_group',
369
- 'style_setting_section'
370
- );
371
-
372
- /**
373
- * Color for text in banner
374
- */
375
- add_settings_field(
376
- 'banner_text_color',
377
- __( 'Banner text color', 'italy-cookie-choices' ),
378
- array( $this, 'italy_cl_option_banner_text_color'),
379
- 'italy_cl_options_group',
380
- 'style_setting_section'
381
- );
382
-
383
- /**
384
- * Text area for custom CSS
385
- */
386
- add_settings_field(
387
- 'customCSS',
388
- __( 'Custom CSS', 'italy-cookie-choices' ),
389
- array( $this, 'italy_cl_option_customCSS'),
390
- 'italy_cl_options_group',
391
- 'style_setting_section'
392
- );
393
-
394
- /**
395
- * Text area for custom CSS class
396
- */
397
- add_settings_field(
398
- 'customClass',
399
- __( 'Custom CSS Class (Optional)', 'italy-cookie-choices' ),
400
- array( $this, 'italy_cl_option_customClass'),
401
- 'italy_cl_options_group',
402
- 'style_setting_section'
403
- );
404
-
405
- /**
406
- * Settings sections for Advanced options
407
- */
408
- add_settings_section(
409
- 'advanced_setting_section',
410
- __( 'Advanced settings', 'italy-cookie-choices' ),
411
- array( $this, 'italy_cl_advanced_settings_section_callback'),
412
- 'italy_cl_options_group'
413
- );
414
-
415
- /**
416
- * cookie name
417
- */
418
- add_settings_field(
419
- 'cookie_name',
420
- __( 'Cookie name', 'italy-cookie-choices' ),
421
- array( $this, 'italy_cl_option_cookie_name'),
422
- 'italy_cl_options_group',
423
- 'advanced_setting_section'
424
- );
425
-
426
- /**
427
- * cookie value
428
- */
429
- add_settings_field(
430
- 'cookie_value',
431
- __( 'Cookie value', 'italy-cookie-choices' ),
432
- array( $this, 'italy_cl_option_cookie_value'),
433
- 'italy_cl_options_group',
434
- 'advanced_setting_section'
435
- );
436
-
437
- /**
438
- * Checkbox for open in new page
439
- */
440
- add_settings_field(
441
- 'target',
442
- __( 'Open policy in new page', 'italy-cookie-choices' ),
443
- array( $this, 'italy_cl_option_target'),
444
- 'italy_cl_options_group',
445
- 'advanced_setting_section'
446
- );
447
-
448
- /**
449
- * Checkbox for activation third part cookie eraser
450
- */
451
- add_settings_field(
452
- 'block',
453
- __( 'Third part cookie block (beta)', 'italy-cookie-choices' ),
454
- array( $this, 'italy_cl_option_block'),
455
- 'italy_cl_options_group',
456
- 'advanced_setting_section'
457
- );
458
-
459
- /**
460
- * Function for custom script allow
461
- */
462
- add_settings_field(
463
- 'custom_script_block_body_exclude',
464
- __( 'Scripts allowed in body', 'italy-cookie-choices' ),
465
- array( $this, 'italy_cl_option_custom_script_block_body_exclude'),
466
- 'italy_cl_options_group',
467
- 'advanced_setting_section'
468
- );
469
-
470
- /**
471
- * Function for custom script block
472
- */
473
- add_settings_field(
474
- 'custom_script_block',
475
- __( 'Scripts to be blocked', 'italy-cookie-choices' ),
476
- array( $this, 'italy_cl_option_custom_script_block'),
477
- 'italy_cl_options_group',
478
- 'advanced_setting_section'
479
- );
480
-
481
- /**
482
- * Function for content message text
483
- */
484
- add_settings_field(
485
- 'content_message_text',
486
- __( 'Text message for locked embedded content', 'italy-cookie-choices' ),
487
- array( $this, 'italy_cl_option_content_message_text'),
488
- 'italy_cl_options_group',
489
- 'advanced_setting_section'
490
- );
491
-
492
- /**
493
- * Function for button text in message
494
- */
495
- add_settings_field(
496
- 'content_message_button_text',
497
- __( 'Button text to activate locked embedded content', 'italy-cookie-choices' ),
498
- array( $this, 'italy_cl_option_content_message_button_text'),
499
- 'italy_cl_options_group',
500
- 'advanced_setting_section'
501
- );
502
-
503
- /**
504
- * Register setting
505
- */
506
- register_setting(
507
- 'italy_cl_options_group',
508
- 'italy_cookie_choices',
509
- array( $this, 'sanitize_callback')
510
- );
511
-
512
-
513
- }
514
-
515
-
516
- /**
517
- * Display message in plugin control panel
518
- * @return string Return message
519
- */
520
- public function italy_cl_settings_section_callback() {
521
-
522
- _e( 'Customize your banner for cookie law', 'italy-cookie-choices' );
523
-
524
- }
525
-
526
- /**
527
- * Snippet for checkbox
528
- * @return strimg Activate banner in front-end Default doesn't display
529
- */
530
- public function italy_cl_option_active($args) {
531
-
532
- $active = ( isset( $this->options['active'] ) ) ? $this->options['active'] : '' ;
533
- ?>
534
-
535
- <input type='checkbox' name='italy_cookie_choices[active]' <?php checked( $active, 1 ); ?> value='1' id="italy_cookie_choices[active]">
536
- <label for="italy_cookie_choices[active]" id="active">
537
- <?php _e( 'Display banner for Cookie Law in front-end', 'italy-cookie-choices' ); ?>
538
- </label>
539
-
540
- <?php
541
-
542
- }
543
-
544
- /**
545
- * Choose how to display banner in page
546
- * @return string Display input and labels in plugin options page
547
- */
548
- public function italy_cl_option_banner($args) {
549
-
550
- $banner = ( isset( $this->options['banner'] ) ) ? $this->options['banner'] : '1' ;
551
-
552
- ?>
553
-
554
- <input name="italy_cookie_choices[banner]" type="radio" value="1" id="radio_1" <?php checked( '1', $banner ); ?> />
555
-
556
- <label for="radio_1" id="label_radio_1">
557
- <?php _e( 'Top Bar (Default, Display a top bar with your message)', 'italy-cookie-choices' ); ?>
558
- </label>
559
-
560
- <br>
561
-
562
- <input name="italy_cookie_choices[banner]" type="radio" value="2" id="radio_2" <?php checked( '2', $banner ); ?> />
563
-
564
- <label for="radio_2" id="label_radio_2">
565
- <?php _e( 'Dialog (Display an overlay with your message)', 'italy-cookie-choices' ); ?>
566
- </label>
567
-
568
- <br>
569
-
570
- <input name="italy_cookie_choices[banner]" type="radio" value="3" id="radio_3" <?php checked( '3', $banner ); ?> />
571
-
572
- <label for="radio_3" id="label_radio_3">
573
- <?php _e( 'Bottom Bar (Display a bar in the footer with your message)', 'italy-cookie-choices' ); ?>
574
- </label>
575
 
576
-
577
 
578
- <?php
579
 
580
- }
581
 
582
- /**
583
- * Snippet for checkbox
584
- * @return strimg Activate banner in front-end Default doesn't display
585
- */
586
- public function italy_cl_option_scroll($args) {
587
 
588
- $scroll = ( isset( $this->options['scroll'] ) ) ? $this->options['scroll'] : '' ;
589
- ?>
590
 
591
- <input type='checkbox' name='italy_cookie_choices[scroll]' <?php checked( $scroll, 1 ); ?> value='1' id="italy_cookie_choices[scroll]">
592
- <label for="italy_cookie_choices[scroll]">
593
- <?php _e( 'Accepts disclosures on mouse scroll event', 'italy-cookie-choices' ); ?>
594
- </label>
595
 
596
- <?php
597
 
598
- }
599
 
600
- /**
601
- * Snippet for second view checkbox $secondView
602
- * @return strimg Activate for accept on second view
603
- * Default do nothing
604
- */
605
- public function italy_cl_option_secondView($args) {
606
 
607
- $secondView = ( isset( $this->options['secondView'] ) ) ? $this->options['secondView'] : '' ;
608
 
609
- ?>
610
 
611
- <input type='checkbox' name='italy_cookie_choices[secondView]' <?php checked( $secondView, 1 ); ?> value='1' id="italy_cookie_choices[secondView]">
612
- <label for="italy_cookie_choices[secondView]">
613
- <?php _e( 'Activate accept on second view', 'italy-cookie-choices' ); ?>
614
- </label>
615
 
616
- <?php
617
 
618
- }
619
 
620
- /**
621
- * Snippet for reload
622
- * @return strimg Reload page after click
623
- */
624
- public function italy_cl_option_reload($args) {
625
 
626
- $reload = ( isset( $this->options['reload'] ) ) ? $this->options['reload'] : '' ;
627
- ?>
628
-
629
- <input type='checkbox' name='italy_cookie_choices[reload]' <?php checked( $reload, 1 ); ?> value='1' id="italy_cookie_choices[reload]">
630
- <label for="italy_cookie_choices[reload]">
631
- <?php _e( 'Refresh page after button click (DEPRECATED)', 'italy-cookie-choices' ); ?>
632
- </label>
633
-
634
- <?php
635
-
636
- }
637
-
638
- /**
639
- * Textarea for the message to display
640
- * @return string
641
- */
642
- public function italy_cl_option_text($args) {
643
-
644
- /**
645
- * Allow HTML tags in text area
646
- * changed esc_textarea( $this->options['text'] ); with wp_kses_post( $this->options['text'] );
647
- * @todo Add padding to text editor
648
- */
649
-
650
- if ( function_exists("wp_editor") ):
651
- wp_editor(
652
- wp_kses_post( $this->options['text'] ),
653
- 'italy_cookie_choices_text',
654
- array(
655
- 'textarea_name' => 'italy_cookie_choices[text]',
656
- 'media_buttons' => false,
657
- 'textarea_rows' => 5,
658
- 'editor_css' => '<style>#wp-italy_cookie_choices_text-wrap{max-width:520px}</style>',
659
- 'teeny' => true
660
- )
661
- );
662
- else:
663
- ?>
664
- <textarea rows="5" cols="70" name="italy_cookie_choices[text]" id="italy_cookie_choices[text]" placeholder="<?php _e( 'Your short cookie policy', 'italy-cookie-choices' ) ?>" ><?php echo wp_kses_post( $this->options['text'] ); ?></textarea>
665
-
666
- <?php endif; ?>
667
-
668
- <br>
669
-
670
- <label for="italy_cookie_choices[text]">
671
- <?php echo __( 'People will see this notice only the first time that they enter your site', 'italy-cookie-choices' ); ?>
672
- </label>
673
-
674
- <?php
675
-
676
- }
677
-
678
- /**
679
- * Input for url policy page
680
- * @return string
681
- */
682
- public function italy_cl_option_url($args) {
683
-
684
- /**
685
- * Get the $post_ID for autocomplete function and put it in javascript var
686
- * @var array
687
- */
688
- $urls = array();
689
- foreach( $this->post_and_page_array as $post )
690
- $urls[] = get_permalink( $post->ID );
691
-
692
- ?>
693
- <script>
694
- var urls = '<?php echo $this->wp_json_encode( $urls ); ?>';
695
- </script>
696
- <input type="text" id="italy_cookie_choices[url]" name="italy_cookie_choices[url]" value="<?php echo esc_url( $this->options['url'] ); ?>" placeholder="<?php _e( 'e.g. http://www.aboutcookies.org/', 'italy-cookie-choices' ) ?>" size="70" />
697
- <br>
698
- <label for="italy_cookie_choices[url]">
699
- <?php echo __( 'Insert here the link to your policy page', 'italy-cookie-choices' ); ?> <a href="post-new.php?post_type=page"><?php _e( 'otherwise create a new one and then add URL to this input', 'italy-cookie-choices' ); ?></a>
700
- <br>
701
- <?php echo __( 'Start typing first two letters of the name of the policy page and then select it from the menu below the input', 'italy-cookie-choices' ); ?>
702
- </label>
703
-
704
- <?php
705
-
706
- }
707
-
708
- /**
709
- * Slug for cookie policy page
710
- * @return strimg Slug for cookie policy page Default null
711
- */
712
- public function italy_cl_option_slug($args) {
713
-
714
- $slug = ( isset( $this->options['slug'] ) ) ? $this->options['slug'] : '' ;
715
-
716
- /**
717
- * Get the $post_name for autocomplete function and put it in javascript var
718
- * @var array
719
- */
720
- $slugs = array();
721
- foreach( $this->post_and_page_array as $post )
722
- $slugs[] = $post->post_name;
723
-
724
- ?>
725
- <script>
726
- var slugs = '<?php echo $this->wp_json_encode( $slugs ); ?>';
727
- </script>
728
- <input type="text" id="italy_cookie_choices[slug]" name="italy_cookie_choices[slug]" value="<?php echo esc_attr( $slug ); ?>" placeholder="<?php _e( 'e.g. privacy-e-cookie', 'italy-cookie-choices' ); ?>" size="70" class="slug_autocomplete"/>
729
- <br>
730
- <label for="italy_cookie_choices[slug]">
731
- <?php _e( 'Insert your cookie policy page slug (e.g. for the page http://www.miodominio.it/privacy-e-cookie/ the slug is <strong>privacy-e-cookie</strong>).<br>In this way it will display only the topbar in your cookie policy page, the scroll and the second view will be deactivated in that page too.', 'italy-cookie-choices' ); ?>
732
- <br>
733
- <?php echo __( 'Start typing first two letters of the name of the policy page and then select it from the menu below the input', 'italy-cookie-choices' ); ?>
734
- </label>
735
 
736
- <?php
737
-
738
- }
739
-
740
- /**
741
- * Input for anchor_text
742
- * @return string
743
- */
744
- public function italy_cl_option_anchor_text($args) {
745
 
746
- ?>
747
- <input type="text" id="italy_cookie_choices[anchor_text]" name="italy_cookie_choices[anchor_text]" value="<?php echo esc_attr( $this->options['anchor_text'] ); ?>" placeholder="<?php _e( 'e.g. More Info', 'italy-cookie-choices' ) ?>" />
748
 
749
- <label for="italy_cookie_choices[anchor_text]">
750
- <?php echo __( 'Insert here anchor text for the link', 'italy-cookie-choices'); ?>
751
- </label>
752
 
753
- <?php
754
 
755
- }
756
 
757
- /**
758
- * Input for anchor_text
759
- * @return string
760
- */
761
- public function italy_cl_option_button_text($args) {
762
 
763
- ?>
764
- <input type="text" id="italy_cookie_choices[button_text]" name="italy_cookie_choices[button_text]" value="<?php echo esc_attr( $this->options['button_text'] ); ?>" placeholder="<?php _e( 'e.g. Close', 'italy-cookie-choices' ) ?>" />
765
 
766
- <label for="italy_cookie_choices[button_text]">
767
- <?php echo __( 'Insert here name of button (e.g. "Close") ', 'italy-cookie-choices' ); ?>
768
- </label>
769
 
770
- <?php
771
 
772
- }
773
 
774
- /**
775
- * NUOVA SETTINGS SECTIONS PER LO STILE
776
- */
777
 
778
- /**
779
- * Display message in stile plugin panel
780
- * @return string
781
- */
782
- public function italy_cl_style_settings_section_callback() {
783
 
784
- _e( 'Customize your style settings', 'italy-cookie-choices' );
785
 
786
- }
787
 
788
- /**
789
- * Snippet for checkbox
790
- * @return strimg Activate banner in front-end Default doesn't display
791
- */
792
- public function italy_cl_option_html_margin($args) {
793
 
794
- $html_margin = ( isset( $this->options['html_margin'] ) ) ? $this->options['html_margin'] : '' ;
795
 
796
- ?>
797
 
798
- <input type='checkbox' name='italy_cookie_choices[html_margin]' <?php checked( $html_margin, 1 ); ?> value='1' id="italy_cookie_choices[html_margin]">
799
- <label for="italy_cookie_choices[html_margin]">
800
- <?php _e( 'Add a page top margin for info top bar, only for default topbar stile', 'italy-cookie-choices' ); ?>
801
- </label>
802
 
803
- <?php
804
 
805
- }
806
-
807
- /**
808
- * Snippet for select
809
- * @return strimg Chose the JS_Template to use.
810
- */
811
- public function italy_cl_option_js_template($args) {
812
 
813
- $js_template = ( isset( $this->options['js_template'] ) ) ? $this->options['js_template'] : $this->js_template ;
814
 
815
- ?>
816
- <select name='italy_cookie_choices[js_template]' id="italy_cookie_choices[js_template]">
817
 
818
- <option value="default" <?php if ( $js_template === 'default' ) echo 'selected';?>><?php _e( 'Default cookiechoices template (centered with text links)', 'italy-cookie-choices' ); ?></option>
819
 
820
- <option value="bigbutton" <?php if ( $js_template === 'bigbutton' ) echo 'selected';?>><?php _e( 'Centered container with left aligned text and big buttons', 'italy-cookie-choices' ); ?></option>
821
 
822
- <option value="smallbutton" <?php if ( $js_template === 'smallbutton' ) echo 'selected';?>><?php _e( 'Centered container with left aligned text and small buttons', 'italy-cookie-choices' ); ?></option>
823
 
824
- <option value="custom" <?php if ( $js_template === 'custom' ) echo 'selected';?>><?php _e( 'My custom CSS', 'italy-cookie-choices' ); ?></option>
825
 
826
- </select>
827
- <label for="italy_cookie_choices[js_template]">
828
- <?php _e( 'Select the template to use', 'italy-cookie-choices' ); ?>
829
- </label>
830
 
831
- <?php
832
 
833
- }
834
 
835
- /**
836
- * Snippet for checkbox
837
- * @return strimg Activate banner in front-end Default doesn't display
838
- */
839
- public function italy_cl_option_banner_bg($args) {
840
 
841
- $banner_bg = ( isset( $this->options['banner_bg'] ) ) ? $this->options['banner_bg'] : '#fff' ;
842
 
843
- ?>
844
 
845
- <input type="text" id="italy_cookie_choices[banner_bg]" name="italy_cookie_choices[banner_bg]" value="<?php echo esc_attr( $banner_bg ); ?>" placeholder="<?php echo esc_attr( $banner_bg ); ?>" class="color-field" data-default-color="#fff"/>
846
 
847
 
848
- <label for="italy_cookie_choices[banner_bg]">
849
- <?php _e( 'Custom Background color for banner', 'italy-cookie-choices' ); ?>
850
- </label>
851
 
852
- <?php
853
 
854
- }
855
 
856
- /**
857
- * Snippet for banner text color
858
- * @return strimg Activate banner in front-end Default doesn't display
859
- */
860
- public function italy_cl_option_banner_text_color($args) {
861
 
862
- $banner_text_color = ( isset( $this->options['banner_text_color'] ) ) ? $this->options['banner_text_color'] : '#000' ;
863
 
864
- ?>
865
 
866
- <input type="text" id="italy_cookie_choices[banner_text_color]" name="italy_cookie_choices[banner_text_color]" value="<?php echo esc_attr( $banner_text_color ); ?>" placeholder="<?php echo esc_attr( $banner_text_color ); ?>" class="color-field" data-default-color="#000"/>
867
 
868
- <label for="italy_cookie_choices[banner_text_color]">
869
- <?php _e( 'Custom text color for banner', 'italy-cookie-choices' ); ?>
870
- </label>
871
 
872
- <?php
873
 
874
- }
875
 
876
- /**
877
- * Textarea for custom CSS
878
- * @return string
879
- */
880
- public function italy_cl_option_customCSS($args) {
881
 
882
- $customCSS = ( isset( $this->options['customCSS'] ) ) ? $this->options['customCSS'] : '' ;
883
 
884
- ?>
885
 
886
- <textarea rows="5" cols="70" name="italy_cookie_choices[customCSS]" id="italy_cookie_choices[customCSS]" placeholder="<?php _e( 'Your custom css', 'italy-cookie-choices' ) ?>" ><?php echo esc_textarea( $customCSS ); ?></textarea>
887
- <br>
888
- <label for="italy_cookie_choices[customCSS]">
889
- <?php echo __( 'Inset here your custom CSS for banner', 'italy-cookie-choices' ); ?>
890
- </label>
891
 
892
- <?php
893
 
894
- }
895
 
896
- /**
897
- * Input for custom CSS class
898
- * @return string
899
- */
900
- public function italy_cl_option_customClass($args) {
901
 
902
- $bannerStyle = ( isset( $this->options['bannerStyle'] ) ) ? esc_attr( $this->options['bannerStyle'] ) : 'bannerStyle' ;
903
 
904
- $contentStyle = ( isset( $this->options['contentStyle'] ) ) ? esc_attr( $this->options['contentStyle'] ) : 'contentStyle' ;
905
 
906
- $consentText = ( isset( $this->options['consentText'] ) ) ? esc_attr( $this->options['consentText'] ) : 'consentText' ;
907
 
908
- $infoClass = ( isset( $this->options['infoClass'] ) ) ? esc_attr( $this->options['infoClass'] ) : 'italybtn' ;
909
 
910
- $closeClass = ( isset( $this->options['closeClass'] ) ) ? esc_attr( $this->options['closeClass'] ) : 'italybtn' ;
911
 
912
- ?>
913
 
914
- <input type="text" id="italy_cookie_choices[bannerStyle]" name="italy_cookie_choices[bannerStyle]" value="<?php echo esc_attr( $bannerStyle ); ?>" placeholder="<?php _e( 'Eg: bannerStyle', 'italy-cookie-choices' ); ?>" />
915
- <label for="italy_cookie_choices[bannerStyle]">
916
- <?php echo __( 'CSS class for div container (Default <code>bannerStyle</code>)', 'italy-cookie-choices' ); ?>
917
- </label>
918
- <br>
919
- <input type="text" id="italy_cookie_choices[contentStyle]" name="italy_cookie_choices[contentStyle]" value="<?php echo esc_attr( $contentStyle ); ?>" placeholder="<?php _e( 'Eg: contentStyle', 'italy-cookie-choices' ); ?>" />
920
- <label for="italy_cookie_choices[contentStyle]">
921
- <?php echo __( 'CSS class for div content (Default <code>contentStyle</code>)', 'italy-cookie-choices' ); ?>
922
- </label>
923
- <br>
924
- <input type="text" id="italy_cookie_choices[consentText]" name="italy_cookie_choices[consentText]" value="<?php echo esc_attr( $consentText ); ?>" placeholder="<?php _e( 'Eg: consentText', 'italy-cookie-choices' );; ?>" />
925
- <label for="italy_cookie_choices[consentText]">
926
- <?php echo __( 'CSS class for span content (Default <code>consentText</code>)', 'italy-cookie-choices' ); ?>
927
- </label>
928
- <br>
929
- <input type="text" id="italy_cookie_choices[infoClass]" name="italy_cookie_choices[infoClass]" value="<?php echo esc_attr( $infoClass ); ?>" placeholder="<?php _e( 'Eg: infoClass', 'italy-cookie-choices' ); ?>" />
930
- <label for="italy_cookie_choices[infoClass]">
931
- <?php echo __( 'CSS class for Info link (Default <code>itaybtn</code>)', 'italy-cookie-choices' ); ?>
932
- </label>
933
- <br>
934
- <input type="text" id="italy_cookie_choices[closeClass]" name="italy_cookie_choices[closeClass]" value="<?php echo esc_attr( $closeClass ); ?>" placeholder="<?php _e( 'Eg: closeClass', 'italy-cookie-choices' ); ?>" />
935
- <label for="italy_cookie_choices[closeClass]">
936
- <?php echo __( 'CSS class for close link (Default <code>itaybtn</code>)', 'italy-cookie-choices' ); ?>
937
- </label>
938
 
939
- <p><?php _e( 'Customize with your personal CSS class', 'italy-cookie-choices' ); ?></p>
940
 
941
- <?php
942
 
943
- }
944
 
945
- /**
946
- * NUOVA SETTINGS SECTIONS PER LE OPZIONI AVANZATE
947
- */
948
 
949
- /**
950
- * Display message in plugin advanced setting section
951
- * @return string
952
- */
953
- public function italy_cl_advanced_settings_section_callback() {
954
 
955
- _e( 'Customize your advanced settings', 'italy-cookie-choices' );
956
 
957
- }
958
 
959
- /**
960
- * Snippet for cookie name
961
- * @return strimg Activate banner in front-end Default doesn't display
962
- */
963
- public function italy_cl_option_cookie_name($args) {
964
 
965
- $cookie_name = ( isset( $this->options['cookie_name'] ) ) ? $this->options['cookie_name'] : $this->cookieName ;
966
 
967
- ?>
968
- <input type="text" id="italy_cookie_choices[cookie_name]" name="italy_cookie_choices[cookie_name]" value="<?php echo esc_attr( $cookie_name ); ?>" placeholder="<?php echo esc_attr( $this->cookieName ); ?>" />
969
 
970
- <label for="italy_cookie_choices[cookie_name]">
971
- <?php _e( 'Insert your cookie name (Default: displayCookieConsent)', 'italy-cookie-choices' ); ?>
972
- </label>
973
 
974
- <?php
975
 
976
- }
977
 
978
- /**
979
- * Snippet for cookie value
980
- * @return strimg Activate banner in front-end Default doesn't display
981
- */
982
- public function italy_cl_option_cookie_value($args) {
983
 
984
- $cookie_value = ( isset( $this->options['cookie_value'] ) ) ? $this->options['cookie_value'] : $this->cookieVal ;
985
 
986
- ?>
987
- <input type="text" id="italy_cookie_choices[cookie_value]" name="italy_cookie_choices[cookie_value]" value="<?php echo esc_attr( $cookie_value ); ?>" placeholder="<?php echo esc_attr( $this->cookieVal ); ?>" />
988
 
989
- <label for="italy_cookie_choices[cookie_value]">
990
- <?php _e( 'Insert your cookie value (Default: y)', 'italy-cookie-choices' ); ?>
991
- </label>
992
 
993
- <?php
994
 
995
- }
996
 
997
- /**
998
- * Snippet for target checkbox
999
- * @return strimg Activate for open policy page in new tab
1000
- * Default open in same tab
1001
- */
1002
- public function italy_cl_option_target($args) {
1003
 
1004
- $target = ( isset( $this->options['target'] ) ) ? $this->options['target'] : '' ;
1005
 
1006
- ?>
1007
 
1008
- <input type='checkbox' name='italy_cookie_choices[target]' <?php checked( $target, 1 ); ?> value='1' id="italy_cookie_choices[target]">
1009
- <label for="italy_cookie_choices[target]">
1010
- <?php _e( 'Open your cookie policy page in new one', 'italy-cookie-choices' ); ?>
1011
- </label>
1012
-
1013
- <?php
1014
-
1015
- }
1016
-
1017
- /**
1018
- * Snippet for target checkbox
1019
- * @return strimg Activate for open policy page in new tab
1020
- * Default open in same tab
1021
- */
1022
- public function italy_cl_option_block($args) {
1023
-
1024
- $all_block = ( isset( $this->options['all_block'] ) ) ? $this->options['all_block'] : '' ;
1025
-
1026
- $block = ( isset( $this->options['block'] ) && $all_block === '' ) ? $this->options['block'] : '' ;
1027
 
1028
- $widget_block = ( isset( $this->options['widget_block'] ) && $all_block === '' ) ? $this->options['widget_block'] : '' ;
1029
 
1030
- ?>
1031
 
1032
- <input type='checkbox' name='italy_cookie_choices[block]' <?php checked( $block, 1 ); ?> value='1' id="italy_cookie_choices[block]">
1033
- <label for="italy_cookie_choices[block]">
1034
- <?php _e( 'Cookie from any embed in your content (Beta) (DEPRECATED)', 'italy-cookie-choices' ); ?>
1035
- </label>
1036
- <br>
1037
- <input type='checkbox' name='italy_cookie_choices[widget_block]' <?php checked( $widget_block, 1 ); ?> value='1' id="italy_cookie_choices[widget_block]">
1038
- <label for="italy_cookie_choices[widget_block]">
1039
- <?php _e( 'Cookie from any embed in your widget area (Beta) (DEPRECATED)', 'italy-cookie-choices' ); ?>
1040
- </label>
1041
- <br>
1042
- <br>
1043
- <input type='checkbox' name='italy_cookie_choices[all_block]' <?php checked( $all_block, 1 ); ?> value='1' id="italy_cookie_choices[all_block]">
1044
- <label for="italy_cookie_choices[all_block]">
1045
- <?php _e( 'Cookie from any embed in all body, except head and footer (Beta)', 'italy-cookie-choices' ); ?>
1046
- </label>
1047
-
1048
- <?php
1049
-
1050
- }
1051
-
1052
- /**
1053
- * Textarea for custom_script_block_body_exclude
1054
- * Scripts allowed in body
1055
- * @return string
1056
- */
1057
- public function italy_cl_option_custom_script_block_body_exclude($args) {
1058
-
1059
- /**
1060
- * Template with list of code example
1061
- */
1062
- require(ITALY_COOKIE_CHOICES_PLUGIN_PATH . 'admin/template/allow-script.php');
1063
-
1064
- $custom_script_block_body_exclude = ( isset( $this->options['custom_script_block_body_exclude'] ) ) ? $this->options['custom_script_block_body_exclude'] : '' ;
1065
-
1066
- ?>
1067
- <!-- <div id="editor"><?php // echo esc_textarea( $custom_script_block_body_exclude ); ?></div> -->
1068
-
1069
- <!-- <input type='checkbox' name='italy_cookie_choices[ppp]' <?php // checked( $block, 1 ); ?> value='1' id="italy_cookie_choices[ppp]"> -->
1070
- <!-- <br> -->
1071
- <textarea rows="5" cols="70" name="italy_cookie_choices[custom_script_block_body_exclude]" id="italy_cookie_choices[custom_script_block_body_exclude]" placeholder="<?php _e( '&lt;script src=&quot;http://domain.com/widget-example.js&quot;&gt;&lt;/script&gt;'."\n".'&lt;---------SEP---------&gt;'."\n".'&lt;script src=&quot;http://otherdomain.com/script-example.js&quot;&gt;&lt;/script&gt;'."\n".'&lt;---------SEP---------&gt;'."\n".'&lt;script src=&quot;http://lastdomain.com/gadget-example.js&quot;&gt;&lt;/script&gt;', 'italy-cookie-choices' ) ?>" class="textarea"><?php echo esc_textarea( $custom_script_block_body_exclude ); ?></textarea>
1072
- <br>
1073
- <a id="SEP" class="button button-secondary add-sep" data-value="<---------SEP--------->">&lt;---------SEP---------&gt;</a>
1074
- <a id="SOM" class="button button-secondary add-sep" data-value="<---------SOMETHING--------->">&lt;---------SOMETHING---------&gt;</a>
1075
-
1076
- <!-- <a href="#TB_inline?width=600&height=550&inlineId=code-example" class="thickbox button button-secondary"><?php // _e( 'View example', 'italy-cookie-choices' ); ?></a> -->
1077
-
1078
- <br>
1079
- <label for="italy_cookie_choices[custom_script_block_body_exclude]">
1080
- <?php echo __( 'Scripts to be excluded from the automatic block.<br />Split each script with <strong><em>&lt;---------SEP---------&gt;</em></strong><br>Use <strong><---------SOMETHING---------></strong> for custom regex', 'italy-cookie-choices' ); ?>
1081
- </label>
1082
- <p>
1083
- <a href="https://github.com/ItalyCookieChoices/italy-cookie-choices/wiki/Custom-script" target="_blank"><?php _e( 'For more information see the documentation', 'italy-cookie-choices' ); ?></a>
1084
- </p>
1085
-
1086
- <?php
1087
-
1088
- }
1089
-
1090
- /**
1091
- * Textarea for content_message_text
1092
- * @return string
1093
- */
1094
- public function italy_cl_option_custom_script_block($args) {
1095
-
1096
- /**
1097
- * Template with block script
1098
- */
1099
- require(ITALY_COOKIE_CHOICES_PLUGIN_PATH . 'admin/template/block-script.php');
1100
-
1101
- $custom_script_block = ( isset( $this->options['custom_script_block'] ) ) ? $this->options['custom_script_block'] : '' ;
1102
-
1103
- ?>
1104
- <textarea rows="5" cols="70" name="italy_cookie_choices[custom_script_block]" id="italy_cookie_choices[custom_script_block]" placeholder="<?php _e( '&lt;script src=&quot;http://domain.com/widget-example.js&quot;&gt;&lt;/script&gt;'."\n".'&lt;---------SEP---------&gt;'."\n".'&lt;script src=&quot;http://otherdomain.com/script-example.js&quot;&gt;&lt;/script&gt;'."\n".'&lt;---------SEP---------&gt;'."\n".'&lt;script src=&quot;http://lastdomain.com/gadget-example.js&quot;&gt;&lt;/script&gt;', 'italy-cookie-choices' ) ?>" ><?php echo esc_textarea( $custom_script_block ); ?></textarea>
1105
- <br>
1106
- <a id="SEP" class="button button-secondary add-sep" data-value="<---------SEP--------->">&lt;---------SEP---------&gt;</a>
1107
- <a id="SOM" class="button button-secondary add-sep" data-value="<---------SOMETHING--------->">&lt;---------SOMETHING---------&gt;</a>
1108
- <br>
1109
- <label for="italy_cookie_choices[custom_script_block]">
1110
- <?php echo __( 'Scripts shown in the head and in the footer does not automatically blocked.<br />Split each script with <strong><em>&lt;---------SEP---------&gt;</em></strong><br>Use <strong><---------SOMETHING---------></strong> for custom regex', 'italy-cookie-choices' ); ?>
1111
- </label>
1112
- <p>
1113
- <a href="https://github.com/ItalyCookieChoices/italy-cookie-choices/wiki/Custom-script" target="_blank"><?php _e( 'For more information see the documentation', 'italy-cookie-choices' ); ?></a>
1114
- </p>
1115
-
1116
- <?php
1117
-
1118
- }
1119
-
1120
- /**
1121
- * Function for custom script block
1122
- * @return string
1123
- */
1124
- public function italy_cl_option_content_message_text($args) {
1125
-
1126
- $content_message_text = ( isset( $this->options['content_message_text'] ) ) ? $this->options['content_message_text'] : '' ;
1127
-
1128
- /**
1129
- * Allow HTML tags in message text area
1130
- * changed esc_textarea( $this->options['text'] ); with wp_kses_post( $this->options['text'] );
1131
- * @todo Add padding to text editor
1132
- */
1133
-
1134
- if ( function_exists("wp_editor") ):
1135
- wp_editor(
1136
- wp_kses_post( $content_message_text ),
1137
- 'italy_cookie_choices_content_message_text',
1138
- array(
1139
- 'textarea_name' => 'italy_cookie_choices[content_message_text]',
1140
- 'media_buttons' => false,
1141
- 'textarea_rows' => 5,
1142
- 'editor_css' => '<style>#wp-italy_cookie_choices_content_message_text-wrap{max-width:520px}</style>',
1143
- 'teeny' => true
1144
- )
1145
- );
1146
- else:
1147
- ?>
1148
- <textarea rows="5" cols="70" name="italy_cookie_choices[content_message_text]" id="italy_cookie_choices[content_message_text]" placeholder="<?php _e( 'Your lock message for embedded contents inside posts, pages and widgets', 'italy-cookie-choices' ) ?>" ><?php echo wp_kses_post( $content_message_text ); ?></textarea>
1149
- <?php endif; ?>
1150
- <br>
1151
- <label for="italy_cookie_choices[content_message_text]">
1152
- <?php echo __( 'People will see this notice only the first time that they enter your site', 'italy-cookie-choices' ); ?>
1153
- </label>
1154
 
1155
- <?php
1156
 
1157
- }
1158
 
1159
- /**
1160
- * Input for content_message_button_text
1161
- * @return string
1162
- */
1163
- public function italy_cl_option_content_message_button_text($args) {
1164
 
1165
- $content_message_button_text = ( isset( $this->options['content_message_button_text'] ) ) ? $this->options['content_message_button_text'] : '' ;
1166
 
1167
- ?>
1168
- <input type="text" id="italy_cookie_choices[content_message_button_text]" name="italy_cookie_choices[content_message_button_text]" value="<?php echo esc_attr( $content_message_button_text ); ?>" placeholder="<?php _e( 'e.g. Close', 'italy-cookie-choices' ) ?>" />
1169
 
1170
- <label for="italy_cookie_choices[content_message_button_text]">
1171
- <?php echo __( 'Insert here name of button (e.g. "Close") ', 'italy-cookie-choices' ); ?>
1172
- </label>
1173
 
1174
- <?php
1175
 
1176
- }
1177
 
1178
- /**
1179
- * Sanitize data
1180
- * @param array $input Data to sanitize
1181
- * @return array Data sanitized
1182
- */
1183
- public function sanitize_callback( $input ){
1184
 
1185
- // require 'class-italy-cookie-choices-sanitize.php';
1186
 
1187
- // new Italy_Cookie_Choices_Sanitize( $input );
1188
 
1189
- $new_input = array();
1190
 
1191
- if( isset( $input['active'] ) )
1192
- $new_input['active'] = $input['active'];
1193
 
1194
- if( isset( $input['banner'] ) )
1195
- $new_input['banner'] = $input['banner'];
1196
 
1197
- if( isset( $input['scroll'] ) )
1198
- $new_input['scroll'] = $input['scroll'];
1199
 
1200
- if( isset( $input['secondView'] ) )
1201
- $new_input['secondView'] = $input['secondView'];
1202
 
1203
- if( isset( $input['reload'] ) )
1204
- $new_input['reload'] = $input['reload'];
1205
-
1206
- /**
1207
- * Multilingual for text, url, anchor_text & button_text
1208
- */
1209
- if( isset( $input['text'] ) ){
1210
 
1211
- $new_input['text'] = wp_kses_post( $input['text'] );
1212
- // $new_input['text'] = sanitize_text_field( $input['text'] );
1213
- register_string( 'Italy Cookie Choices', 'Banner text', $new_input['text'] );
1214
- }
1215
 
1216
- if( isset( $input['url'] ) ){
1217
 
1218
- $new_input['url'] = sanitize_text_field( $input['url'] );
1219
 
1220
- register_string( 'Italy Cookie Choices', 'Banner url', $new_input['url'] );
1221
 
1222
- }
1223
 
1224
- if( isset( $input['slug'] ) ){
1225
 
1226
- $new_input['slug'] = sanitize_text_field( $input['slug'] );
1227
 
1228
- register_string( 'Italy Cookie Choices', 'Banner slug', $new_input['slug'] );
1229
 
1230
- }
1231
 
1232
- if( isset( $input['anchor_text'] ) ){
1233
 
1234
- $new_input['anchor_text'] = sanitize_text_field( $input['anchor_text'] );
1235
 
1236
- register_string( 'Italy Cookie Choices', 'Banner anchor text', $new_input['anchor_text'] );
1237
 
1238
- }
1239
 
1240
- if( isset( $input['button_text'] ) ){
1241
 
1242
- $new_input['button_text'] = sanitize_text_field( $input['button_text'] );
1243
 
1244
- register_string( 'Italy Cookie Choices', 'Banner button text', $new_input['button_text'] );
1245
 
1246
- }
1247
 
1248
- /**
1249
- * Sezione per lo stile
1250
- */
1251
- if( isset( $input['html_margin'] ) )
1252
- $new_input['html_margin'] = $input['html_margin'];
1253
-
1254
- if( isset( $input['js_template'] ) )
1255
- $new_input['js_template'] = $input['js_template'];
1256
-
1257
- if( empty( $input['banner_bg'] ) )
1258
- $new_input['banner_bg'] = '#fff';
1259
- elseif ( isset( $input['banner_bg'] ) )
1260
- $new_input['banner_bg'] = sanitize_text_field( $input['banner_bg'] );
1261
 
1262
- if( empty( $input['banner_text_color'] ) )
1263
- $new_input['banner_text_color'] = '#000';
1264
- elseif ( isset( $input['banner_text_color'] ) )
1265
- $new_input['banner_text_color'] = sanitize_text_field( $input['banner_text_color'] );
1266
 
1267
- if( isset( $input['customCSS'] ) )
1268
- $new_input['customCSS'] = sanitize_text_field( $input['customCSS'] );
1269
 
1270
- if( empty( $input['bannerStyle'] ) )
1271
- $new_input['bannerStyle'] = 'bannerStyle';
1272
- elseif( isset( $input['bannerStyle'] ) )
1273
- $new_input['bannerStyle'] = sanitize_text_field( $input['bannerStyle'] );
1274
 
1275
- if( empty( $input['contentStyle'] ) )
1276
- $new_input['contentStyle'] = 'contentStyle';
1277
- elseif( isset( $input['contentStyle'] ) )
1278
- $new_input['contentStyle'] = sanitize_text_field( $input['contentStyle'] );
1279
 
1280
- if( empty( $input['consentText'] ) )
1281
- $new_input['consentText'] = 'consentText';
1282
- elseif( isset( $input['consentText'] ) )
1283
- $new_input['consentText'] = sanitize_text_field( $input['consentText'] );
1284
 
1285
- if( empty( $input['infoClass'] ) )
1286
- $new_input['infoClass'] = 'italybtn';
1287
- elseif( isset( $input['infoClass'] ) )
1288
- $new_input['infoClass'] = sanitize_text_field( $input['infoClass'] );
1289
 
1290
- if( empty( $input['closeClass'] ) )
1291
- $new_input['closeClass'] = 'italybtn';
1292
- elseif( isset( $input['closeClass'] ) )
1293
- $new_input['closeClass'] = sanitize_text_field( $input['closeClass'] );
1294
 
1295
- /**
1296
- * Sezione per le opzioni avanzate
1297
- * Esempio per add_settings_error()
1298
- * @link https://wordpress.org/support/topic/how-to-use-add_settings_error-for-nested-options-array?replies=2
1299
- * @link http://pastebin.com/K4kJ0DNG
1300
- */
1301
- if( empty( $input['cookie_name'] ) ){
1302
- add_settings_error( 'italy_cookie_id', 'cookie_name_ID', __('Cookie name field it can\'t be empty. Restored default name.', 'italy-cookie-choices' ), 'error');
1303
- $new_input['cookie_name'] = $this->cookieName;
1304
- }
1305
- else
1306
- $new_input['cookie_name'] = sanitize_text_field( $input['cookie_name'] );
1307
 
1308
- if( empty( $input['cookie_value'] ) ){
1309
- add_settings_error( 'italy_cookie_id', 'cookie_name_ID', __('Cookie value field it can\'t be empty. Restored default value.', 'italy-cookie-choices' ), 'error');
1310
- $new_input['cookie_value'] = $this->cookieVal;
1311
- }
1312
- else
1313
- $new_input['cookie_value'] = sanitize_text_field( $input['cookie_value'] );
1314
 
1315
- if( isset( $input['target'] ) )
1316
- $new_input['target'] = $input['target'];
1317
 
1318
- if( isset( $input['block'] ) )
1319
- $new_input['block'] = $input['block'];
1320
 
1321
- if( isset( $input['widget_block'] ) )
1322
- $new_input['widget_block'] = $input['widget_block'];
1323
 
1324
- if( isset( $input['all_block'] ) )
1325
- $new_input['all_block'] = $input['all_block'];
1326
-
1327
- /**
1328
- * Allow script
1329
- */
1330
- if( isset( $input['allow_iframe'] ) )
1331
- $new_input['allow_iframe'] = $input['allow_iframe'];
1332
-
1333
- if( isset( $input['allow_script'] ) )
1334
- $new_input['allow_script'] = $input['allow_script'];
1335
-
1336
- if( isset( $input['allow_embed'] ) )
1337
- $new_input['allow_embed'] = $input['allow_embed'];
1338
-
1339
- if( isset( $input['custom_script_block_body_exclude'] ) )
1340
- $new_input['custom_script_block_body_exclude'] = $input['custom_script_block_body_exclude'];
1341
- /**********************************************************************/
1342
-
1343
- /**
1344
- * Block script
1345
- */
1346
- if( isset( $input['block_iframe'] ) )
1347
- $new_input['block_iframe'] = $input['block_iframe'];
1348
-
1349
- if( isset( $input['block_script'] ) )
1350
- $new_input['block_script'] = $input['block_script'];
1351
-
1352
- if( isset( $input['block_embed'] ) )
1353
- $new_input['block_embed'] = $input['block_embed'];
1354
-
1355
- if( isset( $input['custom_script_block'] ) )
1356
- $new_input['custom_script_block'] = $input['custom_script_block'];
1357
- /**********************************************************************/
1358
-
1359
- if( isset( $input['content_message_text'] ) ){
1360
-
1361
- $new_input['content_message_text'] = wp_kses_post( $input['content_message_text'] );
1362
-
1363
- register_string( 'Italy Cookie Choices', 'Content message text', $new_input['content_message_text'] );
1364
-
1365
- }
1366
-
1367
- if( isset( $input['content_message_button_text'] ) ){
1368
-
1369
- $new_input['content_message_button_text'] = sanitize_text_field( $input['content_message_button_text'] );
1370
-
1371
- register_string( 'Italy Cookie Choices', 'Content message button text', $new_input['content_message_button_text'] );
1372
-
1373
- }
1374
-
1375
- return $new_input;
1376
-
1377
- }
1378
-
1379
- /**
1380
- * Function for color picker in admin
1381
- * @param string $hook_suffix Hook for script
1382
- * @return Append script
1383
- * @link https://make.wordpress.org/core/2012/11/30/new-color-picker-in-wp-3-5/
1384
- * @link http://code.tutsplus.com/articles/how-to-use-wordpress-color-picker-api--wp-33067
1385
- */
1386
- public function add_script_and_style( $hook_suffix ) {
1387
-
1388
- // first check that $hook_suffix is appropriate for your admin page
1389
- if ( 'settings_page_italy-cookie-choices' !== $hook_suffix )
1390
- continue;
1391
-
1392
- /**
1393
- * Add color picker in admin menù
1394
- */
1395
- wp_enqueue_style( 'wp-color-picker' );
1396
-
1397
- /**
1398
- * Load jQuery autocomplete for slug and url input
1399
- */
1400
- wp_enqueue_style( 'jquery-ui-autocomplete' );
1401
- wp_enqueue_script( 'jquery-ui-autocomplete' );
1402
-
1403
- /**
1404
- * Add thickbox for diplay code example
1405
- * @link https://codex.wordpress.org/Javascript_Reference/ThickBox
1406
- */
1407
- // add_thickbox();
1408
-
1409
- /**
1410
- * Load ACE from CDN
1411
- * Functionality for custom script editor and CSS editor
1412
- */
1413
- // wp_register_script('ace', '//cdn.jsdelivr.net/ace/1.1.9/min/ace.js', false, null, true);
1414
- // wp_enqueue_script('ace');
1415
-
1416
- wp_enqueue_style(
1417
- 'italy-cookie-choices-css',
1418
- plugins_url('admin/css/admin.css', ITALY_COOKIE_CHOICES_FILE ),
1419
- array( 'dashicons' ),
1420
- null
1421
- );
1422
-
1423
- wp_enqueue_script(
1424
- 'italy-cookie-choices-script',
1425
- plugins_url('admin/js/src/script.js', ITALY_COOKIE_CHOICES_FILE ),
1426
- array(
1427
- // 'jquery',
1428
- 'wp-color-picker',
1429
- 'jquery-ui-widget',
1430
- 'jquery-ui-autocomplete',
1431
- 'jquery-effects-shake',
1432
- // 'ace'
1433
- ),
1434
- null,
1435
- true
1436
- );
1437
-
1438
- }
1439
-
1440
- /**
1441
- * Add link in plugin activation panel
1442
- * @link https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)
1443
- * @param array $links Array of link in wordpress dashboard
1444
- * @return array Array with my links
1445
- */
1446
- public function plugin_action_links( $links ){
1447
-
1448
- array_unshift($links, '<a href="options-general.php?page=italy-cookie-choices">' . __('Settings','italy-cookie-choices') . '</a>');
1449
-
1450
- array_unshift($links, '<a href="https://github.com/ItalyCookieChoices/italy-cookie-choices/wiki" target="_blank">' . __('Documentation','italy-cookie-choices') . '</a>');
1451
-
1452
- return $links;
1453
- }// plugin_action_links()
1454
-
1455
- /**
1456
- * Set the three array with predefinited third party script|iframe|embed
1457
- * @see https://codex.wordpress.org/Embeds For more embed
1458
- * @todo See above
1459
- * @return void
1460
- */
1461
- private function create_third_party_array(){
1462
-
1463
- $this->iframe_array = array(
1464
- '' => '',
1465
- 'google' => 'google',
1466
- 'google_maps' => 'maps',
1467
- 'youtube' => 'youtube',
1468
- 'disqus' => 'disqus',
1469
- 'twitter' => 'twitter',
1470
- 'vimeo' => 'vimeo',
1471
- 'facebook' => 'facebook',
1472
- );
1473
-
1474
- $this->script_array = array(
1475
- '' => '',
1476
- 'google' => 'google',
1477
- 'google_maps' => 'maps',
1478
- 'googleapis' => 'googleapis',
1479
- 'AdSense' => 'googlesyndication',
1480
- 'doubleclick' => 'doubleclick',
1481
- 'plusone' => 'plusone',
1482
- 'platform' => 'platform',
1483
- 'analytics' => 'analytics',
1484
- 'facebook' => 'facebook',
1485
- 'addthis' => 'addthis',
1486
- 'twitter' => 'twitter',
1487
- 'linkedin' => 'linkedin',
1488
- 'pinterest' => 'pinterest',
1489
- 'disqus' => 'disqus',
1490
- 'vimeo' => 'vimeo',
1491
- 'youtube' => 'youtube',
1492
- 'youtube-nocookie' => 'youtube-nocookie',
1493
- '_getTracker' => '_getTracker',
1494
- 'instagram' => 'instagram',
1495
- 'cdninstagram' => 'cdninstagram',
1496
- 'digg' => 'digg',
1497
- 'eventbrite' => 'eventbrite',
1498
- 'wordpress' => 'wp'
1499
- );
1500
-
1501
- $this->embed_array = array(
1502
- '' => ''
1503
- );
1504
-
1505
- }
1506
-
1507
- /**
1508
- * This function add the HTML to display new functionality for UX allow and block script
1509
- * @param array $array Pass the plugin option array[name]
1510
- * @param string $arr_name A string name of the array
1511
- * @param array $arr_key Array for predefinited script|emebd|iframe
1512
- * This add a select box with script name
1513
- * @return string Return the HTML for new input
1514
- */
1515
- function foreach_script( $array, $arr_name, $arr_key ){
1516
-
1517
- $select = '<select>';
1518
-
1519
- foreach ($arr_key as $key => $value)
1520
- $select .= '<option value="' . $value . '">' . $key . '</option>';
1521
-
1522
- $select .= '</select>';
1523
-
1524
- // <button class=" button" disabled> &emsp; </button>
1525
- $input = '<div class="custom-script">';
1526
- $i = 0;
1527
- foreach ( $array as $key => $value ){
1528
-
1529
- $input .= '<div class="italy-cookie-choices-clone-div"><input type="text" class="regular-text" data-type="' . $arr_name . '" value="' . esc_attr( $value ) .'" name="italy_cookie_choices[' . $arr_name . '][' . esc_attr( $value ) .']" id="italy_cookie_choices[' . $arr_name . '][' . esc_attr( $value ) .']"/> ' . $select . ' <span><a class="button add" style="font-size:22px"> + </a> ' . ( $i === 0 ? '<a class="button cancel" style="font-size:22px"> x </a>' : '<a class=" button remove" style="font-size:22px"> × </a>' ) . '</span></div>';
1530
-
1531
- $i++;
1532
-
1533
- }
1534
- $input .= '</div>';
1535
-
1536
- echo $input;
1537
-
1538
- }
1539
-
1540
- /**
1541
- * Process a settings export from config
1542
- * @since 1.0.0
1543
- */
1544
- function settings_export() {
1545
-
1546
- if ( empty( $_POST[ 'icc_action' ] ) || 'export_settings' !== $_POST[ 'icc_action' ] )
1547
- return;
1548
-
1549
- if ( !wp_verify_nonce( $_POST[ 'icc_export_nonce' ], 'icc_export_nonce' ) )
1550
- return;
1551
-
1552
- if ( !current_user_can( $this->capability ) )
1553
- return;
1554
-
1555
- $settings[0] = $this->options;
1556
-
1557
- ignore_user_abort( true );
1558
-
1559
- nocache_headers();
1560
-
1561
- // date_default_timezone_set('UTC');
1562
- header( 'Content-Type: application/json; charset=utf-8' );
1563
- header( 'Content-Disposition: attachment; filename=italy-cookie-choices-settings-export-' . date( 'm-d-Y' ) . '.json' );
1564
- header( "Expires: 0" );
1565
-
1566
- echo $this->wp_json_encode( $settings, JSON_PRETTY_PRINT );
1567
-
1568
- exit;
1569
- }
1570
-
1571
- /**
1572
- * Process a settings import from a json file
1573
- * @since 1.0.0
1574
- */
1575
- function settings_import() {
1576
-
1577
- if ( empty( $_POST[ 'icc_action' ] ) || 'import_settings' != $_POST[ 'icc_action' ] )
1578
- return;
1579
-
1580
- if ( !wp_verify_nonce( $_POST[ 'icc_import_nonce' ], 'icc_import_nonce' ) )
1581
- return;
1582
-
1583
- if ( !current_user_can( $this->capability ) )
1584
- return;
1585
-
1586
- /**
1587
- * Get the extension of import file
1588
- * @link http://stackoverflow.com/a/19831453 Strict standards: Only variables should be passed by reference
1589
- * @var string
1590
- */
1591
- $file_name = $_FILES[ 'icc_import_file' ][ 'name' ];
1592
- $exploded = explode( '.', $file_name );
1593
- $extension = end( $exploded );
1594
 
1595
- /**
1596
- * If it is not json than die
1597
- */
1598
- if ( $extension !== 'json' )
1599
- wp_die( __( 'Please upload a valid .json file', 'italy-cookie-choices' ), __( 'No valid json file', 'italy-cookie-choices' ), array( 'back_link' => true ) );
1600
 
1601
- /**
1602
- * If the file is empty than die
1603
- */
1604
- if ( $_FILES[ 'icc_import_file' ][ 'size' ] === 0 )
1605
- wp_die( __( 'The json file can\'t be empty', 'italy-cookie-choices' ), __( 'Empty file', 'italy-cookie-choices' ), array( 'back_link' => true ) );
1606
 
1607
- $import_file = $_FILES[ 'icc_import_file' ][ 'tmp_name' ];
1608
-
1609
- /**
1610
- * If $import_file is empty or null than die
1611
- */
1612
- if ( empty( $import_file ) )
1613
- wp_die( __( 'Please upload a file to import', 'italy-cookie-choices' ), __( 'No file import', 'italy-cookie-choices' ), array( 'back_link' => true ) );
1614
 
1615
- /**
1616
- * Retrieve the settings from the file and convert the json object to an array.
1617
- * @var array
1618
- */
1619
- $settings = ( array ) json_decode( file_get_contents( $import_file ) );
1620
 
1621
- update_option( 'italy_cookie_choices', get_object_vars( $settings[0] ) );
1622
 
1623
- wp_safe_redirect( admin_url( 'options-general.php?page=' . 'italy-cookie-choices' ) );
1624
- exit;
1625
- }
1626
 
1627
- }// class
1628
  }//endif
4
  */
5
  if ( !class_exists( 'Italy_Cookie_Choices_Admin' ) ){
6
 
7
+ class Italy_Cookie_Choices_Admin{
8
+
9
+ /**
10
+ * Definition of variables containing the configuration
11
+ * to be applied to the various function calls wordpress
12
+ */
13
+ protected $capability = 'manage_options';
14
+
15
+ /**
16
+ * Global variables and default values
17
+ * @var array
18
+ */
19
+ protected $default_options = array();
20
+
21
+ /**
22
+ * Option
23
+ * @var array
24
+ */
25
+ private $options = array();
26
+
27
+ /**
28
+ * Default Cookie name
29
+ * @var string
30
+ */
31
+ private $cookieName = 'displayCookieConsent';
32
+
33
+ /**
34
+ * Default cookie value
35
+ * @var string
36
+ */
37
+ private $cookieVal = 'y';
38
+
39
+ /**
40
+ * Inizialize banner template to default
41
+ * @var string
42
+ */
43
+ private $js_template = 'default';
44
+
45
+ /**
46
+ * Array of all posts and pages object
47
+ * @var array
48
+ */
49
+ private $post_and_page_array = array();
50
+
51
+ /**
52
+ * Array with predefinited vendor iframe
53
+ * @var array
54
+ */
55
+ private $iframe_array = array();
56
+ /**
57
+ * Array with predefinited vendor script
58
+ * @var array
59
+ */
60
+ private $script_array = array();
61
+ /**
62
+ * Array with predefinited vendor embed
63
+ * @var array
64
+ */
65
+ private $embed_array = array();
66
+
67
+ /**
68
+ * [__construct description]
69
+ */
70
+ public function __construct(){
71
+
72
+ /**
73
+ * Init vendors array
74
+ */
75
+ $this->create_third_party_array();
76
+
77
+ /**
78
+ * Get all posts and pages object and merge for jQuery autocomplete function
79
+ */
80
+ // $this->get_post_and_page_array();
81
+ $this->post_and_page_array = ( is_array( get_pages('numberposts=-1') ) ) ? get_pages('numberposts=-1') : array();
82
+
83
+ /**
84
+ * Add Admin menù page
85
+ */
86
+ add_action( 'admin_menu', array( $this, 'addMenuPage') );
87
+
88
+ /**
89
+ * Init settings
90
+ */
91
+ add_action( 'admin_init', array( $this, 'italy_cl_settings_init') );
92
+
93
+ /**
94
+ * Load script only if is Italy Cookie Choices admin panel
95
+ */
96
+ if ( isset($_GET['page']) && ($_GET['page'] === 'italy-cookie-choices' ) )
97
+ add_action('admin_enqueue_scripts', array( $this, 'add_script_and_style' ));
98
+
99
+ /**
100
+ * Add link in plugin activation panel
101
+ */
102
+ add_filter( 'plugin_action_links_' . ITALY_COOKIE_CHOICES_BASENAME, array( $this, 'plugin_action_links' ) );
103
+
104
+ //Add the export settings method
105
+ add_action( 'admin_init', array( $this, 'settings_export' ) );
106
+ //Add the import settings method
107
+ add_action( 'admin_init', array( $this, 'settings_import' ) );
108
+
109
+ }
110
+
111
+ /**
112
+ * Encode a variable into JSON, with some sanity checks.
113
+ *
114
+ * @since 4.1.0
115
+ *
116
+ * @param mixed $data Variable (usually an array or object) to encode as JSON.
117
+ * @param int $options Optional. Options to be passed to json_encode(). Default 0.
118
+ * @param int $depth Optional. Maximum depth to walk through $data. Must be
119
+ * greater than 0. Default 512.
120
+ * @return bool|string The JSON encoded string, or false if it cannot be encoded.
121
+ */
122
+ public function wp_json_encode( $data, $options = 0, $depth = 512 ) {
123
+
124
+ /*
125
+ * json_encode() has had extra params added over the years.
126
+ * $options was added in 5.3, and $depth in 5.5.
127
+ * We need to make sure we call it with the correct arguments.
128
+ */
129
+ if ( version_compare( PHP_VERSION, '5.5', '>=' ) )
130
+ $args = array( $data, $options, $depth );
131
+ elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) )
132
+ $args = array( $data, $options );
133
+ else
134
+ $args = array( $data );
135
+
136
+ $json = call_user_func_array( 'json_encode', $args );
137
+
138
+ // If json_encode() was successful, no need to do more sanity checking.
139
+ // ... unless we're in an old version of PHP, and json_encode() returned
140
+ // a string containing 'null'. Then we need to do more sanity checking.
141
+ if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) )
142
+ return $json;
143
+
144
+ return call_user_func_array( 'json_encode', $args );
145
+ }
146
+
147
+ /**
148
+ * Add page for italy-cookie-choices admin page
149
+ */
150
+ public function addMenuPage(){
151
+
152
+ add_options_page(
153
+ __('Italy Cookie Choices Dashboard', 'italy-cookie-choices'),
154
+ 'Italy Cookie Choices',
155
+ $this->capability,
156
+ 'italy-cookie-choices',
157
+ array( $this, 'dashboard')
158
+ );
159
+ }
160
+
161
+ /**
162
+ * The dashboard callback
163
+ */
164
+ public function dashboard(){
165
+
166
+ if ( !current_user_can( $this->capability ) )
167
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
168
+
169
+ include_once( 'template/admin.php' );
170
+
171
+ }
172
+
173
+ /**
174
+ * Initialize plugin
175
+ * @return [type] [description]
176
+ */
177
+ public function italy_cl_settings_init() {
178
+
179
+ /**
180
+ * Create default options
181
+ * @var array
182
+ */
183
+ $this->default_options = array(
184
+
185
+ 'text' => '',
186
+ 'url' => '',
187
+ 'anchor_text' => '',
188
+ 'button_text' => '',
189
+ 'cookie_name' => $this->cookieName,
190
+ 'cookie_value' => $this->cookieVal,
191
+ 'content_message_text' => '',
192
+ 'content_message_button_text' => ''
193
+
194
+ );
195
+
196
+ /**
197
+ * All options in array
198
+ * @var array
199
+ */
200
+ $this->options = get_option( 'italy_cookie_choices' );
201
+
202
+ /**
203
+ * If the theme options don't exist, create them.
204
+ */
205
+ if( false === $this->options )
206
+ add_option( 'italy_cookie_choices', $this->default_options );
207
+
208
+ /**
209
+ * Section options page
210
+ */
211
+ add_settings_section(
212
+ 'setting_section',
213
+ __( 'Italy Cookie Choices options page', 'italy-cookie-choices' ),
214
+ array( $this, 'italy_cl_settings_section_callback'),
215
+ 'italy_cl_options_group'
216
+ );
217
+
218
+ /**
219
+ * Checkbox for activation
220
+ */
221
+ add_settings_field(
222
+ 'active',
223
+ __( 'Activate', 'italy-cookie-choices' ),
224
+ array( $this, 'italy_cl_option_active'),
225
+ 'italy_cl_options_group',
226
+ 'setting_section'
227
+ );
228
+
229
+ /**
230
+ * How to display banner
231
+ * Default Bar
232
+ */
233
+ add_settings_field(
234
+ 'banner',
235
+ __( 'Where display the banner', 'italy-cookie-choices' ),
236
+ array( $this, 'italy_cl_option_banner'),
237
+ 'italy_cl_options_group',
238
+ 'setting_section'
239
+ );
240
+
241
+ /**
242
+ * Checkbox for scroll event
243
+ */
244
+ add_settings_field(
245
+ 'scroll',
246
+ __( 'Mouse scroll event', 'italy-cookie-choices' ),
247
+ array( $this, 'italy_cl_option_scroll'),
248
+ 'italy_cl_options_group',
249
+ 'setting_section'
250
+ );
251
+
252
+ /**
253
+ * Checkbox for open in new page
254
+ */
255
+ add_settings_field(
256
+ 'secondView',
257
+ __( 'Accept on second view', 'italy-cookie-choices' ),
258
+ array( $this, 'italy_cl_option_secondView'),
259
+ 'italy_cl_options_group',
260
+ 'setting_section'
261
+ );
262
+
263
+ /**
264
+ * Checkbox for reload page
265
+ */
266
+ add_settings_field(
267
+ 'reload',
268
+ __( 'Refresh page', 'italy-cookie-choices' ),
269
+ array( $this, 'italy_cl_option_reload'),
270
+ 'italy_cl_options_group',
271
+ 'setting_section'
272
+ );
273
+
274
+ /**
275
+ * Input for short policy text
276
+ */
277
+ add_settings_field(
278
+ 'text',
279
+ __( 'Text to display', 'italy-cookie-choices' ),
280
+ array( $this, 'italy_cl_option_text'),
281
+ 'italy_cl_options_group',
282
+ 'setting_section'
283
+ );
284
+
285
+ /**
286
+ * Input for url policy page
287
+ */
288
+ add_settings_field(
289
+ 'url',
290
+ __( 'URL for cookie policy', 'italy-cookie-choices' ),
291
+ array( $this, 'italy_cl_option_url'),
292
+ 'italy_cl_options_group',
293
+ 'setting_section'
294
+ );
295
+
296
+ /**
297
+ * Cookie policy page slug
298
+ */
299
+ add_settings_field(
300
+ 'slug',
301
+ __( 'Cookie policy page slug', 'italy-cookie-choices' ),
302
+ array( $this, 'italy_cl_option_slug'),
303
+ 'italy_cl_options_group',
304
+ 'setting_section'
305
+ );
306
+
307
+ /**
308
+ * Input for anchor text
309
+ */
310
+ add_settings_field(
311
+ 'anchor_text',
312
+ __( 'Anchor text for URL', 'italy-cookie-choices' ),
313
+ array( $this, 'italy_cl_option_anchor_text'),
314
+ 'italy_cl_options_group',
315
+ 'setting_section'
316
+ );
317
+
318
+ /**
319
+ * Input for button text
320
+ */
321
+ add_settings_field(
322
+ 'button_text',
323
+ __( 'Button text', 'italy-cookie-choices' ),
324
+ array( $this, 'italy_cl_option_button_text'),
325
+ 'italy_cl_options_group',
326
+ 'setting_section'
327
+ );
328
+
329
+ /**
330
+ * Settings sections for Style
331
+ */
332
+ add_settings_section(
333
+ 'style_setting_section',
334
+ __( 'Style settings', 'italy-cookie-choices' ),
335
+ array( $this, 'italy_cl_style_settings_section_callback'),
336
+ 'italy_cl_options_group'
337
+ );
338
+
339
+ /**
340
+ * Select box for js_template selection
341
+ */
342
+ add_settings_field(
343
+ 'js_template',
344
+ __( 'CookieChoices Template', 'italy-cookie-choices' ),
345
+ array( $this, 'italy_cl_option_js_template'),
346
+ 'italy_cl_options_group',
347
+ 'style_setting_section'
348
+ );
349
+
350
+ /**
351
+ * Checkbox for activation
352
+ */
353
+ add_settings_field(
354
+ 'html_margin',
355
+ __( 'HTML top margin', 'italy-cookie-choices' ),
356
+ array( $this, 'italy_cl_option_html_margin'),
357
+ 'italy_cl_options_group',
358
+ 'style_setting_section'
359
+ );
360
+
361
+ /**
362
+ * Background color for banner
363
+ */
364
+ add_settings_field(
365
+ 'banner_bg',
366
+ __( 'Banner Background color', 'italy-cookie-choices' ),
367
+ array( $this, 'italy_cl_option_banner_bg'),
368
+ 'italy_cl_options_group',
369
+ 'style_setting_section'
370
+ );
371
+
372
+ /**
373
+ * Color for text in banner
374
+ */
375
+ add_settings_field(
376
+ 'banner_text_color',
377
+ __( 'Banner text color', 'italy-cookie-choices' ),
378
+ array( $this, 'italy_cl_option_banner_text_color'),
379
+ 'italy_cl_options_group',
380
+ 'style_setting_section'
381
+ );
382
+
383
+ /**
384
+ * Text area for custom CSS
385
+ */
386
+ add_settings_field(
387
+ 'customCSS',
388
+ __( 'Custom CSS', 'italy-cookie-choices' ),
389
+ array( $this, 'italy_cl_option_customCSS'),
390
+ 'italy_cl_options_group',
391
+ 'style_setting_section'
392
+ );
393
+
394
+ /**
395
+ * Text area for custom CSS class
396
+ */
397
+ add_settings_field(
398
+ 'customClass',
399
+ __( 'Custom CSS Class (Optional)', 'italy-cookie-choices' ),
400
+ array( $this, 'italy_cl_option_customClass'),
401
+ 'italy_cl_options_group',
402
+ 'style_setting_section'
403
+ );
404
+
405
+ /**
406
+ * Settings sections for Advanced options
407
+ */
408
+ add_settings_section(
409
+ 'advanced_setting_section',
410
+ __( 'Advanced settings', 'italy-cookie-choices' ),
411
+ array( $this, 'italy_cl_advanced_settings_section_callback'),
412
+ 'italy_cl_options_group'
413
+ );
414
+
415
+ /**
416
+ * cookie name
417
+ */
418
+ add_settings_field(
419
+ 'cookie_name',
420
+ __( 'Cookie name', 'italy-cookie-choices' ),
421
+ array( $this, 'italy_cl_option_cookie_name'),
422
+ 'italy_cl_options_group',
423
+ 'advanced_setting_section'
424
+ );
425
+
426
+ /**
427
+ * cookie value
428
+ */
429
+ add_settings_field(
430
+ 'cookie_value',
431
+ __( 'Cookie value', 'italy-cookie-choices' ),
432
+ array( $this, 'italy_cl_option_cookie_value'),
433
+ 'italy_cl_options_group',
434
+ 'advanced_setting_section'
435
+ );
436
+
437
+ /**
438
+ * Checkbox for open in new page
439
+ */
440
+ add_settings_field(
441
+ 'target',
442
+ __( 'Open policy in new page', 'italy-cookie-choices' ),
443
+ array( $this, 'italy_cl_option_target'),
444
+ 'italy_cl_options_group',
445
+ 'advanced_setting_section'
446
+ );
447
+
448
+ /**
449
+ * Checkbox for activation third part cookie eraser
450
+ */
451
+ add_settings_field(
452
+ 'block',
453
+ __( 'Third part cookie block (beta)', 'italy-cookie-choices' ),
454
+ array( $this, 'italy_cl_option_block'),
455
+ 'italy_cl_options_group',
456
+ 'advanced_setting_section'
457
+ );
458
+
459
+ /**
460
+ * Function for custom script allow
461
+ */
462
+ add_settings_field(
463
+ 'custom_script_block_body_exclude',
464
+ __( 'Scripts allowed in body', 'italy-cookie-choices' ),
465
+ array( $this, 'italy_cl_option_custom_script_block_body_exclude'),
466
+ 'italy_cl_options_group',
467
+ 'advanced_setting_section'
468
+ );
469
+
470
+ /**
471
+ * Function for custom script block
472
+ */
473
+ add_settings_field(
474
+ 'custom_script_block',
475
+ __( 'Scripts to be blocked', 'italy-cookie-choices' ),
476
+ array( $this, 'italy_cl_option_custom_script_block'),
477
+ 'italy_cl_options_group',
478
+ 'advanced_setting_section'
479
+ );
480
+
481
+ /**
482
+ * Function for content message text
483
+ */
484
+ add_settings_field(
485
+ 'content_message_text',
486
+ __( 'Text message for locked embedded content', 'italy-cookie-choices' ),
487
+ array( $this, 'italy_cl_option_content_message_text'),
488
+ 'italy_cl_options_group',
489
+ 'advanced_setting_section'
490
+ );
491
+
492
+ /**
493
+ * Function for button text in message
494
+ */
495
+ add_settings_field(
496
+ 'content_message_button_text',
497
+ __( 'Button text to activate locked embedded content', 'italy-cookie-choices' ),
498
+ array( $this, 'italy_cl_option_content_message_button_text'),
499
+ 'italy_cl_options_group',
500
+ 'advanced_setting_section'
501
+ );
502
+
503
+ /**
504
+ * Register setting
505
+ */
506
+ register_setting(
507
+ 'italy_cl_options_group',
508
+ 'italy_cookie_choices',
509
+ array( $this, 'sanitize_callback')
510
+ );
511
+
512
+
513
+ }
514
+
515
+
516
+ /**
517
+ * Display message in plugin control panel
518
+ * @return string Return message
519
+ */
520
+ public function italy_cl_settings_section_callback() {
521
+
522
+ _e( 'Customize your banner for cookie law', 'italy-cookie-choices' );
523
+
524
+ }
525
+
526
+ /**
527
+ * Snippet for checkbox
528
+ * @return strimg Activate banner in front-end Default doesn't display
529
+ */
530
+ public function italy_cl_option_active($args) {
531
+
532
+ $active = ( isset( $this->options['active'] ) ) ? $this->options['active'] : '' ;
533
+ ?>
534
+
535
+ <input type='checkbox' name='italy_cookie_choices[active]' <?php checked( $active, 1 ); ?> value='1' id="italy_cookie_choices[active]">
536
+ <label for="italy_cookie_choices[active]" id="active">
537
+ <?php _e( 'Display banner for Cookie Law in front-end', 'italy-cookie-choices' ); ?>
538
+ </label>
539
+
540
+ <?php
541
+
542
+ }
543
+
544
+ /**
545
+ * Choose how to display banner in page
546
+ * @return string Display input and labels in plugin options page
547
+ */
548
+ public function italy_cl_option_banner($args) {
549
+
550
+ $banner = ( isset( $this->options['banner'] ) ) ? $this->options['banner'] : '1' ;
551
+
552
+ ?>
553
+
554
+ <input name="italy_cookie_choices[banner]" type="radio" value="1" id="radio_1" <?php checked( '1', $banner ); ?> />
555
+
556
+ <label for="radio_1" id="label_radio_1">
557
+ <?php _e( 'Top Bar (Default, Display a top bar with your message)', 'italy-cookie-choices' ); ?>
558
+ </label>
559
+
560
+ <br>
561
+
562
+ <input name="italy_cookie_choices[banner]" type="radio" value="2" id="radio_2" <?php checked( '2', $banner ); ?> />
563
+
564
+ <label for="radio_2" id="label_radio_2">
565
+ <?php _e( 'Dialog (Display an overlay with your message)', 'italy-cookie-choices' ); ?>
566
+ </label>
567
+
568
+ <br>
569
+
570
+ <input name="italy_cookie_choices[banner]" type="radio" value="3" id="radio_3" <?php checked( '3', $banner ); ?> />
571
+
572
+ <label for="radio_3" id="label_radio_3">
573
+ <?php _e( 'Bottom Bar (Display a bar in the footer with your message)', 'italy-cookie-choices' ); ?>
574
+ </label>
575
 
576
+
577
 
578
+ <?php
579
 
580
+ }
581
 
582
+ /**
583
+ * Snippet for checkbox
584
+ * @return strimg Activate banner in front-end Default doesn't display
585
+ */
586
+ public function italy_cl_option_scroll($args) {
587
 
588
+ $scroll = ( isset( $this->options['scroll'] ) ) ? $this->options['scroll'] : '' ;
589
+ ?>
590
 
591
+ <input type='checkbox' name='italy_cookie_choices[scroll]' <?php checked( $scroll, 1 ); ?> value='1' id="italy_cookie_choices[scroll]">
592
+ <label for="italy_cookie_choices[scroll]">
593
+ <?php _e( 'Accepts disclosures on mouse scroll event', 'italy-cookie-choices' ); ?>
594
+ </label>
595
 
596
+ <?php
597
 
598
+ }
599
 
600
+ /**
601
+ * Snippet for second view checkbox $secondView
602
+ * @return strimg Activate for accept on second view
603
+ * Default do nothing
604
+ */
605
+ public function italy_cl_option_secondView($args) {
606
 
607
+ $secondView = ( isset( $this->options['secondView'] ) ) ? $this->options['secondView'] : '' ;
608
 
609
+ ?>
610
 
611
+ <input type='checkbox' name='italy_cookie_choices[secondView]' <?php checked( $secondView, 1 ); ?> value='1' id="italy_cookie_choices[secondView]">
612
+ <label for="italy_cookie_choices[secondView]">
613
+ <?php _e( 'Activate accept on second view', 'italy-cookie-choices' ); ?>
614
+ </label>
615
 
616
+ <?php
617
 
618
+ }
619
 
620
+ /**
621
+ * Snippet for reload
622
+ * @return strimg Reload page after click
623
+ */
624
+ public function italy_cl_option_reload($args) {
625
 
626
+ $reload = ( isset( $this->options['reload'] ) ) ? $this->options['reload'] : '' ;
627
+ ?>
628
+
629
+ <input type='checkbox' name='italy_cookie_choices[reload]' <?php checked( $reload, 1 ); ?> value='1' id="italy_cookie_choices[reload]">
630
+ <label for="italy_cookie_choices[reload]">
631
+ <?php _e( 'Refresh page after button click (DEPRECATED)', 'italy-cookie-choices' ); ?>
632
+ </label>
633
+
634
+ <?php
635
+
636
+ }
637
+
638
+ /**
639
+ * Textarea for the message to display
640
+ * @return string
641
+ */
642
+ public function italy_cl_option_text($args) {
643
+
644
+ /**
645
+ * Allow HTML tags in text area
646
+ * changed esc_textarea( $this->options['text'] ); with wp_kses_post( $this->options['text'] );
647
+ * @todo Add padding to text editor
648
+ */
649
+
650
+ if ( function_exists("wp_editor") ):
651
+ wp_editor(
652
+ wp_kses_post( $this->options['text'] ),
653
+ 'italy_cookie_choices_text',
654
+ array(
655
+ 'textarea_name' => 'italy_cookie_choices[text]',
656
+ 'media_buttons' => false,
657
+ 'textarea_rows' => 5,
658
+ 'editor_css' => '<style>#wp-italy_cookie_choices_text-wrap{max-width:520px}</style>',
659
+ 'teeny' => true
660
+ )
661
+ );
662
+ else:
663
+ ?>
664
+ <textarea rows="5" cols="70" name="italy_cookie_choices[text]" id="italy_cookie_choices[text]" placeholder="<?php _e( 'Your short cookie policy', 'italy-cookie-choices' ) ?>" ><?php echo wp_kses_post( $this->options['text'] ); ?></textarea>
665
+
666
+ <?php endif; ?>
667
+
668
+ <br>
669
+
670
+ <label for="italy_cookie_choices[text]">
671
+ <?php echo __( 'People will see this notice only the first time that they enter your site', 'italy-cookie-choices' ); ?>
672
+ </label>
673
+
674
+ <?php
675
+
676
+ }
677
+
678
+ /**
679
+ * Input for url policy page
680
+ * @return string
681
+ */
682
+ public function italy_cl_option_url($args) {
683
+
684
+ /**
685
+ * Get the $post_ID for autocomplete function and put it in javascript var
686
+ * @var array
687
+ */
688
+ $urls = array();
689
+ foreach( $this->post_and_page_array as $post )
690
+ $urls[] = get_permalink( $post->ID );
691
+
692
+ ?>
693
+ <script>
694
+ var urls = '<?php echo $this->wp_json_encode( $urls ); ?>';
695
+ </script>
696
+ <input type="text" id="italy_cookie_choices[url]" name="italy_cookie_choices[url]" value="<?php echo esc_url( $this->options['url'] ); ?>" placeholder="<?php _e( 'e.g. http://www.aboutcookies.org/', 'italy-cookie-choices' ) ?>" size="70" />
697
+ <br>
698
+ <label for="italy_cookie_choices[url]">
699
+ <?php echo __( 'Insert here the link to your policy page', 'italy-cookie-choices' ); ?> <a href="post-new.php?post_type=page"><?php _e( 'otherwise create a new one and then add URL to this input', 'italy-cookie-choices' ); ?></a>
700
+ <br>
701
+ <?php echo __( 'Start typing first two letters of the name of the policy page and then select it from the menu below the input', 'italy-cookie-choices' ); ?>
702
+ </label>
703
+
704
+ <?php
705
+
706
+ }
707
+
708
+ /**
709
+ * Slug for cookie policy page
710
+ * @return strimg Slug for cookie policy page Default null
711
+ */
712
+ public function italy_cl_option_slug($args) {
713
+
714
+ $slug = ( isset( $this->options['slug'] ) ) ? $this->options['slug'] : '' ;
715
+
716
+ /**
717
+ * Get the $post_name for autocomplete function and put it in javascript var
718
+ * @var array
719
+ */
720
+ $slugs = array();
721
+ foreach( $this->post_and_page_array as $post )
722
+ $slugs[] = $post->post_name;
723
+
724
+ ?>
725
+ <script>
726
+ var slugs = '<?php echo $this->wp_json_encode( $slugs ); ?>';
727
+ </script>
728
+ <input type="text" id="italy_cookie_choices[slug]" name="italy_cookie_choices[slug]" value="<?php echo esc_attr( $slug ); ?>" placeholder="<?php _e( 'e.g. privacy-e-cookie', 'italy-cookie-choices' ); ?>" size="70" class="slug_autocomplete"/>
729
+ <br>
730
+ <label for="italy_cookie_choices[slug]">
731
+ <?php _e( 'Insert your cookie policy page slug (e.g. for the page http://www.miodominio.it/privacy-e-cookie/ the slug is <strong>privacy-e-cookie</strong>).<br>In this way it will display only the topbar in your cookie policy page, the scroll and the second view will be deactivated in that page too.', 'italy-cookie-choices' ); ?>
732
+ <br>
733
+ <?php echo __( 'Start typing first two letters of the name of the policy page and then select it from the menu below the input', 'italy-cookie-choices' ); ?>
734
+ </label>
735
 
736
+ <?php
737
+
738
+ }
739
+
740
+ /**
741
+ * Input for anchor_text
742
+ * @return string
743
+ */
744
+ public function italy_cl_option_anchor_text($args) {
745
 
746
+ ?>
747
+ <input type="text" id="italy_cookie_choices[anchor_text]" name="italy_cookie_choices[anchor_text]" value="<?php echo esc_attr( $this->options['anchor_text'] ); ?>" placeholder="<?php _e( 'e.g. More Info', 'italy-cookie-choices' ) ?>" />
748
 
749
+ <label for="italy_cookie_choices[anchor_text]">
750
+ <?php echo __( 'Insert here anchor text for the link', 'italy-cookie-choices'); ?>
751
+ </label>
752
 
753
+ <?php
754
 
755
+ }
756
 
757
+ /**
758
+ * Input for anchor_text
759
+ * @return string
760
+ */
761
+ public function italy_cl_option_button_text($args) {
762
 
763
+ ?>
764
+ <input type="text" id="italy_cookie_choices[button_text]" name="italy_cookie_choices[button_text]" value="<?php echo esc_attr( $this->options['button_text'] ); ?>" placeholder="<?php _e( 'e.g. Close', 'italy-cookie-choices' ) ?>" />
765
 
766
+ <label for="italy_cookie_choices[button_text]">
767
+ <?php echo __( 'Insert here name of button (e.g. "Close") ', 'italy-cookie-choices' ); ?>
768
+ </label>
769
 
770
+ <?php
771
 
772
+ }
773
 
774
+ /**
775
+ * NUOVA SETTINGS SECTIONS PER LO STILE
776
+ */
777
 
778
+ /**
779
+ * Display message in stile plugin panel
780
+ * @return string
781
+ */
782
+ public function italy_cl_style_settings_section_callback() {
783
 
784
+ _e( 'Customize your style settings', 'italy-cookie-choices' );
785
 
786
+ }
787
 
788
+ /**
789
+ * Snippet for checkbox
790
+ * @return strimg Activate banner in front-end Default doesn't display
791
+ */
792
+ public function italy_cl_option_html_margin($args) {
793
 
794
+ $html_margin = ( isset( $this->options['html_margin'] ) ) ? $this->options['html_margin'] : '' ;
795
 
796
+ ?>
797
 
798
+ <input type='checkbox' name='italy_cookie_choices[html_margin]' <?php checked( $html_margin, 1 ); ?> value='1' id="italy_cookie_choices[html_margin]">
799
+ <label for="italy_cookie_choices[html_margin]">
800
+ <?php _e( 'Add a page top margin for info top bar, only for default topbar stile', 'italy-cookie-choices' ); ?>
801
+ </label>
802
 
803
+ <?php
804
 
805
+ }
806
+
807
+ /**
808
+ * Snippet for select
809
+ * @return strimg Chose the JS_Template to use.
810
+ */
811
+ public function italy_cl_option_js_template($args) {
812
 
813
+ $js_template = ( isset( $this->options['js_template'] ) ) ? $this->options['js_template'] : $this->js_template ;
814
 
815
+ ?>
816
+ <select name='italy_cookie_choices[js_template]' id="italy_cookie_choices[js_template]">
817
 
818
+ <option value="default" <?php if ( $js_template === 'default' ) echo 'selected';?>><?php _e( 'Default cookiechoices template (centered with text links)', 'italy-cookie-choices' ); ?></option>
819
 
820
+ <option value="bigbutton" <?php if ( $js_template === 'bigbutton' ) echo 'selected';?>><?php _e( 'Centered container with left aligned text and big buttons', 'italy-cookie-choices' ); ?></option>
821
 
822
+ <option value="smallbutton" <?php if ( $js_template === 'smallbutton' ) echo 'selected';?>><?php _e( 'Centered container with left aligned text and small buttons', 'italy-cookie-choices' ); ?></option>
823
 
824
+ <option value="custom" <?php if ( $js_template === 'custom' ) echo 'selected';?>><?php _e( 'My custom CSS', 'italy-cookie-choices' ); ?></option>
825
 
826
+ </select>
827
+ <label for="italy_cookie_choices[js_template]">
828
+ <?php _e( 'Select the template to use', 'italy-cookie-choices' ); ?>
829
+ </label>
830
 
831
+ <?php
832
 
833
+ }
834
 
835
+ /**
836
+ * Snippet for checkbox
837
+ * @return strimg Activate banner in front-end Default doesn't display
838
+ */
839
+ public function italy_cl_option_banner_bg($args) {
840
 
841
+ $banner_bg = ( isset( $this->options['banner_bg'] ) ) ? $this->options['banner_bg'] : '#fff' ;
842
 
843
+ ?>
844
 
845
+ <input type="text" id="italy_cookie_choices[banner_bg]" name="italy_cookie_choices[banner_bg]" value="<?php echo esc_attr( $banner_bg ); ?>" placeholder="<?php echo esc_attr( $banner_bg ); ?>" class="color-field" data-default-color="#fff"/>
846
 
847
 
848
+ <label for="italy_cookie_choices[banner_bg]">
849
+ <?php _e( 'Custom Background color for banner', 'italy-cookie-choices' ); ?>
850
+ </label>
851
 
852
+ <?php
853
 
854
+ }
855
 
856
+ /**
857
+ * Snippet for banner text color
858
+ * @return strimg Activate banner in front-end Default doesn't display
859
+ */
860
+ public function italy_cl_option_banner_text_color($args) {
861
 
862
+ $banner_text_color = ( isset( $this->options['banner_text_color'] ) ) ? $this->options['banner_text_color'] : '#000' ;
863
 
864
+ ?>
865
 
866
+ <input type="text" id="italy_cookie_choices[banner_text_color]" name="italy_cookie_choices[banner_text_color]" value="<?php echo esc_attr( $banner_text_color ); ?>" placeholder="<?php echo esc_attr( $banner_text_color ); ?>" class="color-field" data-default-color="#000"/>
867
 
868
+ <label for="italy_cookie_choices[banner_text_color]">
869
+ <?php _e( 'Custom text color for banner', 'italy-cookie-choices' ); ?>
870
+ </label>
871
 
872
+ <?php
873
 
874
+ }
875
 
876
+ /**
877
+ * Textarea for custom CSS
878
+ * @return string
879
+ */
880
+ public function italy_cl_option_customCSS($args) {
881
 
882
+ $customCSS = ( isset( $this->options['customCSS'] ) ) ? $this->options['customCSS'] : '' ;
883
 
884
+ ?>
885
 
886
+ <textarea rows="5" cols="70" name="italy_cookie_choices[customCSS]" id="italy_cookie_choices[customCSS]" placeholder="<?php _e( 'Your custom css', 'italy-cookie-choices' ) ?>" ><?php echo esc_textarea( $customCSS ); ?></textarea>
887
+ <br>
888
+ <label for="italy_cookie_choices[customCSS]">
889
+ <?php echo __( 'Inset here your custom CSS for banner', 'italy-cookie-choices' ); ?>
890
+ </label>
891
 
892
+ <?php
893
 
894
+ }
895
 
896
+ /**
897
+ * Input for custom CSS class
898
+ * @return string
899
+ */
900
+ public function italy_cl_option_customClass($args) {
901
 
902
+ $bannerStyle = ( isset( $this->options['bannerStyle'] ) ) ? esc_attr( $this->options['bannerStyle'] ) : 'bannerStyle' ;
903
 
904
+ $contentStyle = ( isset( $this->options['contentStyle'] ) ) ? esc_attr( $this->options['contentStyle'] ) : 'contentStyle' ;
905
 
906
+ $consentText = ( isset( $this->options['consentText'] ) ) ? esc_attr( $this->options['consentText'] ) : 'consentText' ;
907
 
908
+ $infoClass = ( isset( $this->options['infoClass'] ) ) ? esc_attr( $this->options['infoClass'] ) : 'italybtn' ;
909
 
910
+ $closeClass = ( isset( $this->options['closeClass'] ) ) ? esc_attr( $this->options['closeClass'] ) : 'italybtn' ;
911
 
912
+ ?>
913
 
914
+ <input type="text" id="italy_cookie_choices[bannerStyle]" name="italy_cookie_choices[bannerStyle]" value="<?php echo esc_attr( $bannerStyle ); ?>" placeholder="<?php _e( 'Eg: bannerStyle', 'italy-cookie-choices' ); ?>" />
915
+ <label for="italy_cookie_choices[bannerStyle]">
916
+ <?php echo __( 'CSS class for div container (Default <code>bannerStyle</code>)', 'italy-cookie-choices' ); ?>
917
+ </label>
918
+ <br>
919
+ <input type="text" id="italy_cookie_choices[contentStyle]" name="italy_cookie_choices[contentStyle]" value="<?php echo esc_attr( $contentStyle ); ?>" placeholder="<?php _e( 'Eg: contentStyle', 'italy-cookie-choices' ); ?>" />
920
+ <label for="italy_cookie_choices[contentStyle]">
921
+ <?php echo __( 'CSS class for div content (Default <code>contentStyle</code>)', 'italy-cookie-choices' ); ?>
922
+ </label>
923
+ <br>
924
+ <input type="text" id="italy_cookie_choices[consentText]" name="italy_cookie_choices[consentText]" value="<?php echo esc_attr( $consentText ); ?>" placeholder="<?php _e( 'Eg: consentText', 'italy-cookie-choices' );; ?>" />
925
+ <label for="italy_cookie_choices[consentText]">
926
+ <?php echo __( 'CSS class for span content (Default <code>consentText</code>)', 'italy-cookie-choices' ); ?>
927
+ </label>
928
+ <br>
929
+ <input type="text" id="italy_cookie_choices[infoClass]" name="italy_cookie_choices[infoClass]" value="<?php echo esc_attr( $infoClass ); ?>" placeholder="<?php _e( 'Eg: infoClass', 'italy-cookie-choices' ); ?>" />
930
+ <label for="italy_cookie_choices[infoClass]">
931
+ <?php echo __( 'CSS class for Info link (Default <code>itaybtn</code>)', 'italy-cookie-choices' ); ?>
932
+ </label>
933
+ <br>
934
+ <input type="text" id="italy_cookie_choices[closeClass]" name="italy_cookie_choices[closeClass]" value="<?php echo esc_attr( $closeClass ); ?>" placeholder="<?php _e( 'Eg: closeClass', 'italy-cookie-choices' ); ?>" />
935
+ <label for="italy_cookie_choices[closeClass]">
936
+ <?php echo __( 'CSS class for close link (Default <code>itaybtn</code>)', 'italy-cookie-choices' ); ?>
937
+ </label>
938
 
939
+ <p><?php _e( 'Customize with your personal CSS class', 'italy-cookie-choices' ); ?></p>
940
 
941
+ <?php
942
 
943
+ }
944
 
945
+ /**
946
+ * NUOVA SETTINGS SECTIONS PER LE OPZIONI AVANZATE
947
+ */
948
 
949
+ /**
950
+ * Display message in plugin advanced setting section
951
+ * @return string
952
+ */
953
+ public function italy_cl_advanced_settings_section_callback() {
954
 
955
+ _e( 'Customize your advanced settings', 'italy-cookie-choices' );
956
 
957
+ }
958
 
959
+ /**
960
+ * Snippet for cookie name
961
+ * @return strimg Activate banner in front-end Default doesn't display
962
+ */
963
+ public function italy_cl_option_cookie_name($args) {
964
 
965
+ $cookie_name = ( isset( $this->options['cookie_name'] ) ) ? $this->options['cookie_name'] : $this->cookieName ;
966
 
967
+ ?>
968
+ <input type="text" id="italy_cookie_choices[cookie_name]" name="italy_cookie_choices[cookie_name]" value="<?php echo esc_attr( $cookie_name ); ?>" placeholder="<?php echo esc_attr( $this->cookieName ); ?>" />
969
 
970
+ <label for="italy_cookie_choices[cookie_name]">
971
+ <?php _e( 'Insert your cookie name (Default: displayCookieConsent)', 'italy-cookie-choices' ); ?>
972
+ </label>
973
 
974
+ <?php
975
 
976
+ }
977
 
978
+ /**
979
+ * Snippet for cookie value
980
+ * @return strimg Activate banner in front-end Default doesn't display
981
+ */
982
+ public function italy_cl_option_cookie_value($args) {
983
 
984
+ $cookie_value = ( isset( $this->options['cookie_value'] ) ) ? $this->options['cookie_value'] : $this->cookieVal ;
985
 
986
+ ?>
987
+ <input type="text" id="italy_cookie_choices[cookie_value]" name="italy_cookie_choices[cookie_value]" value="<?php echo esc_attr( $cookie_value ); ?>" placeholder="<?php echo esc_attr( $this->cookieVal ); ?>" />
988
 
989
+ <label for="italy_cookie_choices[cookie_value]">
990
+ <?php _e( 'Insert your cookie value (Default: y)', 'italy-cookie-choices' ); ?>
991
+ </label>
992
 
993
+ <?php
994
 
995
+ }
996
 
997
+ /**
998
+ * Snippet for target checkbox
999
+ * @return strimg Activate for open policy page in new tab
1000
+ * Default open in same tab
1001
+ */
1002
+ public function italy_cl_option_target($args) {
1003
 
1004
+ $target = ( isset( $this->options['target'] ) ) ? $this->options['target'] : '' ;
1005
 
1006
+ ?>
1007
 
1008
+ <input type='checkbox' name='italy_cookie_choices[target]' <?php checked( $target, 1 ); ?> value='1' id="italy_cookie_choices[target]">
1009
+ <label for="italy_cookie_choices[target]">
1010
+ <?php _e( 'Open your cookie policy page in new one', 'italy-cookie-choices' ); ?>
1011
+ </label>
1012
+
1013
+ <?php
1014
+
1015
+ }
1016
+
1017
+ /**
1018
+ * Snippet for target checkbox
1019
+ * @return strimg Activate for open policy page in new tab
1020
+ * Default open in same tab
1021
+ */
1022
+ public function italy_cl_option_block($args) {
1023
+
1024
+ $all_block = ( isset( $this->options['all_block'] ) ) ? $this->options['all_block'] : '' ;
1025
+
1026
+ $block = ( isset( $this->options['block'] ) && $all_block === '' ) ? $this->options['block'] : '' ;
1027
 
1028
+ $widget_block = ( isset( $this->options['widget_block'] ) && $all_block === '' ) ? $this->options['widget_block'] : '' ;
1029
 
1030
+ ?>
1031
 
1032
+ <input type='checkbox' name='italy_cookie_choices[block]' <?php checked( $block, 1 ); ?> value='1' id="italy_cookie_choices[block]">
1033
+ <label for="italy_cookie_choices[block]">
1034
+ <?php _e( 'Cookie from any embed in your content (Beta) (DEPRECATED)', 'italy-cookie-choices' ); ?>
1035
+ </label>
1036
+ <br>
1037
+ <input type='checkbox' name='italy_cookie_choices[widget_block]' <?php checked( $widget_block, 1 ); ?> value='1' id="italy_cookie_choices[widget_block]">
1038
+ <label for="italy_cookie_choices[widget_block]">
1039
+ <?php _e( 'Cookie from any embed in your widget area (Beta) (DEPRECATED)', 'italy-cookie-choices' ); ?>
1040
+ </label>
1041
+ <br>
1042
+ <br>
1043
+ <input type='checkbox' name='italy_cookie_choices[all_block]' <?php checked( $all_block, 1 ); ?> value='1' id="italy_cookie_choices[all_block]">
1044
+ <label for="italy_cookie_choices[all_block]">
1045
+ <?php _e( 'Cookie from any embed in all body, except head and footer (Beta)', 'italy-cookie-choices' ); ?>
1046
+ </label>
1047
+
1048
+ <?php
1049
+
1050
+ }
1051
+
1052
+ /**
1053
+ * Textarea for custom_script_block_body_exclude
1054
+ * Scripts allowed in body
1055
+ * @return string
1056
+ */
1057
+ public function italy_cl_option_custom_script_block_body_exclude($args) {
1058
+
1059
+ /**
1060
+ * Template with list of code example
1061
+ */
1062
+ require(ITALY_COOKIE_CHOICES_PLUGIN_PATH . 'admin/template/allow-script.php');
1063
+
1064
+ $custom_script_block_body_exclude = ( isset( $this->options['custom_script_block_body_exclude'] ) ) ? $this->options['custom_script_block_body_exclude'] : '' ;
1065
+
1066
+ ?>
1067
+ <!-- <div id="editor"><?php // echo esc_textarea( $custom_script_block_body_exclude ); ?></div> -->
1068
+
1069
+ <!-- <input type='checkbox' name='italy_cookie_choices[ppp]' <?php // checked( $block, 1 ); ?> value='1' id="italy_cookie_choices[ppp]"> -->
1070
+ <!-- <br> -->
1071
+ <textarea rows="5" cols="70" name="italy_cookie_choices[custom_script_block_body_exclude]" id="italy_cookie_choices[custom_script_block_body_exclude]" placeholder="<?php _e( '&lt;script src=&quot;http://domain.com/widget-example.js&quot;&gt;&lt;/script&gt;'."\n".'&lt;---------SEP---------&gt;'."\n".'&lt;script src=&quot;http://otherdomain.com/script-example.js&quot;&gt;&lt;/script&gt;'."\n".'&lt;---------SEP---------&gt;'."\n".'&lt;script src=&quot;http://lastdomain.com/gadget-example.js&quot;&gt;&lt;/script&gt;', 'italy-cookie-choices' ) ?>" class="textarea"><?php echo esc_textarea( $custom_script_block_body_exclude ); ?></textarea>
1072
+ <br>
1073
+ <a id="SEP" class="button button-secondary add-sep" data-value="<---------SEP--------->">&lt;---------SEP---------&gt;</a>
1074
+ <a id="SOM" class="button button-secondary add-sep" data-value="<---------SOMETHING--------->">&lt;---------SOMETHING---------&gt;</a>
1075
+
1076
+ <!-- <a href="#TB_inline?width=600&height=550&inlineId=code-example" class="thickbox button button-secondary"><?php // _e( 'View example', 'italy-cookie-choices' ); ?></a> -->
1077
+
1078
+ <br>
1079
+ <label for="italy_cookie_choices[custom_script_block_body_exclude]">
1080
+ <?php echo __( 'Scripts to be excluded from the automatic block.<br />Split each script with <strong><em>&lt;---------SEP---------&gt;</em></strong><br>Use <strong><---------SOMETHING---------></strong> for custom regex', 'italy-cookie-choices' ); ?>
1081
+ </label>
1082
+ <p>
1083
+ <a href="https://github.com/ItalyCookieChoices/italy-cookie-choices/wiki/Custom-script" target="_blank"><?php _e( 'For more information see the documentation', 'italy-cookie-choices' ); ?></a>
1084
+ </p>
1085
+
1086
+ <?php
1087
+
1088
+ }
1089
+
1090
+ /**
1091
+ * Textarea for content_message_text
1092
+ * @return string
1093
+ */
1094
+ public function italy_cl_option_custom_script_block($args) {
1095
+
1096
+ /**
1097
+ * Template with block script
1098
+ */
1099
+ require(ITALY_COOKIE_CHOICES_PLUGIN_PATH . 'admin/template/block-script.php');
1100
+
1101
+ $custom_script_block = ( isset( $this->options['custom_script_block'] ) ) ? $this->options['custom_script_block'] : '' ;
1102
+
1103
+ ?>
1104
+ <textarea rows="5" cols="70" name="italy_cookie_choices[custom_script_block]" id="italy_cookie_choices[custom_script_block]" placeholder="<?php _e( '&lt;script src=&quot;http://domain.com/widget-example.js&quot;&gt;&lt;/script&gt;'."\n".'&lt;---------SEP---------&gt;'."\n".'&lt;script src=&quot;http://otherdomain.com/script-example.js&quot;&gt;&lt;/script&gt;'."\n".'&lt;---------SEP---------&gt;'."\n".'&lt;script src=&quot;http://lastdomain.com/gadget-example.js&quot;&gt;&lt;/script&gt;', 'italy-cookie-choices' ) ?>" ><?php echo esc_textarea( $custom_script_block ); ?></textarea>
1105
+ <br>
1106
+ <a id="SEP" class="button button-secondary add-sep" data-value="<---------SEP--------->">&lt;---------SEP---------&gt;</a>
1107
+ <a id="SOM" class="button button-secondary add-sep" data-value="<---------SOMETHING--------->">&lt;---------SOMETHING---------&gt;</a>
1108
+ <br>
1109
+ <label for="italy_cookie_choices[custom_script_block]">
1110
+ <?php echo __( 'Scripts shown in the head and in the footer does not automatically blocked.<br />Split each script with <strong><em>&lt;---------SEP---------&gt;</em></strong><br>Use <strong><---------SOMETHING---------></strong> for custom regex', 'italy-cookie-choices' ); ?>
1111
+ </label>
1112
+ <p>
1113
+ <a href="https://github.com/ItalyCookieChoices/italy-cookie-choices/wiki/Custom-script" target="_blank"><?php _e( 'For more information see the documentation', 'italy-cookie-choices' ); ?></a>
1114
+ </p>
1115
+
1116
+ <?php
1117
+
1118
+ }
1119
+
1120
+ /**
1121
+ * Function for custom script block
1122
+ * @return string
1123
+ */
1124
+ public function italy_cl_option_content_message_text($args) {
1125
+
1126
+ $content_message_text = ( isset( $this->options['content_message_text'] ) ) ? $this->options['content_message_text'] : '' ;
1127
+
1128
+ /**
1129
+ * Allow HTML tags in message text area
1130
+ * changed esc_textarea( $this->options['text'] ); with wp_kses_post( $this->options['text'] );
1131
+ * @todo Add padding to text editor
1132
+ */
1133
+
1134
+ if ( function_exists("wp_editor") ):
1135
+ wp_editor(
1136
+ wp_kses_post( $content_message_text ),
1137
+ 'italy_cookie_choices_content_message_text',
1138
+ array(
1139
+ 'textarea_name' => 'italy_cookie_choices[content_message_text]',
1140
+ 'media_buttons' => false,
1141
+ 'textarea_rows' => 5,
1142
+ 'editor_css' => '<style>#wp-italy_cookie_choices_content_message_text-wrap{max-width:520px}</style>',
1143
+ 'teeny' => true
1144
+ )
1145
+ );
1146
+ else:
1147
+ ?>
1148
+ <textarea rows="5" cols="70" name="italy_cookie_choices[content_message_text]" id="italy_cookie_choices[content_message_text]" placeholder="<?php _e( 'Your lock message for embedded contents inside posts, pages and widgets', 'italy-cookie-choices' ) ?>" ><?php echo wp_kses_post( $content_message_text ); ?></textarea>
1149
+ <?php endif; ?>
1150
+ <br>
1151
+ <label for="italy_cookie_choices[content_message_text]">
1152
+ <?php echo __( 'People will see this notice only the first time that they enter your site', 'italy-cookie-choices' ); ?>
1153
+ </label>
1154
 
1155
+ <?php
1156
 
1157
+ }
1158
 
1159
+ /**
1160
+ * Input for content_message_button_text
1161
+ * @return string
1162
+ */
1163
+ public function italy_cl_option_content_message_button_text($args) {
1164
 
1165
+ $content_message_button_text = ( isset( $this->options['content_message_button_text'] ) ) ? $this->options['content_message_button_text'] : '' ;
1166
 
1167
+ ?>
1168
+ <input type="text" id="italy_cookie_choices[content_message_button_text]" name="italy_cookie_choices[content_message_button_text]" value="<?php echo esc_attr( $content_message_button_text ); ?>" placeholder="<?php _e( 'e.g. Close', 'italy-cookie-choices' ) ?>" />
1169
 
1170
+ <label for="italy_cookie_choices[content_message_button_text]">
1171
+ <?php echo __( 'Insert here name of button (e.g. "Close") ', 'italy-cookie-choices' ); ?>
1172
+ </label>
1173
 
1174
+ <?php
1175
 
1176
+ }
1177
 
1178
+ /**
1179
+ * Sanitize data
1180
+ * @param array $input Data to sanitize
1181
+ * @return array Data sanitized
1182
+ */
1183
+ public function sanitize_callback( $input ){
1184
 
1185
+ // require 'class-italy-cookie-choices-sanitize.php';
1186
 
1187
+ // new Italy_Cookie_Choices_Sanitize( $input );
1188
 
1189
+ $new_input = array();
1190
 
1191
+ if( isset( $input['active'] ) )
1192
+ $new_input['active'] = $input['active'];
1193
 
1194
+ if( isset( $input['banner'] ) )
1195
+ $new_input['banner'] = $input['banner'];
1196
 
1197
+ if( isset( $input['scroll'] ) )
1198
+ $new_input['scroll'] = $input['scroll'];
1199
 
1200
+ if( isset( $input['secondView'] ) )
1201
+ $new_input['secondView'] = $input['secondView'];
1202
 
1203
+ if( isset( $input['reload'] ) )
1204
+ $new_input['reload'] = $input['reload'];
1205
+
1206
+ /**
1207
+ * Multilingual for text, url, anchor_text & button_text
1208
+ */
1209
+ if( isset( $input['text'] ) ){
1210
 
1211
+ $new_input['text'] = wp_kses_post( $input['text'] );
1212
+ // $new_input['text'] = sanitize_text_field( $input['text'] );
1213
+ register_string( 'Italy Cookie Choices', 'Banner text', $new_input['text'] );
1214
+ }
1215
 
1216
+ if( isset( $input['url'] ) ){
1217
 
1218
+ $new_input['url'] = sanitize_text_field( $input['url'] );
1219
 
1220
+ register_string( 'Italy Cookie Choices', 'Banner url', $new_input['url'] );
1221
 
1222
+ }
1223
 
1224
+ if( isset( $input['slug'] ) ){
1225
 
1226
+ $new_input['slug'] = sanitize_text_field( $input['slug'] );
1227
 
1228
+ register_string( 'Italy Cookie Choices', 'Banner slug', $new_input['slug'] );
1229
 
1230
+ }
1231
 
1232
+ if( isset( $input['anchor_text'] ) ){
1233
 
1234
+ $new_input['anchor_text'] = sanitize_text_field( $input['anchor_text'] );
1235
 
1236
+ register_string( 'Italy Cookie Choices', 'Banner anchor text', $new_input['anchor_text'] );
1237
 
1238
+ }
1239
 
1240
+ if( isset( $input['button_text'] ) ){
1241
 
1242
+ $new_input['button_text'] = sanitize_text_field( $input['button_text'] );
1243
 
1244
+ register_string( 'Italy Cookie Choices', 'Banner button text', $new_input['button_text'] );
1245
 
1246
+ }
1247
 
1248
+ /**
1249
+ * Sezione per lo stile
1250
+ */
1251
+ if( isset( $input['html_margin'] ) )
1252
+ $new_input['html_margin'] = $input['html_margin'];
1253
+
1254
+ if( isset( $input['js_template'] ) )
1255
+ $new_input['js_template'] = $input['js_template'];
1256
+
1257
+ if( empty( $input['banner_bg'] ) )
1258
+ $new_input['banner_bg'] = '#fff';
1259
+ elseif ( isset( $input['banner_bg'] ) )
1260
+ $new_input['banner_bg'] = sanitize_text_field( $input['banner_bg'] );
1261
 
1262
+ if( empty( $input['banner_text_color'] ) )
1263
+ $new_input['banner_text_color'] = '#000';
1264
+ elseif ( isset( $input['banner_text_color'] ) )
1265
+ $new_input['banner_text_color'] = sanitize_text_field( $input['banner_text_color'] );
1266
 
1267
+ if( isset( $input['customCSS'] ) )
1268
+ $new_input['customCSS'] = sanitize_text_field( $input['customCSS'] );
1269
 
1270
+ if( empty( $input['bannerStyle'] ) )
1271
+ $new_input['bannerStyle'] = 'bannerStyle';
1272
+ elseif( isset( $input['bannerStyle'] ) )
1273
+ $new_input['bannerStyle'] = sanitize_text_field( $input['bannerStyle'] );
1274
 
1275
+ if( empty( $input['contentStyle'] ) )
1276
+ $new_input['contentStyle'] = 'contentStyle';
1277
+ elseif( isset( $input['contentStyle'] ) )
1278
+ $new_input['contentStyle'] = sanitize_text_field( $input['contentStyle'] );
1279
 
1280
+ if( empty( $input['consentText'] ) )
1281
+ $new_input['consentText'] = 'consentText';
1282
+ elseif( isset( $input['consentText'] ) )
1283
+ $new_input['consentText'] = sanitize_text_field( $input['consentText'] );
1284
 
1285
+ if( empty( $input['infoClass'] ) )
1286
+ $new_input['infoClass'] = 'italybtn';
1287
+ elseif( isset( $input['infoClass'] ) )
1288
+ $new_input['infoClass'] = sanitize_text_field( $input['infoClass'] );
1289
 
1290
+ if( empty( $input['closeClass'] ) )
1291
+ $new_input['closeClass'] = 'italybtn';
1292
+ elseif( isset( $input['closeClass'] ) )
1293
+ $new_input['closeClass'] = sanitize_text_field( $input['closeClass'] );
1294
 
1295
+ /**
1296
+ * Sezione per le opzioni avanzate
1297
+ * Esempio per add_settings_error()
1298
+ * @link https://wordpress.org/support/topic/how-to-use-add_settings_error-for-nested-options-array?replies=2
1299
+ * @link http://pastebin.com/K4kJ0DNG
1300
+ */
1301
+ if( empty( $input['cookie_name'] ) ){
1302
+ add_settings_error( 'italy_cookie_id', 'cookie_name_ID', __('Cookie name field it can\'t be empty. Restored default name.', 'italy-cookie-choices' ), 'error');
1303
+ $new_input['cookie_name'] = $this->cookieName;
1304
+ }
1305
+ else
1306
+ $new_input['cookie_name'] = sanitize_text_field( $input['cookie_name'] );
1307
 
1308
+ if( empty( $input['cookie_value'] ) ){
1309
+ add_settings_error( 'italy_cookie_id', 'cookie_name_ID', __('Cookie value field it can\'t be empty. Restored default value.', 'italy-cookie-choices' ), 'error');
1310
+ $new_input['cookie_value'] = $this->cookieVal;
1311
+ }
1312
+ else
1313
+ $new_input['cookie_value'] = sanitize_text_field( $input['cookie_value'] );
1314
 
1315
+ if( isset( $input['target'] ) )
1316
+ $new_input['target'] = $input['target'];
1317
 
1318
+ if( isset( $input['block'] ) )
1319
+ $new_input['block'] = $input['block'];
1320
 
1321
+ if( isset( $input['widget_block'] ) )
1322
+ $new_input['widget_block'] = $input['widget_block'];
1323
 
1324
+ if( isset( $input['all_block'] ) )
1325
+ $new_input['all_block'] = $input['all_block'];
1326
+
1327
+ /**
1328
+ * Allow script
1329
+ */
1330
+ if( isset( $input['allow_iframe'] ) )
1331
+ $new_input['allow_iframe'] = $input['allow_iframe'];
1332
+
1333
+ if( isset( $input['allow_script'] ) )
1334
+ $new_input['allow_script'] = $input['allow_script'];
1335
+
1336
+ if( isset( $input['allow_embed'] ) )
1337
+ $new_input['allow_embed'] = $input['allow_embed'];
1338
+
1339
+ if( isset( $input['custom_script_block_body_exclude'] ) )
1340
+ $new_input['custom_script_block_body_exclude'] = $input['custom_script_block_body_exclude'];
1341
+ /**********************************************************************/
1342
+
1343
+ /**
1344
+ * Block script
1345
+ */
1346
+ if( isset( $input['block_iframe'] ) )
1347
+ $new_input['block_iframe'] = $input['block_iframe'];
1348
+
1349
+ if( isset( $input['block_script'] ) )
1350
+ $new_input['block_script'] = $input['block_script'];
1351
+
1352
+ if( isset( $input['block_embed'] ) )
1353
+ $new_input['block_embed'] = $input['block_embed'];
1354
+
1355
+ if( isset( $input['custom_script_block'] ) )
1356
+ $new_input['custom_script_block'] = $input['custom_script_block'];
1357
+ /**********************************************************************/
1358
+
1359
+ if( isset( $input['content_message_text'] ) ){
1360
+
1361
+ $new_input['content_message_text'] = wp_kses_post( $input['content_message_text'] );
1362
+
1363
+ register_string( 'Italy Cookie Choices', 'Content message text', $new_input['content_message_text'] );
1364
+
1365
+ }
1366
+
1367
+ if( isset( $input['content_message_button_text'] ) ){
1368
+
1369
+ $new_input['content_message_button_text'] = sanitize_text_field( $input['content_message_button_text'] );
1370
+
1371
+ register_string( 'Italy Cookie Choices', 'Content message button text', $new_input['content_message_button_text'] );
1372
+
1373
+ }
1374
+
1375
+ return $new_input;
1376
+
1377
+ }
1378
+
1379
+ /**
1380
+ * Function for color picker in admin
1381
+ * @param string $hook_suffix Hook for script
1382
+ * @return Append script
1383
+ * @link https://make.wordpress.org/core/2012/11/30/new-color-picker-in-wp-3-5/
1384
+ * @link http://code.tutsplus.com/articles/how-to-use-wordpress-color-picker-api--wp-33067
1385
+ */
1386
+ public function add_script_and_style( $hook_suffix ) {
1387
+
1388
+ // first check that $hook_suffix is appropriate for your admin page
1389
+ if ( 'settings_page_italy-cookie-choices' !== $hook_suffix )
1390
+ return;
1391
+
1392
+ /**
1393
+ * Add color picker in admin menù
1394
+ */
1395
+ wp_enqueue_style( 'wp-color-picker' );
1396
+
1397
+ /**
1398
+ * Load jQuery autocomplete for slug and url input
1399
+ */
1400
+ wp_enqueue_style( 'jquery-ui-autocomplete' );
1401
+ wp_enqueue_script( 'jquery-ui-autocomplete' );
1402
+
1403
+ /**
1404
+ * Add thickbox for diplay code example
1405
+ * @link https://codex.wordpress.org/Javascript_Reference/ThickBox
1406
+ */
1407
+ // add_thickbox();
1408
+
1409
+ /**
1410
+ * Load ACE from CDN
1411
+ * Functionality for custom script editor and CSS editor
1412
+ */
1413
+ // wp_register_script('ace', '//cdn.jsdelivr.net/ace/1.1.9/min/ace.js', false, null, true);
1414
+ // wp_enqueue_script('ace');
1415
+
1416
+ wp_enqueue_style(
1417
+ 'italy-cookie-choices-css',
1418
+ plugins_url('admin/css/admin.css', ITALY_COOKIE_CHOICES_FILE ),
1419
+ array( 'dashicons' ),
1420
+ null
1421
+ );
1422
+
1423
+ wp_enqueue_script(
1424
+ 'italy-cookie-choices-script',
1425
+ plugins_url('admin/js/src/script.js', ITALY_COOKIE_CHOICES_FILE ),
1426
+ array(
1427
+ // 'jquery',
1428
+ 'wp-color-picker',
1429
+ 'jquery-ui-widget',
1430
+ 'jquery-ui-autocomplete',
1431
+ 'jquery-effects-shake',
1432
+ // 'ace'
1433
+ ),
1434
+ null,
1435
+ true
1436
+ );
1437
+
1438
+ }
1439
+
1440
+ /**
1441
+ * Add link in plugin activation panel
1442
+ * @link https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)
1443
+ * @param array $links Array of link in wordpress dashboard
1444
+ * @return array Array with my links
1445
+ */
1446
+ public function plugin_action_links( $links ){
1447
+
1448
+ array_unshift($links, '<a href="options-general.php?page=italy-cookie-choices">' . __('Settings','italy-cookie-choices') . '</a>');
1449
+
1450
+ array_unshift($links, '<a href="https://github.com/ItalyCookieChoices/italy-cookie-choices/wiki" target="_blank">' . __('Documentation','italy-cookie-choices') . '</a>');
1451
+
1452
+ return $links;
1453
+ }// plugin_action_links()
1454
+
1455
+ /**
1456
+ * Set the three array with predefinited third party script|iframe|embed
1457
+ * @see https://codex.wordpress.org/Embeds For more embed
1458
+ * @todo See above
1459
+ * @return void
1460
+ */
1461
+ private function create_third_party_array(){
1462
+
1463
+ $this->iframe_array = array(
1464
+ '' => '',
1465
+ 'google' => 'google',
1466
+ 'google_maps' => 'maps',
1467
+ 'youtube' => 'youtube',
1468
+ 'disqus' => 'disqus',
1469
+ 'twitter' => 'twitter',
1470
+ 'vimeo' => 'vimeo',
1471
+ 'facebook' => 'facebook',
1472
+ );
1473
+
1474
+ $this->script_array = array(
1475
+ '' => '',
1476
+ 'google' => 'google',
1477
+ 'google_maps' => 'maps',
1478
+ 'googleapis' => 'googleapis',
1479
+ 'AdSense' => 'googlesyndication',
1480
+ 'doubleclick' => 'doubleclick',
1481
+ 'plusone' => 'plusone',
1482
+ 'platform' => 'platform',
1483
+ 'analytics' => 'analytics',
1484
+ 'facebook' => 'facebook',
1485
+ 'addthis' => 'addthis',
1486
+ 'twitter' => 'twitter',
1487
+ 'linkedin' => 'linkedin',
1488
+ 'pinterest' => 'pinterest',
1489
+ 'disqus' => 'disqus',
1490
+ 'vimeo' => 'vimeo',
1491
+ 'youtube' => 'youtube',
1492
+ 'youtube-nocookie' => 'youtube-nocookie',
1493
+ '_getTracker' => '_getTracker',
1494
+ 'instagram' => 'instagram',
1495
+ 'cdninstagram' => 'cdninstagram',
1496
+ 'digg' => 'digg',
1497
+ 'eventbrite' => 'eventbrite',
1498
+ 'wordpress' => 'wp'
1499
+ );
1500
+
1501
+ $this->embed_array = array(
1502
+ '' => ''
1503
+ );
1504
+
1505
+ }
1506
+
1507
+ /**
1508
+ * This function add the HTML to display new functionality for UX allow and block script
1509
+ * @param array $array Pass the plugin option array[name]
1510
+ * @param string $arr_name A string name of the array
1511
+ * @param array $arr_key Array for predefinited script|emebd|iframe
1512
+ * This add a select box with script name
1513
+ * @return string Return the HTML for new input
1514
+ */
1515
+ function foreach_script( $array, $arr_name, $arr_key ){
1516
+
1517
+ $select = '<select>';
1518
+
1519
+ foreach ($arr_key as $key => $value)
1520
+ $select .= '<option value="' . $value . '">' . $key . '</option>';
1521
+
1522
+ $select .= '</select>';
1523
+
1524
+ // <button class=" button" disabled> &emsp; </button>
1525
+ $input = '<div class="custom-script">';
1526
+ $i = 0;
1527
+ foreach ( $array as $key => $value ){
1528
+
1529
+ $input .= '<div class="italy-cookie-choices-clone-div"><input type="text" class="regular-text" data-type="' . $arr_name . '" value="' . esc_attr( $value ) .'" name="italy_cookie_choices[' . $arr_name . '][' . esc_attr( $value ) .']" id="italy_cookie_choices[' . $arr_name . '][' . esc_attr( $value ) .']"/> ' . $select . ' <span><a class="button add" style="font-size:22px"> + </a> ' . ( $i === 0 ? '<a class="button cancel" style="font-size:22px"> x </a>' : '<a class=" button remove" style="font-size:22px"> × </a>' ) . '</span></div>';
1530
+
1531
+ $i++;
1532
+
1533
+ }
1534
+ $input .= '</div>';
1535
+
1536
+ echo $input;
1537
+
1538
+ }
1539
+
1540
+ /**
1541
+ * Process a settings export from config
1542
+ * @since 1.0.0
1543
+ */
1544
+ function settings_export() {
1545
+
1546
+ if ( empty( $_POST[ 'icc_action' ] ) || 'export_settings' !== $_POST[ 'icc_action' ] )
1547
+ return;
1548
+
1549
+ if ( !wp_verify_nonce( $_POST[ 'icc_export_nonce' ], 'icc_export_nonce' ) )
1550
+ return;
1551
+
1552
+ if ( !current_user_can( $this->capability ) )
1553
+ return;
1554
+
1555
+ $settings[0] = $this->options;
1556
+
1557
+ ignore_user_abort( true );
1558
+
1559
+ nocache_headers();
1560
+
1561
+ // date_default_timezone_set('UTC');
1562
+ header( 'Content-Type: application/json; charset=utf-8' );
1563
+ header( 'Content-Disposition: attachment; filename=italy-cookie-choices-settings-export-' . date( 'm-d-Y' ) . '.json' );
1564
+ header( "Expires: 0" );
1565
+
1566
+ echo $this->wp_json_encode( $settings, JSON_PRETTY_PRINT );
1567
+
1568
+ exit;
1569
+ }
1570
+
1571
+ /**
1572
+ * Process a settings import from a json file
1573
+ * @since 1.0.0
1574
+ */
1575
+ function settings_import() {
1576
+
1577
+ if ( empty( $_POST[ 'icc_action' ] ) || 'import_settings' != $_POST[ 'icc_action' ] )
1578
+ return;
1579
+
1580
+ if ( !wp_verify_nonce( $_POST[ 'icc_import_nonce' ], 'icc_import_nonce' ) )
1581
+ return;
1582
+
1583
+ if ( !current_user_can( $this->capability ) )
1584
+ return;
1585
+
1586
+ /**
1587
+ * Get the extension of import file
1588
+ * @link http://stackoverflow.com/a/19831453 Strict standards: Only variables should be passed by reference
1589
+ * @var string
1590
+ */
1591
+ $file_name = $_FILES[ 'icc_import_file' ][ 'name' ];
1592
+ $exploded = explode( '.', $file_name );
1593
+ $extension = end( $exploded );
1594
 
1595
+ /**
1596
+ * If it is not json than die
1597
+ */
1598
+ if ( $extension !== 'json' )
1599
+ wp_die( __( 'Please upload a valid .json file', 'italy-cookie-choices' ), __( 'No valid json file', 'italy-cookie-choices' ), array( 'back_link' => true ) );
1600
 
1601
+ /**
1602
+ * If the file is empty than die
1603
+ */
1604
+ if ( $_FILES[ 'icc_import_file' ][ 'size' ] === 0 )
1605
+ wp_die( __( 'The json file can\'t be empty', 'italy-cookie-choices' ), __( 'Empty file', 'italy-cookie-choices' ), array( 'back_link' => true ) );
1606
 
1607
+ $import_file = $_FILES[ 'icc_import_file' ][ 'tmp_name' ];
1608
+
1609
+ /**
1610
+ * If $import_file is empty or null than die
1611
+ */
1612
+ if ( empty( $import_file ) )
1613
+ wp_die( __( 'Please upload a file to import', 'italy-cookie-choices' ), __( 'No file import', 'italy-cookie-choices' ), array( 'back_link' => true ) );
1614
 
1615
+ /**
1616
+ * Retrieve the settings from the file and convert the json object to an array.
1617
+ * @var array
1618
+ */
1619
+ $settings = ( array ) json_decode( file_get_contents( $import_file ) );
1620
 
1621
+ update_option( 'italy_cookie_choices', get_object_vars( $settings[0] ) );
1622
 
1623
+ wp_safe_redirect( admin_url( 'options-general.php?page=' . 'italy-cookie-choices' ) );
1624
+ exit;
1625
+ }
1626
 
1627
+ }// class
1628
  }//endif
classes/class-italy-cookie-choices-front-end.php CHANGED
@@ -4,923 +4,903 @@
4
  */
5
  if ( !class_exists( 'Italy_Cookie_Choices_Front_End' ) ){
6
 
7
- class Italy_Cookie_Choices_Front_End{
8
-
9
- /**
10
- * Option
11
- * @var array
12
- */
13
- private $options = array();
14
-
15
- /**
16
- * Default Cookie name
17
- * @var string
18
- */
19
- private $cookieName = 'displayCookieConsent';
20
-
21
- /**
22
- * Default cookie value
23
- * @var string
24
- */
25
- private $cookieVal = 'y';
26
-
27
- /**
28
- * Pattern for searching embed code in content and widget
29
- * @var string
30
- */
31
- private $pattern = '#<iframe.*?\/iframe>|<embed.*?>|<script.*?\/script>#is';
32
-
33
- /**
34
- * Snippet for replacements
35
- * @var string
36
- */
37
- private $valore = '';
38
-
39
- /**
40
- * Inizialize banner template to default
41
- * @var string
42
- */
43
- private $js_template = 'default';
44
-
45
- /**
46
- * Array with embed found
47
- * @var array
48
- */
49
- public $js_array = array();
50
-
51
- /**
52
- * If exist set a page slug
53
- * @var string
54
- */
55
- private $slug = '';
56
-
57
- /**
58
- * URL for policy page
59
- * @var string
60
- */
61
- private $url = '';
62
-
63
- /**
64
- * Array with list of allowed script|iframe|embed
65
- * @var array
66
- */
67
- private $allow_script = array();
68
-
69
- /**
70
- * Array with list of blocked script|iframe|embed
71
- * @var array
72
- */
73
- private $block_script = array();
74
-
75
- /**
76
- * [__construct description]
77
- */
78
- public function __construct(){
79
-
80
- $this->options = get_option( 'italy_cookie_choices' );
81
-
82
- /**
83
- * Check for second view option
84
- * @var bol
85
- */
86
- $secondViewOpt = ( isset( $this->options['secondView'] ) ) ? $this->options['secondView'] : '' ;
87
-
88
- /**
89
- * Assegno il valore allo slug nel costruttore
90
- * Default ID 1 perché su null non settava correttamente lo scroll se il valore era assente
91
- * @var bolean
92
- */
93
- $this->slug = ( isset( $this->options['slug'] ) && !empty( $this->options['slug'] ) ) ? esc_attr( get_string( 'Italy Cookie Choices', 'Banner slug', $this->options['slug'] ) ) : 1 ;
94
-
95
- /**
96
- * Assegno il valore della URL della policy page
97
- * Default ID 1 perché su null non settava correttamente lo scroll se il valore era assente
98
- * @var bolean
99
- */
100
- $this->url = ( isset( $this->options['url'] ) && !empty( $this->options['url'] ) ) ? esc_url( get_string( 'Italy Cookie Choices', 'Banner url', $this->options['url'] ) ) : 1 ;
101
-
102
- /*
103
- * Set cookie if the user agree navigating through the pages of the site
104
- */
105
- $secondView = false;
106
-
107
- if( $this->is_policy_page( $secondViewOpt ) ) {
108
-
109
- setcookie($this->options['cookie_name'], $this->options['cookie_value'], time()+(3600*24*365), '/');
110
- $secondView = true;
111
- }
112
-
113
- /**
114
- * Shortcode to put a button in policy page
115
- */
116
- add_shortcode( 'accept_button', array( $this, 'accept_button' ) );
117
- add_shortcode( 'delete_cookie', array( $this, '_delete_cookie' ) );
118
-
119
- if ( !isset( $_COOKIE[ $this->options['cookie_name'] ] ) && !$secondView ){
120
-
121
- // W3TC Disable Caching
122
- if ( !defined( 'DONOTCACHEPAGE' ) )
123
- define('DONOTCACHEPAGE', true);
124
- if ( !defined( 'SID' ) )
125
- define('SID', true);
126
-
127
- /**
128
- * Background color for banner
129
- * @var string
130
- */
131
- $banner_bg = ( isset( $this->options['banner_bg'] ) ) ? $this->options['banner_bg'] : '#ffffff' ;
132
-
133
- /**
134
- * Color for text
135
- * @var string
136
- */
137
- $banner_text_color = ( isset( $this->options['banner_text_color'] ) ) ? $this->options['banner_text_color'] : '#000000' ;
138
-
139
- /**
140
- * Text for banner
141
- * @var string
142
- */
143
- $text = ( isset( $this->options['text'] ) ) ? $this->options['text'] : '' ;
144
-
145
- /**
146
- * Text for buttom
147
- * @var [type]
148
- */
149
- $button_text = ( isset( $this->options['button_text'] ) ) ? $this->options['button_text'] : '' ;
150
-
151
- /**
152
- * Checkbox for third part cookie in content
153
- * @var bol
154
- */
155
- $block = ( isset( $this->options['block'] ) ) ? $this->options['block'] : '' ;
156
-
157
- /**
158
- * Checkbox for third part cookie in widget
159
- * @var bol
160
- */
161
- $widget_block = ( isset( $this->options['widget_block'] ) ) ? $this->options['widget_block'] : '' ;
162
-
163
- /**
164
- * Checkbox for third part cookie in all page (except head and footer)
165
- * @var bol
166
- */
167
- $all_block = ( isset( $this->options['all_block'] ) ) ? $this->options['all_block'] : '' ;
168
-
169
- /**
170
- * Checkbox custom scripts block in BODY
171
- * @var string
172
- */
173
- $custom_script_block_body_exclude = ( isset( $this->options['custom_script_block_body_exclude'] ) ) ? $this->options['custom_script_block_body_exclude'] : '' ;
174
-
175
- $this->get_block_script();
176
- $this->get_allow_script();
177
-
178
- /**
179
- * Checkbox custom scripts block in HEAD and FOOTER
180
- * @var string
181
- */
182
- $custom_script_block = ( isset( $this->options['custom_script_block'] ) ) ? $this->options['custom_script_block'] : '' ;
183
-
184
- /**
185
- * Text to put inside locked post and widget contents
186
- * including the button text
187
- * @var string
188
- */
189
- $content_message_text = ( isset( $this->options['content_message_text'] ) ) ? wp_kses_post( get_string( 'Italy Cookie Choices', 'Content message text', $this->options['content_message_text'] ) ) : '' ;
190
-
191
- /**
192
- * Text for button in locked content and widget
193
- * @var string
194
- */
195
- $content_message_button_text = ( isset( $this->options['content_message_button_text'] ) ) ? esc_attr( get_string( 'Italy Cookie Choices', 'Content message button text', $this->options['content_message_button_text'] ) ) : '' ;
196
-
197
- /**
198
- * Replacement for regex
199
- * @var string
200
- */
201
- $this->valore = '<div class="el"><div style="padding:10px;margin-bottom: 18px;color:' . esc_attr( $banner_text_color ) . ';background-color:' . esc_attr( $banner_bg ) . ';text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);">' . $content_message_text . '&nbsp;&nbsp;<button onclick="cookieChoices.removeCookieConsent()" style="color: ' . esc_attr( $banner_text_color ) . ';padding: 3px;font-size: 12px;line-height: 12px;text-decoration: none;text-transform: uppercase;margin:0;display: inline-block;font-weight: normal; text-align: center; vertical-align: middle; cursor: pointer; border: 1px solid ' . esc_attr( $banner_text_color ) . ';background: rgba(255, 255, 255, 0.03);">' . $content_message_button_text . '</button></div><cookie></div>';
202
-
203
- if ($block)
204
- add_filter( 'the_content', array( $this, 'AutoErase' ), 11);
205
-
206
- if ( $widget_block )
207
- add_filter( 'widget_display_callback', array( $this, 'WidgetErase' ), 11, 3 );
208
-
209
- if ( $all_block ) {
210
- //add_action('wp_footer', array( $this, 'catchBody' ), -1000000);
211
- add_action('wp_head', array( $this, 'bufferBodyStart' ), 1000000);
212
- add_action('wp_footer', array( $this, 'bufferBodyEnd' ), -1000000);
213
- }
214
- if( ( $custom_script_block || $this->block_script ) && $all_block ) {
215
- add_action('template_redirect', array( $this, 'bufferHeadStart' ), 2);
216
- add_action('wp_head', array( $this, 'bufferHeadEnd' ), 99999);
217
- add_action('wp_footer', array( $this, 'bufferFooterStart' ), -99998);
218
- add_action('shutdown', array( $this, 'bufferFooterEnd' ), -1000000);
219
- } else {
220
- /**
221
- * Function for print cookiechoiches inline
222
- */
223
- add_action( 'wp_footer', array( $this, 'print_script_inline'), -99999 );
224
- }
225
-
226
- /**
227
- * Only for debug
228
- */
229
- // var_dump($_COOKIE);
230
- // var_dump(headers_list());
231
-
232
- }
233
-
234
- }//__construct
235
-
236
-
237
- /**
238
- * Get the current page url
239
- * @link http://www.brosulo.net/content/informatica/ottenere-la-url-completa-da-una-pagina-php-0
240
- */
241
- private function CurrentPageURL() {
242
-
243
- if ( isset( $_SERVER['HTTPS'] ) )
244
- $pageURL = $_SERVER['HTTPS'];
245
- else
246
- $pageURL = NULL;
247
-
248
- $pageURL = $pageURL === 'on' ? 'https://' : 'http://';
249
- $pageURL .= $_SERVER["SERVER_NAME"];
250
- $pageURL .= ( $_SERVER['SERVER_PORT'] !== '80' ) ? ':' . $_SERVER["SERVER_PORT"] : '';
251
- $pageURL .= $_SERVER["REQUEST_URI"];
252
-
253
- return $pageURL;
254
-
255
- }
256
-
257
- /**
258
- * Check if is the policy page
259
- * Required url input
260
- * @param boolean $secondViewOpt Check for second view option
261
- * @return boolean Return bolean value
262
- */
263
- private function is_policy_page( $secondViewOpt = false ){
264
-
265
- if(
266
- // if is an HTML request (alternative methods???)
267
- ( strpos( $_SERVER['HTTP_ACCEPT'],'html' ) !== false ) &&
268
- //if the page isn't privacy page
269
- // ( $_SERVER['REQUEST_URI'] != $this->slug ) &&
270
- ( $this->CurrentPageURL() !== $this->url ) &&
271
- //if HTTP_REFERER is set
272
- ( isset( $_SERVER['HTTP_REFERER'] ) ) &&
273
- //if isn't refresh
274
- ( parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH) !== $_SERVER['REQUEST_URI'] ) &&
275
- //if referrer is not privacy page (to be evaluated)
276
- // ( parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH ) != $this->slug ) &&
277
- // ( $_SERVER['HTTP_REFERER'] !== $this->url ) &&
278
- //if the cookie is not already set
279
- ( !isset( $_COOKIE[ $this->options['cookie_name'] ] ) ) &&
280
- //if the referer is in the same domain
281
- ( parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) &&
282
- // If the secondView options is checked
283
- ( $secondViewOpt )
284
- )
285
- return true;
286
- else
287
- return false;
288
-
289
- }
290
-
291
-
292
- private function in_array_match($value, $array) {
293
- foreach($array as $k=>$v) {
294
- if(preg_match('/'.str_replace(preg_quote("<---------SOMETHING--------->"), ".*", preg_quote(preg_replace( "/([\r|\n]*)/is", "", trim($v)), '/')).'/is', preg_replace( "/([\r|\n]*)/is", "", $value))) {
295
- return true;
296
- }
297
- }
298
- return false;
299
- }
300
-
301
- /**
302
- * Remove custom script in header and footer
303
- * @param string $buffer Source of page
304
- * @return string Return the new HTML
305
- */
306
- public function removeCustomScript( $buffer ) {
307
- /**
308
- * Custom script to block
309
- * @var string
310
- */
311
- $custom_script_block = ( isset( $this->options['custom_script_block'] ) ) ? $this->options['custom_script_block'] : '' ;
312
-
313
- if( !$custom_script_block && !$this->block_script )
314
- return $buffer;
315
- else {
316
-
317
- /**
318
- * Replace space with <---------SEP--------->
319
- * @var string
320
- */
321
- $custom_script_block = preg_replace( "/([\r|\n]*)<---------SEP--------->([\r|\n]*)/is", "<---------SEP--------->", $custom_script_block );
322
-
323
- /**
324
- * Convert $custom_script_block to an array
325
- * @var array
326
- */
327
- $custom_script_block_array = explode("<---------SEP--------->", $custom_script_block);
328
-
329
- /**
330
- * Merge the script array from new UX functionality
331
- * @var array
332
- */
333
- $custom_script_block_array = array_merge( $custom_script_block_array, $this->block_script );
334
-
335
- /**
336
- *
337
- */
338
- foreach($custom_script_block_array AS $single_script) {
339
- preg_match_all('/'.str_replace(preg_quote("<---------SOMETHING--------->"), ".*", preg_quote(trim($single_script), '/')).'/is', $buffer, $matches);
340
- if(!empty($matches[0])) {
341
- foreach($matches[0] AS $v) {
342
- $buffer = str_replace(trim($v), "<!-- removed head from Italy Cookie Choices PHP Class -->", $buffer);
343
- $this->js_array[] = trim($v);
344
- }
345
- }
346
- }
347
- return $buffer;
348
- }
349
- }
350
-
351
- public function bufferBodyStart() {
352
- if (ob_get_contents())
353
- ob_end_flush();
354
- ob_start();
355
-
356
- }
357
-
358
- public function bufferBodyEnd() {
359
-
360
- /**
361
- * Check if $custom_script_block_body_exclude is set
362
- * @var string
363
- */
364
- $custom_script_block_body_exclude = ( isset( $this->options['custom_script_block_body_exclude'] ) ) ? $this->options['custom_script_block_body_exclude'] : '' ;
365
-
366
- /**
367
- * Replace space with <---------SEP--------->
368
- * @var string
369
- */
370
- $custom_script_block_body_exclude = preg_replace( "/([\r|\n]*)<---------SEP--------->([\r|\n]*)/is", "<---------SEP--------->", $custom_script_block_body_exclude );
371
-
372
- /**
373
- * Create array
374
- * @var array
375
- */
376
- $custom_script_block_body_exclude_array = explode("<---------SEP--------->", $custom_script_block_body_exclude);
377
-
378
- if( !is_array($custom_script_block_body_exclude_array) || empty( $custom_script_block_body_exclude_array[0] ) )
379
- $custom_script_block_body_exclude_array = array();
380
-
381
- /**
382
- * Merge the script array from new UX functionality
383
- * @var array
384
- */
385
- $custom_script_block_body_exclude_array = array_merge( $custom_script_block_body_exclude_array, $this->allow_script );
386
-
387
- $buffer = ob_get_contents();
388
- if (ob_get_contents())
389
- ob_end_clean();
390
- preg_match("/(.*)(<body.*)/s", $buffer, $matches);
391
- $head = $matches[1];
392
- $body = $matches[2];
393
- preg_match_all( $this->pattern, $body, $body_matches);
394
-
395
- if ( !empty( $body_matches[0] ) ) {
396
- foreach($body_matches[0] AS $k => $v) {
397
-
398
- if( !$this->in_array_match(trim($v), $custom_script_block_body_exclude_array) ) {
399
- $body = preg_replace('/'.str_replace(preg_quote("<---------SOMETHING--------->"), ".*", preg_quote(trim($v), '/')).'/is', $this->valore, $body);
400
- $this->js_array[] = trim($v);
401
- }
402
-
403
- }
404
-
405
- }
406
-
407
- $buffer_new = $head.$body;
408
- echo '<!-- ICCStartBody -->'.$buffer_new.'<!-- ICCEndBody -->';
409
- }
410
-
411
- public function bufferFooterStart() {
412
- /**
413
- * Check if we are in feed page, then do nothing
414
- */
415
- if ( is_feed() )
416
- return;
417
-
418
- if (ob_get_contents())
419
- ob_end_flush();
420
- ob_start();
421
- }
422
-
423
- public function bufferFooterEnd() {
424
- /**
425
- * Check if we are in feed page, then do nothing
426
- */
427
- if ( is_feed() )
428
- return;
429
-
430
- $buffer = ob_get_contents();
431
- if (ob_get_contents())
432
- ob_end_clean();
433
- // if is an HTML request (alternative methods???)
434
- if(strpos($_SERVER["HTTP_ACCEPT"],'html') !== false) {
435
- $buffer_new = $this->removeCustomScript($buffer);
436
- /**
437
- * Function for print cookiechoiches inline
438
- */
439
- $this->print_script_inline();
440
- echo '<!-- ICCStartFooter -->'.$buffer_new.'<!-- ICCEndFooter -->';
441
- } else {
442
- echo $buffer;
443
- }
444
- }
445
-
446
- public function bufferHeadStart() {
447
- if (ob_get_contents())
448
- ob_end_flush();
449
- ob_start();
450
- }
451
-
452
- public function bufferHeadEnd() {
453
- $buffer = ob_get_contents();
454
- if (ob_get_contents())
455
- ob_end_clean();
456
- $buffer_new = $this->removeCustomScript($buffer);
457
- echo '<!-- ICCStartHead -->'.$buffer_new.'<!-- ICCEndHead -->';
458
- }
459
-
460
- /**
461
- * Script preimpostati da escludere dal blocco
462
- * Preparare un array key valore a parte, unico per entrambi
463
- * Questo array sarà utilizzato per generare anche le input dinamicamente
464
- * array(
465
- * 'facebook' => 'script'
466
- * )
467
- * @return array Array con gli script preimpostati
468
- */
469
- private function get_allow_script(){
470
-
471
- $allow_iframe = ( isset( $this->options['allow_iframe'] ) ) ? $this->options['allow_iframe'] : array('');
472
- $allow_script = ( isset( $this->options['allow_script'] ) ) ? $this->options['allow_script'] : array('');
473
- $allow_embed = ( isset( $this->options['allow_embed'] ) ) ? $this->options['allow_embed'] : array('');
474
-
475
- $array = array();
476
-
477
- foreach ( $allow_iframe as $key => $value )
478
- if ( !empty( $value ) )
479
- $this->allow_script[] = '<iframe<---------SOMETHING--------->' . $value . '<---------SOMETHING---------></iframe>';
480
-
481
- // foreach ( $allow_script as $key => $value )
482
- // if ( !empty( $value ) )
483
- // $this->allow_script[] = '<script<---------SOMETHING--------->><---------SOMETHING--------->' . $value . '<---------SOMETHING---------></script>'; $this->allow_script[] = '<script<---------SOMETHING--------->' . $value . '<---------SOMETHING--------->></script>';
484
-
485
- foreach ( $allow_script as $key => $value )
486
- if ( !empty( $value ) )
487
- $this->allow_script[] = '<script<---------SOMETHING--------->' . $value . '<---------SOMETHING---------></script>';
488
-
489
- foreach ( $allow_embed as $key => $value )
490
- if ( !empty($value) )
491
- $this->allow_script[] = '<embed<---------SOMETHING--------->' . $value . '<---------SOMETHING--------->>';
492
-
493
- // return $this->allow_script;
494
-
495
- }
496
-
497
- private function get_block_script( $val = array() ){
498
-
499
- $block_iframe = ( isset( $this->options['block_iframe'] ) ) ? $this->options['block_iframe'] : array('');
500
- $block_script = ( isset( $this->options['block_script'] ) ) ? $this->options['block_script'] : array('');
501
- $block_embed = ( isset( $this->options['block_embed'] ) ) ? $this->options['block_embed'] : array('');
502
-
503
- $array = array();
504
-
505
- foreach ( $block_iframe as $value )
506
- if ( !empty( $value ) )
507
- $this->block_script[] = '<iframe<---------SOMETHING--------->' . $value . '<---------SOMETHING---------></iframe>';
508
-
509
- // foreach ( $block_script as $value )
510
- // if ( !empty( $value ) )
511
- // $this->block_script[] = '<script<---------SOMETHING--------->><---------SOMETHING--------->' . $value . '<---------SOMETHING---------></script>';
512
-
513
- foreach ( $block_script as $value )
514
- if ( !empty( $value ) )
515
- $this->block_script[] = '<script<---------SOMETHING--------->' . $value . '<---------SOMETHING---------></script>';
516
-
517
- foreach ( $block_embed as $value )
518
- if ( !empty( $value ) )
519
- $this->block_script[] = '<embed<---------SOMETHING--------->' . $value . '<---------SOMETHING--------->>';
520
-
521
- // return $this->block_script;
522
-
523
- }
524
-
525
- /**
526
- * Function for matching embed
527
- * @param string $pattern Pattern
528
- * @param string $content Content
529
- * @return array Array with embed found
530
- */
531
- public function matches( $pattern, $content ){
532
-
533
- preg_match_all( $this->pattern, $content, $matches );
534
-
535
- /**
536
- * Memorizzo gli embed trovati e li appendo all'array $js_array
537
- * @var array
538
- */
539
- if ( !empty( $matches[0] ) )
540
- $this->js_array = array_merge( $this->js_array, $matches[0] );
541
-
542
- }
543
-
544
- /**
545
- * Erase third part embed
546
- * @param string $content Article content
547
- */
548
- public function AutoErase( $content ) {
549
-
550
- $this->matches( $this->pattern, $content );
551
-
552
- $content = preg_replace( $this->pattern, $this->valore , $content);
553
-
554
-
555
- return $content;
556
- }
557
-
558
- private function fnFixArray($v) {
559
- if(is_array($v) or is_object($v)){
560
- foreach($v as $k1=>$v1){
561
- $v[$k1] = $this->fnFixArray($v1);
562
- }
563
- return $v;
564
- }
565
-
566
- if(!is_string($v) or empty($v)) return $v;
567
-
568
- $this->matches( $this->pattern, $v );
569
-
570
- return preg_replace( $this->pattern, $this->valore , $v);
571
- }
572
-
573
- /**
574
- * Erase third part in widget area
575
- * @param [type] $instance [description]
576
- * @param [type] $widget [description]
577
- * @param [type] $args [description]
578
- */
579
- public function WidgetErase($instance, $widget, $args){
580
- return $this->fnFixArray($instance);
581
- }
582
-
583
- /**
584
- * Encode a variable into JSON, with some sanity checks.
585
- *
586
- * @since 4.1.0
587
- *
588
- * @param mixed $data Variable (usually an array or object) to encode as JSON.
589
- * @param int $options Optional. Options to be passed to json_encode(). Default 0.
590
- * @param int $depth Optional. Maximum depth to walk through $data. Must be
591
- * greater than 0. Default 512.
592
- * @return bool|string The JSON encoded string, or false if it cannot be encoded.
593
- */
594
- public function wp_json_encode( $data, $options = 0, $depth = 512 ) {
595
-
596
- /*
597
- * json_encode() has had extra params added over the years.
598
- * $options was added in 5.3, and $depth in 5.5.
599
- * We need to make sure we call it with the correct arguments.
600
- */
601
- if ( version_compare( PHP_VERSION, '5.5', '>=' ) )
602
- $args = array( $data, $options, $depth );
603
- elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) )
604
- $args = array( $data, $options );
605
- else
606
- $args = array( $data );
607
-
608
- $json = call_user_func_array( 'json_encode', $args );
609
-
610
- // If json_encode() was successful, no need to do more sanity checking.
611
- // ... unless we're in an old version of PHP, and json_encode() returned
612
- // a string containing 'null'. Then we need to do more sanity checking.
613
- if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) )
614
- return $json;
615
-
616
- return call_user_func_array( 'json_encode', $args );
617
- }
618
-
619
- /**
620
- * Print script inline before </body>
621
- * @return string Print script inline
622
- * @link https://www.cookiechoices.org/
623
- */
624
- public function print_script_inline(){
625
-
626
- // $this->options = get_option( 'italy_cookie_choices' );
627
-
628
- /**
629
- * If is not active exit
630
- */
631
- if ( !isset( $this->options['active'] ) || is_feed() )
632
- return;
633
-
634
- /**
635
- * Accept on scroll
636
- * @var bol
637
- */
638
- $scroll = ( isset( $this->options['scroll'] ) && !( is_page( $this->slug ) || is_single( $this->slug ) ) ) ? $this->options['scroll'] : '' ;
639
-
640
- /**
641
- * Reload on accept
642
- * @var bol
643
- */
644
- $reload = ( isset( $this->options['reload'] ) ) ? $this->options['reload'] : '' ;
645
-
646
- /**
647
- * ADVANCED OPTIONS
648
- */
649
- /**
650
- * Cookie name
651
- * @var string
652
- */
653
- $cookie_name = ( isset( $this->options['cookie_name'] ) ) ? $this->options['cookie_name'] : $this->cookieName ;
654
-
655
- /**
656
- * Cookie value
657
- * @var string/bolean
658
- */
659
- $cookie_value = ( isset( $this->options['cookie_value'] ) ) ? $this->options['cookie_value'] : $this->cookieVal ;
660
-
661
- /**
662
- * Js_Template value
663
- * @var string
664
- */
665
- // $js_template = ( isset( $this->options['js_template'] ) && $this->options['js_template'] !== 'custom') ? $this->options['js_template'] : $this->js_template ;
666
- $js_template = ( isset( $this->options['js_template'] ) ) ? $this->options['js_template'] : $this->js_template ;
667
-
668
- /**
669
- * If is set html_margin checkbox in admin panel then add margin-top to HTML tag
670
- * @var bol
671
- */
672
- $htmlM = '' ;
673
-
674
- /**
675
- * If set open policy page in new browser tab
676
- * @var bol
677
- */
678
- $target = ( isset( $this->options['target'] ) ) ? $this->options['target'] : '' ;
679
-
680
- /**
681
- * Colore dello sfondo della dialog/topbar
682
- * @var string
683
- */
684
- $banner_bg = ( isset( $this->options['banner_bg'] ) && !empty( $this->options['banner_bg'] ) ) ? esc_attr( $this->options['banner_bg'] ) : '#fff' ;
685
-
686
- /**
687
- * Colore del font della dialog/topbar
688
- * @var string
689
- */
690
- $banner_text_color = ( isset( $this->options['banner_text_color'] ) && !empty( $this->options['banner_text_color'] ) ) ? esc_attr( $this->options['banner_text_color'] ) : '#000' ;
691
-
692
- /**
693
- * Custom CSS
694
- * @var string
695
- */
696
- $customCSS = ( isset( $this->options['customCSS'] ) ) ? esc_attr( $this->options['customCSS'] ) : '' ;
697
-
698
- /**
699
- * CSS class for div bannerStyle
700
- * @var string
701
- */
702
- $bannerStyle = ( isset( $this->options['bannerStyle'] ) && !empty( $this->options['bannerStyle'] ) ) ? esc_attr( $this->options['bannerStyle'] ) : 'bannerStyle' ;
703
-
704
- /**
705
- * CSS class for div content
706
- * @var string
707
- */
708
- $contStyle = ( isset( $this->options['contentStyle'] ) && !empty( $this->options['contentStyle'] ) ) ? esc_attr( $this->options['contentStyle'] ) : 'contentStyle' ;
709
-
710
- /**
711
- * CSS class for text in span
712
- * @var string
713
- */
714
- $consentText = ( isset( $this->options['consentText'] ) && !empty( $this->options['consentText'] ) ) ? esc_attr( $this->options['consentText'] ) : 'consentText' ;
715
-
716
- /**
717
- * CSS class for info link
718
- * @var string
719
- */
720
- $infoClass = ( isset( $this->options['infoClass'] ) && !empty( $this->options['infoClass'] ) ) ? esc_attr( $this->options['infoClass'] ) : 'italybtn' ;
721
-
722
- /**
723
- * CSS class for close link
724
- * @var string
725
- */
726
- $closeClass = ( isset( $this->options['closeClass'] ) && !empty( $this->options['closeClass'] ) ) ? esc_attr( $this->options['closeClass'] ) : 'italybtn' ;
727
-
728
- /**
729
- * If $infoClass and $closeClass are exactly alike print only first var
730
- * @var [type]
731
- */
732
- $buttonClass = ( $infoClass === $closeClass ) ? $infoClass : $infoClass . ',.' . $closeClass;
733
-
734
- /**
735
- * Attribute for text for template
736
- * @var string
737
- */
738
- $text_align = 'center';
739
-
740
- /**
741
- * CSS for content style
742
- * @var string
743
- */
744
- $contentStyle = '';
745
-
746
- /**
747
- * Button style
748
- * @var string
749
- */
750
- $buttonStyle = '.' . $buttonClass . '{margin-left:10px;}';
751
 
752
- /**
753
- * Conditional button style for bigbutton or smallbutton
754
- * Default margin
755
- */
756
- if ( $js_template === 'bigbutton' ){
757
-
758
- $buttonStyle = '.' . $buttonClass . '{color:' . $banner_text_color . ';padding:7px 12px;font-size:18px;line-height:18px;text-decoration:none;text-transform:uppercase;margin:10px 20px 2px 0;letter-spacing: 0.125em;display:inline-block;font-weight:normal;text-align:center; vertical-align:middle;cursor:pointer;border:1px solid ' . $banner_text_color . ';background:rgba(255, 255, 255, 0.03);}.' . $consentText . '{display:block}';
759
 
760
- $text_align = 'left';
761
-
762
- }elseif ( $js_template === 'smallbutton' ){
763
-
764
- $buttonStyle = '.' . $buttonClass . '{color:' . $banner_text_color . ';padding:3px 7px;font-size:14px;line-height:14px;text-decoration:none;text-transform:uppercase;margin:10px 20px 2px 0;letter-spacing: 0.115em;display:inline-block;font-weight:normal;text-align:center; vertical-align:middle;cursor:pointer;border:1px solid ' . $banner_text_color . ';background:rgba(255, 255, 255, 0.03);}.' . $consentText . '{display:block}';
765
 
766
- $text_align = 'left';
767
 
768
- }
769
-
770
- /**
771
- * Select what kind of banner to display
772
- * @var $banner Bar/Dialog
773
- * @var $contentStyle Style for content div
774
- * @var $style Style for banner
775
- * @var $bPos Deprecated
776
- * @var $htmlM Bolean for margin top
777
- */
778
- if ( $this->options['banner'] === '1' ) {
779
 
780
- $banner = 'Bar';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
781
 
782
- $contentStyle = ( $js_template === 'bigbutton' || $js_template === 'smallbutton' ) ? '.contentStyle{max-width:980px;margin-right:auto;margin-left:auto;padding:15px;}' : '' ;
 
 
 
 
 
 
783
 
784
- $style = ( $js_template === 'custom' ) ? $customCSS : '#cookieChoiceInfo{background-color: ' . $banner_bg . ';color: ' . $banner_text_color . ';left:0;margin:0;padding:4px;position:fixed;text-align:' . $text_align . ';top:0;width:100%;z-index:9999;}' . $contentStyle . $buttonStyle;
 
 
 
 
785
 
786
- $bPos = 'top:0'; // Deprecato
787
 
788
- $htmlM = ( isset( $this->options['html_margin'] ) ) ? $this->options['html_margin'] : '' ;
 
 
 
 
 
 
 
 
 
 
789
 
790
- } elseif ( $this->options['banner'] === '2' && !( is_page( $this->slug ) || is_single( $this->slug ) ) ) {
791
 
792
- $banner = 'Dialog';
793
 
794
- $style = ( $js_template === 'custom' ) ? $customCSS : '.glassStyle{position:fixed;width:100%;height:100%;z-index:999;top:0;left:0;opacity:0.5;filter:alpha(opacity=50);background-color:#ccc;}.' . $bannerStyle . '{min-width:100%;z-index:9999;position:fixed;top:25%;}.contentStyle{position:relative;background-color:' . $banner_bg . ';padding:20px;box-shadow:4px 4px 25px #888;max-width:80%;margin:0 auto;}' . $buttonStyle;
795
 
796
- $bPos = 'top:0'; // Deprecato
797
 
798
- } elseif ( $this->options['banner'] === '3' ) {
799
 
800
- $banner = 'Bar';
801
 
802
- $contentStyle = ( $js_template === 'bigbutton' || $js_template === 'smallbutton' ) ? '.contentStyle{max-width:980px;margin-right:auto;margin-left:auto;padding:15px;}' : '' ;
803
 
804
- $style = ( $js_template === 'custom' ) ? $customCSS : '#cookieChoiceInfo{background-color: ' . $banner_bg . ';color: ' . $banner_text_color . ';left:0;margin:0;padding:4px;position:fixed;text-align:' . $text_align . ';bottom:0;width:100%;z-index:9999;}' . $contentStyle . $buttonStyle;
805
 
806
- $bPos = 'bottom:0'; // Deprecato
807
 
808
- } else {
809
 
810
- $banner = 'Bar';
811
 
812
- $style = ( $js_template === 'custom' ) ? $customCSS : '#cookieChoiceInfo{background-color: ' . $banner_bg . ';color: ' . $banner_text_color . ';left:0;margin:0;padding:4px;position:fixed;text-align:center;top:0;width:100%;z-index:9999;}' . $contentStyle . $buttonStyle;
813
 
814
- $bPos = 'top:0'; // Deprecato
815
 
816
- }
817
 
818
- /**
819
- * Declarations of JS variables and set parameters
820
- * var elPos = Gestisce la Posizione banner nella funzione _createHeaderElement
821
- * var infoClass = aggiunge una classe personalizzata per il link info
822
- * var closeClass = aggiunge una classe personalizzata per il link di accettazione
823
- * var htmlM = Aggiunge un margine a HTML per la top bar
824
- * var coNA = cookie name
825
- * var coVA = cookie val
826
- * var rel = Setto il reload per la pagina all'accettazione
827
- * var tar = Target -blank
828
- * var bgB = Colore del background della topbar/dialog
829
- * var btcB = Colore del font della topbar/dialog
830
- * var bannerStyle = Variabile per le classe del contenitore
831
- * var contentStyle = Variabile per le classe del contenitore del contenuto
832
- * var consText = Variabile per le classe dello span per il testo
833
- * @var string
834
- */
835
 
836
- $jsVariables = 'var coNA="' . $cookie_name . '",coVA="' . $cookie_value . '";scroll="' . $scroll . '",elPos="fixed",infoClass="' . $infoClass . '",closeClass="' . $closeClass . '",htmlM="' . $htmlM . '",rel="' . $reload . '",tar="' . $target . '",bgB="' . $banner_bg . '",btcB="' . $banner_text_color . '",bPos="' . $bPos . '",bannerStyle="' . $bannerStyle . '",contentStyle="' . $contStyle . '",consText="' . $consentText . '",jsArr = ' . $this->wp_json_encode( apply_filters( 'icc_js_array', $this->js_array ) ) . ';';
837
 
838
- /**
839
- * Snippet per il multilingua
840
- * function get_string return multilanguage $value
841
- * if isn't installed any language plugin return $value
842
- */
843
- $text = $this->wp_json_encode( wp_kses_post( get_string( 'Italy Cookie Choices', 'Banner text', $this->options['text'] ) ) );
844
 
845
- $url = esc_url( get_string( 'Italy Cookie Choices', 'Banner url', $this->options['url'] ) );
846
 
847
- $anchor_text = esc_js( get_string( 'Italy Cookie Choices', 'Banner anchor text', $this->options['anchor_text'] ) );
848
 
849
- $button_text = esc_js( get_string( 'Italy Cookie Choices', 'Banner button text', $this->options['button_text'] ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
850
 
851
- /**
852
- * Snippet for display banner
853
- * @uses json_encode Funzione usate per il testo del messaggio.
854
- * Ricordarsi che aggiunge già
855
- * le doppie virgolette "" alla stringa
856
- * @var string
857
- */
858
- $banner = 'document.addEventListener("DOMContentLoaded", function(event) {cookieChoices.showCookieConsent' . $banner . '(' . $text . ', "' . $button_text . '", "' . $anchor_text . '", "' . $url . '");});';
859
 
860
- /**
861
- * Noscript snippet in case browser has JavaScript disabled
862
- * @var string
863
- */
864
- $noscript = '<noscript><style type="text/css">html{margin-top:35px}</style><div id="cookieChoiceInfo"><span>' . $text . '</span><a href="' . $url . '" class="' . $infoClass . '" target="_blank">' . $anchor_text . '</a></div></noscript>';
 
865
 
866
- /**
867
- * Select wich file to use in debug mode
868
- * @var string
869
- */
870
- // $fileJS = ( WP_DEBUG ) ? '/js/' . $js_template . '/cookiechoices.js' : '/js/' . $js_template . '/cookiechoices.php' ;
871
- $fileJS = ( WP_DEBUG ) ? '/js/default/cookiechoices.js' : '/js/default/cookiechoices.php' ;
872
 
873
- $output_html = '<!-- Italy Cookie Choices -->' . '<style type="text/css">' . $style . '</style><script>' . $jsVariables . file_get_contents( ITALY_COOKIE_CHOICES_DIRNAME . $fileJS ) . $banner . '</script>' . $noscript;
874
 
875
- echo apply_filters( 'icc_output_html', $output_html );
876
 
877
- }
 
 
 
 
 
 
 
878
 
879
- /**
880
- * Shortcode per stampare il bottone nella pagina della policy
881
- * @param array $atts Array con gli attributi dello shortcode
882
- * @param string $content content of shortcode
883
- * @return string Button per l'accettazione
884
- */
885
- public function accept_button( $atts, $content = null ) {
886
 
887
- $button_text = ( isset( $this->options['button_text'] ) ) ? $this->options['button_text'] : '' ;
 
 
 
 
 
888
 
889
- return '<span class="el"><button onclick="cookieChoices.removeCookieConsent()">' . esc_attr( $button_text ) . '</button></span>';
890
 
891
- }
892
 
893
- /**
894
- * Shortcode per stampare il bottone nella pagina della policy
895
- * @param array $atts Array con gli attributi dello shortcode
896
- * @param string $content content of shortcode
897
- * @return string Button per l'accettazione
898
- */
899
- public function _delete_cookie( $atts, $content = null ) {
900
 
901
- // $button_text = ( isset( $this->options['button_text'] ) ) ? $this->options['button_text'] : '' ;
902
- $button_text = 'Delete cookie';
 
 
 
 
 
903
 
904
- return '<span class="ele"><button onclick="deleteCookie()">' . esc_attr( $button_text ) . '</button></span>';
905
 
906
- }
907
 
908
- /**
909
- * Display cookie, only for internal use
910
- * @return string
911
- */
912
- private function _display_cookie(){
913
 
914
- $cookie_list = '<ul>';
 
 
 
 
 
 
915
 
916
- foreach ( $_COOKIE as $key => $val )
917
- $cookie_list .= '<li>Cooke name: ' . $key . ' - val: ' . $val . '</li>';
918
-
919
- $cookie_list .= '</ul>';
920
 
921
- return $cookie_list;
922
 
923
- }
924
 
925
- }// class
926
- }//endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  */
5
  if ( !class_exists( 'Italy_Cookie_Choices_Front_End' ) ){
6
 
7
+ class Italy_Cookie_Choices_Front_End{
8
+
9
+ /**
10
+ * Option
11
+ * @var array
12
+ */
13
+ private $options = array();
14
+
15
+ /**
16
+ * Default Cookie name
17
+ * @var string
18
+ */
19
+ private $cookieName = 'displayCookieConsent';
20
+
21
+ /**
22
+ * Default cookie value
23
+ * @var string
24
+ */
25
+ private $cookieVal = 'y';
26
+
27
+ /**
28
+ * Pattern for searching embed code in content and widget
29
+ * @var string
30
+ */
31
+ private $pattern = '#<iframe.*?\/iframe>|<embed.*?>|<script.*?\/script>#is';
32
+
33
+ /**
34
+ * Snippet for replacements
35
+ * @var string
36
+ */
37
+ private $valore = '';
38
+
39
+ /**
40
+ * Inizialize banner template to default
41
+ * @var string
42
+ */
43
+ private $js_template = 'default';
44
+
45
+ /**
46
+ * Array with embed found
47
+ * @var array
48
+ */
49
+ public $js_array = array();
50
+
51
+ /**
52
+ * If exist set a page slug
53
+ * @var string
54
+ */
55
+ private $slug = '';
56
+
57
+ /**
58
+ * URL for policy page
59
+ * @var string
60
+ */
61
+ private $url = '';
62
+
63
+ /**
64
+ * Array with list of allowed script|iframe|embed
65
+ * @var array
66
+ */
67
+ private $allow_script = array();
68
+
69
+ /**
70
+ * Array with list of blocked script|iframe|embed
71
+ * @var array
72
+ */
73
+ private $block_script = array();
74
+
75
+ /**
76
+ * [__construct description]
77
+ */
78
+ public function __construct(){
79
+
80
+ $this->options = get_option( 'italy_cookie_choices' );
81
+
82
+ /**
83
+ * Check for second view option
84
+ * @var bol
85
+ */
86
+ $secondViewOpt = ( isset( $this->options['secondView'] ) ) ? $this->options['secondView'] : '' ;
87
+
88
+ /**
89
+ * Assegno il valore allo slug nel costruttore
90
+ * Default ID 1 perché su null non settava correttamente lo scroll se il valore era assente
91
+ * @var bolean
92
+ */
93
+ $this->slug = ( isset( $this->options['slug'] ) && !empty( $this->options['slug'] ) ) ? esc_attr( get_string( 'Italy Cookie Choices', 'Banner slug', $this->options['slug'] ) ) : 1 ;
94
+
95
+ /**
96
+ * Assegno il valore della URL della policy page
97
+ * Default ID 1 perché su null non settava correttamente lo scroll se il valore era assente
98
+ * @var bolean
99
+ */
100
+ $this->url = ( isset( $this->options['url'] ) && !empty( $this->options['url'] ) ) ? esc_url( get_string( 'Italy Cookie Choices', 'Banner url', $this->options['url'] ) ) : 1 ;
101
+
102
+ /*
103
+ * Set cookie if the user agree navigating through the pages of the site
104
+ */
105
+ $secondView = false;
106
+
107
+ if( $this->is_policy_page( $secondViewOpt ) ) {
108
+
109
+ setcookie($this->options['cookie_name'], $this->options['cookie_value'], time()+(3600*24*365), '/');
110
+ $secondView = true;
111
+ }
112
+
113
+ /**
114
+ * Shortcode to put a button in policy page
115
+ */
116
+ add_shortcode( 'accept_button', array( $this, 'accept_button' ) );
117
+ add_shortcode( 'delete_cookie', array( $this, '_delete_cookie' ) );
118
+
119
+ if ( !isset( $_COOKIE[ $this->options['cookie_name'] ] ) && !$secondView ){
120
+
121
+ // W3TC Disable Caching
122
+ if ( !defined( 'DONOTCACHEPAGE' ) )
123
+ define('DONOTCACHEPAGE', true);
124
+ if ( !defined( 'SID' ) )
125
+ define('SID', true);
126
+
127
+ /**
128
+ * Background color for banner
129
+ * @var string
130
+ */
131
+ $banner_bg = ( isset( $this->options['banner_bg'] ) ) ? $this->options['banner_bg'] : '#ffffff' ;
132
+
133
+ /**
134
+ * Color for text
135
+ * @var string
136
+ */
137
+ $banner_text_color = ( isset( $this->options['banner_text_color'] ) ) ? $this->options['banner_text_color'] : '#000000' ;
138
+
139
+ /**
140
+ * Text for banner
141
+ * @var string
142
+ */
143
+ $text = ( isset( $this->options['text'] ) ) ? $this->options['text'] : '' ;
144
+
145
+ /**
146
+ * Text for buttom
147
+ * @var [type]
148
+ */
149
+ $button_text = ( isset( $this->options['button_text'] ) ) ? $this->options['button_text'] : '' ;
150
+
151
+ /**
152
+ * Checkbox for third part cookie in content
153
+ * @var bol
154
+ */
155
+ $block = ( isset( $this->options['block'] ) ) ? $this->options['block'] : '' ;
156
+
157
+ /**
158
+ * Checkbox for third part cookie in widget
159
+ * @var bol
160
+ */
161
+ $widget_block = ( isset( $this->options['widget_block'] ) ) ? $this->options['widget_block'] : '' ;
162
+
163
+ /**
164
+ * Checkbox for third part cookie in all page (except head and footer)
165
+ * @var bol
166
+ */
167
+ $all_block = ( isset( $this->options['all_block'] ) ) ? $this->options['all_block'] : '' ;
168
+
169
+ /**
170
+ * Checkbox custom scripts block in BODY
171
+ * @var string
172
+ */
173
+ $custom_script_block_body_exclude = ( isset( $this->options['custom_script_block_body_exclude'] ) ) ? $this->options['custom_script_block_body_exclude'] : '' ;
174
+
175
+ $this->get_block_script();
176
+ $this->get_allow_script();
177
+
178
+ /**
179
+ * Checkbox custom scripts block in HEAD and FOOTER
180
+ * @var string
181
+ */
182
+ $custom_script_block = ( isset( $this->options['custom_script_block'] ) ) ? $this->options['custom_script_block'] : '' ;
183
+
184
+ /**
185
+ * Text to put inside locked post and widget contents
186
+ * including the button text
187
+ * @var string
188
+ */
189
+ $content_message_text = ( isset( $this->options['content_message_text'] ) ) ? wp_kses_post( get_string( 'Italy Cookie Choices', 'Content message text', $this->options['content_message_text'] ) ) : '' ;
190
+
191
+ /**
192
+ * Text for button in locked content and widget
193
+ * @var string
194
+ */
195
+ $content_message_button_text = ( isset( $this->options['content_message_button_text'] ) ) ? esc_attr( get_string( 'Italy Cookie Choices', 'Content message button text', $this->options['content_message_button_text'] ) ) : '' ;
196
+
197
+ /**
198
+ * Replacement for regex
199
+ * @var string
200
+ */
201
+ $this->valore = '<div class="el"><div style="padding:10px;margin-bottom: 18px;color:' . esc_attr( $banner_text_color ) . ';background-color:' . esc_attr( $banner_bg ) . ';text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);">' . $content_message_text . '&nbsp;&nbsp;<button onclick="cookieChoices.removeCookieConsent()" style="color: ' . esc_attr( $banner_text_color ) . ';padding: 3px;font-size: 12px;line-height: 12px;text-decoration: none;text-transform: uppercase;margin:0;display: inline-block;font-weight: normal; text-align: center; vertical-align: middle; cursor: pointer; border: 1px solid ' . esc_attr( $banner_text_color ) . ';background: rgba(255, 255, 255, 0.03);">' . $content_message_button_text . '</button></div><cookie></div>';
202
+
203
+ if ($block)
204
+ add_filter( 'the_content', array( $this, 'AutoErase' ), 11);
205
+
206
+ if ( $widget_block )
207
+ add_filter( 'widget_display_callback', array( $this, 'WidgetErase' ), 11, 3 );
208
+
209
+ if ( $all_block ) {
210
+ //add_action('wp_footer', array( $this, 'catchBody' ), -1000000);
211
+ add_action('wp_head', array( $this, 'bufferBodyStart' ), 1000000);
212
+ add_action('wp_footer', array( $this, 'bufferBodyEnd' ), -1000000);
213
+ }
214
+ if( ( $custom_script_block || $this->block_script ) && $all_block ) {
215
+ add_action('template_redirect', array( $this, 'bufferHeadStart' ), 2);
216
+ add_action('wp_head', array( $this, 'bufferHeadEnd' ), 99999);
217
+ add_action('wp_footer', array( $this, 'bufferFooterStart' ), -99998);
218
+ add_action('shutdown', array( $this, 'bufferFooterEnd' ), -1000000);
219
+ } else {
220
+ /**
221
+ * Function for print cookiechoiches inline
222
+ */
223
+ add_action( 'wp_footer', array( $this, 'print_script_inline'), -99999 );
224
+ }
225
+
226
+ /**
227
+ * Only for debug
228
+ */
229
+ // var_dump($_COOKIE);
230
+ // var_dump(headers_list());
231
+
232
+ }
233
+
234
+ }//__construct
235
+
236
+
237
+ /**
238
+ * Get the current page url
239
+ * @link http://www.brosulo.net/content/informatica/ottenere-la-url-completa-da-una-pagina-php-0
240
+ */
241
+ private function CurrentPageURL() {
242
+
243
+ if ( isset( $_SERVER['HTTPS'] ) )
244
+ $pageURL = $_SERVER['HTTPS'];
245
+ else
246
+ $pageURL = NULL;
247
+
248
+ $pageURL = $pageURL === 'on' ? 'https://' : 'http://';
249
+ $pageURL .= $_SERVER["SERVER_NAME"];
250
+ $pageURL .= ( $_SERVER['SERVER_PORT'] !== '80' ) ? ':' . $_SERVER["SERVER_PORT"] : '';
251
+ $pageURL .= $_SERVER["REQUEST_URI"];
252
+
253
+ return $pageURL;
254
+
255
+ }
256
+
257
+ /**
258
+ * Check if is the policy page
259
+ * Required url input
260
+ * @param boolean $secondViewOpt Check for second view option
261
+ * @return boolean Return bolean value
262
+ */
263
+ private function is_policy_page( $secondViewOpt = false ){
264
+
265
+ if(
266
+ // if is an HTML request (alternative methods???)
267
+ ( strpos( $_SERVER['HTTP_ACCEPT'],'html' ) !== false ) &&
268
+ //if the page isn't privacy page
269
+ // ( $_SERVER['REQUEST_URI'] != $this->slug ) &&
270
+ ( $this->CurrentPageURL() !== $this->url ) &&
271
+ //if HTTP_REFERER is set
272
+ ( isset( $_SERVER['HTTP_REFERER'] ) ) &&
273
+ //if isn't refresh
274
+ ( parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH) !== $_SERVER['REQUEST_URI'] ) &&
275
+ //if referrer is not privacy page (to be evaluated)
276
+ // ( parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH ) != $this->slug ) &&
277
+ // ( $_SERVER['HTTP_REFERER'] !== $this->url ) &&
278
+ //if the cookie is not already set
279
+ ( !isset( $_COOKIE[ $this->options['cookie_name'] ] ) ) &&
280
+ //if the referer is in the same domain
281
+ ( parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) &&
282
+ // If the secondView options is checked
283
+ ( $secondViewOpt )
284
+ )
285
+ return true;
286
+ else
287
+ return false;
288
+
289
+ }
290
+
291
+
292
+ private function in_array_match($value, $array) {
293
+ foreach($array as $k=>$v) {
294
+ if(preg_match('/'.str_replace(preg_quote("<---------SOMETHING--------->"), ".*", preg_quote(preg_replace( "/([\r|\n]*)/is", "", trim($v)), '/')).'/is', preg_replace( "/([\r|\n]*)/is", "", $value))) {
295
+ return true;
296
+ }
297
+ }
298
+ return false;
299
+ }
300
+
301
+ /**
302
+ * Remove custom script in header and footer
303
+ * @param string $buffer Source of page.
304
+ * @return string Return the new HTML
305
+ */
306
+ public function removeCustomScript( $buffer ) {
307
+ /**
308
+ * Custom script to block
309
+ * @var string
310
+ */
311
+ $custom_script_block = ( isset( $this->options['custom_script_block'] ) ) ? $this->options['custom_script_block'] : '' ;
312
+
313
+ if( ! $custom_script_block && ! $this->block_script )
314
+ return $buffer;
315
+ else {
316
+
317
+ /**
318
+ * Replace space with <---------SEP--------->
319
+ * @var string
320
+ */
321
+ $custom_script_block = preg_replace( "/([\r|\n]*)<---------SEP--------->([\r|\n]*)/is", "<---------SEP--------->", $custom_script_block );
322
+
323
+ /**
324
+ * Convert $custom_script_block to an array
325
+ * @var array
326
+ */
327
+ $custom_script_block_array = explode( "<---------SEP--------->", $custom_script_block );
328
+
329
+ /**
330
+ * Merge the script array from new UX functionality
331
+ * @var array
332
+ */
333
+ $custom_script_block_array = array_merge( $custom_script_block_array, $this->block_script );
334
+
335
+ foreach( $custom_script_block_array as $single_script) {
336
+ preg_match_all( '/' . str_replace( preg_quote( "<---------SOMETHING--------->" ), ".*", preg_quote( trim( $single_script ), '/' ) ) . '/is', $buffer, $matches );
337
+ if ( ! empty( $matches[0] ) ) {
338
+ foreach ( $matches[0] as $v ) {
339
+ $buffer = str_replace( trim( $v ), "<!-- removed head from Italy Cookie Choices PHP Class -->", $buffer );
340
+ $this->js_array[] = trim( $v );
341
+ }
342
+ }
343
+ }
344
+ return $buffer;
345
+ }
346
+ }
347
+
348
+ public function bufferBodyStart() {
349
+ if ( ob_get_contents() )
350
+ ob_end_flush();
351
+ ob_start();
352
+
353
+ }
354
+
355
+ public function bufferBodyEnd() {
356
+
357
+ /**
358
+ * Check if $custom_script_block_body_exclude is set
359
+ * @var string
360
+ */
361
+ $custom_script_block_body_exclude = ( isset( $this->options['custom_script_block_body_exclude'] ) ) ? $this->options['custom_script_block_body_exclude'] : '' ;
362
+
363
+ /**
364
+ * Replace space with <---------SEP--------->
365
+ * @var string
366
+ */
367
+ $custom_script_block_body_exclude = preg_replace( "/([\r|\n]*)<---------SEP--------->([\r|\n]*)/is", "<---------SEP--------->", $custom_script_block_body_exclude );
368
+
369
+ /**
370
+ * Create array
371
+ * @var array
372
+ */
373
+ $custom_script_block_body_exclude_array = explode( "<---------SEP--------->", $custom_script_block_body_exclude );
374
+
375
+ if( ! is_array( $custom_script_block_body_exclude_array ) || empty( $custom_script_block_body_exclude_array[0] ) )
376
+ $custom_script_block_body_exclude_array = array();
377
+
378
+ /**
379
+ * Merge the script array from new UX functionality
380
+ * @var array
381
+ */
382
+ $custom_script_block_body_exclude_array = array_merge( $custom_script_block_body_exclude_array, $this->allow_script );
383
+
384
+ $buffer = ob_get_contents();
385
+ if ( ob_get_contents() )
386
+ ob_end_clean();
387
+ preg_match( "/(.*)(<body.*)/s", $buffer, $matches );
388
+ $head = ( isset( $matches[1] ) ) ? $matches[1] : '';
389
+ $body = ( isset( $matches[2] ) ) ? $matches[2] : '';
390
+ preg_match_all( $this->pattern, $body, $body_matches );
391
+
392
+ if ( ! empty( $body_matches[0] ) ) {
393
+ foreach ( $body_matches[0] as $k => $v ) {
394
+
395
+ if ( ! $this->in_array_match( trim( $v ), $custom_script_block_body_exclude_array ) ) {
396
+ $body = preg_replace( '/' . str_replace( preg_quote( "<---------SOMETHING--------->" ), ".*", preg_quote( trim( $v ), '/' ) ) . '/is', $this->valore, $body );
397
+ $this->js_array[] = trim( $v );
398
+ }
399
+ }
400
+ }
401
+
402
+ $buffer_new = $head.$body;
403
+ echo '<!-- ICCStartBody -->' . $buffer_new . '<!-- ICCEndBody -->';
404
+ }
405
+
406
+ public function bufferFooterStart() {
407
+ /**
408
+ * Check if we are in feed page, then do nothing
409
+ */
410
+ if ( is_feed() )
411
+ return;
412
+
413
+ if ( ob_get_contents() )
414
+ ob_end_flush();
415
+ ob_start();
416
+ }
417
+
418
+ public function bufferFooterEnd() {
419
+ /**
420
+ * Check if we are in feed page, then do nothing
421
+ */
422
+ if ( is_feed() )
423
+ return;
424
+
425
+ $buffer = ob_get_contents();
426
+ if ( ob_get_contents() )
427
+ ob_end_clean();
428
+ // If is an HTML request (alternative methods???).
429
+ if( strpos( $_SERVER["HTTP_ACCEPT"], 'html' ) !== false ) {
430
+ $buffer_new = $this->removeCustomScript( $buffer );
431
+ /**
432
+ * Function for print cookiechoiches inline
433
+ */
434
+ $this->print_script_inline();
435
+ echo '<!-- ICCStartFooter -->' . $buffer_new . '<!-- ICCEndFooter -->';
436
+ } else {
437
+ echo $buffer;
438
+ }
439
+ }
440
+
441
+ public function bufferHeadStart() {
442
+ if ( ob_get_contents() )
443
+ ob_end_flush();
444
+ ob_start();
445
+ }
446
+
447
+ public function bufferHeadEnd() {
448
+ $buffer = ob_get_contents();
449
+ if ( ob_get_contents() )
450
+ ob_end_clean();
451
+ $buffer_new = $this->removeCustomScript( $buffer );
452
+ echo '<!-- ICCStartHead -->' . $buffer_new . '<!-- ICCEndHead -->';
453
+ }
454
+
455
+ /**
456
+ * Script preimpostati da escludere dal blocco
457
+ * Preparare un array key valore a parte, unico per entrambi
458
+ * Questo array sarà utilizzato per generare anche le input dinamicamente
459
+ * array(
460
+ * 'facebook' => 'script'
461
+ * )
462
+ * Return the Array con gli script preimpostati.
463
+ */
464
+ private function get_allow_script() {
465
+
466
+ $allow_iframe = ( isset( $this->options['allow_iframe'] ) ) ? $this->options['allow_iframe'] : array( '' );
467
+ $allow_script = ( isset( $this->options['allow_script'] ) ) ? $this->options['allow_script'] : array( '' );
468
+ $allow_embed = ( isset( $this->options['allow_embed'] ) ) ? $this->options['allow_embed'] : array( '' );
469
+
470
+ $array = array();
471
+
472
+ foreach ( $allow_iframe as $key => $value )
473
+ if ( ! empty( $value ) )
474
+ $this->allow_script[] = '<iframe<---------SOMETHING--------->' . $value . '<---------SOMETHING---------></iframe>';
475
+
476
+ foreach ( $allow_script as $key => $value )
477
+ if ( ! empty( $value ) )
478
+ $this->allow_script[] = '<script<---------SOMETHING--------->' . $value . '<---------SOMETHING---------></script>';
479
+
480
+ foreach ( $allow_embed as $key => $value )
481
+ if ( ! empty( $value ) )
482
+ $this->allow_script[] = '<embed<---------SOMETHING--------->' . $value . '<---------SOMETHING--------->>';
483
+
484
+ }
485
+
486
+ private function get_block_script( $val = array() ) {
487
+
488
+ $block_iframe = ( isset( $this->options['block_iframe'] ) ) ? $this->options['block_iframe'] : array( '' );
489
+ $block_script = ( isset( $this->options['block_script'] ) ) ? $this->options['block_script'] : array( '' );
490
+ $block_embed = ( isset( $this->options['block_embed'] ) ) ? $this->options['block_embed'] : array( '' );
491
+
492
+ $array = array();
493
+
494
+ foreach ( $block_iframe as $value )
495
+ if ( ! empty( $value ) )
496
+ $this->block_script[] = '<iframe<---------SOMETHING--------->' . $value . '<---------SOMETHING---------></iframe>';
497
+
498
+ foreach ( $block_script as $value )
499
+ if ( ! empty( $value ) )
500
+ $this->block_script[] = '<script<---------SOMETHING--------->' . $value . '<---------SOMETHING---------></script>';
501
+
502
+ foreach ( $block_embed as $value )
503
+ if ( ! empty( $value ) )
504
+ $this->block_script[] = '<embed<---------SOMETHING--------->' . $value . '<---------SOMETHING--------->>';
505
+
506
+ }
507
+
508
+ /**
509
+ * Function for matching embed, return the Array with embed found
510
+ * @param string $pattern Pattern.
511
+ * @param string $content Content.
512
+ */
513
+ public function matches( $pattern, $content ) {
514
+
515
+ preg_match_all( $this->pattern, $content, $matches );
516
+
517
+ /**
518
+ * Memorizzo gli embed trovati e li appendo all'array $js_array
519
+ * @var array
520
+ */
521
+ if ( ! empty( $matches[0] ) )
522
+ $this->js_array = array_merge( $this->js_array, $matches[0] );
523
+
524
+ }
525
+
526
+ /**
527
+ * Erase third part embed
528
+ * @param string $content Article content.
529
+ */
530
+ public function AutoErase( $content ) {
531
+
532
+ $this->matches( $this->pattern, $content );
533
+
534
+ $content = preg_replace( $this->pattern, $this->valore , $content );
535
+
536
+ return $content;
537
+ }
538
+
539
+ private function fnFixArray( $v ) {
540
+
541
+ if ( is_array( $v ) or is_object( $v ) ) {
542
+
543
+ foreach ( $v as $k1 => $v1 ) {
544
+
545
+ $v[ $k1 ] = $this->fnFixArray( $v1 );
546
+
547
+ }
548
+
549
+ return $v;
550
+
551
+ }
552
+
553
+ if ( ! is_string( $v ) or empty( $v ) ) return $v;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
 
555
+ $this->matches( $this->pattern, $v );
556
+
557
+ return preg_replace( $this->pattern, $this->valore , $v );
558
+
559
+ }
 
 
560
 
561
+ public function WidgetErase( $instance, $widget, $args ) {
 
 
 
 
562
 
563
+ return $this->fnFixArray( $instance );
564
 
565
+ }
 
 
 
 
 
 
 
 
 
 
566
 
567
+ /**
568
+ * Encode a variable into JSON, with some sanity checks.
569
+ *
570
+ * @since 4.1.0
571
+ *
572
+ * @param mixed $data Variable (usually an array or object) to encode as JSON.
573
+ * @param int $options Optional. Options to be passed to json_encode(). Default 0.
574
+ * @param int $depth Optional. Maximum depth to walk through $data. Must be
575
+ * greater than 0. Default 512.
576
+ * @return bool|string The JSON encoded string, or false if it cannot be encoded.
577
+ */
578
+ public function wp_json_encode( $data, $options = 0, $depth = 512 ) {
579
+
580
+ /**
581
+ * json_encode() has had extra params added over the years.
582
+ * $options was added in 5.3, and $depth in 5.5.
583
+ * We need to make sure we call it with the correct arguments.
584
+ */
585
+ if ( version_compare( PHP_VERSION, '5.5', '>=' ) )
586
+ $args = array( $data, $options, $depth );
587
+ elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) )
588
+ $args = array( $data, $options );
589
+ else $args = array( $data );
590
+
591
+ $json = call_user_func_array( 'json_encode', $args );
592
+
593
+ // If json_encode() was successful, no need to do more sanity checking.
594
+ // ... unless we're in an old version of PHP, and json_encode() returned
595
+ // a string containing 'null'. Then we need to do more sanity checking.
596
+ if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) )
597
+ return $json;
598
+
599
+ return call_user_func_array( 'json_encode', $args );
600
+ }
601
+
602
+ /**
603
+ * Print script inline before </body>
604
+ * @return string Print script inline
605
+ * @link https://www.cookiechoices.org/
606
+ */
607
+ public function print_script_inline() {
608
+
609
+ /**
610
+ * If is not active exit
611
+ */
612
+ if ( ! isset( $this->options['active'] ) || is_feed() )
613
+ return;
614
+
615
+ /**
616
+ * Accept on scroll
617
+ * @var bol
618
+ */
619
+ $scroll = ( isset( $this->options['scroll'] ) && ! ( is_page( $this->slug ) || is_single( $this->slug ) ) ) ? $this->options['scroll'] : '' ;
620
+
621
+ /**
622
+ * Reload on accept
623
+ * @var bol
624
+ */
625
+ $reload = ( isset( $this->options['reload'] ) ) ? $this->options['reload'] : '' ;
626
+
627
+ /**
628
+ * ADVANCED OPTIONS
629
+ */
630
+ /**
631
+ * Cookie name
632
+ * @var string
633
+ */
634
+ $cookie_name = ( isset( $this->options['cookie_name'] ) ) ? $this->options['cookie_name'] : $this->cookieName ;
635
+
636
+ /**
637
+ * Cookie value
638
+ * @var string/bolean
639
+ */
640
+ $cookie_value = ( isset( $this->options['cookie_value'] ) ) ? $this->options['cookie_value'] : $this->cookieVal ;
641
+
642
+ /**
643
+ * Js_Template value
644
+ * @var string
645
+ */
646
+ // $js_template = ( isset( $this->options['js_template'] ) && $this->options['js_template'] !== 'custom') ? $this->options['js_template'] : $this->js_template ;
647
+ $js_template = ( isset( $this->options['js_template'] ) ) ? $this->options['js_template'] : $this->js_template ;
648
+
649
+ /**
650
+ * If is set html_margin checkbox in admin panel then add margin-top to HTML tag
651
+ * @var bol
652
+ */
653
+ $htmlM = '' ;
654
+
655
+ /**
656
+ * If set open policy page in new browser tab
657
+ * @var bol
658
+ */
659
+ $target = ( isset( $this->options['target'] ) ) ? $this->options['target'] : '' ;
660
+
661
+ /**
662
+ * Colore dello sfondo della dialog/topbar
663
+ * @var string
664
+ */
665
+ $banner_bg = ( isset( $this->options['banner_bg'] ) && ! empty( $this->options['banner_bg'] ) ) ? esc_attr( $this->options['banner_bg'] ) : '#fff' ;
666
+
667
+ /**
668
+ * Colore del font della dialog/topbar
669
+ * @var string
670
+ */
671
+ $banner_text_color = ( isset( $this->options['banner_text_color'] ) && ! empty( $this->options['banner_text_color'] ) ) ? esc_attr( $this->options['banner_text_color'] ) : '#000' ;
672
+
673
+ /**
674
+ * Custom CSS
675
+ * @var string
676
+ */
677
+ $customCSS = ( isset( $this->options['customCSS'] ) ) ? esc_attr( $this->options['customCSS'] ) : '' ;
678
+
679
+ /**
680
+ * CSS class for div bannerStyle
681
+ * @var string
682
+ */
683
+ $bannerStyle = ( isset( $this->options['bannerStyle'] ) && ! empty( $this->options['bannerStyle'] ) ) ? esc_attr( $this->options['bannerStyle'] ) : 'bannerStyle' ;
684
+
685
+ /**
686
+ * CSS class for div content
687
+ * @var string
688
+ */
689
+ $contStyle = ( isset( $this->options['contentStyle'] ) && ! empty( $this->options['contentStyle'] ) ) ? esc_attr( $this->options['contentStyle'] ) : 'contentStyle' ;
690
+
691
+ /**
692
+ * CSS class for text in span
693
+ * @var string
694
+ */
695
+ $consentText = ( isset( $this->options['consentText'] ) && ! empty( $this->options['consentText'] ) ) ? esc_attr( $this->options['consentText'] ) : 'consentText' ;
696
+
697
+ /**
698
+ * CSS class for info link
699
+ * @var string
700
+ */
701
+ $infoClass = ( isset( $this->options['infoClass'] ) && ! empty( $this->options['infoClass'] ) ) ? esc_attr( $this->options['infoClass'] ) : 'italybtn' ;
702
+
703
+ /**
704
+ * CSS class for close link
705
+ * @var string
706
+ */
707
+ $closeClass = ( isset( $this->options['closeClass'] ) && ! empty( $this->options['closeClass'] ) ) ? esc_attr( $this->options['closeClass'] ) : 'italybtn' ;
708
+
709
+ /**
710
+ * If $infoClass and $closeClass are exactly alike print only first var
711
+ * @var [type]
712
+ */
713
+ $buttonClass = ( $infoClass === $closeClass ) ? $infoClass : $infoClass . ',.' . $closeClass;
714
+
715
+ /**
716
+ * Attribute for text for template
717
+ * @var string
718
+ */
719
+ $text_align = 'center';
720
+
721
+ /**
722
+ * CSS for content style
723
+ * @var string
724
+ */
725
+ $contentStyle = '';
726
+
727
+ /**
728
+ * Button style
729
+ * @var string
730
+ */
731
+ $buttonStyle = '.' . $buttonClass . '{margin-left:10px;}';
732
 
733
+ /**
734
+ * Conditional button style for bigbutton or smallbutton
735
+ * Default margin
736
+ */
737
+ if ( 'bigbutton' === $js_template ) {
738
+
739
+ $buttonStyle = '.' . $buttonClass . '{color:' . $banner_text_color . ';padding:7px 12px;font-size:18px;line-height:18px;text-decoration:none;text-transform:uppercase;margin:10px 20px 2px 0;letter-spacing: 0.125em;display:inline-block;font-weight:normal;text-align:center; vertical-align:middle;cursor:pointer;border:1px solid ' . $banner_text_color . ';background:rgba(255, 255, 255, 0.03);}.' . $consentText . '{display:block}';
740
 
741
+ $text_align = 'left';
742
+
743
+ } elseif ( 'smallbutton' === $js_template ) {
744
+
745
+ $buttonStyle = '.' . $buttonClass . '{color:' . $banner_text_color . ';padding:3px 7px;font-size:14px;line-height:14px;text-decoration:none;text-transform:uppercase;margin:10px 20px 2px 0;letter-spacing: 0.115em;display:inline-block;font-weight:normal;text-align:center; vertical-align:middle;cursor:pointer;border:1px solid ' . $banner_text_color . ';background:rgba(255, 255, 255, 0.03);}.' . $consentText . '{display:block}';
746
 
747
+ $text_align = 'left';
748
 
749
+ }
750
+
751
+ /**
752
+ * Select what kind of banner to display
753
+ * @var $banner Bar/Dialog
754
+ * @var $contentStyle Style for content div
755
+ * @var $style Style for banner
756
+ * @var $bPos Deprecated
757
+ * @var $htmlM Bolean for margin top
758
+ */
759
+ if ( $this->options['banner'] === '1' ) {
760
 
761
+ $banner = 'Bar';
762
 
763
+ $contentStyle = ( 'bigbutton' === $js_template || 'smallbutton' === $js_template ) ? '.contentStyle{max-width:980px;margin-right:auto;margin-left:auto;padding:15px;}' : '' ;
764
 
765
+ $style = ( 'custom' === $js_template ) ? $customCSS : '#cookieChoiceInfo{background-color: ' . $banner_bg . ';color: ' . $banner_text_color . ';left:0;margin:0;padding:4px;position:fixed;text-align:' . $text_align . ';top:0;width:100%;z-index:9999;}' . $contentStyle . $buttonStyle;
766
 
767
+ $bPos = 'top:0'; // Deprecato.
768
 
769
+ $htmlM = ( isset( $this->options['html_margin'] ) ) ? $this->options['html_margin'] : '' ;
770
 
771
+ } elseif ( $this->options['banner'] === '2' && ! ( is_page( $this->slug ) || is_single( $this->slug ) ) ) {
772
 
773
+ $banner = 'Dialog';
774
 
775
+ $style = ( 'custom' === $js_template ) ? $customCSS : '.glassStyle{position:fixed;width:100%;height:100%;z-index:999;top:0;left:0;opacity:0.5;filter:alpha(opacity=50);background-color:#ccc;}.' . $bannerStyle . '{min-width:100%;z-index:9999;position:fixed;top:25%;}.contentStyle{position:relative;background-color:' . $banner_bg . ';padding:20px;box-shadow:4px 4px 25px #888;max-width:80%;margin:0 auto;}' . $buttonStyle;
776
 
777
+ $bPos = 'top:0'; // Deprecato.
778
 
779
+ } elseif ( $this->options['banner'] === '3' ) {
780
 
781
+ $banner = 'Bar';
782
 
783
+ $contentStyle = ( 'bigbutton' === $js_template || 'smallbutton' === $js_template ) ? '.contentStyle{max-width:980px;margin-right:auto;margin-left:auto;padding:15px;}' : '' ;
784
 
785
+ $style = ( 'custom' === $js_template ) ? $customCSS : '#cookieChoiceInfo{background-color: ' . $banner_bg . ';color: ' . $banner_text_color . ';left:0;margin:0;padding:4px;position:fixed;text-align:' . $text_align . ';bottom:0;width:100%;z-index:9999;}' . $contentStyle . $buttonStyle;
786
 
787
+ $bPos = 'bottom:0'; // Deprecato.
788
 
789
+ } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
790
 
791
+ $banner = 'Bar';
792
 
793
+ $style = ( 'custom' === $js_template ) ? $customCSS : '#cookieChoiceInfo{background-color: ' . $banner_bg . ';color: ' . $banner_text_color . ';left:0;margin:0;padding:4px;position:fixed;text-align:center;top:0;width:100%;z-index:9999;}' . $contentStyle . $buttonStyle;
 
 
 
 
 
794
 
795
+ $bPos = 'top:0'; // Deprecato.
796
 
797
+ }
798
 
799
+ /**
800
+ * Declarations of JS variables and set parameters
801
+ * var elPos = Gestisce la Posizione banner nella funzione _createHeaderElement
802
+ * var infoClass = aggiunge una classe personalizzata per il link info
803
+ * var closeClass = aggiunge una classe personalizzata per il link di accettazione
804
+ * var htmlM = Aggiunge un margine a HTML per la top bar
805
+ * var coNA = cookie name
806
+ * var coVA = cookie val
807
+ * var rel = Setto il reload per la pagina all'accettazione
808
+ * var tar = Target -blank
809
+ * var bgB = Colore del background della topbar/dialog
810
+ * var btcB = Colore del font della topbar/dialog
811
+ * var bannerStyle = Variabile per le classe del contenitore
812
+ * var contentStyle = Variabile per le classe del contenitore del contenuto
813
+ * var consText = Variabile per le classe dello span per il testo
814
+ * @var string
815
+ */
816
 
817
+ $jsVariables = 'var coNA="' . $cookie_name . '",coVA="' . $cookie_value . '";scroll="' . $scroll . '",elPos="fixed",infoClass="' . $infoClass . '",closeClass="' . $closeClass . '",htmlM="' . $htmlM . '",rel="' . $reload . '",tar="' . $target . '",bgB="' . $banner_bg . '",btcB="' . $banner_text_color . '",bPos="' . $bPos . '",bannerStyle="' . $bannerStyle . '",contentStyle="' . $contStyle . '",consText="' . $consentText . '",jsArr = ' . $this->wp_json_encode( apply_filters( 'icc_js_array', $this->js_array ) ) . ';';
 
 
 
 
 
 
 
818
 
819
+ /**
820
+ * Snippet per il multilingua
821
+ * function get_string return multilanguage $value
822
+ * if isn't installed any language plugin return $value
823
+ */
824
+ $text = $this->wp_json_encode( wp_kses_post( get_string( 'Italy Cookie Choices', 'Banner text', $this->options['text'] ) ) );
825
 
826
+ $url = esc_url( get_string( 'Italy Cookie Choices', 'Banner url', $this->options['url'] ) );
 
 
 
 
 
827
 
828
+ $anchor_text = esc_js( get_string( 'Italy Cookie Choices', 'Banner anchor text', $this->options['anchor_text'] ) );
829
 
830
+ $button_text = esc_js( get_string( 'Italy Cookie Choices', 'Banner button text', $this->options['button_text'] ) );
831
 
832
+ /**
833
+ * Snippet for display banner
834
+ * @uses json_encode Funzione usate per il testo del messaggio.
835
+ * Ricordarsi che aggiunge già
836
+ * le doppie virgolette "" alla stringa
837
+ * @var string
838
+ */
839
+ $banner = 'document.addEventListener("DOMContentLoaded", function(event) {cookieChoices.showCookieConsent' . $banner . '(' . $text . ', "' . $button_text . '", "' . $anchor_text . '", "' . $url . '");});';
840
 
841
+ /**
842
+ * Noscript snippet in case browser has JavaScript disabled
843
+ * @var string
844
+ */
845
+ $noscript = '<noscript><style type="text/css">html{margin-top:35px}</style><div id="cookieChoiceInfo"><span>' . $text . '</span><a href="' . $url . '" class="' . $infoClass . '" target="_blank">' . $anchor_text . '</a></div></noscript>';
 
 
846
 
847
+ /**
848
+ * Select wich file to use in debug mode
849
+ * @var string
850
+ */
851
+ // $fileJS = ( WP_DEBUG ) ? '/js/' . $js_template . '/cookiechoices.js' : '/js/' . $js_template . '/cookiechoices.php' ;
852
+ $fileJS = ( WP_DEBUG ) ? '/js/default/cookiechoices.js' : '/js/default/cookiechoices.php' ;
853
 
854
+ $output_html = '<!-- Italy Cookie Choices -->' . '<style type="text/css">' . $style . '</style><script>' . $jsVariables . file_get_contents( ITALY_COOKIE_CHOICES_DIRNAME . $fileJS ) . $banner . '</script>' . $noscript;
855
 
856
+ echo apply_filters( 'icc_output_html', $output_html );
857
 
858
+ }
 
 
 
 
 
 
859
 
860
+ /**
861
+ * Shortcode per stampare il bottone nella pagina della policy
862
+ * @param array $atts Array con gli attributi dello shortcode.
863
+ * @param string $content Content of shortcode.
864
+ * @return string Button per l'accettazione
865
+ */
866
+ public function accept_button( $atts, $content = null ) {
867
 
868
+ $button_text = ( isset( $this->options['button_text'] ) ) ? $this->options['button_text'] : '' ;
869
 
870
+ return '<span class="el"><button onclick="cookieChoices.removeCookieConsent()">' . esc_attr( $button_text ) . '</button></span>';
871
 
872
+ }
 
 
 
 
873
 
874
+ /**
875
+ * Shortcode per stampare il bottone nella pagina della policy
876
+ * @param array $atts Array con gli attributi dello shortcode.
877
+ * @param string $content Content of shortcode.
878
+ * @return string Button per l'accettazione
879
+ */
880
+ public function _delete_cookie( $atts, $content = null ) {
881
 
882
+ // $button_text = ( isset( $this->options['button_text'] ) ) ? $this->options['button_text'] : '' ;
883
+ $button_text = 'Delete cookie';
 
 
884
 
885
+ return '<span class="ele"><button onclick="deleteCookie()">' . esc_attr( $button_text ) . '</button></span>';
886
 
887
+ }
888
 
889
+ /**
890
+ * Display cookie, only for internal use
891
+ * @return string
892
+ */
893
+ private function _display_cookie() {
894
+
895
+ $cookie_list = '<ul>';
896
+
897
+ foreach ( $_COOKIE as $key => $val )
898
+ $cookie_list .= '<li>Cooke name: ' . esc_attr( $key ) . ' - val: ' . esc_attr( $val ) . '</li>';
899
+
900
+ $cookie_list .= '</ul>';
901
+
902
+ return $cookie_list;
903
+
904
+ }
905
+ } // class
906
+ } //endif
italy-cookie-choices.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Italy Cookie Choices (for EU Cookie Law)
4
  * Plugin URI: https://plus.google.com/u/0/communities/109254048492234113886
5
  * Description: Italy Cookie Choices allows you to easily comply with the european cookie law and block third part cookie in your page.
6
- * Version: 2.4.1
7
  * Author: Enea Overclokk, Andrea Pernici, Andrea Cardinale
8
  * Author URI: https://github.com/ItalyCookieChoices/italy-cookie-choices
9
  * Text Domain: italy-cookie-choices
3
  * Plugin Name: Italy Cookie Choices (for EU Cookie Law)
4
  * Plugin URI: https://plus.google.com/u/0/communities/109254048492234113886
5
  * Description: Italy Cookie Choices allows you to easily comply with the european cookie law and block third part cookie in your page.
6
+ * Version: 2.4.2
7
  * Author: Enea Overclokk, Andrea Pernici, Andrea Cardinale
8
  * Author URI: https://github.com/ItalyCookieChoices/italy-cookie-choices
9
  * Text Domain: italy-cookie-choices
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link:
4
  Tags: compliance, cookie law, cookies, eu cookie law, eu law, eu privacy directive, privacy, privacy directive, notification, privacy law, cookie law banner, implied consent, third party script, third party cookie
5
  Requires at least: 3.5
6
  Tested up to: 4.5.0
7
- Stable tag: 2.4.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -115,6 +115,14 @@ if it doesn't work activate standard theme and try
115
 
116
  == Changelog ==
117
 
 
 
 
 
 
 
 
 
118
  = 2.4.1 =
119
  Release Date: November 6th, 2015
120
 
4
  Tags: compliance, cookie law, cookies, eu cookie law, eu law, eu privacy directive, privacy, privacy directive, notification, privacy law, cookie law banner, implied consent, third party script, third party cookie
5
  Requires at least: 3.5
6
  Tested up to: 4.5.0
7
+ Stable tag: 2.4.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
115
 
116
  == Changelog ==
117
 
118
+ = 2.4.2 =
119
+ Release Date: December 29th, 2015
120
+
121
+ Dev time: 1h
122
+
123
+ * Fixed PHP7 Fatal error [#149](https://github.com/ItalyCookieChoices/italy-cookie-choices/issues/149)
124
+ * Walking to WPCS
125
+
126
  = 2.4.1 =
127
  Release Date: November 6th, 2015
128