iubenda Cookie Solution for GDPR - Version 2.1.3-beta

Version Description

  • Tweak: Block tracking code from WP AMP plugins
Download this release

Release Info

Developer dfactory
Plugin Icon 128x128 iubenda Cookie Solution for GDPR
Version 2.1.3-beta
Comparing to
See all releases

Code changes from version 2.1.2-beta to 2.1.3-beta

includes/settings.php CHANGED
@@ -415,9 +415,10 @@ class iubenda_Settings {
415
  $iubenda_code = iubenda()->options['cs']['code_default'];
416
 
417
  $per_purpose_enabled = preg_match( '/(?:"|\')perPurposeConsent(?:"|\')\: *(?:"|\'*)true(?:"|\'*)/', $iubenda_code );
 
418
 
419
- if ( $per_purpose_enabled )
420
- $this->add_notice( 'iub_per_purpose_enabled', sprintf( __( 'If you are using per-purpose script blocking please disable the "Leave scripts untouched on the page if the user has already given consent" option. <a href="%s" target="_self">Disable now</a>', 'iubenda' ), esc_url( add_query_arg( 'action', 'disable_skip_parsing', $redirect_to ) ) ), 'notice' );
421
  }
422
 
423
  // render custom notices
@@ -691,12 +692,12 @@ class iubenda_Settings {
691
  public function iub_amp_support() {
692
  echo '
693
  <div id="iub_amp_support_container">
694
- <label><input id="iub_amp_support" type="checkbox" name="iubenda_cookie_law_solution[amp_support]" value="1" ' . checked( true, (bool) iubenda()->options['cs']['amp_support'], false ) . '/>' . __( 'Enable Google AMP caching compatibility.', 'iubenda' ) . '</label>
695
- <p class="description">' . sprintf( __( 'This plugin provides compatibility with Google AMP through <a href="%s" target="_blank">AMP</a> and <a href="%s" target="_blank">AMP for WP</a> WordPress plugins.', 'iubenda' ), 'https://wordpress.org/plugins/amp/', 'https://wordpress.org/plugins/accelerated-mobile-pages/' ) . '</p>
696
  <div id="iub_amp_options_container"' . ( iubenda()->options['cs']['amp_support'] === false ? ' style="display: none;"' : '' ) . '>
697
  <div>
698
- <label><input id="iub_amp_source-local" class="iub_amp_source" type="radio" name="iubenda_cookie_law_solution[amp_source]" value="local" ' . checked( 'local', iubenda()->options['cs']['amp_source'], false ) . ' />' . __( 'Local file', 'iubenda' ) . '</label>
699
- <label><input id="iub_amp_source-remote" class="iub_amp_source" type="radio" name="iubenda_cookie_law_solution[amp_source]" value="remote" ' . checked( 'remote', iubenda()->options['cs']['amp_source'], false ) . ' />' . __( 'Remote file', 'iubenda' ) . '</label>
700
  <p class="description">' . __( 'Select the iubenda AMP configuration file location.', 'iubenda' ) . '</p>
701
  </div>
702
  <div id="iub_amp_template-local"' . ( iubenda()->options['cs']['amp_source'] === 'remote' ? ' style="display: none;"' : '' ) . '>';
@@ -705,8 +706,7 @@ class iubenda_Settings {
705
  <p class="description">' . __( 'No file available. Save changes to generate iubenda AMP configuration file.', 'iubenda' ) . '</p>';
706
  } else {
707
  echo '
708
- <a href="' . iubenda()->get_amp_template_url() . '" target="_blank">' . iubenda()->get_amp_template_url() . '</a>
709
- <p class="description">' . __( 'Autogenerated iubenda AMP configuration file.', 'iubenda' ) . '</p>';
710
  }
711
  echo '
712
  </div>
@@ -714,6 +714,7 @@ class iubenda_Settings {
714
  <label><input id="iub_amp_template" type="text" class="regular-text" name="iubenda_cookie_law_solution[amp_template]" value="' . esc_url( iubenda()->options['cs']['amp_template'] ) . '" /></label>
715
  <p class="description">' . __( 'If you\'re experiencing issues with AMP setup download the generated iubenda AMP configuration file, upload it to any SSL server and paste the file link to the field above.', 'iubenda' ) . '</p>
716
  </div>
 
717
  </div>
718
  </div>';
719
  }
@@ -1150,7 +1151,7 @@ class iubenda_Settings {
1150
 
1151
  // generate amp template file
1152
  if ( isset( $input['amp_support'] ) ) {
1153
- $input['amp_template_done'] = (bool) iubenda()->generate_amp_template();
1154
  $input['amp_template'] = esc_url( $input['amp_template'] );
1155
  }
1156
 
415
  $iubenda_code = iubenda()->options['cs']['code_default'];
416
 
417
  $per_purpose_enabled = preg_match( '/(?:"|\')perPurposeConsent(?:"|\')\: *(?:"|\'*)true(?:"|\'*)/', $iubenda_code );
418
+ $reject_enabled = preg_match( '/(?:"|\')rejectButtonDisplay(?:"|\')\: *(?:"|\'*)true(?:"|\'*)/', $iubenda_code );
419
 
420
+ if ( $per_purpose_enabled || $reject_enabled )
421
+ $this->add_notice( 'iub_per_purpose_enabled', sprintf( __( 'If you are using per-purpose script blocking or Reject option please disable the "Leave scripts untouched on the page if the user has already given consent" option. <a href="%s" target="_self">Disable now</a>', 'iubenda' ), esc_url( add_query_arg( 'action', 'disable_skip_parsing', $redirect_to ) ) ), 'notice' );
422
  }
423
 
424
  // render custom notices
692
  public function iub_amp_support() {
693
  echo '
694
  <div id="iub_amp_support_container">
695
+ <label><input id="iub_amp_support" type="checkbox" name="iubenda_cookie_law_solution[amp_support]" value="1" ' . checked( true, (bool) iubenda()->options['cs']['amp_support'], false ) . '/>' . __( 'Enable Google AMP support.', 'iubenda' ) . '</label>
696
+ <p class="description">' . sprintf( __( 'This feature enables iubenda on AMP pages via the <a href="%s" target="_blank">AMP</a> and <a href="%s" target="_blank">AMP for WP</a> plugins. AMP requires a specific configuration parameters and a page hosted on your domain where the configuration is loaded from. <a href="%s" target="_blank">Learn more on iubenda and AMP</a>.', 'iubenda' ), 'https://wordpress.org/plugins/amp/', 'https://wordpress.org/plugins/accelerated-mobile-pages/', 'https://www.iubenda.com/en/help/3182-cookie-solution-amp#wordpress' ) . '</p>
697
  <div id="iub_amp_options_container"' . ( iubenda()->options['cs']['amp_support'] === false ? ' style="display: none;"' : '' ) . '>
698
  <div>
699
+ <label><input id="iub_amp_source-local" class="iub_amp_source" type="radio" name="iubenda_cookie_law_solution[amp_source]" value="local" ' . checked( 'local', iubenda()->options['cs']['amp_source'], false ) . ' />' . __( 'Auto-generated configuration file', 'iubenda' ) . '</label>
700
+ <label><input id="iub_amp_source-remote" class="iub_amp_source" type="radio" name="iubenda_cookie_law_solution[amp_source]" value="remote" ' . checked( 'remote', iubenda()->options['cs']['amp_source'], false ) . ' />' . __( 'Custom configuration file', 'iubenda' ) . '</label>
701
  <p class="description">' . __( 'Select the iubenda AMP configuration file location.', 'iubenda' ) . '</p>
702
  </div>
703
  <div id="iub_amp_template-local"' . ( iubenda()->options['cs']['amp_source'] === 'remote' ? ' style="display: none;"' : '' ) . '>';
706
  <p class="description">' . __( 'No file available. Save changes to generate iubenda AMP configuration file.', 'iubenda' ) . '</p>';
707
  } else {
708
  echo '
709
+ <a href="' . iubenda()->AMP->get_amp_template_url() . '" target="_blank">' . iubenda()->AMP->get_amp_template_url() . '</a>';
 
710
  }
711
  echo '
712
  </div>
714
  <label><input id="iub_amp_template" type="text" class="regular-text" name="iubenda_cookie_law_solution[amp_template]" value="' . esc_url( iubenda()->options['cs']['amp_template'] ) . '" /></label>
715
  <p class="description">' . __( 'If you\'re experiencing issues with AMP setup download the generated iubenda AMP configuration file, upload it to any SSL server and paste the file link to the field above.', 'iubenda' ) . '</p>
716
  </div>
717
+ <p class="description">' . sprintf( __( 'Seeing the AMP cookie notice when testing from Google but not when visiting your AMP pages directly? <a href="%s" target="_blank">Learn how to fix it</a>.', 'iubenda' ), 'https://www.iubenda.com/en/help/3182-cookie-solution-amp#amp-domain' ) . '</p>
718
  </div>
719
  </div>';
720
  }
1151
 
1152
  // generate amp template file
1153
  if ( isset( $input['amp_support'] ) ) {
1154
+ $input['amp_template_done'] = (bool) iubenda()->AMP->generate_amp_template();
1155
  $input['amp_template'] = esc_url( $input['amp_template'] );
1156
  }
1157
 
iubenda_cookie_solution.php CHANGED
@@ -12,7 +12,7 @@
12
  Domain Path: /languages
13
 
14
  Cookie and Consent Solution for the GDPR & ePrivacy
15
- Copyright (C) 2018-2019, iubenda s.r.l
16
 
17
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
18
 
@@ -99,6 +99,7 @@ class iubenda {
99
 
100
  self::$instance->includes();
101
 
 
102
  self::$instance->forms = new iubenda_Forms();
103
  self::$instance->settings = new iubenda_Settings();
104
  }
@@ -145,16 +146,11 @@ class iubenda {
145
  add_action( 'after_setup_theme', array( $this, 'register_shortcode' ) );
146
  add_action( 'wp_head', array( $this, 'wp_head_cs' ), 0 );
147
  add_action( 'wp_head', array( $this, 'wp_head_cons' ), 1 );
148
- // add_action( 'wp_footer', array( $this, 'wp_footer_cons' ), 1 );
149
  add_action( 'template_redirect', array( $this, 'output_start' ), 0 );
150
  add_action( 'shutdown', array( $this, 'output_end' ), 100 );
151
  add_action( 'template_redirect', array( $this, 'disable_jetpack_tracking' ) );
152
-
153
- // WP AMP support
154
- add_action( 'amp_post_template_head', array( $this, 'wp_head_amp' ), 100 );
155
- add_action( 'amp_post_template_footer', array( $this, 'wp_footer_amp' ), 100 );
156
- add_action( 'wp_head', array( $this, 'wp_head_amp' ), 100 );
157
- add_action( 'wp_footer', array( $this, 'wp_footer_amp' ), 100 );
158
  }
159
 
160
  /**
@@ -176,6 +172,7 @@ class iubenda {
176
  private function includes() {
177
  include_once( IUBENDA_PLUGIN_PATH . 'includes/settings.php' );
178
  include_once( IUBENDA_PLUGIN_PATH . 'includes/forms.php' );
 
179
  }
180
 
181
  /**
@@ -230,6 +227,8 @@ class iubenda {
230
  * @return void
231
  */
232
  public function activation() {
 
 
233
  add_option( 'iubenda_cookie_law_solution', $this->options['cs'], '', 'no' );
234
  add_option( 'iubenda_cookie_law_solution', $this->options['cons'], '', 'no' );
235
  add_option( 'iubenda_cookie_law_version', $this->version, '', 'no' );
@@ -249,6 +248,27 @@ class iubenda {
249
  }
250
  }
251
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  /**
253
  * Load textdomain.
254
  *
@@ -297,6 +317,7 @@ class iubenda {
297
  * @return mixed
298
  */
299
  public function wp_head_cs() {
 
300
  // check content type
301
  if ( (bool) $this->options['cs']['ctype'] == true ) {
302
  $iub_headers = headers_list();
@@ -391,38 +412,6 @@ class iubenda {
391
  }
392
  }
393
 
394
- /**
395
- * Add wp_head consent solution content.
396
- *
397
- * @return mixed
398
- */
399
- public function wp_footer_cons() {
400
- if ( ! empty( $this->options['cons']['public_api_key'] ) ) {
401
- echo '<script type="text/javascript">
402
- console.log( document.getElementById( "wpcf7-f136-p87-o1" ).getElementsByClassName( "wpcf7-form" )[0] );
403
- console.log( document.getElementById( "wpcf7-f136-p87-o1" ).getElementsByClassName( "wpcf7-submit" )[0] );
404
-
405
- _iub.cons_instructions.push( [ "load", {
406
- submitElement: document.getElementById( "wpcf7-f136-p87-o1" ).getElementsByClassName( "wpcf7-submit" )[0],
407
- form: {
408
- selector: document.getElementById( "wpcf7-f136-p87-o1" ).getElementsByClassName( "wpcf7-form" )[0],
409
- map: {
410
- subject: {
411
- first_name: "your-name",
412
- last_name: "your-name",
413
- email: "your-email"
414
- },
415
- preferences: {
416
- acceptance: "acceptance"
417
- }
418
- }
419
- }
420
- } ]
421
- );
422
- </script>';
423
- }
424
- }
425
-
426
  /**
427
  * Initialize html output.
428
  *
@@ -503,11 +492,11 @@ class iubenda {
503
 
504
  // experimental class
505
  if ( $this->options['cs']['parser_engine'] == 'new' ) {
506
- $iubenda = new iubendaParser( mb_convert_encoding( $output, 'HTML-ENTITIES', 'UTF-8' ), array(
507
- 'type' => 'faster',
508
  'amp' => $this->options['cs']['amp_support'],
509
- 'scripts' => $scripts,
510
- 'iframes' => $iframes
511
  ) );
512
 
513
  // render output
@@ -517,11 +506,11 @@ class iubenda {
517
  $output .= '<!-- Parsed with iubenda experimental class in ' . round( microtime( true ) - $startime, 4 ) . ' sec. -->';
518
  // default class
519
  } else {
520
- $iubenda = new iubendaParser( $output, array(
521
  'type' => 'page',
522
  'amp' => $this->options['cs']['amp_support'],
523
- 'scripts' => $scripts,
524
- 'iframes' => $iframes
525
  ) );
526
 
527
  // render output
@@ -615,231 +604,38 @@ class iubenda {
615
  }
616
 
617
  /**
618
- * Add AMP consent HTML to head.
619
  *
620
- * @return mixed
621
  */
622
- public function wp_head_amp() {
623
- if ( $this->options['cs']['amp_support'] === false )
624
- return;
625
-
626
- if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() || ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) ) {
627
- echo '
628
- <script async custom-element="amp-consent" src="https://cdn.ampproject.org/v0/amp-consent-0.1.js"></script>
629
- <script async custom-element="amp-iframe" src="https://cdn.ampproject.org/v0/amp-iframe-0.1.js"></script>';
630
- // optional geo support
631
- echo '
632
- <script async custom-element="amp-geo" src="https://cdn.ampproject.org/v0/amp-geo-0.1.js"></script>';
633
- // CSS style
634
- echo '
635
- <style amp-custom>
636
- .popupOverlay {
637
- position:fixed;
638
- top: 0;
639
- bottom: 0;
640
- left: 0;
641
- right: 0;
642
- }
643
- </style>';
644
- }
645
- }
646
 
647
- /**
648
- * Add AMP consent HTML to footer.
649
- *
650
- * @return mixed
651
- */
652
- public function wp_footer_amp() {
653
- if ( $this->options['cs']['amp_support'] === false )
654
  return;
655
 
656
- if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() || ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) ) {
657
-
658
- $site_data = $this->parse_site_data();
659
-
660
- if ( empty( $site_data ) )
661
- return;
662
-
663
- // local file
664
- if ( $this->options['cs']['amp_source'] === 'local' ) {
665
- $template_url = $this->get_amp_template_url();
666
- // remote file
667
- } else {
668
- $template_url = esc_url( $this->options['cs']['amp_template'] );
669
- }
670
-
671
- if ( empty( $template_url ) )
672
- return;
673
-
674
- echo '
675
- <amp-consent id="myUserConsent" layout="nodisplay">
676
- <script type="application/json">
677
- {
678
- "consentInstanceId": "consent' . $site_data['site_id'] . '",
679
- "consentRequired": true,
680
- "promptUI": "myConsentFlow"
681
- }
682
- </script>
683
- <div id="myConsentFlow" class="popupOverlay">
684
- <amp-iframe
685
- layout="fill"
686
- sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox"
687
- src="' . esc_url( $template_url ) . '">
688
- <div placeholder>' . __( 'Loading', 'iubenda' ) . '</div>
689
- </amp-iframe>
690
- </div>
691
- </amp-consent>';
692
- }
693
- }
694
 
695
- /**
696
- * Prepare HTML iframe template for the AMP.
697
- *
698
- * @return mixed
699
- */
700
- public function prepare_amp_template() {
701
- $html = '';
702
- $site_data = $this->parse_site_data();
703
-
704
- if ( ! empty( $site_data ) ) {
705
-
706
- $html .= '<!DOCTYPE html>
707
- <html lang="' . $site_data['lang'] . '">
708
- <head>
709
- <meta charset="UTF-8">
710
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
711
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
712
- <title>AMP Cookie Consent</title>
713
- <script type="text/javascript">
714
- var _iub = _iub || [];
715
- _iub.csConfiguration = {
716
- lang: \'' . $site_data['lang'] . '\',
717
- siteId: ' . $site_data['site_id'] . ', // your own site ID
718
- cookiePolicyId: ' . $site_data['policy_id'] . ', // your own cookie policy ID
719
-
720
- enableCMP: true,
721
- askConsentIfCMPNotFound: true,
722
- isTCFConsentGlobal: true,
723
- googleAdsPreferenceManagement: true,
724
-
725
- banner: {
726
- position: \'float-bottom-center\',
727
- acceptButtonDisplay: true,
728
- customizeButtonDisplay: true,
729
- rejectButtonDisplay: true,
730
- backgroundOverlay: true
731
- },
732
- callback: {
733
- onPreferenceExpressed: function(preference) {
734
- var consentAction = \'reject\';
735
- if (preference && preference.consent) {
736
- consentAction = \'accept\';
737
- }
738
- console.log(\'send consent-response\', consentAction);
739
- window.parent.postMessage({
740
- type: \'consent-response\',
741
- action: consentAction
742
- }, \'*\');
743
- }
744
- }
745
- };
746
- </script>
747
- <script async src="https://cdn.iubenda.com/cs/beta/iubenda_cs.js"></script>
748
- </head>
749
- <body></body>
750
- </html>';
751
- }
752
 
753
- return $html;
754
- }
755
-
756
- /**
757
- * Get local file template url;
758
- *
759
- * @return string
760
- */
761
- public function get_amp_template_url() {
762
- // get basic site host and template file data
763
- $template_url = '';
764
- $file_url = IUBENDA_PLUGIN_URL . '/templates/amp.html';
765
- // $file_url = 'https://cdn.iubenda.com/cs/test/cs-for-amp.html'; // debug only
766
- $parsed_site = parse_url( home_url() );
767
- $parsed_file = parse_url( $file_url );
768
- $site_host = $parsed_site['host'] !== 'localhost' ? $this->domain( $parsed_site['host'] ) : 'localhost';
769
- $file_host = $parsed_file['host'] !== 'localhost' ? $this->domain( $parsed_file['host'] ) : 'localhost';
770
- $is_localhost = (bool) $file_host == 'localhost';
771
- $is_subdomain = ! $is_localhost ? (bool) ( $parsed_file['host'] !== $file_host ) : false;
772
-
773
- // check if file host and server host match
774
- // if not, we're good to go
775
- if ( $site_host !== $file_host ) {
776
- $template_url = $file_url;
777
- // if are located on same host do additional tweaks
778
- } else {
779
- // all ok if we're on different subdomains
780
- if ( $parsed_site['host'] !== $parsed_file['host'] )
781
- $template_url = $file_url;
782
- // same hosts, let's tweak the http/https
783
- else {
784
- $has_www = strpos( $parsed_file['host'], 'www.' ) === 0;
785
-
786
- // add or remove www from url string to make iframe url pass AMP validation
787
- $tweaked_host = ! $is_localhost && ! $is_subdomain ? ! $has_www ? 'www.' . $parsed_file['host'] : preg_replace( '/^www\./i', '', $parsed_file['host'] ) : $parsed_file['host'];
788
-
789
- // generate new url
790
- $tweaked_url = $parsed_file['scheme'] . '://' . $tweaked_host . ( isset( $parsed_file['port'] ) ? ':' . $parsed_file['port'] : '' ) . $parsed_file['path'] . ( ! empty( $parsed_file['query'] ) ? '?' . $parsed_file['query'] : '' );
791
-
792
- // check if file url is valid
793
- if ( $tweaked_url ) {
794
- $template_url = $tweaked_url;
795
- }
796
- }
797
  }
798
-
799
- /*
800
- print_r( $file_url );
801
- print_r( $parsed_site );
802
- print_r( $parsed_file );
803
- print_r( $site_host );
804
- print_r( $file_host );
805
- print_r( $template_url );
806
- exit;
807
- */
808
-
809
- return $template_url;
810
- }
811
-
812
- /**
813
- * Generate HTML iframe template for the AMP.
814
- *
815
- * @return mixed
816
- */
817
- public function generate_amp_template() {
818
- $template_file = IUBENDA_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'amp.html';
819
- $html = $this->prepare_amp_template();
820
-
821
- // bail if the template was not created properly
822
- if ( empty( $html ) )
823
- return false;
824
-
825
- // bail if the file is writable
826
- if ( ! is_writable( $template_file ) )
827
- return false;
828
-
829
- // write the file
830
- $fh = fopen( $template_file, 'w' );
831
- fwrite( $fh, $html );
832
- fclose( $fh );
833
-
834
- return true;
835
  }
836
 
837
  /**
838
- * Get site data parsed from iubenda code
839
  *
840
  * @return array
841
  */
842
- public function parse_site_data() {
 
843
  $data = array();
844
 
845
  // get iubenda code
@@ -857,22 +653,33 @@ class iubenda {
857
 
858
  // get site data
859
  if ( ! empty( $iubenda_code ) ) {
860
- $iubenda_code = $this->parse_code( $iubenda_code, true );
 
 
 
861
 
862
- // get lang
863
- $data['lang'] = $this->multilang === true && defined( 'ICL_LANGUAGE_CODE' ) && isset( $this->options['cs']['code_' . ICL_LANGUAGE_CODE] ) ? ICL_LANGUAGE_CODE : 'en';
864
 
865
- // get site id from code
866
- preg_match( '/(?:"|\')siteId(?:"|\') *\: *(\d+),/', $iubenda_code, $matches );
867
 
868
- if ( ! empty( $matches ) )
869
- $data['site_id'] = $matches[1];
870
 
871
- // get policy id from code
872
- preg_match( '/(?:"|\')cookiePolicyId(?:"|\') *\: *(\d+),/', $iubenda_code, $matches );
873
 
874
- if ( ! empty( $matches ) )
875
- $data['policy_id'] = $matches[1];
 
 
 
 
 
 
 
 
876
  }
877
 
878
  return $data;
12
  Domain Path: /languages
13
 
14
  Cookie and Consent Solution for the GDPR & ePrivacy
15
+ Copyright (C) 2018-2020, iubenda s.r.l
16
 
17
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
18
 
99
 
100
  self::$instance->includes();
101
 
102
+ self::$instance->AMP = new iubenda_AMP();
103
  self::$instance->forms = new iubenda_Forms();
104
  self::$instance->settings = new iubenda_Settings();
105
  }
146
  add_action( 'after_setup_theme', array( $this, 'register_shortcode' ) );
147
  add_action( 'wp_head', array( $this, 'wp_head_cs' ), 0 );
148
  add_action( 'wp_head', array( $this, 'wp_head_cons' ), 1 );
 
149
  add_action( 'template_redirect', array( $this, 'output_start' ), 0 );
150
  add_action( 'shutdown', array( $this, 'output_end' ), 100 );
151
  add_action( 'template_redirect', array( $this, 'disable_jetpack_tracking' ) );
152
+ add_action( 'admin_init', array( $this, 'maybe_do_upgrade' ) );
153
+ add_action( 'upgrader_process_complete', array( $this, 'upgrade' ), 10, 2 );
 
 
 
 
154
  }
155
 
156
  /**
172
  private function includes() {
173
  include_once( IUBENDA_PLUGIN_PATH . 'includes/settings.php' );
174
  include_once( IUBENDA_PLUGIN_PATH . 'includes/forms.php' );
175
+ include_once( IUBENDA_PLUGIN_PATH . 'includes/amp.php' );
176
  }
177
 
178
  /**
227
  * @return void
228
  */
229
  public function activation() {
230
+ set_transient( 'iub_activation_completed', 1, 3600 );
231
+
232
  add_option( 'iubenda_cookie_law_solution', $this->options['cs'], '', 'no' );
233
  add_option( 'iubenda_cookie_law_solution', $this->options['cons'], '', 'no' );
234
  add_option( 'iubenda_cookie_law_version', $this->version, '', 'no' );
248
  }
249
  }
250
 
251
+ /**
252
+ * Plugin upgrae.
253
+ *
254
+ * @return void
255
+ */
256
+ public function upgrade( $upgrader_object, $option ) {
257
+ // the path to our plugin's main file
258
+ $our_plugin = plugin_basename( __FILE__ );
259
+
260
+ // if an update has taken place and the updated type is plugins and the plugins element exists
261
+ if ( $options['action'] == 'update' && $options['type'] == 'plugin' && isset( $options['plugins'] ) ) {
262
+ // iterate through the plugins being updated and check if ours is there
263
+ foreach ( $options['plugins'] as $plugin ) {
264
+ if ( $plugin == $our_plugin ) {
265
+ // set a transient to record that our plugin has just been updated
266
+ set_transient( 'iub_upgrade_completed', 1, 3600 );
267
+ }
268
+ }
269
+ }
270
+ }
271
+
272
  /**
273
  * Load textdomain.
274
  *
317
  * @return mixed
318
  */
319
  public function wp_head_cs() {
320
+
321
  // check content type
322
  if ( (bool) $this->options['cs']['ctype'] == true ) {
323
  $iub_headers = headers_list();
412
  }
413
  }
414
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
  /**
416
  * Initialize html output.
417
  *
492
 
493
  // experimental class
494
  if ( $this->options['cs']['parser_engine'] == 'new' ) {
495
+ $iubenda = new iubendaParser( mb_convert_encoding( $output, 'HTML-ENTITIES', 'UTF-8' ), array(
496
+ 'type' => 'faster',
497
  'amp' => $this->options['cs']['amp_support'],
498
+ 'scripts' => $scripts,
499
+ 'iframes' => $iframes
500
  ) );
501
 
502
  // render output
506
  $output .= '<!-- Parsed with iubenda experimental class in ' . round( microtime( true ) - $startime, 4 ) . ' sec. -->';
507
  // default class
508
  } else {
509
+ $iubenda = new iubendaParser( $output, array(
510
  'type' => 'page',
511
  'amp' => $this->options['cs']['amp_support'],
512
+ 'scripts' => $scripts,
513
+ 'iframes' => $iframes
514
  ) );
515
 
516
  // render output
604
  }
605
 
606
  /**
607
+ * Perform actions on plugin installation/upgrade.
608
  *
609
+ * @return void
610
  */
611
+ public function maybe_do_upgrade() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
612
 
613
+ // bail if no activation or upgrade transient is set
614
+ if ( ! get_transient( 'iub_upgrade_completed' ) && ! get_transient( 'iub_activation_completed' ) )
 
 
 
 
 
615
  return;
616
 
617
+ // delete the activation transient
618
+ delete_transient( 'iub_activation_completed' );
619
+ // delete the upgrade transient
620
+ delete_transient( 'iub_upgrade_completed' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
621
 
622
+ // bail if activating from network, or bulk, or within an iFrame
623
+ if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) )
624
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
625
 
626
+ // generate AMP template file if AMP plugins available
627
+ if ( function_exists( 'is_amp_endpoint' ) || function_exists( 'ampforwp_is_amp_endpoint' ) ) {
628
+ iubenda()->AMP->generate_amp_template();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
629
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
630
  }
631
 
632
  /**
633
+ * Get configuration data parsed from iubenda code
634
  *
635
  * @return array
636
  */
637
+ public function parse_configuration( $mode = true ) {
638
+ $mode = ! empty( $mode ) ? 'full' : 'basic';
639
  $data = array();
640
 
641
  // get iubenda code
653
 
654
  // get site data
655
  if ( ! empty( $iubenda_code ) ) {
656
+ $parsed_code = $this->parse_code( $iubenda_code, true );
657
+
658
+ // strip tags
659
+ $parsed_code = wp_kses( $parsed_code, array() );
660
 
661
+ // get configuration
662
+ preg_match( '/_iub.csConfiguration *= *{(.*?)\};/', $parsed_code, $matches );
663
 
664
+ if ( ! empty( $matches[1] ) )
665
+ $parsed_code = '{' . $matches[1] . '}';
666
 
667
+ // decode
668
+ $decoded = json_decode( $parsed_code, true );
669
 
670
+ if ( ! empty( $decoded ) && is_array( $decoded ) ) {
671
+ $data = $decoded;
672
 
673
+ // basic mode
674
+ if ( $mode === 'basic' ) {
675
+ if ( isset( $data['banner'] ) )
676
+ unset( $data['banner'] );
677
+ if ( isset( $data['callback'] ) )
678
+ unset( $data['callback'] );
679
+ if ( isset( $data['perPurposeConsent'] ) )
680
+ unset( $data['perPurposeConsent'] );
681
+ }
682
+ }
683
  }
684
 
685
  return $data;
readme.txt CHANGED
@@ -134,6 +134,9 @@ We will be very happy to receive feedback here: [Uservoice forum](http://support
134
 
135
  == Changelog ==
136
 
 
 
 
137
  = 2.1.2-beta =
138
  * New: Google AMP compatibility option
139
 
@@ -388,5 +391,5 @@ We will be very happy to receive feedback here: [Uservoice forum](http://support
388
 
389
  == Upgrade Notice ==
390
 
391
- = 2.1.2-beta =
392
- * New: Google AMP compatibility option
134
 
135
  == Changelog ==
136
 
137
+ = 2.1.3-beta =
138
+ * Tweak: Block tracking code from WP AMP plugins
139
+
140
  = 2.1.2-beta =
141
  * New: Google AMP compatibility option
142
 
391
 
392
  == Upgrade Notice ==
393
 
394
+ = 2.1.3-beta =
395
+ * Tweak: Block tracking code from WP AMP plugins
templates/amp.html CHANGED
@@ -5,6 +5,33 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
  <title>AMP Cookie Consent</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  </head>
9
  <body></body>
10
  </html>
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
  <title>AMP Cookie Consent</title>
8
+ <script type="text/javascript">
9
+ var _iub = _iub || [];
10
+ _iub.csConfiguration = {
11
+ cookiePolicyInOtherWindow:true,reloadOnConsent:false,consentOnScroll:false,consentOnButton:false,lang:"en",siteId:825619,cookiePolicyId:8134524,
12
+ banner: {
13
+ position: 'float-bottom-center',
14
+ acceptButtonDisplay: true,
15
+ customizeButtonDisplay: true,
16
+ rejectButtonDisplay: true,
17
+ backgroundOverlay: true
18
+ },
19
+ callback: {
20
+ onPreferenceExpressed: function(preference) {
21
+ var consentAction = 'reject';
22
+ if (preference && preference.consent) {
23
+ consentAction = 'accept';
24
+ }
25
+ console.log('send consent-response', consentAction);
26
+ window.parent.postMessage({
27
+ type: 'consent-response',
28
+ action: consentAction
29
+ }, '*');
30
+ }
31
+ }
32
+ };
33
+ </script>
34
+ <script async src="https://cdn.iubenda.com/cs/beta/iubenda_cs.js"></script>
35
  </head>
36
  <body></body>
37
  </html>