iubenda Cookie Solution for GDPR - Version 2.1.4-beta

Version Description

  • New: Multilingual support from AMP
Download this release

Release Info

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

Code changes from version 2.0.3 to 2.1.4-beta

css/admin.css CHANGED
@@ -42,6 +42,12 @@
42
  #iub_parser_engine_container > div:not(:last-child) {
43
  margin-bottom: 10px;
44
  }
 
 
 
 
 
 
45
  #iubenda-tabs .contextual-help-wrap {
46
  overflow: auto;
47
  margin: 0;
@@ -62,9 +68,18 @@
62
  #iubenda-tabs .help-tab-content {
63
  margin-right: 0;
64
  }
65
- #iubenda-tabs .help-tab-content textarea {
66
- margin-top: 18px;
67
- width: 100%;
 
 
 
 
 
 
 
 
 
68
  }
69
  #iubenda-tabs .postbox-container .widefat {
70
  border: none;
42
  #iub_parser_engine_container > div:not(:last-child) {
43
  margin-bottom: 10px;
44
  }
45
+ #iub_amp_options_container {
46
+ margin-top: 10px;
47
+ }
48
+ #iub_amp_options_container > div:not(:last-child) {
49
+ margin-bottom: 10px;
50
+ }
51
  #iubenda-tabs .contextual-help-wrap {
52
  overflow: auto;
53
  margin: 0;
68
  #iubenda-tabs .help-tab-content {
69
  margin-right: 0;
70
  }
71
+ #iubenda-tabs .help-tab-content .description {
72
+ margin-bottom: 10px;
73
+ }
74
+ #iubenda-tabs .help-tab-content .custom-script-field, #iubenda-tabs .help-tab-content .custom-iframe-field {
75
+ padding-bottom: 10px;
76
+ }
77
+ #iubenda-tabs .help-tab-content .custom-script-field input, #iubenda-tabs .help-tab-content .custom-iframe-field input {
78
+ vertical-align: middle;
79
+ }
80
+ #tab-panel-scripts, #tab-panel-iframes {
81
+ margin-top: 16px;
82
+ margin-bottom: 18px;
83
  }
84
  #iubenda-tabs .postbox-container .widefat {
85
  border: none;
includes/amp.php ADDED
@@ -0,0 +1,364 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // exit if accessed directly
3
+ if ( ! defined( 'ABSPATH' ) )
4
+ exit;
5
+
6
+ /**
7
+ * iubenda_AMP class.
8
+ *
9
+ * @class iubenda_AMP
10
+ */
11
+ class iubenda_AMP {
12
+
13
+ /**
14
+ * Class constructor.
15
+ */
16
+ public function __construct() {
17
+ // actions
18
+ add_action( 'wp_head', array( $this, 'wp_head_amp' ), 100 );
19
+ add_action( 'wp_footer', array( $this, 'wp_footer_amp' ), 100 );
20
+ add_action( 'amp_post_template_css', array( $this, 'amp_post_template_css' ), 100 );
21
+ add_action( 'amp_post_template_footer', array( $this, 'wp_footer_amp' ), 100 );
22
+ add_action( 'amp_post_template_footer', array( $this, 'fix_analytics_amp_for_wp' ), 1 );
23
+
24
+ // filters
25
+ add_filter( 'amp_post_template_data', array( $this, 'amp_post_template_data' ), 100 );
26
+ add_filter( 'amp_analytics_entries', array( $this, 'fix_analytics_wp_amp' ), 10 );
27
+ }
28
+
29
+ /**
30
+ * Add scripts and CSS to WP AMP plugin in Transitional mode.
31
+ *
32
+ * @return mixed
33
+ */
34
+ public function wp_head_amp() {
35
+ if ( iubenda()->options['cs']['amp_support'] === false )
36
+ return;
37
+
38
+ if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() && ! function_exists( 'ampforwp_is_amp_endpoint' ) ) {
39
+ echo '
40
+ <script async custom-element="amp-consent" src="https://cdn.ampproject.org/v0/amp-consent-latest.js"></script>
41
+ <script async custom-element="amp-iframe" src="https://cdn.ampproject.org/v0/amp-iframe-latest.js"></script>';
42
+ /* optional geo support
43
+ echo '
44
+ <script async custom-element="amp-geo" src="https://cdn.ampproject.org/v0/amp-geo-0.1.js"></script>';
45
+ */
46
+ // CSS style
47
+ echo '
48
+ <style amp-custom>
49
+ .popupOverlay {
50
+ position:fixed;
51
+ top: 0;
52
+ bottom: 0;
53
+ left: 0;
54
+ right: 0;
55
+ }
56
+ amp-iframe {
57
+ margin: 0;
58
+ }
59
+ amp-consent.amp-active {
60
+ position:fixed;
61
+ top: 0;
62
+ bottom: 0;
63
+ left: 0;
64
+ right: 0;
65
+ }
66
+ </style>';
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Add AMP consent HTML to WP AMP plugin in Transitional mode.
72
+ *
73
+ * @return mixed
74
+ */
75
+ public function wp_footer_amp() {
76
+ if ( iubenda()->options['cs']['amp_support'] === false )
77
+ return;
78
+
79
+ if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() || ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) ) {
80
+
81
+ // get code
82
+ if ( iubenda()->multilang && ! empty( iubenda()->lang_current ) ) {
83
+ $code = iubenda()->options['cs']['code_' . iubenda()->lang_current];
84
+ } else {
85
+ $code = iubenda()->options['cs']['code_default'];
86
+ }
87
+
88
+ $configuration = iubenda()->parse_configuration( $code );
89
+
90
+ if ( empty( $configuration ) )
91
+ return;
92
+
93
+ // local file
94
+ if ( iubenda()->options['cs']['amp_source'] === 'local' ) {
95
+ // multilang support
96
+ if ( iubenda()->multilang && ! empty( iubenda()->lang_current ) )
97
+ $template_url = $this->get_amp_template_url( iubenda()->lang_current );
98
+ else
99
+ $template_url = $this->get_amp_template_url();
100
+ // remote file
101
+ } else {
102
+ // multilang support
103
+ if ( iubenda()->multilang && ! empty( iubenda()->lang_current ) )
104
+ $template_url = esc_url( isset( iubenda()->options['cs']['amp_template'][iubenda()->lang_current] ) ? iubenda()->options['cs']['amp_template'][iubenda()->lang_current] : '' );
105
+ else
106
+ $template_url = esc_url( iubenda()->options['cs']['amp_template'] );
107
+ }
108
+
109
+ if ( empty( $template_url ) )
110
+ return;
111
+
112
+ echo '
113
+ <amp-consent id="myUserConsent" layout="nodisplay">
114
+ <script type="application/json">
115
+ {
116
+ "consentInstanceId": "consent' . $configuration['siteId'] . '",
117
+ "consentRequired": true,
118
+ "promptUI": "myConsentFlow"
119
+ }
120
+ </script>
121
+ <div id="myConsentFlow" class="popupOverlay">
122
+ <amp-iframe
123
+ layout="fill"
124
+ sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox"
125
+ src="' . esc_url( $template_url ) . '">
126
+ <div placeholder>' . __( 'Loading', 'iubenda' ) . '</div>
127
+ </amp-iframe>
128
+ </div>
129
+ </amp-consent>';
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Add scripts to AMP for WP plugin and WP AMP plugin in Standard mode.
135
+ *
136
+ * @return mixed
137
+ */
138
+ public function amp_post_template_data( $data ) {
139
+ if ( iubenda()->options['cs']['amp_support'] === false )
140
+ return $data;
141
+
142
+ if ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) {
143
+ $data['amp_component_scripts'] = array_merge( $data['amp_component_scripts'],
144
+ array( 'amp-consent' => 'https://cdn.ampproject.org/v0/amp-consent-latest.js' )
145
+ );
146
+ $data['amp_component_scripts'] = array_merge( $data['amp_component_scripts'],
147
+ array( 'amp-iframe' => 'https://cdn.ampproject.org/v0/amp-iframe-latest.js' )
148
+ );
149
+ }
150
+
151
+ return $data;
152
+ }
153
+
154
+ /**
155
+ * Add CSS to AMP for WP plugin and WP AMP plugin in Standard mode.
156
+ *
157
+ * @return mixed
158
+ */
159
+ public function amp_post_template_css( $data ) {
160
+ if ( iubenda()->options['cs']['amp_support'] === false )
161
+ return;
162
+
163
+ echo '
164
+ .popupOverlay {
165
+ position:fixed;
166
+ top: 0;
167
+ bottom: 0;
168
+ left: 0;
169
+ right: 0;
170
+ }
171
+ amp-iframe {
172
+ margin: 0;
173
+ }
174
+ amp-consent.amp-active {
175
+ position:fixed;
176
+ top: 0;
177
+ bottom: 0;
178
+ left: 0;
179
+ right: 0;
180
+ }';
181
+ }
182
+
183
+ /**
184
+ * Block analytics in AMP for WP plugin.
185
+ *
186
+ * @return mixed
187
+ */
188
+ public function fix_analytics_amp_for_wp( $data ) {
189
+ if ( iubenda()->options['cs']['amp_support'] === false )
190
+ return $data;
191
+
192
+ global $redux_builder_amp;
193
+
194
+ if ( $redux_builder_amp == null ) {
195
+ $redux_builder_amp = get_option( 'redux_builder_amp', true );
196
+ }
197
+
198
+ // trick to block the analytics using global $redux_builder_amp variable
199
+ if ( ! iubendaParser::consent_given() )
200
+ $redux_builder_amp = true;
201
+
202
+ return $data;
203
+ }
204
+
205
+ /**
206
+ * Block analytics in WP AMP plugin.
207
+ *
208
+ * @return mixed
209
+ */
210
+ public function fix_analytics_wp_amp( $analytics_entries ) {
211
+ if ( iubenda()->options['cs']['amp_support'] === false )
212
+ return $analytics_entries;
213
+
214
+ // block the analytics using the entries filter hook
215
+ if ( ! iubendaParser::consent_given() && ! empty( $analytics_entries ) && is_array( $analytics_entries ) ) {
216
+ foreach ( $analytics_entries as $id => $entry ) {
217
+ $entry['attributes'] = ! empty( $entry['attributes'] ) ? $entry['attributes'] : array();
218
+
219
+ $analytics_entries[$id]['attributes'] = array_merge( array( 'data-block-on-consent' => '_till_accepted' ), $entry['attributes'] );
220
+ }
221
+ }
222
+
223
+ return $analytics_entries;
224
+ }
225
+
226
+ /**
227
+ * Prepare HTML iframe template for the AMP.
228
+ *
229
+ * @return mixed
230
+ */
231
+ public function prepare_amp_template( $code ) {
232
+ $html = '';
233
+
234
+ $configuration_raw = iubenda()->parse_configuration( $code );
235
+
236
+ if ( ! empty( $configuration_raw ) ) {
237
+ // get script
238
+ $script_src = ! empty( $configuration_raw['script'] ) ? $configuration_raw['script'] : '//cdn.iubenda.com/cs/iubenda_cs.js';
239
+
240
+ // remove from configuration
241
+ if ( isset( $configuration_raw['script'] ) )
242
+ unset( $configuration_raw['script'] );
243
+
244
+ // encode array
245
+ $configuration = json_encode( $configuration_raw );
246
+
247
+ // remove quotes
248
+ $configuration = preg_replace( '/"([a-zA-Z]+[a-zA-Z0-9]*)":/', '$1:', $configuration );
249
+ // replace brackets
250
+ $configuration = str_replace( array( '{', '}' ), '', $configuration );
251
+
252
+ $html .= '<!DOCTYPE html>
253
+ <html lang="' . $configuration_raw['lang'] . '">
254
+ <head>
255
+ <meta charset="UTF-8">
256
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
257
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
258
+ <title>' . __( 'AMP Cookie Consent', 'iubenda' ) . '</title>
259
+ <script type="text/javascript">
260
+ var _iub = _iub || [];
261
+ _iub.csConfiguration = {
262
+ ';
263
+ // print configuration
264
+ $html .= $configuration . ',';
265
+ $html .= '
266
+ banner: {
267
+ position: \'float-bottom-center\',
268
+ acceptButtonDisplay: true,
269
+ customizeButtonDisplay: true,
270
+ rejectButtonDisplay: true,
271
+ backgroundOverlay: true
272
+ },
273
+ callback: {
274
+ onPreferenceExpressed: function(preference) {
275
+ var consentAction = \'reject\';
276
+ if (preference && preference.consent) {
277
+ consentAction = \'accept\';
278
+ }
279
+ console.log(\'send consent-response\', consentAction);
280
+ window.parent.postMessage({
281
+ type: \'consent-response\',
282
+ action: consentAction
283
+ }, \'*\');
284
+ }
285
+ }
286
+ };
287
+ </script>
288
+ <script async src="' . $script_src . '"></script>
289
+ </head>
290
+ <body></body>
291
+ </html>';
292
+ }
293
+
294
+ return $html;
295
+ }
296
+
297
+ /**
298
+ * Get local file template url;
299
+ *
300
+ * @return string
301
+ */
302
+ public function get_amp_template_url( $template_lang = '' ) {
303
+ $template_url = '';
304
+ $template_lang = ! empty( $template_lang ) && is_string( $template_lang ) ? $template_lang : '';
305
+
306
+ // get basic site host and template file data
307
+ $file_url = ! empty( $template_lang ) ? IUBENDA_PLUGIN_URL . '/templates/amp' . '-' . $template_lang . '.html' : IUBENDA_PLUGIN_URL . '/templates/amp.html';
308
+ // $file_url = 'https://cdn.iubenda.com/cs/test/cs-for-amp.html'; // debug only
309
+ $parsed_site = parse_url( home_url() );
310
+ $parsed_file = parse_url( $file_url );
311
+ $site_host = $parsed_site['host'] !== 'localhost' ? iubenda()->domain( $parsed_site['host'] ) : 'localhost';
312
+ $file_host = $parsed_file['host'] !== 'localhost' ? iubenda()->domain( $parsed_file['host'] ) : 'localhost';
313
+ $is_localhost = (bool) ( $site_host == 'localhost' );
314
+ $is_subdomain = ! $is_localhost ? (bool) ( $parsed_file['host'] !== $file_host ) : false;
315
+
316
+ // check if file host and server host match
317
+ // if not, we're good to go
318
+ if ( $site_host !== $file_host ) {
319
+ $template_url = $file_url;
320
+ // if are located on same host do additional tweaks
321
+ } else {
322
+ // all ok if we're on different subdomains
323
+ if ( $parsed_site['host'] !== $parsed_file['host'] )
324
+ $template_url = $file_url;
325
+ // same hosts, let's tweak the http/https
326
+ else {
327
+ $has_www = strpos( $parsed_file['host'], 'www.' ) === 0;
328
+
329
+ // add or remove www from url string to make iframe url pass AMP validation
330
+ $tweaked_host = ! $is_localhost && ! $is_subdomain ? ( ! $has_www ? 'www.' . $parsed_file['host'] : preg_replace( '/^www\./i', '', $parsed_file['host'] ) ) : $parsed_file['host'];
331
+
332
+ // generate new url
333
+ $tweaked_url = $parsed_file['scheme'] . '://' . $tweaked_host . ( isset( $parsed_file['port'] ) ? ':' . $parsed_file['port'] : '' ) . $parsed_file['path'] . ( ! empty( $parsed_file['query'] ) ? '?' . $parsed_file['query'] : '' );
334
+
335
+ // check if file url is valid
336
+ if ( $tweaked_url ) {
337
+ $template_url = $tweaked_url;
338
+ }
339
+ }
340
+ }
341
+
342
+ return $template_url;
343
+ }
344
+
345
+ /**
346
+ * Generate HTML iframe template for the AMP.
347
+ *
348
+ * @return mixed
349
+ */
350
+ public function generate_amp_template( $code, $lang = '' ) {
351
+ $template_dir = IUBENDA_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
352
+ $template_file = $template_dir . ( ! empty( $lang ) && in_array( $lang, array_keys( iubenda()->languages ) ) ? 'amp' . '-' . $lang . '.html' : 'amp.html' );
353
+ $html = $this->prepare_amp_template( $code );
354
+
355
+ // bail if the template was not created properly
356
+ if ( empty( $html ) )
357
+ return false;
358
+
359
+ $result = file_put_contents( $template_file, $html );
360
+
361
+ return (bool) $result;
362
+ }
363
+
364
+ }
includes/forms.php CHANGED
@@ -339,7 +339,7 @@ class iubenda_Forms {
339
  $args = wp_parse_args( $args, $defaults );
340
 
341
  // sanitize args
342
- $args['ID'] = ! empty( $args['ID'] ) ? (int) $args['ID'] : 0;
343
  $args['status'] = ! empty( $args['status'] ) && in_array( $args['status'], array_keys( $this->statuses ) ) ? $args['status'] : 'publish';
344
  $args['object_type'] = 'post';
345
  $args['object_id'] = ! empty( $args['object_id'] ) ? (int) $args['object_id'] : 0;
@@ -371,8 +371,8 @@ class iubenda_Forms {
371
  if ( ! $args['form_source'] || ! $args['form_fields'] )
372
  return false;
373
 
374
- $post = get_post( (int) $args['ID'] );
375
- $update = ! $post ? false : true;
376
 
377
  // insert new form
378
  if ( ! $update ) {
339
  $args = wp_parse_args( $args, $defaults );
340
 
341
  // sanitize args
342
+ $args['ID'] = ! empty( $args['ID'] ) ? absint( $args['ID'] ) : 0;
343
  $args['status'] = ! empty( $args['status'] ) && in_array( $args['status'], array_keys( $this->statuses ) ) ? $args['status'] : 'publish';
344
  $args['object_type'] = 'post';
345
  $args['object_id'] = ! empty( $args['object_id'] ) ? (int) $args['object_id'] : 0;
371
  if ( ! $args['form_source'] || ! $args['form_fields'] )
372
  return false;
373
 
374
+ $post = $args['ID'] !== 0 ? get_post( $args['ID'] ) : false;
375
+ $update = empty( $post ) ? false : true;
376
 
377
  // insert new form
378
  if ( ! $update ) {
includes/settings.php CHANGED
@@ -22,7 +22,7 @@ class iubenda_Settings {
22
  add_action( 'admin_init', array( $this, 'register_options' ) );
23
  add_action( 'admin_init', array( $this, 'update_plugin' ), 9 );
24
  add_action( 'admin_init', array( $this, 'admin_page_redirect' ), 20 );
25
- add_action( 'admin_init', array( $this, 'process_actions' ) );
26
  add_action( 'admin_menu', array( $this, 'admin_menu_options' ) );
27
  add_action( 'admin_notices', array( $this, 'settings_errors' ) );
28
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
@@ -45,7 +45,7 @@ class iubenda_Settings {
45
  'full_name' => __( 'string', 'iubenda' ),
46
  // 'verified' => __( 'boolean', 'iubenda' ),
47
  );
48
-
49
  $this->legal_notices = array(
50
  'privacy_policy',
51
  'cookie_policy',
@@ -67,6 +67,15 @@ class iubenda_Settings {
67
  )
68
  );
69
 
 
 
 
 
 
 
 
 
 
70
  $links = array(
71
  'en' => array(
72
  'iab' => 'https://www.iubenda.com/en/help/7440-enable-preference-management-iab-framework',
@@ -118,6 +127,7 @@ class iubenda_Settings {
118
  add_settings_field( 'iub_output_feed', __( 'RSS feed', 'iubenda' ), array( $this, 'iub_output_feed' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
119
  add_settings_field( 'iub_output_post', __( 'POST requests', 'iubenda' ), array( $this, 'iub_output_post' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
120
  add_settings_field( 'iub_menu_position', __( 'Menu position', 'iubenda' ), array( $this, 'iub_menu_position' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
 
121
  add_settings_field( 'iub_deactivation', __( 'Deactivation', 'iubenda' ), array( $this, 'iub_deactivation' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
122
 
123
  // forms list
@@ -313,13 +323,13 @@ class iubenda_Settings {
313
 
314
  // multilang support
315
  if ( ! empty( iubenda()->languages ) ) {
316
- foreach ( iubenda()->languages as $lang ) {
317
- $code = get_option( 'iubenda-code-' . $lang );
318
 
319
  if ( ! empty( $code ) ) {
320
- $options['code_' . $lang] = $code;
321
 
322
- delete_option( 'iubenda-code-' . $lang );
323
  }
324
  }
325
  }
@@ -341,6 +351,15 @@ class iubenda_Settings {
341
  }
342
 
343
  $tab_key = ! empty( $_GET['tab'] ) ? esc_attr( $_GET['tab'] ) : 'cs';
 
 
 
 
 
 
 
 
 
344
  ?>
345
  <div class="wrap">
346
 
@@ -382,6 +401,26 @@ class iubenda_Settings {
382
  </div>
383
 
384
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  // render custom notices
386
  $this->print_notices();
387
  ?>
@@ -514,18 +553,63 @@ class iubenda_Settings {
514
  </div>
515
  <div id="contextual-help-tabs-wrap-2" class="contextual-help-tabs-wrap">
516
  <div id="tab-panel-scripts" class="help-tab-content active">
517
- <textarea name="iubenda_cookie_law_solution[custom_scripts]" class="large-text" cols="50" rows="10">' . esc_textarea( implode( "\n", iubenda()->options['cs']['custom_scripts'] ) ) . '</textarea>
518
- <p class="description">' . __( 'Enter the list of custom scripts you’d like to block here (one per line)', 'iubenda' ) . '</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
519
  </div>
520
  <div id="tab-panel-iframes" class="help-tab-content">
521
- <textarea name="iubenda_cookie_law_solution[custom_iframes]" class="large-text" cols="50" rows="10">' . esc_textarea( implode( "\n", iubenda()->options['cs']['custom_iframes'] ) ) . '</textarea>
522
- <p class="description">' . __( 'Enter the list of custom iframes you’d like to block here (one per line). ', 'iubenda' ) . '</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
523
  </div>
524
  </div>
525
  </div>
526
  </div>';
527
  }
528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
529
  /**
530
  * Parsing option.
531
  *
@@ -534,7 +618,7 @@ class iubenda_Settings {
534
  public function iub_parse() {
535
  echo '
536
  <div id="iub_parse_container">
537
- <label><input id="iub_parse" type="checkbox" name="iubenda_cookie_law_solution[parse]" value="1" ' . checked( true, (bool) iubenda()->options['cs']['parse'], false ) . '/>' . __( 'Automatically block scripts detected by the plugin.', 'iubenda' ) . '</label>
538
  <p class="description">' . '(' . sprintf( __( "see <a href=\"%s\" target=\"_blank\">our documentation</a> for the list of detected scripts.", 'iubenda' ), $this->links['documentation'] ) . ')' . '</p>
539
  <div id="iub_parser_engine_container"' . ( iubenda()->options['cs']['parse'] === false ? ' style="display: none;"' : '' ) . '>
540
  <div>
@@ -544,7 +628,7 @@ class iubenda_Settings {
544
  </div>
545
  <div>
546
  <label><input id="iub_skip_parsing" type="checkbox" name="iubenda_cookie_law_solution[skip_parsing]" value="1" ' . checked( true, (bool) iubenda()->options['cs']['skip_parsing'], false ) . '/>' . __( 'Leave scripts untouched on the page if the user has already given consent', 'iubenda' ) . '</label>
547
- <p class="description">(' . __( "improves performance, highly recommended, to be deactivated only if your site uses a caching system", 'iubenda' ) . ')</p>
548
  </div>
549
  </div>
550
  </div>';
@@ -599,6 +683,60 @@ class iubenda_Settings {
599
  <p class="description">' . __( 'Select whether to display iubenda in a top admin menu or the Settings submenu.', 'iubenda' ) . '</p>
600
  </div>';
601
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
602
 
603
  /**
604
  * Deactivation option.
@@ -1027,40 +1165,87 @@ class iubenda_Settings {
1027
  $input['output_feed'] = (bool) isset( $input['output_feed'] );
1028
  $input['output_post'] = (bool) isset( $input['output_post'] );
1029
  $input['menu_position'] = isset( $input['menu_position'] ) && in_array( $input['menu_position'], array( 'topmenu', 'submenu' ) ) ? $input['menu_position'] : iubenda()->defaults['cs']['menu_position'];
 
1030
  $input['deactivation'] = (bool) isset( $input['deactivation'] );
1031
 
1032
  // multilang support
1033
  if ( iubenda()->multilang && ! empty( iubenda()->languages ) ) {
 
 
1034
  foreach ( iubenda()->languages as $lang_id => $lang_name ) {
1035
- $input['code_' . $lang_id] = ! empty( $input['code_' . $lang_id] ) ? iubenda()->parse_code( $input['code_' . $lang_id] ) : '';
1036
 
1037
  // handle default lang too
1038
  if ( $lang_id == iubenda()->lang_default ) {
1039
  $input['code_default'] = ! empty( $input['code_' . $lang_id] ) ? iubenda()->parse_code( $input['code_' . $lang_id] ) : iubenda()->options['cs']['code_default'];
1040
  }
1041
  }
1042
- } else
1043
- $input['code_default'] = ! empty( $input['code_default'] ) ? iubenda()->parse_code( $input['code_default'] ) : '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1044
 
1045
  // scripts
1046
- if ( isset( $input['custom_scripts'] ) ) {
1047
- $input['custom_scripts'] = trim( $input['custom_scripts'] );
1048
 
1049
- if ( ! empty( $input['custom_scripts'] ) )
1050
- $input['custom_scripts'] = array_map( 'trim', explode( "\n", str_replace( "\r", '', $input['custom_scripts'] ) ) );
1051
- else
1052
- $input['custom_scripts'] = array();
 
 
 
 
 
 
 
1053
  } else
1054
  $input['custom_scripts'] = array();
1055
 
1056
  // iframes
1057
- if ( isset( $input['custom_iframes'] ) ) {
1058
- $input['custom_iframes'] = trim( $input['custom_iframes'] );
1059
 
1060
- if ( ! empty( $input['custom_iframes'] ) )
1061
- $input['custom_iframes'] = array_map( 'trim', explode( "\n", str_replace( "\r", '', $input['custom_iframes'] ) ) );
1062
- else
1063
- $input['custom_iframes'] = array();
 
 
 
 
 
 
 
1064
  } else
1065
  $input['custom_iframes'] = array();
1066
 
@@ -1119,13 +1304,22 @@ class iubenda_Settings {
1119
 
1120
  if ( ! $page )
1121
  return;
 
 
 
 
 
 
 
 
 
1122
 
1123
  // add comments cookie option notice
1124
  if ( $tab_key != 'cs' && ! empty( iubenda()->options['cons']['public_api_key'] ) ) {
1125
  $cookies_enabled = get_option( 'show_comments_cookies_opt_in' );
1126
 
1127
  if ( ! $cookies_enabled ) {
1128
- iubenda()->settings->add_notice( 'iub_comment_cookies_disabled', sprintf( __( 'Please enable comments cookies opt-in checkbox in the <a href="%s" target="_blank">Discussion settings</a>.', 'iubenda' ), esc_url( admin_url( 'options-discussion.php' ) ) ), 'notice' );
1129
  }
1130
  }
1131
 
@@ -1137,23 +1331,15 @@ class iubenda_Settings {
1137
 
1138
  // new forms notice
1139
  if ( ! empty( $result['new'] ) )
1140
- iubenda()->settings->add_notice( 'iub_autodetect_success', sprintf( _n( '%d form detected successfully.', '%d forms detected successfully.', count( $result['new'] ), 'iubenda' ), $result ), 'success' );
1141
 
1142
  // forms changed notice
1143
  if ( ! empty( $result['updated'] ) )
1144
- iubenda()->settings->add_notice( 'iub_autodetect_success', sprintf( _n( '%d form change detected.', '%d form changes detected.', count( $result['updated'] ), 'iubenda' ), $result ), 'success' );
1145
 
1146
  // no changes notice
1147
  if ( empty( $result['new'] ) && empty( $result['updated'] ) )
1148
- iubenda()->settings->add_notice( 'iub_autodetect_success', __( 'No forms or form changes detected.', 'iubenda' ), 'error' );
1149
-
1150
- if ( iubenda()->options['cs']['menu_position'] === 'submenu' && $pagenow === 'admin.php' ) {
1151
- // sub menu
1152
- $redirect_to = admin_url( 'options-general.php?page=iubenda&tab=cons' );
1153
- } else {
1154
- // top menu
1155
- $redirect_to = admin_url( 'admin.php?page=iubenda&tab=cons' );
1156
- }
1157
 
1158
  // make sure it's current host location
1159
  wp_safe_redirect( $redirect_to );
@@ -1213,7 +1399,7 @@ class iubenda_Settings {
1213
 
1214
  // bail if empty fields
1215
  if ( empty( $subject ) || empty( $preferences ) ) {
1216
- iubenda()->settings->add_notice( 'iub_form_fields_missing', __( 'Form saving failed. Please fill the Subject and Preferences fields.', 'iubenda' ), 'error' );
1217
  return;
1218
  }
1219
 
@@ -1237,13 +1423,13 @@ class iubenda_Settings {
1237
  if ( $result ) {
1238
  // form save, inform about form status update
1239
  if ( empty( $form->form_subject ) && empty( $form->form_preferences ) ) {
1240
- iubenda()->settings->add_notice( 'iub_form_saved', __( 'Form saved successfully - form status changed to Mapped.', 'iubenda' ), 'success' );
1241
  // form update
1242
  } else {
1243
- iubenda()->settings->add_notice( 'iub_form_updated', __( 'Form updated successfully.', 'iubenda' ), 'success' );
1244
  }
1245
  } else {
1246
- iubenda()->settings->add_notice( 'iub_form_failed', __( 'Form saving failed.', 'iubenda' ), 'error' );
1247
  }
1248
 
1249
  break;
@@ -1260,15 +1446,30 @@ class iubenda_Settings {
1260
  $result = iubenda()->forms->delete_form( $id );
1261
 
1262
  if ( $result )
1263
- iubenda()->settings->add_notice( 'iub_form_deleted', __( 'Form deleted successfully.', 'iubenda' ), 'success' );
1264
  else
1265
- iubenda()->settings->add_notice( 'iub_form_delete_failed', __( 'Form delete failed.', 'iubenda' ), 'error' );
1266
-
1267
- $redirect_to = admin_url( 'admin.php?page=iubenda&tab=cons' );
1268
 
1269
  // make sure it's current host location
1270
  wp_safe_redirect( $redirect_to );
1271
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1272
  break;
1273
 
1274
  default :
22
  add_action( 'admin_init', array( $this, 'register_options' ) );
23
  add_action( 'admin_init', array( $this, 'update_plugin' ), 9 );
24
  add_action( 'admin_init', array( $this, 'admin_page_redirect' ), 20 );
25
+ add_action( 'admin_init', array( $this, 'process_actions' ), 20 );
26
  add_action( 'admin_menu', array( $this, 'admin_menu_options' ) );
27
  add_action( 'admin_notices', array( $this, 'settings_errors' ) );
28
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
45
  'full_name' => __( 'string', 'iubenda' ),
46
  // 'verified' => __( 'boolean', 'iubenda' ),
47
  );
48
+
49
  $this->legal_notices = array(
50
  'privacy_policy',
51
  'cookie_policy',
67
  )
68
  );
69
 
70
+ $this->tag_types = array(
71
+ 0 => __( 'Not set', 'iubenda' ),
72
+ 1 => __( 'Strictly necessary', 'iubenda' ),
73
+ 2 => __( 'Basic interactions & functionalities', 'iubenda' ),
74
+ 3 => __( 'Experience enhancement', 'iubenda' ),
75
+ 4 => __( 'Analytics', 'iubenda' ),
76
+ 5 => __( 'Targeting & Advertising', 'iubenda' )
77
+ );
78
+
79
  $links = array(
80
  'en' => array(
81
  'iab' => 'https://www.iubenda.com/en/help/7440-enable-preference-management-iab-framework',
127
  add_settings_field( 'iub_output_feed', __( 'RSS feed', 'iubenda' ), array( $this, 'iub_output_feed' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
128
  add_settings_field( 'iub_output_post', __( 'POST requests', 'iubenda' ), array( $this, 'iub_output_post' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
129
  add_settings_field( 'iub_menu_position', __( 'Menu position', 'iubenda' ), array( $this, 'iub_menu_position' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
130
+ add_settings_field( 'iub_amp_support', __( 'Google AMP', 'iubenda' ), array( $this, 'iub_amp_support' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
131
  add_settings_field( 'iub_deactivation', __( 'Deactivation', 'iubenda' ), array( $this, 'iub_deactivation' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
132
 
133
  // forms list
323
 
324
  // multilang support
325
  if ( ! empty( iubenda()->languages ) ) {
326
+ foreach ( iubenda()->languages as $lang_id => $lang_name ) {
327
+ $code = get_option( 'iubenda-code-' . $lang_id );
328
 
329
  if ( ! empty( $code ) ) {
330
+ $options['code_' . $lang_id] = $code;
331
 
332
+ delete_option( 'iubenda-code-' . $lang_id );
333
  }
334
  }
335
  }
351
  }
352
 
353
  $tab_key = ! empty( $_GET['tab'] ) ? esc_attr( $_GET['tab'] ) : 'cs';
354
+
355
+ // get redirect url
356
+ if ( iubenda()->options['cs']['menu_position'] === 'submenu' && $pagenow === 'admin.php' ) {
357
+ // sub menu
358
+ $redirect_to = admin_url( 'options-general.php?page=iubenda&tab=' . $tab_key );
359
+ } else {
360
+ // top menu
361
+ $redirect_to = admin_url( 'admin.php?page=iubenda&tab=' . $tab_key );
362
+ }
363
  ?>
364
  <div class="wrap">
365
 
401
  </div>
402
 
403
  <?php
404
+ // add per-purpose notice
405
+ if ( $tab_key === 'cs' && iubenda()->options['cs']['skip_parsing'] ) {
406
+ $iubenda_code = '';
407
+
408
+ if ( iubenda()->multilang === true && defined( 'ICL_LANGUAGE_CODE' ) && isset( iubenda()->options['cs']['code_' . ICL_LANGUAGE_CODE] ) ) {
409
+ $iubenda_code = iubenda()->options['cs']['code_' . ICL_LANGUAGE_CODE];
410
+
411
+ // no code for current language, use default
412
+ if ( ! $iubenda_code )
413
+ $iubenda_code = iubenda()->options['cs']['code_default'];
414
+ } else
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
425
  $this->print_notices();
426
  ?>
553
  </div>
554
  <div id="contextual-help-tabs-wrap-2" class="contextual-help-tabs-wrap">
555
  <div id="tab-panel-scripts" class="help-tab-content active">
556
+ <p class="description">' . __( 'Provide a list of custom scripts you’d like to block and assign their purpose.', 'iubenda' ) . '</p>
557
+ <div id="custom-script-field-template" class="template-field" style="display: none;">
558
+ <input type="text" class="regular-text" value="" name="iubenda_cookie_law_solution[custom_scripts][script][]" placeholder="' . __( 'Enter custom script', 'iubenda' ) . '" /> ' . $this->render_tag_types( 'script', 0 ) . ' <a href="#" class="remove-custom-script-field button-secondary" title="' . __( 'Remove', 'iubenda' ) . '">-</a>
559
+ </div>';
560
+
561
+ if ( ! empty( iubenda()->options['cs']['custom_scripts'] ) ) {
562
+ foreach ( iubenda()->options['cs']['custom_scripts'] as $script => $type ) {
563
+ echo '
564
+ <div class="custom-script-field">
565
+ <input type="text" class="regular-text" value="' . esc_attr( $script ) . '" name="iubenda_cookie_law_solution[custom_scripts][script][]" placeholder="' . __( 'Enter custom script', 'iubenda' ) . '" /> ' . $this->render_tag_types( 'script', $type ) . ' <a href="#" class="remove-custom-script-field button-secondary" title="' . __( 'Remove', 'iubenda' ) . '">-</a>
566
+ </div>';
567
+ }
568
+ }
569
+
570
+ echo '
571
+ <a href="#" class="add-custom-script-field button-secondary">Add New Script</a>
572
  </div>
573
  <div id="tab-panel-iframes" class="help-tab-content">
574
+ <p class="description">' . __( 'Provide a list of custom iframes you’d like to block and assign their purpose. ', 'iubenda' ) . '</p>
575
+ <div id="custom-iframe-field-template" class="template-field" style="display: none;">
576
+ <input type="text" class="regular-text" value="" name="iubenda_cookie_law_solution[custom_iframes][iframe][]" placeholder="' . __( 'Enter custom iframe', 'iubenda' ) . '" /> ' . $this->render_tag_types( 'iframe', 0 ) . ' <a href="#" class="remove-custom-iframe-field button-secondary" title="' . __( 'Remove', 'iubenda' ) . '">-</a>
577
+ </div>';
578
+
579
+ if ( ! empty( iubenda()->options['cs']['custom_iframes'] ) ) {
580
+ foreach ( iubenda()->options['cs']['custom_iframes'] as $iframe => $type ) {
581
+ echo '
582
+ <div class="custom-iframe-field">
583
+ <input type="text" class="regular-text" value="' . esc_attr( $iframe ) . '" name="iubenda_cookie_law_solution[custom_iframes][iframe][]" placeholder="' . __( 'Enter custom iframe', 'iubenda' ) . '" /> ' . $this->render_tag_types( 'iframe', $type ) . ' <a href="#" class="remove-custom-iframe-field button-secondary" title="' . __( 'Remove', 'iubenda' ) . '">-</a>
584
+ </div>';
585
+ }
586
+ }
587
+
588
+ echo '
589
+ <a href="#" class="add-custom-iframe-field button-secondary">Add New Iframe</a>
590
  </div>
591
  </div>
592
  </div>
593
  </div>';
594
  }
595
 
596
+ /**
597
+ * Prepare tag types select.
598
+ *
599
+ * @param string $type
600
+ * @param int $selected
601
+ * @return string
602
+ */
603
+ function render_tag_types( $type, $selected ) {
604
+ $html = '<select name="iubenda_cookie_law_solution[custom_' . $type . 's][type][]">';
605
+
606
+ foreach ( $this->tag_types as $tag_id => $tag_name ) {
607
+ $html .= '<option value="' . esc_attr( $tag_id ) . '" ' . selected( $selected, $tag_id, false ) . '>' . esc_html( $tag_name ) . '</option>';
608
+ }
609
+
610
+ return $html . '</select>';
611
+ }
612
+
613
  /**
614
  * Parsing option.
615
  *
618
  public function iub_parse() {
619
  echo '
620
  <div id="iub_parse_container">
621
+ <label><input id="iub_parse" type="checkbox" name="iubenda_cookie_law_solution[parse]" value="1" ' . checked( true, (bool) iubenda()->options['cs']['parse'], false ) . '/>' . __( 'Automatically block scripts detected by the plugin', 'iubenda' ) . '</label>
622
  <p class="description">' . '(' . sprintf( __( "see <a href=\"%s\" target=\"_blank\">our documentation</a> for the list of detected scripts.", 'iubenda' ), $this->links['documentation'] ) . ')' . '</p>
623
  <div id="iub_parser_engine_container"' . ( iubenda()->options['cs']['parse'] === false ? ' style="display: none;"' : '' ) . '>
624
  <div>
628
  </div>
629
  <div>
630
  <label><input id="iub_skip_parsing" type="checkbox" name="iubenda_cookie_law_solution[skip_parsing]" value="1" ' . checked( true, (bool) iubenda()->options['cs']['skip_parsing'], false ) . '/>' . __( 'Leave scripts untouched on the page if the user has already given consent', 'iubenda' ) . '</label>
631
+ <p class="description">(' . __( "improves performance, highly recommended, to be deactivated only if your site uses a caching system or if you're collecting per-category consent.", 'iubenda' ) . ')</p>
632
  </div>
633
  </div>
634
  </div>';
683
  <p class="description">' . __( 'Select whether to display iubenda in a top admin menu or the Settings submenu.', 'iubenda' ) . '</p>
684
  </div>';
685
  }
686
+
687
+ /**
688
+ * Google AMP support option.
689
+ *
690
+ * @return mixed
691
+ */
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 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;"' : '' ) . '>';
704
+ if ( empty( iubenda()->options['cs']['amp_template_done'] ) ) {
705
+ echo '
706
+ <p class="description">' . __( 'No file available. Save changes to generate iubenda AMP configuration file.', 'iubenda' ) . '</p>';
707
+ } else {
708
+ // multilang support
709
+ if ( iubenda()->multilang && ! empty( iubenda()->languages ) ) {
710
+ foreach ( iubenda()->languages as $lang_id => $lang_name ) {
711
+ echo $lang_name . ':
712
+ <a href="' . iubenda()->AMP->get_amp_template_url( $lang_id ) . '" target="_blank">' . iubenda()->AMP->get_amp_template_url( $lang_id ) . '</a><br />';
713
+ }
714
+ } else {
715
+ echo '
716
+ <a href="' . iubenda()->AMP->get_amp_template_url() . '" target="_blank">' . iubenda()->AMP->get_amp_template_url() . '</a>';
717
+ }
718
+ }
719
+ echo '
720
+ </div>
721
+ <div id="iub_amp_template-remote"' . ( iubenda()->options['cs']['amp_source'] === 'local' ? ' style="display: none;"' : '' ) . '>';
722
+
723
+ // multilang support
724
+ if ( iubenda()->multilang && ! empty( iubenda()->languages ) ) {
725
+ foreach ( iubenda()->languages as $lang_id => $lang_name ) {
726
+ echo $lang_name . ':
727
+ <label><input id="iub_amp_template-' . $lang_id . '" type="text" class="regular-text" name="iubenda_cookie_law_solution[amp_template][' . $lang_id . ']" value="' . ( isset( iubenda()->options['cs']['amp_template'][$lang_id] ) ? esc_url( iubenda()->options['cs']['amp_template'][$lang_id] ) : '' ) . '" /></label><br />';
728
+ }
729
+ } else {
730
+ echo '
731
+ <label><input id="iub_amp_template" type="text" class="regular-text" name="iubenda_cookie_law_solution[amp_template]" value="' . ( isset( iubenda()->options['cs']['amp_template'] ) ? esc_url( iubenda()->options['cs']['amp_template'] ) : '' ) . '" /></label>';
732
+ }
733
+ echo '
734
+ <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>
735
+ </div>
736
+ <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>
737
+ </div>
738
+ </div>';
739
+ }
740
 
741
  /**
742
  * Deactivation option.
1165
  $input['output_feed'] = (bool) isset( $input['output_feed'] );
1166
  $input['output_post'] = (bool) isset( $input['output_post'] );
1167
  $input['menu_position'] = isset( $input['menu_position'] ) && in_array( $input['menu_position'], array( 'topmenu', 'submenu' ) ) ? $input['menu_position'] : iubenda()->defaults['cs']['menu_position'];
1168
+ $input['amp_support'] = (bool) isset( $input['amp_support'] );
1169
  $input['deactivation'] = (bool) isset( $input['deactivation'] );
1170
 
1171
  // multilang support
1172
  if ( iubenda()->multilang && ! empty( iubenda()->languages ) ) {
1173
+ $iubenda_code = array();
1174
+
1175
  foreach ( iubenda()->languages as $lang_id => $lang_name ) {
1176
+ $input['code_' . $lang_id] = $iubenda_code[$lang_id] = ! empty( $input['code_' . $lang_id] ) ? iubenda()->parse_code( $input['code_' . $lang_id] ) : '';
1177
 
1178
  // handle default lang too
1179
  if ( $lang_id == iubenda()->lang_default ) {
1180
  $input['code_default'] = ! empty( $input['code_' . $lang_id] ) ? iubenda()->parse_code( $input['code_' . $lang_id] ) : iubenda()->options['cs']['code_default'];
1181
  }
1182
  }
1183
+ } else {
1184
+ $iubenda_code = '';
1185
+
1186
+ $input['code_default'] = $iubenda_code = ! empty( $input['code_default'] ) ? iubenda()->parse_code( $input['code_default'] ) : '';
1187
+ }
1188
+
1189
+ // generate amp template file
1190
+ if ( isset( $input['amp_support'] ) ) {
1191
+ $template_done = false;
1192
+
1193
+ if ( ! empty( $iubenda_code ) ) {
1194
+ if ( is_array( $iubenda_code ) ) {
1195
+ $template_done = array();
1196
+
1197
+ foreach ( $iubenda_code as $lang => $code ) {
1198
+ $template_done[$lang] = (bool) iubenda()->AMP->generate_amp_template( $code, $lang );
1199
+ }
1200
+ } else {
1201
+ $template_done = (bool) iubenda()->AMP->generate_amp_template( $iubenda_code );
1202
+ }
1203
+ }
1204
+
1205
+ $input['amp_template_done'] = $template_done;
1206
+
1207
+ if ( is_array( $input['amp_template'] ) ) {
1208
+ foreach ( $input['amp_template'] as $lang => $template ) {
1209
+ $input['amp_template'][$lang] = esc_url( $template );
1210
+ }
1211
+ } else {
1212
+ $input['amp_template'] = esc_url( $input['amp_template'] );
1213
+ }
1214
+ }
1215
 
1216
  // scripts
1217
+ if ( ! empty( $input['custom_scripts'] ) && ! empty( $input['custom_scripts']['script'] ) && ! empty( $input['custom_scripts']['type'] ) ) {
1218
+ $scripts = array();
1219
 
1220
+ // first field is template
1221
+ if ( count( $input['custom_scripts']['script'] ) > 1 ) {
1222
+ foreach ( $input['custom_scripts']['script'] as $number => $script ) {
1223
+ $trimmed = trim( $script );
1224
+
1225
+ if ( $trimmed !== '' )
1226
+ $scripts[$trimmed] = (int) $input['custom_scripts']['type'][$number];
1227
+ }
1228
+ }
1229
+
1230
+ $input['custom_scripts'] = $scripts;
1231
  } else
1232
  $input['custom_scripts'] = array();
1233
 
1234
  // iframes
1235
+ if ( ! empty( $input['custom_iframes'] ) && ! empty( $input['custom_iframes']['iframe'] ) && ! empty( $input['custom_iframes']['type'] ) ) {
1236
+ $iframes = array();
1237
 
1238
+ // first field is template
1239
+ if ( count( $input['custom_iframes']['iframe'] ) > 1 ) {
1240
+ foreach ( $input['custom_iframes']['iframe'] as $number => $iframe ) {
1241
+ $trimmed = trim( $iframe );
1242
+
1243
+ if ( $trimmed !== '' )
1244
+ $iframes[$trimmed] = (int) $input['custom_iframes']['type'][$number];
1245
+ }
1246
+ }
1247
+
1248
+ $input['custom_iframes'] = $iframes;
1249
  } else
1250
  $input['custom_iframes'] = array();
1251
 
1304
 
1305
  if ( ! $page )
1306
  return;
1307
+
1308
+ // get redirect url
1309
+ if ( iubenda()->options['cs']['menu_position'] === 'submenu' && $pagenow === 'admin.php' ) {
1310
+ // sub menu
1311
+ $redirect_to = admin_url( 'options-general.php?page=iubenda&tab=' . $tab_key );
1312
+ } else {
1313
+ // top menu
1314
+ $redirect_to = admin_url( 'admin.php?page=iubenda&tab=' . $tab_key );
1315
+ }
1316
 
1317
  // add comments cookie option notice
1318
  if ( $tab_key != 'cs' && ! empty( iubenda()->options['cons']['public_api_key'] ) ) {
1319
  $cookies_enabled = get_option( 'show_comments_cookies_opt_in' );
1320
 
1321
  if ( ! $cookies_enabled ) {
1322
+ $this->add_notice( 'iub_comment_cookies_disabled', sprintf( __( 'Please enable comments cookies opt-in checkbox in the <a href="%s" target="_blank">Discussion settings</a>.', 'iubenda' ), esc_url( admin_url( 'options-discussion.php' ) ) ), 'notice' );
1323
  }
1324
  }
1325
 
1331
 
1332
  // new forms notice
1333
  if ( ! empty( $result['new'] ) )
1334
+ $this->add_notice( 'iub_autodetect_success', sprintf( _n( '%d form detected successfully.', '%d forms detected successfully.', count( $result['new'] ), 'iubenda' ), $result ), 'success' );
1335
 
1336
  // forms changed notice
1337
  if ( ! empty( $result['updated'] ) )
1338
+ $this->add_notice( 'iub_autodetect_success', sprintf( _n( '%d form change detected.', '%d form changes detected.', count( $result['updated'] ), 'iubenda' ), $result ), 'success' );
1339
 
1340
  // no changes notice
1341
  if ( empty( $result['new'] ) && empty( $result['updated'] ) )
1342
+ $this->add_notice( 'iub_autodetect_success', __( 'No forms or form changes detected.', 'iubenda' ), 'error' );
 
 
 
 
 
 
 
 
1343
 
1344
  // make sure it's current host location
1345
  wp_safe_redirect( $redirect_to );
1399
 
1400
  // bail if empty fields
1401
  if ( empty( $subject ) || empty( $preferences ) ) {
1402
+ $this->add_notice( 'iub_form_fields_missing', __( 'Form saving failed. Please fill the Subject and Preferences fields.', 'iubenda' ), 'error' );
1403
  return;
1404
  }
1405
 
1423
  if ( $result ) {
1424
  // form save, inform about form status update
1425
  if ( empty( $form->form_subject ) && empty( $form->form_preferences ) ) {
1426
+ $this->add_notice( 'iub_form_saved', __( 'Form saved successfully - form status changed to Mapped.', 'iubenda' ), 'success' );
1427
  // form update
1428
  } else {
1429
+ $this->add_notice( 'iub_form_updated', __( 'Form updated successfully.', 'iubenda' ), 'success' );
1430
  }
1431
  } else {
1432
+ $this->add_notice( 'iub_form_failed', __( 'Form saving failed.', 'iubenda' ), 'error' );
1433
  }
1434
 
1435
  break;
1446
  $result = iubenda()->forms->delete_form( $id );
1447
 
1448
  if ( $result )
1449
+ $this->add_notice( 'iub_form_deleted', __( 'Form deleted successfully.', 'iubenda' ), 'success' );
1450
  else
1451
+ $this->add_notice( 'iub_form_delete_failed', __( 'Form delete failed.', 'iubenda' ), 'error' );
 
 
1452
 
1453
  // make sure it's current host location
1454
  wp_safe_redirect( $redirect_to );
1455
+ exit;
1456
+
1457
+ break;
1458
+
1459
+ case 'disable_skip_parsing' :
1460
+
1461
+ // disable skip parsing option
1462
+ $options = iubenda()->options['cs'];
1463
+ $options['skip_parsing'] = false;
1464
+
1465
+ update_option( 'iubenda_cookie_law_solution', $options );
1466
+
1467
+ $this->add_notice( 'iub_settings_updated', __( 'Settings saved.', 'iubenda' ), 'success' );
1468
+
1469
+ // make sure it's current host location
1470
+ wp_safe_redirect( $redirect_to );
1471
+ exit;
1472
+
1473
  break;
1474
 
1475
  default :
iubenda-cookie-class/README.md CHANGED
@@ -98,6 +98,13 @@ These operations take place in accordance with the rules explained in [this guid
98
 
99
  ## Changelog
100
 
 
 
 
 
 
 
 
101
  ##### 3.4.0
102
  * New: Introducing wildcard support for scripts and iframes
103
 
98
 
99
  ## Changelog
100
 
101
+ ##### 4.1.0
102
+ * New: Google AMP support
103
+
104
+ ##### 4.0.0
105
+ * New: Per-purpose script blocking support
106
+ * New: Reject button support
107
+
108
  ##### 3.4.0
109
  * New: Introducing wildcard support for scripts and iframes
110
 
iubenda-cookie-class/iubenda.class.php CHANGED
@@ -3,9 +3,9 @@
3
  * iubenda.class.php
4
  *
5
  * @author iubenda s.r.l
6
- * @copyright 2018-2019, iubenda s.r.l
7
  * @license GNU/GPL
8
- * @version 3.4.0
9
  * @deprecated
10
  *
11
  * This program is free software: you can redistribute it and/or modify
@@ -27,118 +27,117 @@ class iubendaParser {
27
  // variables
28
  const IUB_REGEX_PATTERN = '/<!--\s*IUB_COOKIE_POLICY_START\s*-->(.*?)<!--\s*IUB_COOKIE_POLICY_END\s*-->/s';
29
  const IUB_REGEX_PATTERN_2 = '/<!--\s*IUB-COOKIE-BLOCK-START\s*-->(.*?)<!--\s*IUB-COOKIE-BLOCK-END\s*-->/s';
 
30
  const IUB_REGEX_SKIP_PATTERN = '/<!--\s*IUB-COOKIE-BLOCK-SKIP-START\s*-->(.*?)<!--\s*IUB-COOKIE-BLOCK-SKIP-END\s*-->/s';
31
 
32
  // scripts
33
- public $auto_script_tags = array(
34
- // google
35
- 'apis.google.com/js/plusone.js',
36
- 'apis.google.com/js/client/plusone.js',
37
- 'apis.google.com/js/platform.js',
38
- 'apis.google.com/js/api.js', // oauth
39
- 'cse.google.com/cse.js', // site search
40
- 'googlesyndication.com/pagead/js/adsbygoogle.js',
41
- 'googlesyndication.com/pagead/show_ads.js',
42
- 'googleadservices.com/pagead/conversion.js',
43
- 'googletagmanager.com/gtm.js',
44
- 'www.googletagmanager.com/gtag/js',
45
- 'google.com/recaptcha/',
46
- 'www.youtube.com/iframe_api',
47
- 'youtu.be',
48
- 'window.adsbygoogle',
49
- // twitter
50
- 'platform.twitter.com/widgets.js',
51
- 'static.ads-twitter.com',
52
- // facebook
53
- 'connect.facebook.net',
54
- // instagram
55
- 'instawidget.net/js/instawidget.js',
56
- // sharethis
57
- 'sharethis.com/button/buttons.js',
58
- // addthis
59
- 'addthis.com/js/',
60
- // disqus
61
- 'disqus.com/embed.js',
62
- // linkedin
63
- 'platform.linkedin.com/in.js',
64
- // scorecardresearch
65
- 'scorecardresearch.com/beacon.js',
66
- // neodata
67
- 'neodatagroup.com',
68
- // criteo
69
- 'static.criteo.net/js/',
70
- // adagio
71
- 'adagionet.com/uploads/js/sipra.js',
72
- // rainbowtgx
73
- 'cdn-wx.rainbowtgx.com/rtgx.js',
74
- // pinterest
75
- 'pinterest.com/js/pinit.js',
76
- // linkpulse
77
- 'lp4.io',
78
- // optimizely
79
- 'cdn.optimizely.com/js/',
80
- // getsatisfaction
81
- 'loader.engage.gsfn.us/loader.js',
82
- // outbrain
83
- 'outbrain.js',
84
- // headway
85
- 'headwayapp.co/widget.js',
86
- // codepen
87
- 'codepen.io',
88
- // freshchat
89
- 'wchat.freshchat.com',
90
- // uservoice
91
- 'widget.uservoice.com',
92
- 'UserVoice.push',
93
- // adroll
94
- 's.adroll.com',
95
- // olark
96
- 'static.olark.com/jsclient/loader0.js',
97
- // cxense
98
- 'scdn.cxense.com',
99
- // segment
100
- 'cdn.segment.io/analytics.js',
101
- 'cdn.segment.com/analytics.js',
102
- // kissmetrics
103
- 'i.kissmetrics.com/i.js',
104
- // mixpanel
105
- 'cdn.mxpnl.com',
106
- // pingdom
107
- 'rum-static.pingdom.net/prum.min.js',
108
- // bing
109
- 'bat.bing.com',
110
- // elevio
111
- 'cdn.elev.io',
112
- // paypal
113
- 'paypalobjects.com/js/external/api.js', // paypal login
114
- 'paypalobjects.com/api/checkout.js', // paypal checkout
115
- );
116
 
117
  // iframes
118
- public $auto_iframe_tags = array(
119
- // google
120
- 'apis.google.com',
121
- 'maps.google.it/maps',
122
- 'maps.google.com/maps',
123
- 'www.google.com/maps/embed',
124
- 'googletagmanager.com/ns.html',
125
- 'window.adsbygoogle',
126
- // youtube
127
- 'youtube.com',
128
- // twitter
129
- 'platform.twitter.com',
130
- // facebook
131
- 'www.facebook.com/plugins/like.php',
132
- 'www.facebook.com/*/plugins/like.php',
133
- 'www.facebook.com/plugins/likebox.php',
134
- 'www.facebook.com/*/plugins/likebox.php',
135
- // vimeo
136
- 'player.vimeo.com',
137
- // 4w
138
- '4wnet.com'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  );
140
 
141
  private $type = 'page';
 
142
  public $iub_comments_detected = array();
143
  public $skipped_comments_detected = array();
144
  public $iframes_skipped = array();
@@ -162,18 +161,11 @@ class iubendaParser {
162
  * @param array $args
163
  */
164
  public function __construct( $content_page = '', $args = array() ) {
165
- // check scripts
166
- if ( ! empty( $args['scripts'] ) && is_array( $args['scripts'] ) ) {
167
- $this->auto_script_tags = array_unique( array_merge( $this->auto_script_tags, $args['scripts'] ) );
168
- }
169
-
170
- // check iframes
171
- if ( ! empty( $args['iframes'] ) && is_array( $args['iframes'] ) ) {
172
- $this->auto_iframe_tags = array_unique( array_merge( $this->auto_iframe_tags, $args['iframes'] ) );
173
- }
174
-
175
  // valid type?
176
  $this->type = ! empty( $args['type'] ) && in_array( $args['type'], array( 'page', 'faster' ), true ) ? $args['type'] : 'page';
 
 
 
177
 
178
  // load Simple HTML DOM if needed
179
  if ( ! function_exists( 'file_get_html' ) || ! function_exists( 'str_get_html' ) )
@@ -182,6 +174,49 @@ class iubendaParser {
182
  // set content
183
  $this->original_content_page = $content_page;
184
  $this->content_page = $content_page;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  }
186
 
187
  /**
@@ -199,45 +234,123 @@ class iubendaParser {
199
  * @return boolean
200
  */
201
  static function consent_given() {
 
 
202
  foreach ( $_COOKIE as $key => $value ) {
203
- if ( self::strpos_array( $key, array( '_iub_cs-s', '_iub_cs' ) ) )
204
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  }
206
 
207
- return false;
208
  }
209
 
210
  /**
211
- * Static, utility function: strpos for array wilth wildcard support
212
  *
213
- * @param type $haystack
214
- * @param type $needle
215
- * @return boolean
216
  */
217
- static function strpos_array( $haystack, $needle ) {
218
- if ( empty( $haystack ) || empty( $needle ) )
219
- return false;
220
 
221
- $needle = ! is_array( $needle ) ? array( $needle ) : $needle;
222
-
223
- foreach ( $needle as $need ) {
224
- // wildcard?
225
- if ( strpos( $need, '/*/' ) !== false ) {
226
- // strtok - removes query string
227
- // str_replace - removes double slashes // from url
228
- // preg_replace - removes http or https from url
229
- $haystack = strtok( str_replace( '//', '', preg_replace( "(^https?://)", "", $haystack ) ), '?' );
230
-
231
- if ( fnmatch( $need, $haystack ) !== false )
232
- return true;
233
- // regular
234
- } else {
235
- if ( strpos( $haystack, $need ) !== false )
236
- return true;
237
  }
238
  }
239
-
240
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  }
242
 
243
  /**
@@ -246,7 +359,7 @@ class iubendaParser {
246
  * @param mixed $content
247
  * @return mixed
248
  */
249
- public function create_tags( $content ) {
250
  $elements = $content->find( "*" );
251
  $js = '';
252
 
@@ -258,6 +371,13 @@ class iubendaParser {
258
 
259
  switch ( $e->tag ) {
260
  case 'script':
 
 
 
 
 
 
 
261
  $class = $e->class;
262
  $e->class = $class . ' ' . $this->iub_class;
263
  $e->type = 'text/plain';
@@ -265,6 +385,13 @@ class iubendaParser {
265
  break;
266
 
267
  case 'iframe':
 
 
 
 
 
 
 
268
  $new_src = $this->iub_empty;
269
  $class = $e->class;
270
  $e->suppressedsrc = $e->src;
@@ -274,7 +401,7 @@ class iubendaParser {
274
  break;
275
 
276
  default:
277
- $js = $e->outertext;
278
  break;
279
  }
280
  }
@@ -301,11 +428,6 @@ class iubendaParser {
301
 
302
  switch ( $element->tag ) {
303
  case 'script':
304
- $class = trim( $element->class );
305
- $element->class = ( $class !== '' ? $class . ' ' : '' ) . $this->iub_class_skip;
306
- $js .= $element->outertext;
307
- break;
308
-
309
  case 'iframe':
310
  $class = trim( $element->class );
311
  $element->class = ( $class !== '' ? $class . ' ' : '' ) . $this->iub_class_skip;
@@ -331,15 +453,18 @@ class iubendaParser {
331
  public function parse_scripts() {
332
  switch ( $this->type ) {
333
  case 'page':
334
- $html = str_get_html( $this->content_page, $lowercase = true, $force_tags_closed = true, $strip = false );
 
335
 
336
  if ( is_object( $html ) ) {
 
337
  $scripts = $html->find( 'script' );
338
 
339
  if ( is_array( $scripts ) ) {
340
  $count = count( $scripts );
341
  $class_skip = $this->iub_class_skip;
342
 
 
343
  for ( $j = 0; $j < $count; $j ++ ) {
344
  $s = $scripts[$j];
345
  $script_class = trim( $s->class );
@@ -360,8 +485,10 @@ class iubendaParser {
360
 
361
  if ( ! empty( $s->innertext ) ) {
362
  $this->scripts_inline_detected[] = $s->innertext;
 
 
363
 
364
- if ( self::strpos_array( $s->innertext, $this->auto_script_tags ) !== false ) {
365
  $class = $s->class;
366
  $s->class = $class . ' ' . $this->iub_class_inline;
367
  $s->type = 'text/plain';
@@ -372,11 +499,21 @@ class iubendaParser {
372
 
373
  if ( $src ) {
374
  $this->scripts_detected[] = $src;
 
 
375
 
376
- if ( self::strpos_array( $src, $this->auto_script_tags ) !== false ) {
377
  $class = $s->class;
378
  $s->class = $class . ' ' . $this->iub_class;
379
  $s->type = 'text/plain';
 
 
 
 
 
 
 
 
380
  $this->scripts_converted[] = $src;
381
  }
382
  }
@@ -523,16 +660,30 @@ class iubendaParser {
523
  // add inline script as detected
524
  if ( ! empty( $script->nodeValue ) )
525
  $this->scripts_inline_detected[] = $script->nodeValue;
 
 
 
526
 
527
- if ( self::strpos_array( $src, $script_tags ) ) {
528
  $script->setAttribute( 'type', 'text/plain' );
529
  $script->setAttribute( 'class', $script->getAttribute( 'class' ) . ' ' . $class );
 
 
 
 
 
 
 
530
 
531
  // add script as converted
532
  $this->scripts_converted[] = $src;
533
- } elseif ( self::strpos_array( $script->nodeValue, $script_tags ) ) {
534
  $script->setAttribute( 'type', 'text/plain' );
535
  $script->setAttribute( 'class', $script->getAttribute( 'class' ) . ' ' . $class_inline );
 
 
 
 
536
 
537
  // add inline script as converted
538
  $this->scripts_inline_converted[] = $script->nodeValue;
@@ -560,7 +711,7 @@ class iubendaParser {
560
  public function parse_iframes() {
561
  switch ( $this->type ) {
562
  case 'page':
563
- $html = str_get_html( $this->content_page, $lowercase = true, $force_tags_closed = true, $strip = false );
564
 
565
  if ( is_object( $html ) ) {
566
  $iframes = $html->find( 'iframe' );
@@ -587,11 +738,21 @@ class iubendaParser {
587
  $src = $i->src;
588
  $this->iframes_detected[] = $src;
589
 
590
- if ( self::strpos_array( $src, $this->auto_iframe_tags ) !== false ) {
 
 
591
  $class = $i->class;
592
  $i->suppressedsrc = $src;
593
  $i->src = $this->iub_empty;
594
  $i->class = $class . ' ' . $this->iub_class;
 
 
 
 
 
 
 
 
595
  $this->iframes_converted[] = $src;
596
  }
597
  }
@@ -642,11 +803,20 @@ class iubendaParser {
642
 
643
  // add iframe as detected
644
  $this->iframes_detected[] = $src;
 
 
645
 
646
- if ( self::strpos_array( $src, $iframe_tags ) ) {
647
  $iframe->setAttribute( 'src', $empty );
648
  $iframe->setAttribute( 'suppressedsrc', $src );
649
  $iframe->setAttribute( 'class', $iframe_class . ' ' . $class );
 
 
 
 
 
 
 
650
 
651
  // add iframe as converted
652
  $this->iframes_converted[] = $src;
@@ -685,7 +855,7 @@ class iubendaParser {
685
  // get HTML dom from string
686
  $html = str_get_html( $scripts[1][$j], true, true, false );
687
 
688
- // skip scripts and iframes inside IUBENDAs comments
689
  $js_scripts[] = $this->skip_tags( $html );
690
  }
691
 
@@ -696,26 +866,40 @@ class iubendaParser {
696
  unset( $scripts );
697
 
698
  // block
699
- foreach ( array( 'IUB_REGEX_PATTERN', 'IUB_REGEX_PATTERN_2' ) as $pattern ) {
700
  preg_match_all( constant( 'self::' . $pattern ), $this->content_page, $scripts );
701
 
 
 
 
 
 
 
 
 
 
 
 
702
  // found any content?
703
- if ( is_array( $scripts[1] ) ) {
704
- $count = count( $scripts[1] );
705
  $js_scripts = array();
706
 
707
  for ( $j = 0; $j < $count; $j++ ) {
708
- $this->iub_comments_detected[] = $scripts[1][$j];
709
 
710
  // get HTML dom from string
711
- $html = str_get_html( $scripts[1][$j], $lowercase = true, $force_tags_closed = true, $strip = false );
 
 
 
712
 
713
  // convert scripts, iframes and other code inside IUBENDAs comment in text/plain to not generate cookies
714
- $js_scripts[] = $this->create_tags( $html );
715
  }
716
 
717
- if ( ( is_array( $scripts[1] ) && is_array( $js_scripts ) ) && ( $count >= 1 && count( $js_scripts ) >= 1 ) )
718
- $this->content_page = strtr( $this->content_page, array_combine( $scripts[1], $js_scripts ) );
719
  }
720
  }
721
  }
@@ -753,16 +937,88 @@ class iubendaParser {
753
  <script>
754
  var iCallback = function(){};
755
 
756
- if ('callback' in _iub.csConfiguration) {
757
- if ('onConsentGiven' in _iub.csConfiguration.callback)
758
  iCallback = _iub.csConfiguration.callback.onConsentGiven;
759
 
760
  _iub.csConfiguration.callback.onConsentGiven = function() {
761
  iCallback();
762
 
763
- jQuery('noscript._no_script_iub').each(function (a, b) { var el = jQuery(b); el.after(el.html()); });
764
  };
765
  };
766
  </script>";
767
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
768
  }
3
  * iubenda.class.php
4
  *
5
  * @author iubenda s.r.l
6
+ * @copyright 2018-2020, iubenda s.r.l
7
  * @license GNU/GPL
8
+ * @version 4.1.0
9
  * @deprecated
10
  *
11
  * This program is free software: you can redistribute it and/or modify
27
  // variables
28
  const IUB_REGEX_PATTERN = '/<!--\s*IUB_COOKIE_POLICY_START\s*-->(.*?)<!--\s*IUB_COOKIE_POLICY_END\s*-->/s';
29
  const IUB_REGEX_PATTERN_2 = '/<!--\s*IUB-COOKIE-BLOCK-START\s*-->(.*?)<!--\s*IUB-COOKIE-BLOCK-END\s*-->/s';
30
+ const IUB_REGEX_PURPOSE_PATTERN = '/<!--\s*IUB-COOKIE-BLOCK-START-PURPOSE-(\d+)\s*-->(.*?)<!--\s*IUB-COOKIE-BLOCK-END-PURPOSE-\d+\s*-->/s';
31
  const IUB_REGEX_SKIP_PATTERN = '/<!--\s*IUB-COOKIE-BLOCK-SKIP-START\s*-->(.*?)<!--\s*IUB-COOKIE-BLOCK-SKIP-END\s*-->/s';
32
 
33
  // scripts
34
+ public $auto_script_tags = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  // iframes
37
+ public $auto_iframe_tags = array();
38
+
39
+ // purposes
40
+ public $purposes = array();
41
+
42
+ // per-purpose scripts
43
+ public $script_tags = array(
44
+ // Strictly necessary
45
+ 1 => array(),
46
+ // Basic interactions & functionalities
47
+ 2 => array(
48
+ 'apis.google.com/js/api.js',
49
+ 'cse.google.com/cse.js',
50
+ 'googletagmanager.com/gtm.js',
51
+ 'loader.engage.gsfn.us/loader.js',
52
+ 'headwayapp.co/widget.js',
53
+ 'wchat.freshchat.com',
54
+ 'widget.uservoice.com',
55
+ 'UserVoice.push',
56
+ 'static.olark.com/jsclient/loader0.js',
57
+ 'cdn.elev.io',
58
+ 'paypalobjects.com/js/external/api.js',
59
+ 'paypalobjects.com/api/checkout.js'
60
+ ),
61
+ // Experience enhancement
62
+ 3 => array(
63
+ 'apis.google.com/js/plusone.js',
64
+ 'apis.google.com/js/client/plusone.js',
65
+ 'apis.google.com/js/platform.js',
66
+ 'www.youtube.com/iframe_api',
67
+ 'youtu.be',
68
+ 'platform.twitter.com/widgets.js',
69
+ 'instawidget.net/js/instawidget.js',
70
+ 'disqus.com/embed.js',
71
+ 'platform.linkedin.com/in.js',
72
+ 'pinterest.com/js/pinit.js',
73
+ 'codepen.io',
74
+ 'bat.bing.com'
75
+ ),
76
+ // Analytics
77
+ 4 => array(
78
+ 'sharethis.com/button/buttons.js',
79
+ 'addthis.com/js/',
80
+ 'scorecardresearch.com/beacon.js',
81
+ 'neodatagroup.com',
82
+ 'lp4.io',
83
+ 'cdn.optimizely.com/js/',
84
+ 'cdn.segment.io/analytics.js',
85
+ 'cdn.segment.com/analytics.js',
86
+ 'i.kissmetrics.com/i.js',
87
+ 'cdn.mxpnl.com',
88
+ 'rum-static.pingdom.net/prum.min.js'
89
+ ),
90
+ // Targeting & Advertising
91
+ 5 => array(
92
+ 'googlesyndication.com/pagead/js/adsbygoogle.js',
93
+ 'googlesyndication.com/pagead/show_ads.js',
94
+ 'googleadservices.com/pagead/conversion.js',
95
+ 'www.googletagmanager.com/gtag/js',
96
+ 'window.adsbygoogle',
97
+ 'static.ads-twitter.com',
98
+ 'connect.facebook.net',
99
+ 'static.criteo.net/js/',
100
+ 'adagionet.com/uploads/js/sipra.js',
101
+ 'cdn-wx.rainbowtgx.com/rtgx.js',
102
+ 'outbrain.js',
103
+ 's.adroll.com',
104
+ 'scdn.cxense.com'
105
+ )
106
+ );
107
+
108
+ // per-purpose iframes
109
+ public $iframe_tags = array(
110
+ // Strictly necessary
111
+ 1 => array(),
112
+ // Basic interactions & functionalities
113
+ 2 => array(
114
+ 'googletagmanager.com/ns.html'
115
+ ),
116
+ // Experience enhancement
117
+ 3 => array(
118
+ 'apis.google.com',
119
+ 'maps.google.it/maps',
120
+ 'maps.google.com/maps',
121
+ 'www.google.com/maps/embed',
122
+ 'youtube.com',
123
+ 'platform.twitter.com',
124
+ 'player.vimeo.com',
125
+ 'www.facebook.com/plugins/like.php',
126
+ 'www.facebook.com/*/plugins/like.php',
127
+ 'www.facebook.com/plugins/likebox.php',
128
+ 'www.facebook.com/*/plugins/likebox.php'
129
+ ),
130
+ // Analytics
131
+ 4 => array(),
132
+ // Targeting & Advertising
133
+ 5 => array(
134
+ 'window.adsbygoogle',
135
+ '4wnet.com'
136
+ )
137
  );
138
 
139
  private $type = 'page';
140
+ private $amp = false;
141
  public $iub_comments_detected = array();
142
  public $skipped_comments_detected = array();
143
  public $iframes_skipped = array();
161
  * @param array $args
162
  */
163
  public function __construct( $content_page = '', $args = array() ) {
 
 
 
 
 
 
 
 
 
 
164
  // valid type?
165
  $this->type = ! empty( $args['type'] ) && in_array( $args['type'], array( 'page', 'faster' ), true ) ? $args['type'] : 'page';
166
+
167
+ // amp support>
168
+ $this->amp = (bool) ( isset( $args['amp'] ) && $args['amp'] === true );
169
 
170
  // load Simple HTML DOM if needed
171
  if ( ! function_exists( 'file_get_html' ) || ! function_exists( 'str_get_html' ) )
174
  // set content
175
  $this->original_content_page = $content_page;
176
  $this->content_page = $content_page;
177
+
178
+ // get purposes
179
+ $this->purposes = self::get_purposes();
180
+
181
+ // check for additional scripts
182
+ if ( ! empty( $args['scripts'] ) && is_array( $args['scripts'] ) ) {
183
+ // array is not multidimensional, backward compatibility, so block it
184
+ if ( ! is_array( reset( $args['scripts'] ) ) ) {
185
+ $this->auto_script_tags = array_merge( $this->auto_script_tags, $args['scripts'] );
186
+ // array is multidimensional, assign per purpose
187
+ } else {
188
+ // block unassigned script
189
+ if ( array_key_exists( 0, $args['scripts'] ) ) {
190
+ $this->auto_script_tags = array_merge( $this->auto_script_tags, $args['scripts'][0] );
191
+ unset( $args['scripts'][0] );
192
+ }
193
+
194
+ $this->script_tags = $this->array_merge_custom( $this->script_tags, $args['scripts'] );
195
+ }
196
+ }
197
+
198
+ // check for additional iframes
199
+ if ( ! empty( $args['iframes'] ) && is_array( $args['iframes'] ) ) {
200
+ // array is not multidimensional, backward compatibility, so assign block it
201
+ if ( ! is_array( reset( $args['iframes'] ) ) ) {
202
+ $this->auto_iframe_tags = array_merge( $this->auto_iframe_tags, $args['iframes'] );
203
+ // array is multidimensional, assign per purpose
204
+ } else {
205
+ // block unassigned script
206
+ if ( array_key_exists( 0, $args['iframes'] ) ) {
207
+ $this->auto_iframe_tags = array_merge( $this->auto_iframe_tags, $args['iframes'][0] );
208
+ unset( $args['iframes'][0] );
209
+ }
210
+
211
+ $this->iframe_tags = $this->array_merge_custom( $this->iframe_tags, $args['iframes'] );
212
+ }
213
+ }
214
+
215
+ // get script tags to block
216
+ $this->auto_script_tags = array_unique( self::get_script_tags() );
217
+
218
+ // get iframes tags to block
219
+ $this->auto_iframe_tags = array_unique( self::get_iframe_tags() );
220
  }
221
 
222
  /**
234
  * @return boolean
235
  */
236
  static function consent_given() {
237
+ $consent_given = false;
238
+
239
  foreach ( $_COOKIE as $key => $value ) {
240
+ $found = self::strpos_array( $key, array( '_iub_cs-s', '_iub_cs' ) );
241
+
242
+ if ( $found !== false ) {
243
+ $consent_data = json_decode( stripslashes( $value ), true );
244
+
245
+ // read cookie value if given
246
+ if ( isset( $consent_data['consent'] ) && $consent_data['consent'] == true )
247
+ $consent_given = true;
248
+
249
+ // read purposes if given
250
+ if ( ! empty( $consent_data['purposes'] ) && is_array( $consent_data['purposes'] ) ) {
251
+ // all purposes accepted, consent given
252
+ if ( ! in_array( false, $consent_data['purposes'] ) )
253
+ $consent_given = true;
254
+ }
255
+ }
256
  }
257
 
258
+ return $consent_given;
259
  }
260
 
261
  /**
262
+ * Get user accepted purposes.
263
  *
264
+ * @return array
 
 
265
  */
266
+ static function get_purposes() {
267
+ $purposes = array();
 
268
 
269
+ if ( ! empty( $_COOKIE ) ) {
270
+ foreach ( $_COOKIE as $key => $value ) {
271
+ $found = self::strpos_array( $key, array( '_iub_cs-s', '_iub_cs' ) );
272
+
273
+ if ( $found !== false ) {
274
+