iubenda Cookie Solution for GDPR - Version 1.14.2-beta1

Version Description

  • Fix: repository issues breaking the update
Download this release

Release Info

Developer Facens
Plugin Icon 128x128 iubenda Cookie Solution for GDPR
Version 1.14.2-beta1
Comparing to
See all releases

Code changes from version 1.14.1 to 1.14.2-beta1

iubenda-cookie-class/iubenda.class.faster.php ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * iubenda.class.php
4
+ * version: 2.0.2
5
+ * codename: Faster
6
+ * @author: Copyright 2015 iubenda
7
+ * @license GNU/GPL
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
+ */
22
+
23
+ class iubendaFaster {
24
+ /*
25
+ Variables
26
+ */
27
+
28
+ private $getBlack = array(
29
+ array(
30
+ /*
31
+ Domains
32
+ */
33
+
34
+ "platform.twitter.com/widgets.js",
35
+ "apis.google.com/js/plusone.js",
36
+ "apis.google.com/js/platform.js",
37
+ "connect.facebook.net",
38
+ "www.youtube.com/iframe_api",
39
+ "pagead2.googlesyndication.com/pagead/js/adsbygoogle.js",
40
+ "sharethis.com/button/buttons.js",
41
+ "addthis.com/js/",
42
+ /*
43
+ JavaScript
44
+ */
45
+ "window.adsbygoogle"
46
+ ),
47
+ array
48
+ (
49
+ "youtube.com",
50
+ "platform.twitter.com",
51
+ "www.facebook.com/plugins/like.php",
52
+ "www.facebook.com/plugins/likebox.php",
53
+ "apis.google.com",
54
+ "www.google.com/maps/embed/",
55
+ "player.vimeo.com/video",
56
+ "maps.google.it/maps",
57
+ "www.google.com/maps/embed"
58
+ )
59
+ );
60
+
61
+ /**/
62
+ private $getBlank = "//cdn.iubenda.com/cookie_solution/empty.html";
63
+ private $getClass = array( "_iub_cs_activate", "_iub_cs_activate-inline" );
64
+
65
+ /*
66
+ Methods
67
+ */
68
+
69
+ public function isBlack( $offender, $blacklist ) {
70
+ /*
71
+ Check if a string is in the black list.
72
+ */
73
+
74
+ if ( empty( $offender ) || empty( $blacklist ) ) {
75
+
76
+ return false;
77
+ }
78
+
79
+ /**/
80
+
81
+ foreach ( $blacklist as $black ) {
82
+ if ( strpos( $offender, $black ) !== false ) {
83
+
84
+ return true;
85
+ }
86
+ }
87
+
88
+ /**/
89
+
90
+ return false;
91
+ }
92
+
93
+ /**/
94
+
95
+ public function isParse( $offender ) {
96
+ /*
97
+ Parse the entrie document and search for black elements.
98
+ */
99
+
100
+ libxml_use_internal_errors( true );
101
+
102
+ /**/
103
+
104
+ $src = "";
105
+
106
+ $blank = $this->getBlank;
107
+ $class = $this->getClass;
108
+
109
+ $list_1 = $this->getBlack[0];
110
+ $list_2 = $this->getBlack[1];
111
+
112
+ $document = new DOMDocument();
113
+
114
+ /**/
115
+
116
+ $document->formatOutput = true;
117
+ $document->preserveWhiteSpace = false;
118
+
119
+ /**/
120
+
121
+ $document->loadHTML( $offender );
122
+
123
+ /**/
124
+
125
+ $scripts = $document->getElementsByTagName( "script" );
126
+ $iframes = $document->getElementsByTagName( "iframe" );
127
+
128
+ /*
129
+ Parse the founded elements and check who is in black.
130
+ */
131
+
132
+ foreach ( $scripts as $script ) {
133
+ $src = $script->getAttribute( "src" );
134
+
135
+ /**/
136
+
137
+ if ( $this->isBlack( $src, $list_1 ) ) {
138
+ $script->setAttribute( "type", "text/plain" );
139
+ $script->setAttribute( "class", $script->getAttribute( "class" ) . " " . $class[0] );
140
+ } elseif ( $this->isBlack( $script->nodeValue, $list_1 ) ) {
141
+ $script->setAttribute( "type", "text/plain" );
142
+ $script->setAttribute( "class", $script->getAttribute( "class" ) . " " . $class[1] );
143
+ }
144
+ }
145
+ foreach ( $iframes as $iframe ) {
146
+
147
+ $src = $iframe->getAttribute( "src" );
148
+
149
+ /**/
150
+
151
+ if ( $this->isBlack( $src, $list_2 ) ) {
152
+ $iframe->setAttribute( "src", $blank );
153
+ $iframe->setAttribute( "suppressedsrc", $src );
154
+ $iframe->setAttribute( "class", $iframe->getAttribute( "class" ) . " " . $class[0] );
155
+ }
156
+ }
157
+
158
+ /**/
159
+
160
+ $offender = $document->saveHTML();
161
+
162
+ /**/
163
+
164
+ libxml_use_internal_errors( false );
165
+
166
+ /**/
167
+
168
+ return $offender;
169
+ }
170
+
171
+ }
iubenda-cookie-class/iubenda.class.php ADDED
@@ -0,0 +1,379 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * iubenda.class.php
4
+ * version: 1.0.2
5
+ * @author: Copyright 2015 iubenda
6
+ * @license GNU/GPL
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+
22
+ class iubendaPage {
23
+
24
+ const IUB_REGEX_PATTERN = '/<!--\s*IUB_COOKIE_POLICY_START\s*-->(.*?)<!--\s*IUB_COOKIE_POLICY_END\s*-->/sU';
25
+
26
+ public $auto_script_tags = array(
27
+ 'platform.twitter.com/widgets.js',
28
+ 'apis.google.com/js/plusone.js',
29
+ 'apis.google.com/js/platform.js',
30
+ 'connect.facebook.net',
31
+ 'www.youtube.com/iframe_api',
32
+ 'pagead2.googlesyndication.com/pagead/js/adsbygoogle.js',
33
+ 'sharethis.com/button/buttons.js',
34
+ 'addthis.com/js/',
35
+ 'window.adsbygoogle'
36
+ );
37
+ public $auto_iframe_tags = array(
38
+ 'youtube.com',
39
+ 'platform.twitter.com',
40
+ 'www.facebook.com/plugins/like.php',
41
+ 'www.facebook.com/plugins/likebox.php',
42
+ 'apis.google.com',
43
+ 'www.google.com/maps/embed/',
44
+ 'player.vimeo.com/video',
45
+ 'maps.google.it/maps',
46
+ 'www.google.com/maps/embed',
47
+ 'window.adsbygoogle'
48
+ );
49
+ public $iub_comments_detected = array();
50
+ public $iframe_detected = array();
51
+ public $iframe_converted = array();
52
+ public $scripts_detected = array();
53
+ public $scripts_inline_detected = array();
54
+ public $scripts_inline_converted = array();
55
+ public $scripts_converted = array();
56
+
57
+ /*
58
+ construct: the whole HTML output of the page
59
+ */
60
+
61
+ public function __construct( $content_page ) {
62
+ $this->original_content_page = $content_page;
63
+ $this->content_page = $content_page;
64
+ }
65
+
66
+ /*
67
+ print iubenda banner, parameter: the script code of iubenda to print the banner
68
+ */
69
+
70
+ public function print_banner( $banner ) {
71
+ return $banner.= "\n
72
+ <script>
73
+ var iCallback = function(){};
74
+
75
+ if('callback' in _iub.csConfiguration) {
76
+ if('onConsentGiven' in _iub.csConfiguration.callback) iCallback = _iub.csConfiguration.callback.onConsentGiven;
77
+
78
+ _iub.csConfiguration.callback.onConsentGiven = function()
79
+ {
80
+ iCallback();
81
+
82
+ /*
83
+ * Separator
84
+ */
85
+
86
+ jQuery('noscript._no_script_iub').each(function (a, b) { var el = jQuery(b); el.after(el.html()); });
87
+ };
88
+ };
89
+ </script>";
90
+ }
91
+
92
+ /*
93
+ Static, detect bot & crawler
94
+ */
95
+
96
+ static function bot_detected() {
97
+ return (isset( $_SERVER['HTTP_USER_AGENT'] ) && preg_match( '/bot|crawl|slurp|spider|google|yahoo/i', $_SERVER['HTTP_USER_AGENT'] ));
98
+ }
99
+
100
+ /*
101
+ Static, utility function: Return true if the user has already given consent on the page
102
+ */
103
+
104
+ static function consent_given() {
105
+ foreach ( $_COOKIE as $key => $value ) {
106
+ if ( iubendaPage::strpos_array( $key, array( '_iub_cs-s', '_iub_cs' ) ) ) {
107
+ return true;
108
+ }
109
+ }
110
+ return false;
111
+ }
112
+
113
+ /*
114
+ Static, utility function: strpos for array
115
+ */
116
+
117
+ static function strpos_array( $haystack, $needle ) {
118
+ if ( is_array( $needle ) ) {
119
+ foreach ( $needle as $need ) {
120
+ if ( strpos( $haystack, $need ) !== false ) {
121
+ return true;
122
+ }
123
+ }
124
+ } else {
125
+ if ( strpos( $haystack, $need ) !== false ) {
126
+ return true;
127
+ }
128
+ }
129
+ return false;
130
+ }
131
+
132
+ /* Convert scripts, iframe and other code inside IUBENDAs comment in text/plain to not generate cookies */
133
+
134
+ public function create_tags( $html ) {
135
+
136
+ $elements = $html->find( "*" );
137
+ $js = '';
138
+
139
+ if ( is_array( $elements ) ) {
140
+ $count = count( $elements );
141
+ for ( $j = 0; $j < $count; $j ++ ) {
142
+ $e = $elements[$j];
143
+ switch ( $e->tag ) {
144
+ case 'script':
145
+ $class = $e->class;
146
+ $e->class = $class . ' _iub_cs_activate';
147
+ $e->type = 'text/plain';
148
+ $js.= $e->outertext;
149
+ break;
150
+
151
+ case 'iframe':
152
+ $new_src = "//cdn.iubenda.com/cookie_solution/empty.html";
153
+ $class = $e->class;
154
+ $e->suppressedsrc = $e->src;
155
+ $e->src = $new_src;
156
+ $e->class = $class . ' _iub_cs_activate';
157
+ $js.= $e->outertext;
158
+ break;
159
+
160
+ default:
161
+ $js = $html;
162
+ break;
163
+ }
164
+ }
165
+ }
166
+ return $js;
167
+ }
168
+
169
+ /* Parse all IUBENDAs comment and convert the code inside with create_tags method */
170
+
171
+ public function parse_iubenda_comments() {
172
+ preg_match_all( self::IUB_REGEX_PATTERN, $this->content_page, $scripts );
173
+ if ( is_array( $scripts[1] ) ) {
174
+ $count = count( $scripts[1] );
175
+ $js_scripts = array();
176
+ for ( $j = 0; $j < $count; $j ++ ) {
177
+ $this->iub_comments_detected[] = $scripts[1][$j];
178
+ $html = str_get_html( $scripts[1][$j], $lowercase = true, $forceTagsClosed = true, $stripRN = false );
179
+ $js_scripts[] = $this->create_tags( $html );
180
+ }
181
+
182
+ if ( is_array( $scripts[1] ) && is_array( $js_scripts ) ) {
183
+ if ( count( $scripts[1] ) >= 1 && count( $js_scripts ) >= 1 ) {
184
+ $this->content_page = strtr( $this->content_page, array_combine( $scripts[1], $js_scripts ) );
185
+ }
186
+ }
187
+ }
188
+ }
189
+
190
+ /* Parse automatically all the scripts in the page and converts it in text/plain
191
+ if src or the whole output has inside one of the elements in $auto_script_tags array */
192
+
193
+ public function parse_scripts() {
194
+
195
+ $html = str_get_html( $this->content_page, $lowercase = true, $forceTagsClosed = true, $stripRN = false );
196
+ if ( is_object( $html ) ) {
197
+ $scripts = $html->find( "script" );
198
+ if ( is_array( $scripts ) ) {
199
+ $count = count( $scripts );
200
+ for ( $j = 0; $j < $count; $j ++ ) {
201
+ $s = $scripts[$j];
202
+ if ( ! empty( $s->innertext ) ) {
203
+ $this->scripts_detected[] = $s->innertext;
204
+ if ( iubendaPage::strpos_array( $s->innertext, $this->auto_script_tags ) !== false ) {
205
+ $class = $s->class;
206
+ $s->class = $class . ' _iub_cs_activate-inline';
207
+ $s->type = 'text/plain';
208
+ $this->scripts_converted[] = $s->innertext;
209
+ }
210
+ } else {
211
+ $src = $s->src;
212
+ if ( $src ) {
213
+ $this->scripts_inline_detected[] = $src;
214
+ if ( iubendaPage::strpos_array( $src, $this->auto_script_tags ) !== false ) {
215
+ $class = $s->class;
216
+ $s->class = $class . ' _iub_cs_activate';
217
+ $s->type = 'text/plain';
218
+ $this->scripts_inline_converted[] = $src;
219
+ }
220
+ }
221
+ }
222
+ }
223
+ }
224
+
225
+ /*
226
+ * AdSense check by Peste Vasile Alexandru, AdSense here
227
+ */
228
+
229
+ $ad_found = false;
230
+
231
+ while ( preg_match( "#google_ad_client =(.*?);#i", $html ) ) {
232
+ $ad_found = true;
233
+ $ad_client = null;
234
+ $ad_slot = null;
235
+ $ad_width = null;
236
+ $ad_height = null;
237
+ $ad_block = null;
238
+
239
+ /**/
240
+
241
+ preg_match( "#google_ad_client =(.*?);#i", $html, $ad_client );
242
+ preg_match( "#google_ad_slot =(.*?);#i", $html, $ad_slot );
243
+ preg_match( "#google_ad_width =(.*?);#i", $html, $ad_width );
244
+ preg_match( "#google_ad_height =(.*?);#i", $html, $ad_height );
245
+
246
+ /**/
247
+
248
+ $html = preg_replace( "#google_ad_client =(.*?);#i", "", $html, 1 );
249
+ $html = preg_replace( "#google_ad_slot =(.*?);#i", "", $html, 1 );
250
+ $html = preg_replace( "#google_ad_width =(.*?);#i", "", $html, 1 );
251
+ $html = preg_replace( "#google_ad_height =(.*?);#i", "", $html, 1 );
252
+
253
+ /**/
254
+
255
+ $ad_client = trim( $ad_client[1] );
256
+ $ad_slot = trim( $ad_slot[1] );
257
+ $ad_width = trim( $ad_width[1] );
258
+ $ad_height = trim( $ad_height[1] );
259
+
260
+ /**/
261
+
262
+ $ad_class = 'class="_iub_cs_activate_google_ads"';
263
+ $ad_style = 'style="width:' . $ad_width . 'px; height:' . $ad_height . 'px;"';
264
+
265
+ $ad_client = 'data-client=' . $ad_client;
266
+ $ad_slot = 'data-slot=' . $ad_slot;
267
+ $ad_width = 'data-width="' . $ad_width . '"';
268
+ $ad_height = 'data-height="' . $ad_height . '"';
269
+
270
+ /**/
271
+
272
+ $ad_block = "<div $ad_style $ad_class $ad_width $ad_height $ad_slot $ad_client></div>";
273
+
274
+ /**/
275
+
276
+ $html = preg_replace( '#(<[^>]+) src="//pagead2.googlesyndication.com/pagead/show_ads.js"(.*?)</script>#i', $ad_block, $html, 1 );
277
+ }
278
+
279
+ /**/
280
+
281
+ if ( $ad_found ) {
282
+ $adsense_callback = "
283
+ <script>
284
+ function iubenda_adsense_unblock(){
285
+ var t = 1;
286
+ jQuery('._iub_cs_activate_google_ads').each(function() {
287
+ var banner = jQuery(this);
288
+ setTimeout(function(){
289
+ var client = banner.data('client');
290
+ var slot = banner.data('slot');
291
+ var width = banner.data('width');
292
+ var height = banner.data('height');
293
+ var adsense_script = '<scr'+'ipt>'
294
+ + 'google_ad_client = " . chr( 34 ) . "'+client+'" . chr( 34 ) . ";'
295
+ + 'google_ad_slot = '+slot+';'
296
+ + 'google_ad_width = '+width+';'
297
+ + 'google_ad_height = '+height+';'
298
+ + '</scr'+'ipt>';
299
+ var script = document.createElement('script');
300
+ var ads = document.createElement('ads');
301
+ var w = document.write;
302
+ script.setAttribute('type', 'text/javascript');
303
+ script.setAttribute('src', 'http://pagead2.googlesyndication.com/pagead/show_ads.js');
304
+ document.write = (function(params) {
305
+ ads.innerHTML = params;
306
+ document.write = w;
307
+ });
308
+ banner.html(adsense_script).append(ads).append(script);
309
+ }, t);
310
+ t += 300;
311
+ });
312
+ }
313
+ if('callback' in _iub.csConfiguration) {
314
+ _iub.csConfiguration.callback.onConsentGiven = iubenda_adsense_unblock;
315
+ }
316
+ else
317
+ {
318
+ _iub.csConfiguration.callback = {};
319
+
320
+ _iub.csConfiguration.callback.onConsentGiven = iubenda_adsense_unblock;
321
+ }
322
+ </script>
323
+ ";
324
+
325
+ $html = str_replace( "</body>", $adsense_callback . "</body>", $html );
326
+ }
327
+
328
+ /**/
329
+
330
+ $this->content_page = $html;
331
+ }
332
+ }
333
+
334
+ /* Parse automatically all the iframe in the page and change the src to suppressedsrc
335
+ if src has inside one of the elements in $auto_iframe_tags array */
336
+
337
+ public function parse_iframe() {
338
+ $html = str_get_html( $this->content_page, $lowercase = true, $forceTagsClosed = true, $stripRN = false );
339
+ if ( is_object( $html ) ) {
340
+ $iframes = $html->find( "iframe" );
341
+ if ( is_array( $iframes ) ) {
342
+ $count = count( $iframes );
343
+ for ( $j = 0; $j < $count; $j ++ ) {
344
+ $i = $iframes[$j];
345
+ $src = $i->src;
346
+ $this->iframe_detected[] = $src;
347
+ if ( iubendaPage::strpos_array( $src, $this->auto_iframe_tags ) !== false ) {
348
+ $new_src = "//cdn.iubenda.com/cookie_solution/empty.html";
349
+ $class = $i->class;
350
+ $i->suppressedsrc = $src;
351
+ $i->src = $new_src;
352
+ $i->class = $class . ' _iub_cs_activate';
353
+ $this->iframe_converted[] = $src;
354
+ }
355
+ }
356
+ }
357
+ $this->content_page = $html;
358
+ }
359
+ }
360
+
361
+ /*
362
+ Call three methods to parse the page, iubendas comment, scripts + iframe
363
+ */
364
+
365
+ public function parse() {
366
+ $this->parse_iubenda_comments();
367
+ $this->parse_scripts();
368
+ $this->parse_iframe();
369
+ }
370
+
371
+ /*
372
+ Return the final page to output
373
+ */
374
+
375
+ public function get_converted_page() {
376
+ return $this->content_page;
377
+ }
378
+
379
+ }
iubenda-cookie-class/simple_html_dom.php ADDED
@@ -0,0 +1,1734 @@