Version Description
- Fix: Safari unrecognized expression on CSS wildcards
Download this release
Release Info
Developer | dfactory |
Plugin | ![]() |
Version | 2.0.3 |
Comparing to | |
See all releases |
Code changes from version 2.1.3.1 to 2.0.3
- css/admin.css +3 -18
- includes/amp.php +0 -347
- includes/forms.php +3 -3
- includes/settings.php +40 -196
- iubenda-cookie-class/README.md +0 -7
- iubenda-cookie-class/iubenda.class.php +171 -427
- iubenda_cookie_solution.php +93 -287
- js/admin.js +7 -62
- js/frontend.js +1 -1
- languages/iubenda-cookie-law-solution-it_IT.mo +0 -0
- languages/iubenda-cookie-law-solution-it_IT.po +257 -393
- languages/iubenda-cookie-law-solution.pot +103 -196
- readme.txt +5 -19
- templates/amp.html +0 -37
css/admin.css
CHANGED
@@ -42,12 +42,6 @@
|
|
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,18 +62,9 @@
|
|
68 |
#iubenda-tabs .help-tab-content {
|
69 |
margin-right: 0;
|
70 |
}
|
71 |
-
#iubenda-tabs .help-tab-content
|
72 |
-
|
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;
|
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 |
#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;
|
includes/amp.php
DELETED
@@ -1,347 +0,0 @@
|
|
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.
|
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 footer.
|
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 |
-
$configuration = iubenda()->parse_configuration();
|
82 |
-
|
83 |
-
if ( empty( $configuration ) )
|
84 |
-
return;
|
85 |
-
|
86 |
-
// local file
|
87 |
-
if ( iubenda()->options['cs']['amp_source'] === 'local' ) {
|
88 |
-
$template_url = $this->get_amp_template_url();
|
89 |
-
// remote file
|
90 |
-
} else {
|
91 |
-
$template_url = esc_url( iubenda()->options['cs']['amp_template'] );
|
92 |
-
}
|
93 |
-
|
94 |
-
if ( empty( $template_url ) )
|
95 |
-
return;
|
96 |
-
|
97 |
-
echo '
|
98 |
-
<amp-consent id="myUserConsent" layout="nodisplay">
|
99 |
-
<script type="application/json">
|
100 |
-
{
|
101 |
-
"consentInstanceId": "consent' . $configuration['siteId'] . '",
|
102 |
-
"consentRequired": true,
|
103 |
-
"promptUI": "myConsentFlow"
|
104 |
-
}
|
105 |
-
</script>
|
106 |
-
<div id="myConsentFlow" class="popupOverlay">
|
107 |
-
<amp-iframe
|
108 |
-
layout="fill"
|
109 |
-
sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox"
|
110 |
-
src="' . esc_url( $template_url ) . '">
|
111 |
-
<div placeholder>' . __( 'Loading', 'iubenda' ) . '</div>
|
112 |
-
</amp-iframe>
|
113 |
-
</div>
|
114 |
-
</amp-consent>';
|
115 |
-
}
|
116 |
-
}
|
117 |
-
|
118 |
-
/**
|
119 |
-
* Add scripts to AMP for WP plugin.
|
120 |
-
*
|
121 |
-
* @return mixed
|
122 |
-
*/
|
123 |
-
public function amp_post_template_data( $data ) {
|
124 |
-
if ( iubenda()->options['cs']['amp_support'] === false )
|
125 |
-
return $data;
|
126 |
-
|
127 |
-
if ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) {
|
128 |
-
$data['amp_component_scripts'] = array_merge( $data['amp_component_scripts'],
|
129 |
-
array( 'amp-consent' => 'https://cdn.ampproject.org/v0/amp-consent-latest.js' )
|
130 |
-
);
|
131 |
-
$data['amp_component_scripts'] = array_merge( $data['amp_component_scripts'],
|
132 |
-
array( 'amp-iframe' => 'https://cdn.ampproject.org/v0/amp-iframe-latest.js' )
|
133 |
-
);
|
134 |
-
}
|
135 |
-
|
136 |
-
return $data;
|
137 |
-
}
|
138 |
-
|
139 |
-
/**
|
140 |
-
* Add CSS to AMP for WP plugin.
|
141 |
-
*
|
142 |
-
* @return mixed
|
143 |
-
*/
|
144 |
-
public function amp_post_template_css( $data ) {
|
145 |
-
if ( iubenda()->options['cs']['amp_support'] === false )
|
146 |
-
return;
|
147 |
-
|
148 |
-
if ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) {
|
149 |
-
?>
|
150 |
-
.popupOverlay {
|
151 |
-
position:fixed;
|
152 |
-
top: 0;
|
153 |
-
bottom: 0;
|
154 |
-
left: 0;
|
155 |
-
right: 0;
|
156 |
-
}
|
157 |
-
amp-iframe {
|
158 |
-
margin: 0;
|
159 |
-
}
|
160 |
-
amp-consent.amp-active {
|
161 |
-
position:fixed;
|
162 |
-
top: 0;
|
163 |
-
bottom: 0;
|
164 |
-
left: 0;
|
165 |
-
right: 0;
|
166 |
-
}
|
167 |
-
<?php
|
168 |
-
}
|
169 |
-
}
|
170 |
-
|
171 |
-
/**
|
172 |
-
* Block analytics in AMP for WP plugin.
|
173 |
-
*
|
174 |
-
* @return mixed
|
175 |
-
*/
|
176 |
-
public function fix_analytics_amp_for_wp( $data ) {
|
177 |
-
if ( iubenda()->options['cs']['amp_support'] === false )
|
178 |
-
return $data;
|
179 |
-
|
180 |
-
global $redux_builder_amp;
|
181 |
-
|
182 |
-
if ( $redux_builder_amp == null ) {
|
183 |
-
$redux_builder_amp = get_option( 'redux_builder_amp', true );
|
184 |
-
}
|
185 |
-
|
186 |
-
// trick to block the analytics using global $redux_builder_amp variable
|
187 |
-
if ( ! iubendaParser::consent_given() )
|
188 |
-
$redux_builder_amp = true;
|
189 |
-
|
190 |
-
return $data;
|
191 |
-
}
|
192 |
-
|
193 |
-
/**
|
194 |
-
* Block analytics in WP AMP plugin.
|
195 |
-
*
|
196 |
-
* @return mixed
|
197 |
-
*/
|
198 |
-
public function fix_analytics_wp_amp( $analytics_entries ) {
|
199 |
-
if ( iubenda()->options['cs']['amp_support'] === false )
|
200 |
-
return $analytics_entries;
|
201 |
-
|
202 |
-
// block the analytics using the entries filter hook
|
203 |
-
if ( ! iubendaParser::consent_given() && ! empty( $analytics_entries ) && is_array( $analytics_entries ) ) {
|
204 |
-
foreach ( $analytics_entries as $id => $entry ) {
|
205 |
-
$entry['attributes'] = ! empty( $entry['attributes'] ) ? $entry['attributes'] : array();
|
206 |
-
|
207 |
-
$analytics_entries[$id]['attributes'] = array_merge( array( 'data-block-on-consent' => '_till_accepted' ), $entry['attributes'] );
|
208 |
-
}
|
209 |
-
}
|
210 |
-
|
211 |
-
return $analytics_entries;
|
212 |
-
}
|
213 |
-
|
214 |
-
/**
|
215 |
-
* Prepare HTML iframe template for the AMP.
|
216 |
-
*
|
217 |
-
* @return mixed
|
218 |
-
*/
|
219 |
-
public function prepare_amp_template() {
|
220 |
-
$html = '';
|
221 |
-
$configuration_raw = iubenda()->parse_configuration( false );
|
222 |
-
|
223 |
-
if ( ! empty( $configuration_raw ) ) {
|
224 |
-
// encode array
|
225 |
-
$configuration = json_encode( $configuration_raw );
|
226 |
-
// remove quotes
|
227 |
-
$configuration = preg_replace( '/"([a-zA-Z]+[a-zA-Z0-9]*)":/', '$1:', $configuration );
|
228 |
-
// replace brackets
|
229 |
-
$configuration = str_replace( array( '{', '}' ), '', $configuration );
|
230 |
-
|
231 |
-
$html .= '<!DOCTYPE html>
|
232 |
-
<html lang="' . $configuration_raw['lang'] . '">
|
233 |
-
<head>
|
234 |
-
<meta charset="UTF-8">
|
235 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
236 |
-
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
237 |
-
<title>AMP Cookie Consent</title>
|
238 |
-
<script type="text/javascript">
|
239 |
-
var _iub = _iub || [];
|
240 |
-
_iub.csConfiguration = {
|
241 |
-
';
|
242 |
-
// print configuration
|
243 |
-
$html .= $configuration . ',';
|
244 |
-
$html .= '
|
245 |
-
banner: {
|
246 |
-
position: \'float-bottom-center\',
|
247 |
-
acceptButtonDisplay: true,
|
248 |
-
customizeButtonDisplay: true,
|
249 |
-
rejectButtonDisplay: true,
|
250 |
-
backgroundOverlay: true
|
251 |
-
},
|
252 |
-
callback: {
|
253 |
-
onPreferenceExpressed: function(preference) {
|
254 |
-
var consentAction = \'reject\';
|
255 |
-
if (preference && preference.consent) {
|
256 |
-
consentAction = \'accept\';
|
257 |
-
}
|
258 |
-
console.log(\'send consent-response\', consentAction);
|
259 |
-
window.parent.postMessage({
|
260 |
-
type: \'consent-response\',
|
261 |
-
action: consentAction
|
262 |
-
}, \'*\');
|
263 |
-
}
|
264 |
-
}
|
265 |
-
};
|
266 |
-
</script>
|
267 |
-
<script async src="https://cdn.iubenda.com/cs/beta/iubenda_cs.js"></script>
|
268 |
-
</head>
|
269 |
-
<body></body>
|
270 |
-
</html>';
|
271 |
-
}
|
272 |
-
|
273 |
-
return $html;
|
274 |
-
}
|
275 |
-
|
276 |
-
/**
|
277 |
-
* Get local file template url;
|
278 |
-
*
|
279 |
-
* @return string
|
280 |
-
*/
|
281 |
-
public function get_amp_template_url() {
|
282 |
-
// get basic site host and template file data
|
283 |
-
$template_url = '';
|
284 |
-
$file_url = IUBENDA_PLUGIN_URL . '/templates/amp.html';
|
285 |
-
// $file_url = 'https://cdn.iubenda.com/cs/test/cs-for-amp.html'; // debug only
|
286 |
-
$parsed_site = parse_url( home_url() );
|
287 |
-
$parsed_file = parse_url( $file_url );
|
288 |
-
$site_host = $parsed_site['host'] !== 'localhost' ? iubenda()->domain( $parsed_site['host'] ) : 'localhost';
|
289 |
-
$file_host = $parsed_file['host'] !== 'localhost' ? iubenda()->domain( $parsed_file['host'] ) : 'localhost';
|
290 |
-
$is_localhost = (bool) ( $site_host == 'localhost' );
|
291 |
-
$is_subdomain = ! $is_localhost ? (bool) ( $parsed_file['host'] !== $file_host ) : false;
|
292 |
-
|
293 |
-
// check if file host and server host match
|
294 |
-
// if not, we're good to go
|
295 |
-
if ( $site_host !== $file_host ) {
|
296 |
-
$template_url = $file_url;
|
297 |
-
// if are located on same host do additional tweaks
|
298 |
-
} else {
|
299 |
-
// all ok if we're on different subdomains
|
300 |
-
if ( $parsed_site['host'] !== $parsed_file['host'] )
|
301 |
-
$template_url = $file_url;
|
302 |
-
// same hosts, let's tweak the http/https
|
303 |
-
else {
|
304 |
-
$has_www = strpos( $parsed_file['host'], 'www.' ) === 0;
|
305 |
-
|
306 |
-
// add or remove www from url string to make iframe url pass AMP validation
|
307 |
-
$tweaked_host = ! $is_localhost && ! $is_subdomain ? ( ! $has_www ? 'www.' . $parsed_file['host'] : preg_replace( '/^www\./i', '', $parsed_file['host'] ) ) : $parsed_file['host'];
|
308 |
-
|
309 |
-
// generate new url
|
310 |
-
$tweaked_url = $parsed_file['scheme'] . '://' . $tweaked_host . ( isset( $parsed_file['port'] ) ? ':' . $parsed_file['port'] : '' ) . $parsed_file['path'] . ( ! empty( $parsed_file['query'] ) ? '?' . $parsed_file['query'] : '' );
|
311 |
-
|
312 |
-
// check if file url is valid
|
313 |
-
if ( $tweaked_url ) {
|
314 |
-
$template_url = $tweaked_url;
|
315 |
-
}
|
316 |
-
}
|
317 |
-
}
|
318 |
-
|
319 |
-
return $template_url;
|
320 |
-
}
|
321 |
-
|
322 |
-
/**
|
323 |
-
* Generate HTML iframe template for the AMP.
|
324 |
-
*
|
325 |
-
* @return mixed
|
326 |
-
*/
|
327 |
-
public function generate_amp_template() {
|
328 |
-
$template_file = IUBENDA_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'amp.html';
|
329 |
-
$html = $this->prepare_amp_template();
|
330 |
-
|
331 |
-
// bail if the template was not created properly
|
332 |
-
if ( empty( $html ) )
|
333 |
-
return false;
|
334 |
-
|
335 |
-
// bail if the file is writable
|
336 |
-
if ( ! is_writable( $template_file ) )
|
337 |
-
return false;
|
338 |
-
|
339 |
-
// write the file
|
340 |
-
$fh = fopen( $template_file, 'w' );
|
341 |
-
fwrite( $fh, $html );
|
342 |
-
fclose( $fh );
|
343 |
-
|
344 |
-
return true;
|
345 |
-
}
|
346 |
-
|
347 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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'] ) ?
|
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 =
|
375 |
-
$update =
|
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'] ) ? (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 |
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 ) {
|
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,15 +67,6 @@ class iubenda_Settings {
|
|
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,7 +118,6 @@ class iubenda_Settings {
|
|
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
|
@@ -351,15 +341,6 @@ class iubenda_Settings {
|
|
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,26 +382,6 @@ class iubenda_Settings {
|
|
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,63 +514,18 @@ class iubenda_Settings {
|
|
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 |
-
<
|
557 |
-
<
|
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 |
-
<
|
575 |
-
<
|
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 |
*
|
@@ -628,7 +544,7 @@ class iubenda_Settings {
|
|
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
|
632 |
</div>
|
633 |
</div>
|
634 |
</div>';
|
@@ -683,41 +599,6 @@ class iubenda_Settings {
|
|
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 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;"' : '' ) . '>';
|
704 |
-
if ( iubenda()->options['cs']['amp_template_done'] === false ) {
|
705 |
-
echo '
|
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>
|
713 |
-
<div id="iub_amp_template-remote"' . ( iubenda()->options['cs']['amp_source'] === 'local' ? ' style="display: none;"' : '' ) . '>
|
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 |
-
}
|
721 |
|
722 |
/**
|
723 |
* Deactivation option.
|
@@ -1146,14 +1027,7 @@ class iubenda_Settings {
|
|
1146 |
$input['output_feed'] = (bool) isset( $input['output_feed'] );
|
1147 |
$input['output_post'] = (bool) isset( $input['output_post'] );
|
1148 |
$input['menu_position'] = isset( $input['menu_position'] ) && in_array( $input['menu_position'], array( 'topmenu', 'submenu' ) ) ? $input['menu_position'] : iubenda()->defaults['cs']['menu_position'];
|
1149 |
-
$input['amp_support'] = (bool) isset( $input['amp_support'] );
|
1150 |
$input['deactivation'] = (bool) isset( $input['deactivation'] );
|
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 |
|
1158 |
// multilang support
|
1159 |
if ( iubenda()->multilang && ! empty( iubenda()->languages ) ) {
|
@@ -1169,38 +1043,24 @@ class iubenda_Settings {
|
|
1169 |
$input['code_default'] = ! empty( $input['code_default'] ) ? iubenda()->parse_code( $input['code_default'] ) : '';
|
1170 |
|
1171 |
// scripts
|
1172 |
-
if (
|
1173 |
-
$
|
1174 |
-
|
1175 |
-
// first field is template
|
1176 |
-
if ( count( $input['custom_scripts']['script'] ) > 1 ) {
|
1177 |
-
foreach ( $input['custom_scripts']['script'] as $number => $script ) {
|
1178 |
-
$trimmed = trim( $script );
|
1179 |
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
$input['custom_scripts'] = $scripts;
|
1186 |
} else
|
1187 |
$input['custom_scripts'] = array();
|
1188 |
|
1189 |
// iframes
|
1190 |
-
if (
|
1191 |
-
$
|
1192 |
-
|
1193 |
-
// first field is template
|
1194 |
-
if ( count( $input['custom_iframes']['iframe'] ) > 1 ) {
|
1195 |
-
foreach ( $input['custom_iframes']['iframe'] as $number => $iframe ) {
|
1196 |
-
$trimmed = trim( $iframe );
|
1197 |
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
$input['custom_iframes'] = $iframes;
|
1204 |
} else
|
1205 |
$input['custom_iframes'] = array();
|
1206 |
|
@@ -1259,22 +1119,13 @@ class iubenda_Settings {
|
|
1259 |
|
1260 |
if ( ! $page )
|
1261 |
return;
|
1262 |
-
|
1263 |
-
// get redirect url
|
1264 |
-
if ( iubenda()->options['cs']['menu_position'] === 'submenu' && $pagenow === 'admin.php' ) {
|
1265 |
-
// sub menu
|
1266 |
-
$redirect_to = admin_url( 'options-general.php?page=iubenda&tab=' . $tab_key );
|
1267 |
-
} else {
|
1268 |
-
// top menu
|
1269 |
-
$redirect_to = admin_url( 'admin.php?page=iubenda&tab=' . $tab_key );
|
1270 |
-
}
|
1271 |
|
1272 |
// add comments cookie option notice
|
1273 |
if ( $tab_key != 'cs' && ! empty( iubenda()->options['cons']['public_api_key'] ) ) {
|
1274 |
$cookies_enabled = get_option( 'show_comments_cookies_opt_in' );
|
1275 |
|
1276 |
if ( ! $cookies_enabled ) {
|
1277 |
-
|
1278 |
}
|
1279 |
}
|
1280 |
|
@@ -1286,15 +1137,23 @@ class iubenda_Settings {
|
|
1286 |
|
1287 |
// new forms notice
|
1288 |
if ( ! empty( $result['new'] ) )
|
1289 |
-
|
1290 |
|
1291 |
// forms changed notice
|
1292 |
if ( ! empty( $result['updated'] ) )
|
1293 |
-
|
1294 |
|
1295 |
// no changes notice
|
1296 |
if ( empty( $result['new'] ) && empty( $result['updated'] ) )
|
1297 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1298 |
|
1299 |
// make sure it's current host location
|
1300 |
wp_safe_redirect( $redirect_to );
|
@@ -1354,7 +1213,7 @@ class iubenda_Settings {
|
|
1354 |
|
1355 |
// bail if empty fields
|
1356 |
if ( empty( $subject ) || empty( $preferences ) ) {
|
1357 |
-
|
1358 |
return;
|
1359 |
}
|
1360 |
|
@@ -1378,13 +1237,13 @@ class iubenda_Settings {
|
|
1378 |
if ( $result ) {
|
1379 |
// form save, inform about form status update
|
1380 |
if ( empty( $form->form_subject ) && empty( $form->form_preferences ) ) {
|
1381 |
-
|
1382 |
// form update
|
1383 |
} else {
|
1384 |
-
|
1385 |
}
|
1386 |
} else {
|
1387 |
-
|
1388 |
}
|
1389 |
|
1390 |
break;
|
@@ -1401,30 +1260,15 @@ class iubenda_Settings {
|
|
1401 |
$result = iubenda()->forms->delete_form( $id );
|
1402 |
|
1403 |
if ( $result )
|
1404 |
-
|
1405 |
else
|
1406 |
-
|
|
|
|
|
1407 |
|
1408 |
// make sure it's current host location
|
1409 |
wp_safe_redirect( $redirect_to );
|
1410 |
-
|
1411 |
-
|
1412 |
-
break;
|
1413 |
-
|
1414 |
-
case 'disable_skip_parsing' :
|
1415 |
-
|
1416 |
-
// disable skip parsing option
|
1417 |
-
$options = iubenda()->options['cs'];
|
1418 |
-
$options['skip_parsing'] = false;
|
1419 |
-
|
1420 |
-
update_option( 'iubenda_cookie_law_solution', $options );
|
1421 |
-
|
1422 |
-
$this->add_notice( 'iub_settings_updated', __( 'Settings saved.', 'iubenda' ), 'success' );
|
1423 |
-
|
1424 |
-
// make sure it's current host location
|
1425 |
-
wp_safe_redirect( $redirect_to );
|
1426 |
-
exit;
|
1427 |
-
|
1428 |
break;
|
1429 |
|
1430 |
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' ) );
|
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 |
$links = array(
|
71 |
'en' => array(
|
72 |
'iab' => 'https://www.iubenda.com/en/help/7440-enable-preference-management-iab-framework',
|
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
|
341 |
}
|
342 |
|
343 |
$tab_key = ! empty( $_GET['tab'] ) ? esc_attr( $_GET['tab'] ) : 'cs';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
?>
|
345 |
<div class="wrap">
|
346 |
|
382 |
</div>
|
383 |
|
384 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
// render custom notices
|
386 |
$this->print_notices();
|
387 |
?>
|
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 |
*
|
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 |
<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 |
$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 ) ) {
|
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 |
|
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 |
|
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 |
|
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 |
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 |
$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 :
|
iubenda-cookie-class/README.md
CHANGED
@@ -98,13 +98,6 @@ These operations take place in accordance with the rules explained in [this guid
|
|
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 |
|
98 |
|
99 |
## Changelog
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
##### 3.4.0
|
102 |
* New: Introducing wildcard support for scripts and iframes
|
103 |
|
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-
|
7 |
* @license GNU/GPL
|
8 |
-
* @version 4.
|
9 |
* @deprecated
|
10 |
*
|
11 |
* This program is free software: you can redistribute it and/or modify
|
@@ -27,117 +27,118 @@ 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_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 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
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,11 +162,18 @@ class iubendaParser {
|
|
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,49 +182,6 @@ class iubendaParser {
|
|
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,123 +199,45 @@ class iubendaParser {
|
|
234 |
* @return boolean
|
235 |
*/
|
236 |
static function consent_given() {
|
237 |
-
$consent_given = false;
|
238 |
-
|
239 |
foreach ( $_COOKIE as $key => $value ) {
|
240 |
-
|
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
|
259 |
}
|
260 |
|
261 |
/**
|
262 |
-
*
|
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 |
-
$consent_data = json_decode( $value, true );
|
275 |
-
|
276 |
-
// read purposes if given
|
277 |
-
if ( ! empty( $consent_data['purposes'] ) && is_array( $consent_data['purposes'] ) )
|
278 |
-
$purposes = $consent_data['purposes'];
|
279 |
-
}
|
280 |
-
}
|
281 |
-
}
|
282 |
-
|
283 |
-
return $purposes;
|
284 |
-
}
|
285 |
-
|
286 |
-
/**
|
287 |
-
* Get script tags to be blocked.
|
288 |
-
*
|
289 |
-
* @return array
|
290 |
-
*/
|
291 |
-
private function get_script_tags() {
|
292 |
-
$tags = $this->auto_script_tags;
|
293 |
-
|
294 |
-
foreach ( $this->script_tags as $purpose_id => $tags_list ) {
|
295 |
-
// empty tags list, go to another
|
296 |
-
if ( empty( $tags_list ) )
|
297 |
-
continue;
|
298 |
-
|
299 |
-
// purposes available, filter per purpose
|
300 |
-
if ( ! empty( $this->purposes ) ) {
|
301 |
-
// don't block scripts unavailable in the user purposes
|
302 |
-
// if ( array_key_exists( $purpose_id, $this->purposes ) && $this->purposes[$purpose_id] == false ) {
|
303 |
-
|
304 |
-
// block scripts unavailable in the user purposes
|
305 |
-
if ( ! isset( $this->purposes[$purpose_id] ) || $this->purposes[$purpose_id] == false ) {
|
306 |
-
foreach ( $tags_list as $tag ) {
|
307 |
-
$tags[] = $tag;
|
308 |
-
}
|
309 |
-
}
|
310 |
-
// no purposes yet, just add all scripts
|
311 |
-
} else {
|
312 |
-
foreach ( $tags_list as $tag ) {
|
313 |
-
$tags[] = $tag;
|
314 |
-
}
|
315 |
-
}
|
316 |
-
}
|
317 |
-
|
318 |
-
return $tags;
|
319 |
-
}
|
320 |
-
|
321 |
-
/**
|
322 |
-
* Get iframe tags to be blocked.
|
323 |
*
|
324 |
-
* @
|
|
|
|
|
325 |
*/
|
326 |
-
|
327 |
-
$
|
|
|
328 |
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
//
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
// no purposes yet, just add all scripts
|
346 |
-
} else {
|
347 |
-
foreach ( $tags_list as $tag ) {
|
348 |
-
$tags[] = $tag;
|
349 |
-
}
|
350 |
}
|
351 |
}
|
352 |
-
|
353 |
-
return
|
354 |
}
|
355 |
|
356 |
/**
|
@@ -359,7 +246,7 @@ class iubendaParser {
|
|
359 |
* @param mixed $content
|
360 |
* @return mixed
|
361 |
*/
|
362 |
-
public function create_tags( $content
|
363 |
$elements = $content->find( "*" );
|
364 |
$js = '';
|
365 |
|
@@ -371,13 +258,6 @@ class iubendaParser {
|
|
371 |
|
372 |
switch ( $e->tag ) {
|
373 |
case 'script':
|
374 |
-
if ( $args['pattern'] === 'IUB_REGEX_PURPOSE_PATTERN' )
|
375 |
-
$e->{'data-iub-purposes'} = $args['number'];
|
376 |
-
|
377 |
-
// AMP support
|
378 |
-
if ( $this->amp )
|
379 |
-
$e->{'data-block-on-consent'} = '_till_accepted';
|
380 |
-
|
381 |
$class = $e->class;
|
382 |
$e->class = $class . ' ' . $this->iub_class;
|
383 |
$e->type = 'text/plain';
|
@@ -385,13 +265,6 @@ class iubendaParser {
|
|
385 |
break;
|
386 |
|
387 |
case 'iframe':
|
388 |
-
if ( $args['pattern'] === 'IUB_REGEX_PURPOSE_PATTERN' )
|
389 |
-
$e->{'data-iub-purposes'} = $args['number'];
|
390 |
-
|
391 |
-
// AMP support
|
392 |
-
if ( $this->amp )
|
393 |
-
$e->{'data-block-on-consent'} = '_till_accepted';
|
394 |
-
|
395 |
$new_src = $this->iub_empty;
|
396 |
$class = $e->class;
|
397 |
$e->suppressedsrc = $e->src;
|
@@ -401,7 +274,7 @@ class iubendaParser {
|
|
401 |
break;
|
402 |
|
403 |
default:
|
404 |
-
$js
|
405 |
break;
|
406 |
}
|
407 |
}
|
@@ -428,6 +301,11 @@ class iubendaParser {
|
|
428 |
|
429 |
switch ( $element->tag ) {
|
430 |
case 'script':
|
|
|
|
|
|
|
|
|
|
|
431 |
case 'iframe':
|
432 |
$class = trim( $element->class );
|
433 |
$element->class = ( $class !== '' ? $class . ' ' : '' ) . $this->iub_class_skip;
|
@@ -453,18 +331,15 @@ class iubendaParser {
|
|
453 |
public function parse_scripts() {
|
454 |
switch ( $this->type ) {
|
455 |
case 'page':
|
456 |
-
|
457 |
-
$html = str_get_html( $this->content_page, true, true, false );
|
458 |
|
459 |
if ( is_object( $html ) ) {
|
460 |
-
// get scripts
|
461 |
$scripts = $html->find( 'script' );
|
462 |
|
463 |
if ( is_array( $scripts ) ) {
|
464 |
$count = count( $scripts );
|
465 |
$class_skip = $this->iub_class_skip;
|
466 |
|
467 |
-
// loop through scripts
|
468 |
for ( $j = 0; $j < $count; $j ++ ) {
|
469 |
$s = $scripts[$j];
|
470 |
$script_class = trim( $s->class );
|
@@ -485,10 +360,8 @@ class iubendaParser {
|
|
485 |
|
486 |
if ( ! empty( $s->innertext ) ) {
|
487 |
$this->scripts_inline_detected[] = $s->innertext;
|
488 |
-
|
489 |
-
$found = self::strpos_array( $s->innertext, $this->auto_script_tags );
|
490 |
|
491 |
-
if ( $
|
492 |
$class = $s->class;
|
493 |
$s->class = $class . ' ' . $this->iub_class_inline;
|
494 |
$s->type = 'text/plain';
|
@@ -499,21 +372,11 @@ class iubendaParser {
|
|
499 |
|
500 |
if ( $src ) {
|
501 |
$this->scripts_detected[] = $src;
|
502 |
-
|
503 |
-
$found = self::strpos_array( $src, $this->auto_script_tags );
|
504 |
|
505 |
-
if ( $
|
506 |
$class = $s->class;
|
507 |
$s->class = $class . ' ' . $this->iub_class;
|
508 |
$s->type = 'text/plain';
|
509 |
-
|
510 |
-
// add data-iub-purposes attribute
|
511 |
-
$s->{'data-iub-purposes'} = $this->recursive_array_search( $found, $this->script_tags );
|
512 |
-
|
513 |
-
// AMP support
|
514 |
-
if ( $this->amp )
|
515 |
-
$s->{'data-block-on-consent'} = '_till_accepted';
|
516 |
-
|
517 |
$this->scripts_converted[] = $src;
|
518 |
}
|
519 |
}
|
@@ -660,30 +523,16 @@ class iubendaParser {
|
|
660 |
// add inline script as detected
|
661 |
if ( ! empty( $script->nodeValue ) )
|
662 |
$this->scripts_inline_detected[] = $script->nodeValue;
|
663 |
-
|
664 |
-
$found = self::strpos_array( $src, $script_tags );
|
665 |
-
$found_inline = self::strpos_array( $script->nodeValue, $script_tags );
|
666 |
|
667 |
-
if ( $
|
668 |
$script->setAttribute( 'type', 'text/plain' );
|
669 |
$script->setAttribute( 'class', $script->getAttribute( 'class' ) . ' ' . $class );
|
670 |
-
|
671 |
-
// add data-iub-purposes attribute
|
672 |
-
$script->setAttribute( 'data-iub-purposes', $this->recursive_array_search( $found, $this->script_tags ) );
|
673 |
-
|
674 |
-
// AMP support
|
675 |
-
if ( $this->amp )
|
676 |
-
$script->setAttribute( 'data-block-on-consent', '_till_accepted' );
|
677 |
|
678 |
// add script as converted
|
679 |
$this->scripts_converted[] = $src;
|
680 |
-
} elseif ( $
|
681 |
$script->setAttribute( 'type', 'text/plain' );
|
682 |
$script->setAttribute( 'class', $script->getAttribute( 'class' ) . ' ' . $class_inline );
|
683 |
-
|
684 |
-
// AMP support
|
685 |
-
if ( $this->amp )
|
686 |
-
$script->setAttribute( 'data-block-on-consent', '_till_accepted' );
|
687 |
|
688 |
// add inline script as converted
|
689 |
$this->scripts_inline_converted[] = $script->nodeValue;
|
@@ -711,7 +560,7 @@ class iubendaParser {
|
|
711 |
public function parse_iframes() {
|
712 |
switch ( $this->type ) {
|
713 |
case 'page':
|
714 |
-
$html = str_get_html( $this->content_page, true, true, false );
|
715 |
|
716 |
if ( is_object( $html ) ) {
|
717 |
$iframes = $html->find( 'iframe' );
|
@@ -738,21 +587,11 @@ class iubendaParser {
|
|
738 |
$src = $i->src;
|
739 |
$this->iframes_detected[] = $src;
|
740 |
|
741 |
-
|
742 |
-
|
743 |
-
if ( $found !== false ) {
|
744 |
$class = $i->class;
|
745 |
$i->suppressedsrc = $src;
|
746 |
$i->src = $this->iub_empty;
|
747 |
$i->class = $class . ' ' . $this->iub_class;
|
748 |
-
|
749 |
-
// add data-iub-purposes attribute
|
750 |
-
$i->{'data-iub-purposes'} = $this->recursive_array_search( $found, $this->iframe_tags );
|
751 |
-
|
752 |
-
// AMP support
|
753 |
-
if ( $this->amp )
|
754 |
-
$i->{'data-block-on-consent'} = '_till_accepted';
|
755 |
-
|
756 |
$this->iframes_converted[] = $src;
|
757 |
}
|
758 |
}
|
@@ -803,20 +642,11 @@ class iubendaParser {
|
|
803 |
|
804 |
// add iframe as detected
|
805 |
$this->iframes_detected[] = $src;
|
806 |
-
|
807 |
-
$found = self::strpos_array( $src, $iframe_tags );
|
808 |
|
809 |
-
if ( $
|
810 |
$iframe->setAttribute( 'src', $empty );
|
811 |
$iframe->setAttribute( 'suppressedsrc', $src );
|
812 |
$iframe->setAttribute( 'class', $iframe_class . ' ' . $class );
|
813 |
-
|
814 |
-
// per purpose, add data-iub-purposes attribute
|
815 |
-
$iframe->setAttribute( 'data-iub-purposes', $this->recursive_array_search( $found, $this->iframe_tags ) );
|
816 |
-
|
817 |
-
// AMP support
|
818 |
-
if ( $this->amp )
|
819 |
-
$iframe->setAttribute( 'data-block-on-consent', '_till_accepted' );
|
820 |
|
821 |
// add iframe as converted
|
822 |
$this->iframes_converted[] = $src;
|
@@ -855,7 +685,7 @@ class iubendaParser {
|
|
855 |
// get HTML dom from string
|
856 |
$html = str_get_html( $scripts[1][$j], true, true, false );
|
857 |
|
858 |
-
// skip scripts and iframes inside
|
859 |
$js_scripts[] = $this->skip_tags( $html );
|
860 |
}
|
861 |
|
@@ -866,40 +696,26 @@ class iubendaParser {
|
|
866 |
unset( $scripts );
|
867 |
|
868 |
// block
|
869 |
-
foreach ( array( 'IUB_REGEX_PATTERN', 'IUB_REGEX_PATTERN_2'
|
870 |
preg_match_all( constant( 'self::' . $pattern ), $this->content_page, $scripts );
|
871 |
|
872 |
-
$chunks = array();
|
873 |
-
$args = array(
|
874 |
-
'pattern' => $pattern
|
875 |
-
);
|
876 |
-
|
877 |
-
if ( $pattern === 'IUB_REGEX_PURPOSE_PATTERN' ) {
|
878 |
-
$numbers = $scripts[1];
|
879 |
-
$chunks = $scripts[2];
|
880 |
-
} else
|
881 |
-
$chunks = $scripts[1];
|
882 |
-
|
883 |
// found any content?
|
884 |
-
if ( is_array( $
|
885 |
-
$count = count( $
|
886 |
$js_scripts = array();
|
887 |
|
888 |
for ( $j = 0; $j < $count; $j++ ) {
|
889 |
-
$this->iub_comments_detected[] = $
|
890 |
|
891 |
// get HTML dom from string
|
892 |
-
$html = str_get_html( $
|
893 |
-
|
894 |
-
if ( $pattern === 'IUB_REGEX_PURPOSE_PATTERN' )
|
895 |
-
$args['number'] = $numbers[$j];
|
896 |
|
897 |
// convert scripts, iframes and other code inside IUBENDAs comment in text/plain to not generate cookies
|
898 |
-
$js_scripts[] = $this->create_tags( $html
|
899 |
}
|
900 |
|
901 |
-
if ( ( is_array( $
|
902 |
-
$this->content_page = strtr( $this->content_page, array_combine( $
|
903 |
}
|
904 |
}
|
905 |
}
|
@@ -937,88 +753,16 @@ class iubendaParser {
|
|
937 |
<script>
|
938 |
var iCallback = function(){};
|
939 |
|
940 |
-
if (
|
941 |
-
if (
|
942 |
iCallback = _iub.csConfiguration.callback.onConsentGiven;
|
943 |
|
944 |
_iub.csConfiguration.callback.onConsentGiven = function() {
|
945 |
iCallback();
|
946 |
|
947 |
-
jQuery(
|
948 |
};
|
949 |
};
|
950 |
</script>";
|
951 |
}
|
952 |
-
|
953 |
-
/**
|
954 |
-
* Static, utility function: strpos for array wilth wildcard support
|
955 |
-
*
|
956 |
-
* @param type $haystack
|
957 |
-
* @param type $needle
|
958 |
-
* @return boolean
|
959 |
-
*/
|
960 |
-
static function strpos_array( $haystack, $needle ) {
|
961 |
-
if ( empty( $haystack ) || empty( $needle ) )
|
962 |
-
return false;
|
963 |
-
|
964 |
-
$needle = ! is_array( $needle ) ? array( $needle ) : $needle;
|
965 |
-
|
966 |
-
foreach ( $needle as $need ) {
|
967 |
-
// wildcard?
|
968 |
-
if ( strpos( $need, '/*/' ) !== false ) {
|
969 |
-
// strtok - removes query string
|
970 |
-
// str_replace - removes double slashes // from url
|
971 |
-
// preg_replace - removes http or https from url
|
972 |
-
$haystack = strtok( str_replace( '//', '', preg_replace( "(^https?://)", "", $haystack ) ), '?' );
|
973 |
-
|
974 |
-
if ( fnmatch( $need, $haystack ) !== false )
|
975 |
-
return $need;
|
976 |
-
// regular
|
977 |
-
} else {
|
978 |
-
if ( strpos( $haystack, $need ) !== false )
|
979 |
-
return $need;
|
980 |
-
}
|
981 |
-
}
|
982 |
-
|
983 |
-
return false;
|
984 |
-
}
|
985 |
-
|
986 |
-
/**
|
987 |
-
* Custom array merge helper function.
|
988 |
-
*
|
989 |
-
* @return array
|
990 |
-
*/
|
991 |
-
public function array_merge_custom( $builtin, $data ) {
|
992 |
-
foreach ( $data as $type => $array ) {
|
993 |
-
// if ( $type === 0 )
|
994 |
-
// continue;
|
995 |
-
|
996 |
-
foreach ( $array as $block ) {
|
997 |
-
$builtin[$type][] = $block;
|
998 |
-
}
|
999 |
-
|
1000 |
-
$builtin[$type] = array_unique( $builtin[$type] );
|
1001 |
-
}
|
1002 |
-
|
1003 |
-
return $builtin;
|
1004 |
-
}
|
1005 |
-
|
1006 |
-
/**
|
1007 |
-
* Array search helper function.
|
1008 |
-
*
|
1009 |
-
* @param type $needle
|
1010 |
-
* @param type $haystack
|
1011 |
-
* @return boolean
|
1012 |
-
*/
|
1013 |
-
public function recursive_array_search( $needle, $haystack ) {
|
1014 |
-
foreach ( $haystack as $key => $value ) {
|
1015 |
-
$current_key = $key;
|
1016 |
-
if ( $needle === $value OR ( is_array( $value ) &&
|
1017 |
-
$this->recursive_array_search( $needle, $value ) !== false) ) {
|
1018 |
-
return $current_key;
|
1019 |
-
}
|
1020 |
-
}
|
1021 |
-
return false;
|
1022 |
-
}
|
1023 |
-
|
1024 |
}
|
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 |
// 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 |
* @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 |
// set content
|
183 |
$this->original_content_page = $content_page;
|
184 |
$this->content_page = $content_page;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
}
|
186 |
|
187 |
/**
|
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 |
* @param mixed $content
|
247 |
* @return mixed
|
248 |
*/
|
249 |
+
public function create_tags( $content ) {
|
250 |
$elements = $content->find( "*" );
|
251 |
$js = '';
|
252 |
|
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 |
break;
|
266 |
|
267 |
case 'iframe':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
$new_src = $this->iub_empty;
|
269 |
$class = $e->class;
|
270 |
$e->suppressedsrc = $e->src;
|
274 |
break;
|
275 |
|
276 |
default:
|
277 |
+
$js = $e->outertext;
|
278 |
break;
|
279 |
}
|
280 |
}
|
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 |
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 |
|
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 |
|
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 |
// 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 |
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 |
$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 |
|
643 |
// add iframe as detected
|
644 |
$this->iframes_detected[] = $src;
|
|