Version Description
- TCF v2 Support
Download this release
Release Info
Developer | iubenda |
Plugin | iubenda Cookie Solution for GDPR |
Version | 2.3.6-beta |
Comparing to | |
See all releases |
Code changes from version 2.3.5 to 2.3.6-beta
- includes/amp.php +58 -53
- readme.txt +3 -0
includes/amp.php
CHANGED
@@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) )
|
|
9 |
* @class iubenda_AMP
|
10 |
*/
|
11 |
class iubenda_AMP {
|
12 |
-
|
13 |
/**
|
14 |
* Class constructor.
|
15 |
*/
|
@@ -20,12 +20,12 @@ class iubenda_AMP {
|
|
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 |
*
|
@@ -39,7 +39,7 @@ class iubenda_AMP {
|
|
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 |
-
|
43 |
// optional geo support
|
44 |
if ( iubenda()->multilang && ! empty( iubenda()->lang_current ) ) {
|
45 |
$code = iubenda()->options['cs']['code_' . iubenda()->lang_current];
|
@@ -77,7 +77,7 @@ class iubenda_AMP {
|
|
77 |
</style>';
|
78 |
}
|
79 |
}
|
80 |
-
|
81 |
/**
|
82 |
* Add AMP consent HTML to WP AMP plugin in Transitional mode.
|
83 |
*
|
@@ -95,12 +95,12 @@ class iubenda_AMP {
|
|
95 |
} else {
|
96 |
$code = iubenda()->options['cs']['code_default'];
|
97 |
}
|
98 |
-
|
99 |
$configuration = iubenda()->parse_configuration( $code );
|
100 |
|
101 |
if ( empty( $configuration ) )
|
102 |
return;
|
103 |
-
|
104 |
// local file
|
105 |
if ( iubenda()->options['cs']['amp_source'] === 'local' ) {
|
106 |
// multilang support
|
@@ -125,7 +125,8 @@ class iubenda_AMP {
|
|
125 |
<script type="application/json">
|
126 |
{
|
127 |
"consentInstanceId": "consent' . $configuration['siteId'] . '",
|
128 |
-
"consentRequired":
|
|
|
129 |
"promptUI": "myConsentFlow"
|
130 |
}
|
131 |
</script>
|
@@ -158,7 +159,7 @@ class iubenda_AMP {
|
|
158 |
array( 'amp-iframe' => 'https://cdn.ampproject.org/v0/amp-iframe-latest.js' )
|
159 |
);
|
160 |
}
|
161 |
-
|
162 |
return $data;
|
163 |
}
|
164 |
|
@@ -170,7 +171,7 @@ class iubenda_AMP {
|
|
170 |
public function amp_post_template_css( $data ) {
|
171 |
if ( iubenda()->options['cs']['amp_support'] === false )
|
172 |
return;
|
173 |
-
|
174 |
echo '
|
175 |
.popupOverlay {
|
176 |
position:fixed;
|
@@ -212,7 +213,7 @@ amp-consent.amp-active {
|
|
212 |
|
213 |
return $data;
|
214 |
}
|
215 |
-
|
216 |
/**
|
217 |
* Block analytics in WP AMP plugin.
|
218 |
*
|
@@ -226,11 +227,11 @@ amp-consent.amp-active {
|
|
226 |
if ( ! iubendaParser::consent_given() && ! empty( $analytics_entries ) && is_array( $analytics_entries ) ) {
|
227 |
foreach ( $analytics_entries as $id => $entry ) {
|
228 |
$entry['attributes'] = ! empty( $entry['attributes'] ) ? $entry['attributes'] : array();
|
229 |
-
|
230 |
$analytics_entries[$id]['attributes'] = array_merge( array( 'data-block-on-consent' => '_till_accepted' ), $entry['attributes'] );
|
231 |
}
|
232 |
}
|
233 |
-
|
234 |
return $analytics_entries;
|
235 |
}
|
236 |
|
@@ -241,20 +242,20 @@ amp-consent.amp-active {
|
|
241 |
*/
|
242 |
public function prepare_amp_template( $code ) {
|
243 |
$html = '';
|
244 |
-
|
245 |
$configuration_raw = iubenda()->parse_configuration( $code );
|
246 |
|
247 |
if ( ! empty( $configuration_raw ) ) {
|
248 |
// get script
|
249 |
$script_src = ! empty( $configuration_raw['script'] ) ? $configuration_raw['script'] : '//cdn.iubenda.com/cs/iubenda_cs.js';
|
250 |
-
|
251 |
// remove from configuration
|
252 |
if ( isset( $configuration_raw['script'] ) )
|
253 |
unset( $configuration_raw['script'] );
|
254 |
-
|
255 |
// encode array
|
256 |
$configuration = json_encode( $configuration_raw );
|
257 |
-
|
258 |
// remove quotes
|
259 |
$configuration = preg_replace( '/"([a-zA-Z]+[a-zA-Z0-9]*)":/', '$1:', $configuration );
|
260 |
// replace brackets
|
@@ -283,37 +284,41 @@ amp-consent.amp-active {
|
|
283 |
backgroundOverlay: true
|
284 |
},
|
285 |
callback: { // Mandatory
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
|
|
|
|
|
|
|
|
317 |
}
|
318 |
};
|
319 |
</script>
|
@@ -334,7 +339,7 @@ amp-consent.amp-active {
|
|
334 |
public function get_amp_template_url( $template_lang = '' ) {
|
335 |
$template_url = '';
|
336 |
$template_lang = ! empty( $template_lang ) && is_string( $template_lang ) ? $template_lang : '';
|
337 |
-
|
338 |
// get basic site host and template file data
|
339 |
$file_url = ! empty( $template_lang ) ? IUBENDA_PLUGIN_URL . '/templates/amp' . '-' . $template_lang . '.html' : IUBENDA_PLUGIN_URL . '/templates/amp.html';
|
340 |
// $file_url = 'https://cdn.iubenda.com/cs/test/cs-for-amp.html'; // debug only
|
@@ -360,7 +365,7 @@ amp-consent.amp-active {
|
|
360 |
|
361 |
// add or remove www from url string to make iframe url pass AMP validation
|
362 |
$tweaked_host = ! $is_localhost && ( ! $is_subdomain || $has_www ) ? ( ! $has_www ? 'www.' . $parsed_file['host'] : preg_replace( '/^www\./i', '', $parsed_file['host'] ) ) : $parsed_file['host'];
|
363 |
-
|
364 |
// generate new url
|
365 |
$tweaked_url = $parsed_file['scheme'] . '://' . $tweaked_host . ( isset( $parsed_file['port'] ) ? ':' . $parsed_file['port'] : '' ) . $parsed_file['path'] . ( ! empty( $parsed_file['query'] ) ? '?' . $parsed_file['query'] : '' );
|
366 |
|
@@ -382,7 +387,7 @@ amp-consent.amp-active {
|
|
382 |
public function generate_amp_template( $code = '', $lang = '' ) {
|
383 |
if ( empty( $code ) )
|
384 |
return false;
|
385 |
-
|
386 |
$template_dir = IUBENDA_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
|
387 |
$template_file = $template_dir . ( ! empty( $lang ) && in_array( $lang, array_keys( iubenda()->languages ) ) ? 'amp' . '-' . $lang . '.html' : 'amp.html' );
|
388 |
$html = $this->prepare_amp_template( $code );
|
@@ -395,5 +400,5 @@ amp-consent.amp-active {
|
|
395 |
|
396 |
return (bool) $result;
|
397 |
}
|
398 |
-
|
399 |
-
}
|
9 |
* @class iubenda_AMP
|
10 |
*/
|
11 |
class iubenda_AMP {
|
12 |
+
|
13 |
/**
|
14 |
* Class constructor.
|
15 |
*/
|
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 |
*
|
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 |
+
|
43 |
// optional geo support
|
44 |
if ( iubenda()->multilang && ! empty( iubenda()->lang_current ) ) {
|
45 |
$code = iubenda()->options['cs']['code_' . iubenda()->lang_current];
|
77 |
</style>';
|
78 |
}
|
79 |
}
|
80 |
+
|
81 |
/**
|
82 |
* Add AMP consent HTML to WP AMP plugin in Transitional mode.
|
83 |
*
|
95 |
} else {
|
96 |
$code = iubenda()->options['cs']['code_default'];
|
97 |
}
|
98 |
+
|
99 |
$configuration = iubenda()->parse_configuration( $code );
|
100 |
|
101 |
if ( empty( $configuration ) )
|
102 |
return;
|
103 |
+
|
104 |
// local file
|
105 |
if ( iubenda()->options['cs']['amp_source'] === 'local' ) {
|
106 |
// multilang support
|
125 |
<script type="application/json">
|
126 |
{
|
127 |
"consentInstanceId": "consent' . $configuration['siteId'] . '",
|
128 |
+
"consentRequired": "remote",
|
129 |
+
"checkConsentHref": "https://cdn.iubenda.com/cs/amp/checkConsent",
|
130 |
"promptUI": "myConsentFlow"
|
131 |
}
|
132 |
</script>
|
159 |
array( 'amp-iframe' => 'https://cdn.ampproject.org/v0/amp-iframe-latest.js' )
|
160 |
);
|
161 |
}
|
162 |
+
|
163 |
return $data;
|
164 |
}
|
165 |
|
171 |
public function amp_post_template_css( $data ) {
|
172 |
if ( iubenda()->options['cs']['amp_support'] === false )
|
173 |
return;
|
174 |
+
|
175 |
echo '
|
176 |
.popupOverlay {
|
177 |
position:fixed;
|
213 |
|
214 |
return $data;
|
215 |
}
|
216 |
+
|
217 |
/**
|
218 |
* Block analytics in WP AMP plugin.
|
219 |
*
|
227 |
if ( ! iubendaParser::consent_given() && ! empty( $analytics_entries ) && is_array( $analytics_entries ) ) {
|
228 |
foreach ( $analytics_entries as $id => $entry ) {
|
229 |
$entry['attributes'] = ! empty( $entry['attributes'] ) ? $entry['attributes'] : array();
|
230 |
+
|
231 |
$analytics_entries[$id]['attributes'] = array_merge( array( 'data-block-on-consent' => '_till_accepted' ), $entry['attributes'] );
|
232 |
}
|
233 |
}
|
234 |
+
|
235 |
return $analytics_entries;
|
236 |
}
|
237 |
|
242 |
*/
|
243 |
public function prepare_amp_template( $code ) {
|
244 |
$html = '';
|
245 |
+
|
246 |
$configuration_raw = iubenda()->parse_configuration( $code );
|
247 |
|
248 |
if ( ! empty( $configuration_raw ) ) {
|
249 |
// get script
|
250 |
$script_src = ! empty( $configuration_raw['script'] ) ? $configuration_raw['script'] : '//cdn.iubenda.com/cs/iubenda_cs.js';
|
251 |
+
|
252 |
// remove from configuration
|
253 |
if ( isset( $configuration_raw['script'] ) )
|
254 |
unset( $configuration_raw['script'] );
|
255 |
+
|
256 |
// encode array
|
257 |
$configuration = json_encode( $configuration_raw );
|
258 |
+
|
259 |
// remove quotes
|
260 |
$configuration = preg_replace( '/"([a-zA-Z]+[a-zA-Z0-9]*)":/', '$1:', $configuration );
|
261 |
// replace brackets
|
284 |
backgroundOverlay: true
|
285 |
},
|
286 |
callback: { // Mandatory
|
287 |
+
onPreferenceExpressed: function(preference) {
|
288 |
+
var AMP_CONSENT_STRING_MAX_LENGTH = 1024;
|
289 |
+
var consentObject = {
|
290 |
+
type: \'consent-response\',
|
291 |
+
action: preference && preference.consent ? \'accept\' : \'reject\'
|
292 |
+
};
|
293 |
+
|
294 |
+
if (typeof window.__tcfapi === \'function\') {
|
295 |
+
__tcfapi(\'getTCData\', 2, function(res) {
|
296 |
+
var consentString = res.tcString;
|
297 |
+
|
298 |
+
if (consentString.length <= AMP_CONSENT_STRING_MAX_LENGTH) {
|
299 |
+
consentObject.info = consentString;
|
300 |
+
}
|
301 |
+
|
302 |
+
console.log(\'send consent-response\', consentObject.action, \'with CMP v2 consent string\', consentString);
|
303 |
+
window.parent.postMessage(consentObject, \'*\');
|
304 |
+
});
|
305 |
+
}
|
306 |
+
else if (typeof window.__cmp === \'function\') {
|
307 |
+
__cmp(\'getConsentData\', null, function(res) {
|
308 |
+
var consentString = res.consentData;
|
309 |
+
|
310 |
+
if (consentString.length <= AMP_CONSENT_STRING_MAX_LENGTH) {
|
311 |
+
consentObject.info = consentString;
|
312 |
+
}
|
313 |
+
|
314 |
+
console.log(\'send consent-response\', consentObject.action, \'with CMP consent string\', consentString);
|
315 |
+
window.parent.postMessage(consentObject, \'*\');
|
316 |
+
});
|
317 |
+
} else {
|
318 |
+
console.log(\'send consent-response\', consentObject.action);
|
319 |
+
window.parent.postMessage(consentObject, \'*\');
|
320 |
+
}
|
321 |
+
}
|
322 |
}
|
323 |
};
|
324 |
</script>
|
339 |
public function get_amp_template_url( $template_lang = '' ) {
|
340 |
$template_url = '';
|
341 |
$template_lang = ! empty( $template_lang ) && is_string( $template_lang ) ? $template_lang : '';
|
342 |
+
|
343 |
// get basic site host and template file data
|
344 |
$file_url = ! empty( $template_lang ) ? IUBENDA_PLUGIN_URL . '/templates/amp' . '-' . $template_lang . '.html' : IUBENDA_PLUGIN_URL . '/templates/amp.html';
|
345 |
// $file_url = 'https://cdn.iubenda.com/cs/test/cs-for-amp.html'; // debug only
|
365 |
|
366 |
// add or remove www from url string to make iframe url pass AMP validation
|
367 |
$tweaked_host = ! $is_localhost && ( ! $is_subdomain || $has_www ) ? ( ! $has_www ? 'www.' . $parsed_file['host'] : preg_replace( '/^www\./i', '', $parsed_file['host'] ) ) : $parsed_file['host'];
|
368 |
+
|
369 |
// generate new url
|
370 |
$tweaked_url = $parsed_file['scheme'] . '://' . $tweaked_host . ( isset( $parsed_file['port'] ) ? ':' . $parsed_file['port'] : '' ) . $parsed_file['path'] . ( ! empty( $parsed_file['query'] ) ? '?' . $parsed_file['query'] : '' );
|
371 |
|
387 |
public function generate_amp_template( $code = '', $lang = '' ) {
|
388 |
if ( empty( $code ) )
|
389 |
return false;
|
390 |
+
|
391 |
$template_dir = IUBENDA_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
|
392 |
$template_file = $template_dir . ( ! empty( $lang ) && in_array( $lang, array_keys( iubenda()->languages ) ) ? 'amp' . '-' . $lang . '.html' : 'amp.html' );
|
393 |
$html = $this->prepare_amp_template( $code );
|
400 |
|
401 |
return (bool) $result;
|
402 |
}
|
403 |
+
|
404 |
+
}
|
readme.txt
CHANGED
@@ -150,6 +150,9 @@ We will be very happy to receive feedback here: [Uservoice forum](https://suppor
|
|
150 |
|
151 |
== Changelog ==
|
152 |
|
|
|
|
|
|
|
153 |
= 2.3.5 =
|
154 |
* Security Fix: limit url sanitize to http protocols
|
155 |
|
150 |
|
151 |
== Changelog ==
|
152 |
|
153 |
+
= 2.3.6-beta =
|
154 |
+
* TCF v2 Support
|
155 |
+
|
156 |
= 2.3.5 =
|
157 |
* Security Fix: limit url sanitize to http protocols
|
158 |
|