iubenda Cookie Solution for GDPR - Version 1.15.0

Version Description

  • New: Option to select iubenda menu position
  • Tweak: iubenda faster class regex update
  • Tweak: Enable style tag in iubenda code field
  • Tweak: Changed default parser method
Download this release

Release Info

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

Code changes from version 1.14.3 to 1.15.0

iubenda-cookie-class/iubenda.class.faster.php CHANGED
@@ -1,9 +1,9 @@
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
@@ -21,16 +21,15 @@
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",
@@ -39,9 +38,7 @@ class iubendaFaster {
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
@@ -62,22 +59,20 @@ class iubendaFaster {
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
 
@@ -85,21 +80,22 @@ class iubendaFaster {
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
 
@@ -111,29 +107,18 @@ class iubendaFaster {
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] );
@@ -146,8 +131,6 @@ class iubendaFaster {
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 );
@@ -155,17 +138,88 @@ class iubendaFaster {
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
  }
1
  <?php
2
  /**
3
  * iubenda.class.php
4
+ * version: 2.0.3
5
  * codename: Faster
6
+ * @author: Copyright 2018 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
21
  */
22
 
23
  class iubendaFaster {
24
+
25
+ // variables
26
+ const IUB_REGEX_PATTERN = '/<!--\s*IUB_COOKIE_POLICY_START\s*-->(.*?)<!--\s*IUB_COOKIE_POLICY_END\s*-->/s';
27
+ const IUB_REGEX_PATTERN_2 = '/<!--\s*IUB-COOKIE-BLOCK-START\s*-->(.*?)<!--\s*IUB-COOKIE-BLOCK-END\s*-->/s';
28
 
29
+ public $iub_comments_detected = array();
30
  private $getBlack = array(
31
  array(
32
+ // domains
 
 
 
33
  "platform.twitter.com/widgets.js",
34
  "apis.google.com/js/plusone.js",
35
  "apis.google.com/js/platform.js",
38
  "pagead2.googlesyndication.com/pagead/js/adsbygoogle.js",
39
  "sharethis.com/button/buttons.js",
40
  "addthis.com/js/",
41
+ // javascript
 
 
42
  "window.adsbygoogle"
43
  ),
44
  array
59
  private $getBlank = "//cdn.iubenda.com/cookie_solution/empty.html";
60
  private $getClass = array( "_iub_cs_activate", "_iub_cs_activate-inline" );
61
 
62
+ /**
63
+ * Methods
64
+ *
65
+ * @param type $offender
66
+ * @param type $blacklist
67
+ * @return boolean
68
  */
 
69
  public function isBlack( $offender, $blacklist ) {
70
+ // check if a string is in the black list.
 
 
 
71
  if ( empty( $offender ) || empty( $blacklist ) ) {
72
 
73
  return false;
74
  }
75
 
 
 
76
  foreach ( $blacklist as $black ) {
77
  if ( strpos( $offender, $black ) !== false ) {
78
 
80
  }
81
  }
82
 
 
 
83
  return false;
84
  }
85
 
86
+ /**
87
+ * Parse automatically all the scripts in the page and converts it in text/plain
88
+ * if src or the whole output has inside one of the elements in $auto_script_tags array
89
+ *
90
+ * @param mixed $content
91
+ * @return mixed
92
+ */
93
+ public function isParse( $content ) {
94
+ // parse the entrie document and search for black elements.
95
  libxml_use_internal_errors( true );
96
 
97
+ // parse all IUBENDAs comment and convert the code inside
98
+ $content = $this->parse_iubenda_comments( $content );
99
 
100
  $src = "";
101
 
107
 
108
  $document = new DOMDocument();
109
 
 
 
110
  $document->formatOutput = true;
111
  $document->preserveWhiteSpace = false;
112
 
113
+ $document->loadHTML( $content );
 
 
 
 
114
 
115
  $scripts = $document->getElementsByTagName( "script" );
116
  $iframes = $document->getElementsByTagName( "iframe" );
117
 
118
+ // parse the founded elements and check who is in black.
 
 
 
119
  foreach ( $scripts as $script ) {
120
  $src = $script->getAttribute( "src" );
121
 
 
 
122
  if ( $this->isBlack( $src, $list_1 ) ) {
123
  $script->setAttribute( "type", "text/plain" );
124
  $script->setAttribute( "class", $script->getAttribute( "class" ) . " " . $class[0] );
131
 
132
  $src = $iframe->getAttribute( "src" );
133
 
 
 
134
  if ( $this->isBlack( $src, $list_2 ) ) {
135
  $iframe->setAttribute( "src", $blank );
136
  $iframe->setAttribute( "suppressedsrc", $src );
138
  }
139
  }
140
 
141
+ $content = $document->saveHTML();
142
 
143
+ libxml_use_internal_errors( false );
144
 
145
+ return $content;
146
+ }
147
 
148
+ /**
149
+ * Parse all IUBENDAs comment and convert the code inside with create_tags method
150
+ *
151
+ * @param mixed $content
152
+ * @return mixed
153
+ */
154
+ public function parse_iubenda_comments( $content ) {
155
+ foreach ( array( 'IUB_REGEX_PATTERN', 'IUB_REGEX_PATTERN_2' ) as $pattern ) {
156
+ preg_match_all( constant( 'self::' . $pattern ), $content, $scripts );
157
+
158
+ // found any content?
159
+ if ( is_array( $scripts[1] ) ) {
160
+ $count = count( $scripts[1] );
161
+ $js_scripts = array();
162
+
163
+ for ( $j = 0; $j < $count; $j ++ ) {
164
+ // keep it for testing
165
+ $this->iub_comments_detected[] = $scripts[1][$j];
166
+
167
+ // get HTML dom from string
168
+ $html = str_get_html( $scripts[1][$j], true, true, false );
169
+
170
+ // convert scripts, iframes and other code inside IUBENDAs comment in text/plain to not generate cookies
171
+ $js_scripts[] = $this->create_tags( $html );
172
+ }
173
 
174
+ if ( is_array( $js_scripts ) && $count >= 1 && count( $js_scripts ) >= 1 )
175
+ $content = strtr( $content, array_combine( $scripts[1], $js_scripts ) );
176
+ }
177
+ }
178
+
179
+ return $content;
180
+ }
181
+
182
+ /**
183
+ * Convert scripts, iframe and other code inside IUBENDAs comment in text/plain to not generate cookies
184
+ *
185
+ * @param mixed $content
186
+ * @return mixed
187
+ */
188
+ public function create_tags( $content ) {
189
+ $elements = $content->find( "*" );
190
+ $js = '';
191
+
192
+ if ( is_array( $elements ) ) {
193
+ $count = count( $elements );
194
+
195
+ for ( $j = 0; $j < $count; $j ++ ) {
196
+ $e = $elements[$j];
197
+
198
+ switch ( $e->tag ) {
199
+ case 'script':
200
+ $class = $e->class;
201
+ $e->class = $class . ' _iub_cs_activate';
202
+ $e->type = 'text/plain';
203
+ $js .= $e->outertext;
204
+ break;
205
+
206
+ case 'iframe':
207
+ $new_src = "//cdn.iubenda.com/cookie_solution/empty.html";
208
+ $class = $e->class;
209
+ $e->suppressedsrc = $e->src;
210
+ $e->src = $new_src;
211
+ $e->class = $class . ' _iub_cs_activate';
212
+ $js .= $e->outertext;
213
+ break;
214
+
215
+ default:
216
+ $js = $content;
217
+ break;
218
+ }
219
+ }
220
+ }
221
 
222
+ return $js;
223
  }
224
 
225
  }
iubenda-cookie-class/iubenda.class.php CHANGED
@@ -1,8 +1,8 @@
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
@@ -21,7 +21,9 @@
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',
@@ -54,21 +56,24 @@ class iubendaPage {
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
 
@@ -89,18 +94,20 @@ if('callback' in _iub.csConfiguration) {
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' ) ) ) {
@@ -110,10 +117,13 @@ if('callback' in _iub.csConfiguration) {
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 ) {
@@ -129,8 +139,12 @@ if('callback' in _iub.csConfiguration) {
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( "*" );
@@ -145,7 +159,7 @@ if('callback' in _iub.csConfiguration) {
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':
@@ -154,7 +168,7 @@ if('callback' in _iub.csConfiguration) {
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:
@@ -166,33 +180,38 @@ if('callback' in _iub.csConfiguration) {
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 ) ) {
@@ -222,10 +241,7 @@ if('callback' in _iub.csConfiguration) {
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 ) ) {
@@ -236,29 +252,21 @@ if('callback' in _iub.csConfiguration) {
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
 
@@ -267,17 +275,11 @@ if('callback' in _iub.csConfiguration) {
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>
@@ -325,17 +327,17 @@ if('callback' in _iub.csConfiguration) {
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 ) ) {
@@ -358,20 +360,20 @@ if('callback' in _iub.csConfiguration) {
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
  }
1
  <?php
2
  /**
3
  * iubenda.class.php
4
+ * version: 1.0.3
5
+ * @author: Copyright 2018 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
21
 
22
  class iubendaPage {
23
 
24
+ // variables
25
+ const IUB_REGEX_PATTERN = '/<!--\s*IUB_COOKIE_POLICY_START\s*-->(.*?)<!--\s*IUB_COOKIE_POLICY_END\s*-->/s';
26
+ const IUB_REGEX_PATTERN_2 = '/<!--\s*IUB-COOKIE-BLOCK-START\s*-->(.*?)<!--\s*IUB-COOKIE-BLOCK-END\s*-->/s';
27
 
28
  public $auto_script_tags = array(
29
  'platform.twitter.com/widgets.js',
56
  public $scripts_inline_converted = array();
57
  public $scripts_converted = array();
58
 
59
+ /**
60
+ * Construct: the whole HTML output of the page
61
+ *
62
+ * @param mixed $content_page
63
  */
 
64
  public function __construct( $content_page ) {
65
  $this->original_content_page = $content_page;
66
  $this->content_page = $content_page;
67
  }
68
 
69
+ /**
70
+ * Print iubenda banner, parameter: the script code of iubenda to print the banner
71
+ *
72
+ * @param string $banner
73
+ * @return string
74
  */
 
75
  public function print_banner( $banner ) {
76
+ return $banner .= "\n
77
  <script>
78
  var iCallback = function(){};
79
 
94
  </script>";
95
  }
96
 
97
+ /**
98
+ * Static, detect bot & crawler
99
+ *
100
+ * @return bool
101
  */
 
102
  static function bot_detected() {
103
+ return ( isset( $_SERVER['HTTP_USER_AGENT'] ) && preg_match( '/bot|crawl|slurp|spider|google|yahoo/i', $_SERVER['HTTP_USER_AGENT'] ) );
104
  }
105
 
106
+ /**
107
+ * Static, utility function: Return true if the user has already given consent on the page
108
+ *
109
+ * @return boolean
110
  */
 
111
  static function consent_given() {
112
  foreach ( $_COOKIE as $key => $value ) {
113
  if ( iubendaPage::strpos_array( $key, array( '_iub_cs-s', '_iub_cs' ) ) ) {
117
  return false;
118
  }
119
 
120
+ /**
121
+ * Static, utility function: strpos for array
122
+ *
123
+ * @param type $haystack
124
+ * @param type $needle
125
+ * @return boolean
126
  */
 
127
  static function strpos_array( $haystack, $needle ) {
128
  if ( is_array( $needle ) ) {
129
  foreach ( $needle as $need ) {
139
  return false;
140
  }
141
 
142
+ /**
143
+ * Convert scripts, iframe and other code inside IUBENDAs comment in text/plain to not generate cookies
144
+ *
145
+ * @param mixed $html
146
+ * @return mixed
147
+ */
148
  public function create_tags( $html ) {
149
 
150
  $elements = $html->find( "*" );
159
  $class = $e->class;
160
  $e->class = $class . ' _iub_cs_activate';
161
  $e->type = 'text/plain';
162
+ $js .= $e->outertext;
163
  break;
164
 
165
  case 'iframe':
168
  $e->suppressedsrc = $e->src;
169
  $e->src = $new_src;
170
  $e->class = $class . ' _iub_cs_activate';
171
+ $js .= $e->outertext;
172
  break;
173
 
174
  default:
180
  return $js;
181
  }
182
 
183
+ /**
184
+ * Parse all IUBENDAs comment and convert the code inside with create_tags method
185
+ */
186
  public function parse_iubenda_comments() {
187
+ foreach ( array( 'IUB_REGEX_PATTERN', 'IUB_REGEX_PATTERN_2' ) as $pattern ) {
188
+ preg_match_all( constant( 'self::' . $pattern ), $this->content_page, $scripts );
189
+
190
+ if ( is_array( $scripts[1] ) ) {
191
+ $count = count( $scripts[1] );
192
+ $js_scripts = array();
193
+ for ( $j = 0; $j < $count; $j ++ ) {
194
+ $this->iub_comments_detected[] = $scripts[1][$j];
195
+ $html = str_get_html( $scripts[1][$j], $lowercase = true, $forceTagsClosed = true, $stripRN = false );
196
+ $js_scripts[] = $this->create_tags( $html );
197
+ }
198
 
199
+ if ( is_array( $scripts[1] ) && is_array( $js_scripts ) ) {
200
+ if ( count( $scripts[1] ) >= 1 && count( $js_scripts ) >= 1 ) {
201
+ $this->content_page = strtr( $this->content_page, array_combine( $scripts[1], $js_scripts ) );
202
+ }
203
  }
204
  }
205
  }
206
  }
207
 
208
+ /**
209
+ * Parse automatically all the scripts in the page and converts it in text/plain
210
+ * if src or the whole output has inside one of the elements in $auto_script_tags array
211
+ */
212
  public function parse_scripts() {
 
213
  $html = str_get_html( $this->content_page, $lowercase = true, $forceTagsClosed = true, $stripRN = false );
214
+
215
  if ( is_object( $html ) ) {
216
  $scripts = $html->find( "script" );
217
  if ( is_array( $scripts ) ) {
241
  }
242
  }
243
 
244
+ // AdSense check by Peste Vasile Alexandru, AdSense here
 
 
 
245
  $ad_found = false;
246
 
247
  while ( preg_match( "#google_ad_client =(.*?);#i", $html ) ) {
252
  $ad_height = null;
253
  $ad_block = null;
254
 
 
 
255
  preg_match( "#google_ad_client =(.*?);#i", $html, $ad_client );
256
  preg_match( "#google_ad_slot =(.*?);#i", $html, $ad_slot );
257
  preg_match( "#google_ad_width =(.*?);#i", $html, $ad_width );
258
  preg_match( "#google_ad_height =(.*?);#i", $html, $ad_height );
259
 
 
 
260
  $html = preg_replace( "#google_ad_client =(.*?);#i", "", $html, 1 );
261
  $html = preg_replace( "#google_ad_slot =(.*?);#i", "", $html, 1 );
262
  $html = preg_replace( "#google_ad_width =(.*?);#i", "", $html, 1 );
263
  $html = preg_replace( "#google_ad_height =(.*?);#i", "", $html, 1 );
264
 
 
 
265
  $ad_client = trim( $ad_client[1] );
266
  $ad_slot = trim( $ad_slot[1] );
267
  $ad_width = trim( $ad_width[1] );
268
  $ad_height = trim( $ad_height[1] );
269
 
 
 
270
  $ad_class = 'class="_iub_cs_activate_google_ads"';
271
  $ad_style = 'style="width:' . $ad_width . 'px; height:' . $ad_height . 'px;"';
272
 
275
  $ad_width = 'data-width="' . $ad_width . '"';
276
  $ad_height = 'data-height="' . $ad_height . '"';
277
 
 
 
278
  $ad_block = "<div $ad_style $ad_class $ad_width $ad_height $ad_slot $ad_client></div>";
279
 
 
 
280
  $html = preg_replace( '#(<[^>]+) src="//pagead2.googlesyndication.com/pagead/show_ads.js"(.*?)</script>#i', $ad_block, $html, 1 );
281
  }
282
 
 
 
283
  if ( $ad_found ) {
284
  $adsense_callback = "
285
  <script>
327
  $html = str_replace( "</body>", $adsense_callback . "</body>", $html );
328
  }
329
 
 
 
330
  $this->content_page = $html;
331
  }
332
  }
333
 
334
+ /**
335
+ * Parse automatically all the iframe in the page and change the src to suppressedsrc
336
+ * if src has inside one of the elements in $auto_iframe_tags array
337
+ */
338
  public function parse_iframe() {
339
  $html = str_get_html( $this->content_page, $lowercase = true, $forceTagsClosed = true, $stripRN = false );
340
+
341
  if ( is_object( $html ) ) {
342
  $iframes = $html->find( "iframe" );
343
  if ( is_array( $iframes ) ) {
360
  }
361
  }
362
 
363
+ /**
364
+ * Call three methods to parse the page, iubendas comment, scripts + iframe
365
  */
 
366
  public function parse() {
367
  $this->parse_iubenda_comments();
368
  $this->parse_scripts();
369
  $this->parse_iframe();
370
  }
371
 
372
+ /**
373
+ * Return the final page to output
374
+ *
375
+ * @return mixed
376
  */
 
377
  public function get_converted_page() {
378
  return $this->content_page;
379
  }
iubenda-cookie-class/test.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * test.php
4
- * @author: Copyright 2015 iubenda
5
  * @license GNU/GPL
6
  * This program is free software: you can redistribute it and/or modify
7
  * it under the terms of the GNU General Public License as published by
@@ -16,99 +16,98 @@
16
  * You should have received a copy of the GNU General Public License
17
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
  */
19
- ini_set( 'max_execution_time', 300 );
 
20
  ?>
21
 
22
  <html>
23
- <head>
24
- <!-- Latest compiled and minified CSS -->
25
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
26
-
27
- <!-- Optional theme -->
28
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
29
- <style>
30
- ul { margin: 0; padding: 0;}
31
- ul li { list-style-type: none; }
32
- </style>
33
- </head>
34
- <body>
35
- <div class="container">
36
- <div class="row">
37
- <div class="col-md-12">
38
- <h1>iubenda class test</h1>
39
- <form action="" method="POST">
40
- <strong>URL WEBSITE</strong><BR>
41
- <input type="text" name="url">
42
- <input type="submit" class="btn" value="Analyze">
43
- </form>
44
- </div>
45
-
46
- <?php
47
- $url = $_POST['url'];
48
- if ( $url || $_GET['url'] ) {
49
-
50
- function print_stuff( $array ) {
51
- if ( count( $array ) ) {
52
- echo "<ul>";
53
- foreach ( $array as $r ) {
54
- echo "<li><pre><code>" . htmlspecialchars( $r ) . "</code></pre></li>";
55
- }
56
- echo "</ul>";
57
- } else {
58
- echo "<p>Nothing</p>";
59
- }
60
  }
 
 
 
 
 
61
 
62
- echo '<div class="col-md-12" style="padding-bottom:150px;"><h2>RESULTS</H2>';
63
-
64
- include_once 'iubenda.class.php';
65
- include_once 'simple_html_dom.php';
66
 
67
- if ( $_GET['url'] ) {
68
- $content = file_get_contents( 'A' );
69
- } else {
70
- $content = file_get_contents( $url );
71
- }
72
 
73
- $page = new iubendaPage( $content );
74
- $page->parse();
75
 
76
- $iub_comments_detected = count( $page->iub_comments_detected );
77
- $scripts_detected = count( $page->scripts_detected );
78
- $iframe_detected = count( $page->iframe_detected );
79
- $iframe_converted = count( $page->iframe_converted );
80
- $script_inline_converted = count( $page->scripts_inline_converted );
81
- $script_converted = count( $page->scripts_converted );
82
 
83
- echo "<p>Iubenda comments detected: $iub_comments_detected<br>Iubenda automatic stuff<br>Iframe detected: $iframe_detected<br>Iframe autoconverted: $iframe_converted<br>Scripts detected: $scripts_detected<br>Inline scripts autoconverted: $script_inline_converted<br>Scripts autoconverted: $script_converted</p>";
84
 
85
- echo "<H3>DETAILS</H3>";
86
 
87
- echo "<H4>iubenda comments stuff</h4>";
88
- print_stuff( $page->iub_comments_detected );
89
 
90
- echo "<H4>Script detected</h4>";
91
- print_stuff( $page->scripts_detected );
92
-
93
- echo "<H4>Script converted</h4>";
94
- print_stuff( $page->scripts_converted );
95
-
96
- echo "<H4>Script inline converted</h4>";
97
- print_stuff( $page->scripts_inline_converted );
98
 
99
- echo "<H4>Iframe detected</h4>";
100
- print_stuff( $page->iframe_detected );
101
-
102
- echo "<H4>Iframe converted</h4>";
103
- print_stuff( $page->iframe_converted );
104
 
105
 
106
 
107
- echo "</div>";
108
- }
109
- ?>
110
- </div>
111
- </div>
112
 
113
- </body>
114
  </html>
1
  <?php
2
  /**
3
  * test.php
4
+ * @author: Copyright 2018 iubenda
5
  * @license GNU/GPL
6
  * This program is free software: you can redistribute it and/or modify
7
  * it under the terms of the GNU General Public License as published by
16
  * You should have received a copy of the GNU General Public License
17
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
  */
19
+
20
+ ini_set('max_execution_time', 300);
21
  ?>
22
 
23
  <html>
24
+ <head>
25
+ <!-- Latest compiled and minified CSS -->
26
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
27
+
28
+ <!-- Optional theme -->
29
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
30
+ <style>
31
+ ul { margin: 0; padding: 0;}
32
+ ul li { list-style-type: none; }
33
+ </style>
34
+ </head>
35
+ <body>
36
+ <div class="container">
37
+ <div class="row">
38
+ <div class="col-md-12">
39
+ <h1>iubenda class test</h1>
40
+ <form action="" method="POST">
41
+ <strong>URL WEBSITE</strong><BR>
42
+ <input type="text" name="url">
43
+ <input type="submit" class="btn" value="Analyze">
44
+ </form>
45
+ </div>
46
+
47
+ <?php
48
+ $url = $_POST['url'];
49
+
50
+ if ( $url || $_GET['url'] ) {
51
+
52
+ function print_stuff( $array ) {
53
+ if ( count( $array ) ) {
54
+ echo "<ul>";
55
+ foreach ( $array as $r ) {
56
+ echo "<li><pre><code>" . htmlspecialchars( $r ) . "</code></pre></li>";
 
 
 
 
57
  }
58
+ echo "</ul>";
59
+ } else {
60
+ echo "<p>Nothing</p>";
61
+ }
62
+ }
63
 
64
+ echo '<div class="col-md-12" style="padding-bottom:150px;"><h2>RESULTS</H2>';
65
+
66
+ include_once 'iubenda.class.php';
67
+ include_once 'simple_html_dom.php';
68
 
69
+ if ( $_GET['url'] ) {
70
+ $content = file_get_contents( 'A' );
71
+ } else {
72
+ $content = file_get_contents( $url );
73
+ }
74
 
75
+ $page = new Page( $content );
76
+ $page->parse();
77
 
78
+ $iub_comments_detected = count( $page->iub_comments_detected );
79
+ $scripts_detected = count( $page->scripts_detected );
80
+ $iframe_detected = count( $page->iframe_detected );
81
+ $iframe_converted = count( $page->iframe_converted );
82
+ $script_inline_converted = count( $page->scripts_inline_converted );
83
+ $script_converted = count( $page->scripts_converted );
84
 
85
+ echo "<p>Iubenda comments detected: $iub_comments_detected<br>Iubenda automatic stuff<br>Iframe detected: $iframe_detected<br>Iframe autoconverted: $iframe_converted<br>Scripts detected: $scripts_detected<br>Inline scripts autoconverted: $script_inline_converted<br>Scripts autoconverted: $script_converted</p>";
86
 
87
+ echo "<H3>DETAILS</H3>";
88
 
89
+ echo "<H4>iubenda comments stuff</h4>";
90
+ print_stuff( $page->iub_comments_detected );
91
 
92
+ echo "<H4>Script detected</h4>";
93
+ print_stuff( $page->scripts_detected );
94
+ echo "<H4>Script converted</h4>";
95
+ print_stuff( $page->scripts_converted );
96
+ echo "<H4>Script inline converted</h4>";
97
+ print_stuff( $page->scripts_inline_converted );
 
 
98
 
99
+ echo "<H4>Iframe detected</h4>";
100
+ print_stuff( $page->iframe_detected );
101
+ echo "<H4>Iframe converted</h4>";
102
+ print_stuff( $page->iframe_converted );
 
103
 
104
 
105
 
106
+ echo "</div>";
107
+ }
108
+ ?>
109
+ </div>
110
+ </div>
111
 
112
+ </body>
113
  </html>
iubenda-cookie-class/usage.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * usage.php
4
- * @author: Copyright 2015 iubenda
5
  * @license GNU/GPL
6
  * This program is free software: you can redistribute it and/or modify
7
  * it under the terms of the GNU General Public License as published by
@@ -16,38 +16,32 @@
16
  * You should have received a copy of the GNU General Public License
17
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
  */
 
19
  // the "$html" parameter must contain the content of the web page with the iubenda JavaScript banner/policy included
20
 
21
  function iubenda_system( $html ) {
22
  if ( empty( $html ) )
23
  return;
24
 
25
- /*
26
- * Separator
27
- */
28
-
29
  if ( ! function_exists( "file_get_html" ) ) {
30
  require_once("simple_html_dom.php");
31
  }
32
 
33
  require_once("iubenda.class.php");
34
 
35
- /*
36
- * Separator
37
- */
38
-
39
- if ( ! iubendaPage::consent_given() && ! iubendaPage::bot_detected() ) {
40
  $page = new Page( $html );
41
  $page->parse();
42
  $html = $page->get_converted_page();
43
  }
44
 
45
- /* Finished */
46
-
47
  return $html;
48
  }
49
 
50
- /*
51
  *
52
  * Example:
53
  *
1
  <?php
2
  /**
3
  * usage.php
4
+ * @author: Copyright 2018 iubenda
5
  * @license GNU/GPL
6
  * This program is free software: you can redistribute it and/or modify
7
  * it under the terms of the GNU General Public License as published by
16
  * You should have received a copy of the GNU General Public License
17
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
  */
19
+
20
  // the "$html" parameter must contain the content of the web page with the iubenda JavaScript banner/policy included
21
 
22
  function iubenda_system( $html ) {
23
  if ( empty( $html ) )
24
  return;
25
 
26
+ // separator
 
 
 
27
  if ( ! function_exists( "file_get_html" ) ) {
28
  require_once("simple_html_dom.php");
29
  }
30
 
31
  require_once("iubenda.class.php");
32
 
33
+ // separator
34
+ if ( ! Page::consent_given() && ! Page::bot_detected() ) {
 
 
 
35
  $page = new Page( $html );
36
  $page->parse();
37
  $html = $page->get_converted_page();
38
  }
39
 
40
+ // finished
 
41
  return $html;
42
  }
43
 
44
+ /**
45
  *
46
  * Example:
47
  *
iubenda_cookie_solution.php CHANGED
@@ -1,750 +1,780 @@
1
- <?php
2
- /*
3
- Plugin Name: iubenda Cookie Solution
4
- Plugin URI: https://www.iubenda.com
5
- Description: The iubenda Cookie Solution allows you to manage all aspects of the cookie law on WP.
6
- Version: 1.14.3
7
- Author: iubenda
8
- Author URI: https://www.iubenda.com
9
- License: MIT License
10
- License URI: http://opensource.org/licenses/MIT
11
- Text Domain: iubenda-cookie-law-solution
12
- Domain Path: /languages
13
-
14
- ibenda Cookie Solution
15
- Copyright (C) 2016-2017, iubenda s.r.l
16
-
17
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
18
-
19
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- */
23
-
24
- // exit if accessed directly
25
- if ( ! defined( 'ABSPATH' ) )
26
- exit;
27
-
28
- // define contants
29
- define( 'IUB_DEBUG', false );
30
-
31
- // set plugin instance
32
- $iubenda_cookie_law_solution = new iubenda_Cookie_Law_Solution();
33
-
34
- /**
35
- * iubenda_Cookie_Law_Solution final class.
36
- *
37
- * @class iubenda_Cookie_Law_Solution
38
- * @version 1.14.3
39
- */
40
- class iubenda_Cookie_Law_Solution {
41
-
42
- public $options;
43
- public $defaults = array(
44
- 'parse' => false, // iubenda_parse
45
- 'skip_parsing' => true, // skip_parsing
46
- 'ctype' => true, // iubenda_ctype
47
- 'parse' => false, // iubenda_parse
48
- 'parser_engine' => 'default', // parser_engine
49
- 'output_feed' => true, // iubenda_output_feed
50
- 'code_default' => false, // iubenda-code-default,
51
- 'loading' => 'header',
52
- 'deactivation' => false
53
- );
54
- public $version = '1.14.3';
55
- public $no_html = false;
56
- public $links = array();
57
- public $multilang = false;
58
- public $languages = array();
59
- public $lang_default = '';
60
-
61
- /**
62
- * Class constructor.
63
- */
64
- public function __construct() {
65
- register_activation_hook( __FILE__, array( $this, 'activation' ) );
66
- register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );
67
-
68
- // settings
69
- $this->options = array_merge( $this->defaults, (array) get_option( 'iubenda_cookie_law_solution', $this->defaults ) );
70
-
71
- // actions
72
- add_action( 'admin_init', array( $this, 'register_options' ) );
73
- add_action( 'admin_init', array( $this, 'update_plugin' ), 9 );
74
- add_action( 'admin_menu', array( $this, 'admin_menu_options' ) );
75
- add_action( 'admin_notices', array( $this, 'settings_errors' ) );
76
- // add_action( 'admin_menu', array( $this, 'save_options' ), 9 );
77
- add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
78
- add_action( 'plugins_loaded', array( $this, 'init' ) );
79
- add_action( 'after_setup_theme', array( $this, 'register_shortcode' ) );
80
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
81
- add_action( 'admin_print_styles', array( $this, 'admin_print_styles' ) );
82
- add_action( 'init', array( $this, 'script_position' ) );
83
- add_action( 'template_redirect', array( $this, 'output_start' ), 0 );
84
- add_action( 'shutdown', array( $this, 'output_end' ), 100 );
85
- }
86
-
87
- /**
88
- * Initialize plugin.
89
- *
90
- * @return void
91
- */
92
- public function init() {
93
-
94
- // check if WPML or Polylang is active
95
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
96
-
97
- // Polylang support
98
- if ( is_plugin_active( 'polylang/polylang.php' ) && function_exists( 'PLL' ) ) {
99
- $this->multilang = true;
100
-
101
- // get registered languages
102
- $registered_languages = PLL()->model->get_languages_list();
103
-
104
- if ( ! empty( $registered_languages ) ) {
105
- foreach ( $registered_languages as $language )
106
- $this->languages[$language->slug] = $language->name;
107
- }
108
-
109
- // get default language
110
- $this->lang_default = pll_default_language();
111
-
112
- // WPML support
113
- } elseif ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && class_exists( 'SitePress' ) ) {
114
- $this->multilang = true;
115
-
116
- global $sitepress;
117
-
118
- // get registered languages
119
- $registered_languages = icl_get_languages();
120
-
121
- if ( ! empty( $registered_languages ) ) {
122
- foreach ( $registered_languages as $language )
123
- $this->languages[$language['code']] = $language['display_name'];
124
- }
125
-
126
- // get default language
127
- $this->lang_default = $sitepress->get_default_language();
128
- }
129
-
130
- // load Simple HTML DOM if needed
131
- if ( ! function_exists( 'file_get_html' ) ) {
132
- require_once( dirname( __FILE__ ) . '/iubenda-cookie-class/simple_html_dom.php' );
133
- }
134
-
135
- // load plugin class
136
- require_once( dirname( __FILE__ ) . '/iubenda-cookie-class/iubenda.class.faster.php' );
137
- require_once( dirname( __FILE__ ) . '/iubenda-cookie-class/iubenda.class.php' );
138
-
139
- $links = array(
140
- 'en' => array(
141
- 'guide' => 'https://www.iubenda.com/en/iubenda-cookie-law-solution',
142
- 'plugin_page' => 'https://www.iubenda.com/en/help/posts/1215',
143
- 'generating_code' => 'https://www.iubenda.com/en/help/posts/1177',
144
- 'support_forum' => 'https://support.iubenda.com/forums/314835-general/suggestions/9670701-discussion-regarding-the-iubenda-cookie-law-soluti',
145
- 'documentation' => 'https://www.iubenda.com/en/help/posts/1215'
146
- ),
147
- 'it' => array(
148
- 'guide' => 'https://www.iubenda.com/it/soluzione-cookie-law',
149
- 'plugin_page' => 'https://www.iubenda.com/it/help/posts/810',
150
- 'generating_code' => 'https://www.iubenda.com/it/help/posts/680',
151
- 'support_forum' => 'https://support.iubenda.com/forums/314835-general/suggestions/9670701-discussion-regarding-the-iubenda-cookie-law-soluti',
152
- 'documentation' => 'https://www.iubenda.com/it/help/posts/810',
153
- )
154
- );
155
-
156
- $locale = explode( '_', get_locale() );
157
- $locale_code = $locale[0];
158
-
159
- // assign links
160
- $this->links = in_array( $locale_code, array_keys( $links ) ) ? $links[$locale_code] : $links['en'];
161
- }
162
-
163
- /**
164
- * Plugin activation.
165
- *
166
- * @return void
167
- */
168
- public function activation() {
169
- add_option( 'iubenda_cookie_law_solution', $this->options, '', 'no' );
170
- add_option( 'iubenda_cookie_law_version', $this->version, '', 'no' );
171
- }
172
-
173
- /**
174
- * Plugin deactivation.
175
- *
176
- * @return void
177
- */
178
- public function deactivation() {
179
- // remove options from database?
180
- if ( $this->options['deactivation'] ) {
181
- delete_option( 'iubenda_cookie_law_solution' );
182
- delete_option( 'iubenda_cookie_law_version' );
183
- }
184
- }
185
-
186
- /**
187
- * Plugin options migration for versions < 1.14.0
188
- *
189
- * @return void
190
- */
191
- public function update_plugin() {
192
- if ( ! current_user_can( 'install_plugins' ) )
193
- return;
194
-
195
- $db_version = get_option( 'iubenda_cookie_law_version' );
196
- $db_version = ! $db_version ? '1.13.0' : $db_version;
197
-
198
- if ( $db_version != false ) {
199
- if ( version_compare( $db_version, '1.14.0', '<' ) ) {
200
- $options = array();
201
-
202
- $old_new = array(
203
- 'iubenda_parse' => 'parse',
204
- 'skip_parsing' => 'skip_parsing',
205
- 'iubenda_ctype' => 'ctype',
206
- 'iubenda_parse' => 'parse',
207
- 'parser_engine' => 'parser_engine',
208
- 'iubenda_output_feed' => 'output_feed',
209
- 'iubenda-code-default' => 'code_default',
210
- 'default_skip_parsing' => '',
211
- 'default_iubendactype' => '',
212
- 'default_iubendaparse' => '',
213
- 'default_parser_engine' => '',
214
- 'iub_code' => '',
215
- );
216
-
217
- foreach ( $old_new as $old => $new ) {
218
- if ( $new ) {
219
- $options[$new] = get_option( $old );
220
- }
221
- delete_option( $old );
222
- }
223
-
224
- // multilang support
225
- if ( ! empty( $this->languages ) ) {
226
- foreach ( $this->languages as $lang ) {
227
- $code = get_option( 'iubenda-code-' . $lang );
228
-
229
- if ( ! empty( $code ) ) {
230
- $options['code_' . $lang] = $code;
231
-
232
- delete_option( 'iubenda-code-' . $lang );
233
- }
234
- }
235
- }
236
-
237
- add_option( 'iubenda_cookie_law_solution', $options, '', 'no' );
238
- add_option( 'iubenda_cookie_law_version', $this->version, '', 'no' );
239
- }
240
- }
241
- }
242
-
243
- /**
244
- * Register shortcode function.
245
- */
246
- public function register_shortcode() {
247
- add_shortcode( 'iub-cookie-policy', array( $this, 'shortcode' ) );
248
- }
249
-
250
- /**
251
- * Handle shortcode function.
252
- *
253
- * @param array $atts
254
- * @param mixed $content
255
- * @return mixed
256
- */
257
- public function shortcode( $atts, $content = '' ) {
258
- return '<!--IUB_COOKIE_POLICY_START-->' . do_shortcode( $content ) . '<!--IUB_COOKIE_POLICY_END-->';
259
- }
260
-
261
- /**
262
- * Add submenu.
263
- */
264
- public function admin_menu_options() {
265
- add_menu_page(
266
- 'iubenda', 'iubenda', apply_filters( 'iubenda_cookie_law_cap', 'manage_options' ), 'iubenda-cookie-law-solution', array( $this, 'options_page' ), 'none'
267
- );
268
- }
269
-
270
- /**
271
- * Load textdomain.
272
- */
273
- public function load_textdomain() {
274
- load_plugin_textdomain( 'iubenda-cookie-law-solution', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
275
- }
276
-
277
- /**
278
- * Load admin scripts and styles.
279
- *
280
- * @param string $page
281
- * @return void
282
- */
283
- public function admin_enqueue_scripts( $page ) {
284
- if ( $page !== 'toplevel_page_iubenda-cookie-law-solution' )
285
- return;
286
-
287
- wp_enqueue_script(
288
- 'iubenda-admin', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' )
289
- );
290
-
291
- wp_enqueue_style( 'iubenda-admin', plugins_url( 'css/admin.css', __FILE__ ) );
292
- }
293
-
294
- /**
295
- * Load admin style inline, for menu icon only.
296
- *
297
- * @return mixed
298
- */
299
- public function admin_print_styles() {
300
- echo '
301
- <style>
302
- a.toplevel_page_iubenda-cookie-law-solution .wp-menu-image {
303
- background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDkuNDE4IiBoZWlnaHQ9IjI3My4wMTgiIHZpZXdCb3g9IjAgMCAxMDkuNDE4IDI3My4wMTgiPjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBmaWxsPSIjRkZGIiBkPSJNMTA5LjQxOCA1NC41M0MxMDkuNDE4IDI0LjQwNCA4NC45MzYgMCA1NC43MDggMCAyNC40ODYgMCAwIDI0LjQwNCAwIDU0LjUzYzAgMTQuNzY1IDUuOSAyOC4xNCAxNS40ODcgMzcuOTUzTDQuMTI0IDI3My4wMThoMTAzLjg3TDk2LjQ3NyA4OS43MzJjOC4wODYtOS41MDQgMTIuOTQtMjEuNzgyIDEyLjk0LTM1LjIwMnptLTY1LjM2LTkuOTAzQzQ3LjAwNyA0MS42OCA1MC42MyA0MC4yIDU0LjkzIDQwLjJjNC4yIDAgNy43NzMgMS40OCAxMC43MjUgNC40MjcgMi45NDggMi45NDggNC40MjQgNi41MjIgNC40MjQgMTAuNzI0IDAgNC4xOTctMS40NzYgNy43OTUtNC40MjQgMTAuNzk1LTIuOTUyIDMtNi41MjQgNC40OTgtMTAuNzI0IDQuNDk4LTQuMTk4IDAtNy44LTEuNDk4LTEwLjc5Ny00LjQ5OC0zLTMtNC41LTYuNi00LjUtMTAuNzk0LS4wMDItNC4yIDEuNDczLTcuNzc0IDQuNDI2LTEwLjcyM3ptNDQuMTY1IDIwOC44M0gyMS40ODZ2LTUuNDAyYzYuNyAwIDExLjItLjY0NiAxMy40OTgtMS45NDYgMi4yOTgtMS4yOTUgNC4xMjUtMy40NSA1LjQ3NS02LjQ0NyAxLjM0Ni0zIDIuMDIzLTguNzQ3IDIuMDIzLTE3LjI0N3YtNTIuOTQzYzAtMTQuODk4LS40NTMtMjQuNTQtMS4zNTItMjguOTQ0LS42OTgtMy4xOTYtMS43OTctNS40Mi0zLjMtNi42Ny0xLjQ5NS0xLjI1LTMuNTQ4LTEuODc0LTYuMTQ3LTEuODc0LTIuNzk4IDAtNi4yLjc1LTEwLjE5NyAyLjI1bC0yLjEwMi01LjQgNDEuMzk0LTE2Ljc5N2g2LjZ2MTEwLjM3N2MwIDguNTk4LjYyNCAxNC4zMiAxLjg3NSAxNy4xNyAxLjI1IDIuODQ4IDMuMDk2IDQuOTc0IDUuNTQ4IDYuMzc0IDIuNDUgMS40MDMgNi45MjYgMi4wOTcgMTMuNDIzIDIuMDk3djUuNHoiLz48L3N2Zz4=);
304
- background-position: center center;
305
- background-repeat: no-repeat;
306
- background-size: 7px auto;
307
- }
308
- </style>
309
- ';
310
- }
311
-
312
- /**
313
- * Enqueue frontend scripts.
314
- *
315
- * @return mixed
316
- */
317
- public function script_position() {
318
- // break on admin side
319
- if ( is_admin() ) {
320
- return;
321
- }
322
-
323
- if ( $this->options['loading'] === 'footer' ) {
324
- add_action( 'wp_footer', array( $this, 'script_load' ), 99 );
325
- } else {
326
- add_action( 'wp_head', array( $this, 'script_load' ), 99 );
327
- }
328
- }
329
-
330
- /**
331
- * Load scripts.
332
- *
333
- * @return string
334
- */
335
- public function script_load() {
336
- /* check if user is logged in, then disable the banner.
337
- if ( is_user_logged_in() ) {
338
- return;
339
- }
340
- */
341
-
342
- // check content type
343
- if ( (bool) $this->options['ctype'] == true ) {
344
- $iub_headers = headers_list();
345
- $destroy = true;
346
-
347
- foreach ( $iub_headers as $h ) {
348
- if ( strpos( $h, "Content-Type: text/html" ) !== false || strpos( $h, "Content-type: text/html" ) !== false ) {
349
- $destroy = false;
350
- }
351
- }
352
-
353
- if ( $destroy ) {
354
- $this->no_html = true;
355
- }
356
- }
357
-
358
- // is post or not html content type?
359
- if ( $_POST || $this->no_html ) {
360
- return;
361
- }
362
-
363
- // initial head output
364
- $iubenda_code = "";
365
-
366
- if ( $this->multilang === true && defined( 'ICL_LANGUAGE_CODE' ) && isset( $this->options['code_' . ICL_LANGUAGE_CODE] ) ) {
367
- $iubenda_code .= $this->options['code_' . ICL_LANGUAGE_CODE];
368
-
369
- // no code for current language, use default
370
- if ( ! $iubenda_code ) {
371
- $iubenda_code .= $this->options['code_default'];
372
- }
373
- } else {
374
- $iubenda_code .= $this->options['code_default'];
375
- }
376
-
377
- $iubenda_code = apply_filters( 'iubenda_script_code', $iubenda_code );
378
-
379
- $iubenda_code .= "\n
380
- <script>
381
- var iCallback = function() {};
382
-
383
- if ( typeof _iub.csConfiguration != 'undefined' ) {
384
- if ( 'callback' in _iub.csConfiguration ) {
385
- if ( 'onConsentGiven' in _iub.csConfiguration.callback )
386
- iCallback = _iub.csConfiguration.callback.onConsentGiven;
387
-
388
- _iub.csConfiguration.callback.onConsentGiven = function() {
389
- iCallback();
390
-
391
- /* separator */
392
- jQuery('noscript._no_script_iub').each(function (a, b) { var el = jQuery(b); el.after(el.html()); });
393
- }
394
- }
395
- }
396
- </script>";
397
-
398
- echo apply_filters( 'iubenda_code', $iubenda_code );
399
- }
400
-
401
- /**
402
- * Initialize html output.
403
- *
404
- * @return void
405
- */
406
- public function output_start() {
407
- if ( ! is_admin() ) {
408
- ob_start( array( $this, 'output_callback' ) );
409
- }
410
- }
411
-
412
- /**
413
- * Finish html output.
414
- *
415
- * @return void
416
- */
417
- public function output_end() {
418
- if ( ! is_admin() && ob_get_level() ) {
419
- ob_end_flush();
420
- }
421
- }
422
-
423
- /**
424
- * Handle final html output.
425
- *
426
- * @param mixed $output
427
- * @return mixed
428
- */
429
- public function output_callback( $output ) {
430
- // break on ajax, xmlrpc or iub_no_parse request
431
- if (
432
- ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST )
433
- || ( defined( 'DOING_AJAX' ) && DOING_AJAX )
434
- || isset( $_SERVER["HTTP_X_REQUESTED_WITH"] )
435
- || isset( $_GET['iub_no_parse'] )
436
- ) {
437
- return $output;
438
- }
439
-
440
- // break on admin side
441
- if ( is_admin() ) {
442
- return $output;
443
- }
444
-
445
- // break for logged in users?
446
- /* if ( is_user_logged_in() ) {
447
- return $output;
448
- }
449
- */
450
-
451
- // break on rss feed
452
- if ( is_feed() && $this->options['output_feed'] ) {
453
- return $output;
454
- }
455
-
456
- if ( strpos( $output, "<html" ) === false ) {
457
- return $output;
458
- } elseif ( strpos( $output, "<html" ) > 200 ) {
459
- return $output;
460
- }
461
-
462
- // check whether to run parser or not
463
- if (
464
- ! $this->options['parse'] || ( iubendaPage::consent_given() && $this->options['skip_parsing'] ) || iubendaPage::bot_detected() || $_POST || $this->no_html ) {
465
-
466
- return $output;
467
- }
468
-
469
- $startime = microtime( true );
470
-
471
- // experimental class
472
- if ( $this->options['parser_engine'] == 'new' ) {
473
- $faster = new iubendaFaster;
474
-
475
- // render output
476
- $output = $faster->isParse( mb_convert_encoding( $output, 'HTML-ENTITIES', 'UTF-8' ) );
477
-
478
- // append signature
479
- $output .= '<!-- Parsed with iubenda experimental class in ' . round( microtime( true ) - $startime, 4 ) . ' sec. -->';
480
- // default class
481
- } else {
482
- $page = new iubendaPage( $output );
483
- $page->parse();
484
-
485
- // render output
486
- $output = $page->get_converted_page();
487
-
488
- // append signature
489
- $output .= '<!-- Parsed with iubenda default class in ' . round( microtime( true ) - $startime, 4 ) . ' sec. -->';
490
- }
491
-
492
- return apply_filters( 'iubenda_final_output', $output );
493
- }
494
-
495
- /**
496
- * Register plugin options.
497
- */
498
- public function register_options() {
499
- register_setting( 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution', array( $this, 'save_options' ) );
500
-
501
- add_settings_section( 'iubenda_cookie_law_solution', '', '', 'iubenda_cookie_law_solution' );
502
- add_settings_field( 'iub_code', __( 'Code', 'iubenda-cookie-law-solution' ), array( $this, 'iub_code' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
503
- add_settings_field( 'iub_parse', __( 'Scripts blocking', 'iubenda-cookie-law-solution' ), array( $this, 'iub_parse' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
504
- add_settings_field( 'iub_loading', __( 'Scripts loading', 'iubenda-cookie-law-solution' ), array( $this, 'iub_loading' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
505
- add_settings_field( 'iub_ctype', __( 'Content type', 'iubenda-cookie-law-solution' ), array( $this, 'iub_ctype' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
506
- add_settings_field( 'iub_output_feed', __( 'RSS feed', 'iubenda-cookie-law-solution' ), array( $this, 'iub_output_feed' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
507
- add_settings_field( 'iub_deactivatioin', __( 'Deactivation', 'iubenda-cookie-law-solution' ), array( $this, 'iub_deactivation' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
508
- }
509
-
510
- /**
511
- * Display errors and notices.
512
- */
513
- public function settings_errors() {
514
- settings_errors( 'iub_settings_errors' );
515
- }
516
-
517
- /**
518
- * Code option.
519
- *
520
- * @return mixed
521
- */
522
- public function iub_code() {
523
- // multilang support
524
- if ( $this->multilang && ! empty( $this->languages ) ) {
525
- echo '
526
- <div id="contextual-help-wrap" class="hidden" tabindex="-1" style="display: block;">
527
- <div id="contextual-help-back"></div>
528
- <div id="contextual-help-columns">
529
- <div class="contextual-help-tabs">
530
- <ul>';
531
- foreach ( $this->languages as $lang_id => $lang_name ) {
532
- echo '
533
- <li id="tab-link-overview" class="' . ( $this->lang_default == $lang_id ? 'active' : '' ) . '">
534
- <a href="#tab-panel-' . $lang_id . '" aria-controls="tab-panel-' . $lang_id . '">' . $lang_name . '</a>
535
- </li>';
536
- }
537
- echo '
538
- </ul>
539
- </div>
540
-
541
- <div class="contextual-help-tabs-wrap">';
542
- foreach ( $this->languages as $lang_id => $lang_name ) {
543
- // get code for the language
544
- $code = ! empty( $this->options['code_' . $lang_id] ) ? html_entity_decode( trim( wp_kses( $this->options['code_' . $lang_id], array( 'script' => array( 'type' => array(), 'src' => array(), 'charset' => array(), 'async' => array() ) ) ) ) ) : '';
545
- // handle default, if empty
546
- $code = empty( $code ) && $lang_id == $this->lang_default ? html_entity_decode( trim( wp_kses( $this->options['code_default'], array( 'script' => array( 'type' => array(), 'src' => array(), 'charset' => array(), 'async' => array() ) ) ) ) ) : $code;
547
-
548
- echo '
549
- <div id="tab-panel-' . $lang_id . '" class="help-tab-content' . ( $this->lang_default == $lang_id ? ' active' : '' ) . '">
550
- <textarea name="iubenda_cookie_law_solution[code_' . $lang_id . ']" class="large-text" cols="50" rows="10">' . $code . '</textarea>
551
- <p class="description">' . sprintf( __( 'Enter the iubenda code for %s.', 'iubenda-cookie-law-solution' ), $lang_name ) . '</p>
552
- </div>';
553
- }
554
- echo '
555
- </div>
556
- </div>
557
- </div>';
558
- } else {
559
- echo '
560
- <div id="iub_code_default">
561
- <textarea name="iubenda_cookie_law_solution[code_default]" class="large-text" cols="50" rows="10">' . html_entity_decode( trim( wp_kses( $this->options['code_default'], array( 'script' => array( 'type' => array(), 'src' => array(), 'charset' => array(), 'async' => array() ) ) ) ) ) . '</textarea>
562
- <p class="description">' . __( 'Enter the iubenda code.', 'iubenda-cookie-law-solution' ) . '</p>
563
- </div>';
564
- }
565
- }
566
-
567
- /**
568
- * Parsing option.
569
- *
570
- * @return mixed
571
- */
572
- public function iub_parse() {
573
- echo '
574
- <div id="iub_parse_container">
575
- <label><input id="iub_parse" type="checkbox" name="iubenda_cookie_law_solution[parse]" value="1" ' . checked( true, (bool) $this->options['parse'], false ) . '/>' . __( 'Automatically block scripts detected by the plugin.', 'iubenda-cookie-law-solution' ) . '</label>
576
- <p class="description">' . '(' . sprintf( __( "see <a href=\"%s\" target=\"_blank\">our documentation</a> for the list of detected scripts.", 'iubenda-cookie-law-solution' ), $this->links['documentation'] ) . ')' . '</p>
577
- <div id="iub_parser_engine_container"' . ( $this->options['parse'] === false ? ' style="display: none;"' : '' ) . '>
578
- <div>
579
- <label><input id="iub_parser_engine-default" type="radio" name="iubenda_cookie_law_solution[parser_engine]" value="default" ' . checked( 'default', $this->options['parser_engine'], false ) . ' />' . __( 'Default', 'iubenda-cookie-law-solution' ) . '</label>
580
- <label><input id="iub_parser_engine-new" type="radio" name="iubenda_cookie_law_solution[parser_engine]" value="new" ' . checked( 'new', $this->options['parser_engine'], false ) . ' />' . __( 'Experimental', 'iubenda-cookie-law-solution' ) . '</label>
581
- <p class="description">' . __( 'Select parsing engine.', 'iubenda-cookie-law-solution' ) . '</p>
582
- </div>
583
- <div>
584
- <label><input id="iub_skip_parsing" type="checkbox" name="iubenda_cookie_law_solution[skip_parsing]" value="1" ' . checked( true, (bool) $this->options['skip_parsing'], false ) . '/>' . __( 'Leave scripts untouched on the page if the user has already given consent', 'iubenda-cookie-law-solution' ) . '</label>
585
- <p class="description">(' . __( "improves performance, highly recommended, to be deactivated only if your site uses a caching system", 'iubenda-cookie-law-solution' ) . ')</p>
586
- </div>
587
- </div>
588
- </div>';
589
- }
590
-
591
- /**
592
- * Scripts loading option.
593
- *
594
- * @return mixed
595
- */
596
- public function iub_loading() {
597
- echo '
598
- <div id="iub_loading_container">
599
- <label><input id="iub_loading-header" type="radio" name="iubenda_cookie_law_solution[loading]" value="header" ' . checked( 'header', $this->options['loading'], false ) . ' />' . __( 'Header', 'iubenda-cookie-law-solution' ) . '</label>
600
- <label><input id="iub_loading_footer" type="radio" name="iubenda_cookie_law_solution[loading]" value="footer" ' . checked( 'footer', $this->options['loading'], false ) . ' />' . __( 'Footer', 'iubenda-cookie-law-solution' ) . '</label>
601
- <p class="description">' . __( 'Select scripts loading position.', 'iubenda-cookie-law-solution' ) . '</p>
602
- </div>';
603
- }
604
-
605
- /**
606
- * Ctype option.
607
- *
608
- * @return mixed
609
- */
610
- public function iub_ctype() {
611
- echo '
612
- <div id="iub_ctype_container">
613
- <label><input id="iub_ctype" type="checkbox" name="iubenda_cookie_law_solution[ctype]" value="1" ' . checked( true, (bool) $this->options['ctype'], false ) . '/>' . __( 'Restrict the plugin to run only for requests that have "Content-type: text / html" (recommended)', 'iubenda-cookie-law-solution' ) . '</label>
614
- </div>';
615
- }
616
-
617
- /**
618
- * RSS feed option.
619
- *
620
- * @return mixed
621
- */
622
- public function iub_output_feed() {
623
- echo '
624
- <div id="iub_output_feed_container">
625
- <label><input id="iub_ctype" type="checkbox" name="iubenda_cookie_law_solution[output_feed]" value="1" ' . checked( true, (bool) $this->options['output_feed'], false ) . '/>' . __( 'Do not run the plugin inside the RSS feed (recommended)', 'iubenda-cookie-law-solution' ) . '</label>
626
- </div>';
627
- }
628
-
629
- /**
630
- * Deactivation option.
631
- *
632
- * @return mixed
633
- */
634
- public function iub_deactivation() {
635
- echo '
636
- <div id="iub_deactivation_container">
637
- <label><input id="iub_deactivation" type="checkbox" name="iubenda_cookie_law_solution[deactivation]" value="1" ' . checked( true, (bool) $this->options['deactivation'], false ) . '/>' . __( 'Delete all plugin data upon deactivation?', 'iubenda-cookie-law-solution' ) . '</label>
638
- </div>';
639
- }
640
-
641
- /**
642
- * Save options.
643
- *
644
- * @return void
645
- */
646
- public function save_options( $input ) {
647
- if ( ! current_user_can( apply_filters( 'iubenda_cookie_law_cap', 'manage_options' ) ) )
648
- return;
649
-
650
- // save options
651
- if ( isset( $_POST['save_iubenda_options'] ) ) {
652
- $input['parse'] = (bool) isset( $input['parse'] );
653
- $input['parser_engine'] = isset( $input['parser_engine'] ) && in_array( $input['parser_engine'], array( 'default', 'new' ) ) ? $input['parser_engine'] : $this->defaults['parser_engine'];
654
- $input['loading'] = isset( $input['loading'] ) && in_array( $input['loading'], array( 'header', 'footer' ) ) ? $input['loading'] : $this->defaults['loading'];
655
- $input['skip_parsing'] = (bool) isset( $input['skip_parsing'] );
656
- $input['ctype'] = (bool) isset( $input['ctype'] );
657
- $input['output_feed'] = (bool) isset( $input['output_feed'] );
658
- $input['deactivation'] = (bool) isset( $input['deactivation'] );
659
-
660
- // multilang support
661
- if ( $this->multilang && ! empty( $this->languages ) ) {
662
- foreach ( $this->languages as $lang_id => $lang_name ) {
663
- $input['code_' . $lang_id] = ! empty( $input['code_' . $lang_id] ) ? wp_kses( $input['code_' . $lang_id], array( 'script' => array( 'type' => array(), 'src' => array(), 'charset' => array(), 'async' => array() ) ) ) : '';
664
-
665
- // handle default lang too
666
- if ( $lang_id == $this->lang_default ) {
667
- $input['code_default'] = ! empty( $input['code_' . $lang_id] ) ? wp_kses( $input['code_' . $lang_id], array( 'script' => array( 'type' => array(), 'src' => array(), 'charset' => array(), 'async' => array() ) ) ) : $this->options['code_default'];
668
- }
669
- }
670
- } else {
671
- $input['code_default'] = ! empty( $input['code_default'] ) ? wp_kses( $input['code_default'], array( 'script' => array( 'type' => array(), 'src' => array(), 'charset' => array(), 'async' => array() ) ) ) : '';
672
- }
673
-
674
- add_settings_error( 'iub_settings_errors', 'iub_settings_updated', __( 'Settings saved.', 'iubenda-cookie-law-solution' ), 'updated' );
675
- // reset options
676
- } elseif ( isset( $_POST['reset_iubenda_options'] ) ) {
677
- $input = $this->defaults;
678
-
679
- // multilang support
680
- if ( $this->multilang && ! empty( $this->languages ) ) {
681
- foreach ( $this->languages as $lang_id => $lang_name ) {
682
- $input['code_' . $lang_id] = '';
683
- }
684
- }
685
- add_settings_error( 'iub_settings_errors', 'iub_settings_restored', __( 'Settings restored to defaults.', 'iubenda-cookie-law-solution' ), 'updated' );
686
- }
687
-
688
- return $input;
689
- }
690
-
691
- /**
692
- * Load admin options page.
693
- *
694
- * @return void
695
- */
696
- public function options_page() {
697
- if ( ! current_user_can( apply_filters( 'iubenda_cookie_law_cap', 'manage_options' ) ) ) {
698
- wp_die( __( "You don't have permission to access this page.", 'iubenda-cookie-law-solution' ) );
699
- }
700
- ?>
701
- <div class="wrap">
702
- <div id="iubenda-view">
703
- <?php
704
- echo '
705
- <a class="iubenda-link" href="http://iubenda.com"><img id="iubenda-logo" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG4AAAAdCAMAAAB8M6mmAAAAhFBMVEUAAAA0O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0I0O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr3/////G69+35tdTw5/U8Ofx+vdiyKd+0rep4c/i9e8otIeN17/AB1g0AAAAHnRSTlMAEBAgIDAwQEBQUGBwcICAkJCgoLCwwMDQ0ODg8PCQCZ0FAAACrklEQVR4Xr2V63LbIBCFF1OZKBCiKAohlK7kXHt5//cruyDjjFTX42l9fnhh1+yHGB0EAJu7kXS/gUto8zRmPV2Edz/OergA7ctYtV0DCKPPBCgrF7kb4rzs3incrCzpEd05LKEDolqkb4nzNr1RuF1UB8TzcE1E/CPu+7Rbxwnozn06Eddw25H0wr9XsJQh3Flyazh4HGd9hRWpf4zbfptx15fAwR53dRHcWHFSkQDKoOJ05w5M1NjBdXpvFU0WW9TlHidN73rbVtz7844PU7mIiADQOkyaccIjqQOW6DHQ/3yTxiYg2pQhqVIfMPYDYiwZHdF3gdpk3K/XadoVH6hCgbbivMcsyzSPhntiFBAcbcOj6xI/QKl7UYynciOTj9YWJ/z8scfBjIOKQ68ADC2n8+oKNc37FHuqp7xMsQGuRzHvV1U/tMVQVwm0O4oLIg+4v0CkKXNiChZxEMVmbQrN/tBjweVdygXu7g84B3N/D6AxWhYdY8ZZgDroM6QaQUfGiwXu8Tiu5UyP0e3VLHERccUIqseCuzkVJzjjMEDVAtfgCk4HdLrgbk/FQcHhMZxa4hqPLg0WuKcTce1fcPITTvMbtoIbj+MaHvWIAxQFuXqYuuLYMKH08xQeTsVpbqRrPx1h9VVxFcd+6w77PX7G+dmtC5zDILK90XAl2nUjoD7A2fJUzRK3AYCBLzc5JCwqIarNTdmHxaRg7YBR5Gl3iJOx8EyKVkjFuxO8qhky7nV6m79ALXdDLyhGxXdf0EJYjO1s9yLFN2TZjgiIngaaSt4FjPla55AWc5o+dx/P0zQ9fzCOT5EfMBU19+nygl5CkeVEaCo6gOfI76AKuewwWgnQ0NRJcNwVxirGgdSGOlkFs5SxLZFrwppaXUoZ6qD1PFWSQ8p9wl3D/9ZvoAF23RgFj1kAAAAASUVORK5CYII="/></a>
706
- <p class="iubenda-text">
707
- ' . __( "This plugin is the easiest and most comprehensive way to adapt your WordPress site to the European cookie law. Upon your user's first visit, the plugin will take care of collecting their consent, of blocking the most popular among the scripts that install cookies and subsequently reactivate these scripts as soon as consent is provided. The basic settings include obtaining consent by a simple scroll action (the most effective method) and script reactivation without refreshing the page.", 'iubenda-cookie-law-solution' ) . '
708
- </p>
709
- <p class="iubenda-text">
710
- <span class="iubenda-title">' . __( "Would you like to know more about the cookie law?", 'iubenda-cookie-law-solution' ) . '</span><br />
711
- ' . sprintf( __( "Read our <a href=\"%s\" class=\"iubenda-url\" target=\"_blank\">complete guide to the cookie law.</a>", 'iubenda-cookie-law-solution' ), $this->links['guide'] ) . '
712
- </p>
713
- <p class="iubenda-text">
714
- <span class="iubenda-title">' . __( "What is the full functionality of the plugin?", 'iubenda-cookie-law-solution' ) . '</span><br />
715
- ' . sprintf( __( "Visit our <a href=\"%s\" class=\"iubenda-url\" target=\"_blank\">plugin page.</a>", 'iubenda-cookie-law-solution' ), $this->links['plugin_page'] ) . '
716
- </p>
717
- <p class="iubenda-text">
718
- <span class="iubenda-title">' . __( "Enter the iubenda code for the Cookie Solution below.", 'iubenda-cookie-law-solution' ) . '</span><br />
719
- ' . sprintf( __( "In order to run the plugin, you need to enter the iubenda code that activates the cookie law banner and the cookie policy in the form below. This code can be generated on www.iubenda.com, following <a href=\"%s\" class=\"iubenda-url\" target=\"_blank\">this guide.</a>", 'iubenda-cookie-law-solution' ), $this->links['generating_code'] ) . '
720
- </p>';
721
- ?>
722
- <form id="iubenda-tabs" action="options.php" method="post">
723
- <?php
724
- settings_fields( 'iubenda_cookie_law_solution' );
725
- do_settings_sections( 'iubenda_cookie_law_solution' );
726
-
727
- echo ' <p class="submit">';
728
- submit_button( '', 'primary', 'save_iubenda_options', false );
729
- echo ' ';
730
- submit_button( __( 'Reset to defaults', 'iubenda-cookie-law-solution' ), 'secondary', 'reset_iubenda_options', false );
731
- echo ' </p>';
732
- ?>
733
- </form>
734
- <?php echo '
735
- <p class="iubenda-text">
736
- <span class="iubenda-title">' . __( 'Need support for this plugin?', 'iubenda-cookie-law-solution' ) . '</span><br />
737
- ' . sprintf( __( "Visit our <a href=\"%s\" class=\"iubenda-url\" target=\"_blank\">support forum.</a>", 'iubenda-cookie-law-solution' ), $this->links['support_forum'] ) . '
738
- </p>
739
- <p class="iubenda-text">
740
- <span class="iubenda-title">' . __( 'Want to try a beta version of this plugin with the latest features?', 'iubenda-cookie-law-solution' ) . '</span><br />
741
- ' . sprintf( __( "Visit our <a href=\"%s\" class=\"iubenda-url\" target=\"_blank\">documentation pages</a> and follow the instructions to install a beta version.", 'iubenda-cookie-law-solution' ), $this->links['documentation'] ) . '
742
- </p>';
743
- ?>
744
- </div>
745
- <div class="clear"></div>
746
- </div>
747
- <?php
748
- }
749
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
750
  }
1
+ <?php
2
+ /*
3
+ Plugin Name: iubenda Cookie Solution for GDPR
4
+ Plugin URI: https://www.iubenda.com
5
+ Description: iubenda Cookie Solution allows you to make your website GDPR compliant and manage all aspects of cookie law on WP.
6
+ Version: 1.15.0
7
+ Author: iubenda
8
+ Author URI: https://www.iubenda.com
9
+ License: MIT License
10
+ License URI: http://opensource.org/licenses/MIT
11
+ Text Domain: iubenda-cookie-law-solution
12
+ Domain Path: /languages
13
+
14
+ ibenda Cookie Solution
15
+ Copyright (C) 2018, iubenda s.r.l
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ // exit if accessed directly
25
+ if ( ! defined( 'ABSPATH' ) )
26
+ exit;
27
+
28
+ // define contants
29
+ define( 'IUB_DEBUG', false );
30
+
31
+ // set plugin instance
32
+ $iubenda_cookie_law_solution = new iubenda_Cookie_Law_Solution();
33
+
34
+ /**
35
+ * iubenda_Cookie_Law_Solution final class.
36
+ *
37
+ * @class iubenda_Cookie_Law_Solution
38
+ * @version 1.15.0
39
+ */
40
+ class iubenda_Cookie_Law_Solution {
41
+
42
+ public $options;
43
+ public $defaults = array(
44
+ 'parse' => false, // iubenda_parse
45
+ 'skip_parsing' => true, // skip_parsing
46
+ 'ctype' => true, // iubenda_ctype
47
+ 'parse' => false, // iubenda_parse
48
+ 'parser_engine' => 'new', // parser_engine
49
+ 'output_feed' => true, // iubenda_output_feed
50
+ 'code_default' => false, // iubenda-code-default,
51
+ 'menu_position' => 'topmenu',
52
+ 'deactivation' => false
53
+ );
54
+ public $version = '1.15.0';
55
+ public $no_html = false;
56
+ public $links = array();
57
+ public $multilang = false;
58
+ public $languages = array();
59
+ public $lang_default = '';
60
+
61
+ /**
62
+ * Class constructor.
63
+ */
64
+ public function __construct() {
65
+ register_activation_hook( __FILE__, array( $this, 'activation' ) );
66
+ register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );
67
+
68
+ // settings
69
+ $this->options = array_merge( $this->defaults, (array) get_option( 'iubenda_cookie_law_solution', $this->defaults ) );
70
+
71
+ // actions
72
+ add_action( 'admin_init', array( $this, 'register_options' ) );
73
+ add_action( 'admin_init', array( $this, 'update_plugin' ), 9 );
74
+ add_action( 'admin_init', array( $this, 'admin_page_redirect' ), 20 );
75
+ add_action( 'admin_menu', array( $this, 'admin_menu_options' ) );
76
+ add_action( 'admin_notices', array( $this, 'settings_errors' ) );
77
+ // add_action( 'admin_menu', array( $this, 'save_options' ), 9 );
78
+ add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
79
+ add_action( 'plugins_loaded', array( $this, 'init' ) );
80
+ add_action( 'after_setup_theme', array( $this, 'register_shortcode' ) );
81
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
82
+ add_action( 'admin_print_styles', array( $this, 'admin_print_styles' ) );
83
+ add_action( 'wp_head', array( $this, 'wp_head' ), 99 );
84
+ add_action( 'template_redirect', array( $this, 'output_start' ), 0 );
85
+ add_action( 'shutdown', array( $this, 'output_end' ), 100 );
86
+ }
87
+
88
+ /**
89
+ * Initialize plugin.
90
+ *
91
+ * @return void
92
+ */
93
+ public function init() {
94
+
95
+ // check if WPML or Polylang is active
96
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
97
+
98
+ // Polylang support
99
+ if ( is_plugin_active( 'polylang/polylang.php' ) && function_exists( 'PLL' ) ) {
100
+ $this->multilang = true;
101
+
102
+ // get registered languages
103
+ $registered_languages = PLL()->model->get_languages_list();
104
+
105
+ if ( ! empty( $registered_languages ) ) {
106
+ foreach ( $registered_languages as $language )
107
+ $this->languages[$language->slug] = $language->name;
108
+ }
109
+
110
+ // get default language
111
+ $this->lang_default = pll_default_language();
112
+
113
+ // WPML support
114
+ } elseif ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && class_exists( 'SitePress' ) ) {
115
+ $this->multilang = true;
116
+
117
+ global $sitepress;
118
+
119
+ // get registered languages
120
+ $registered_languages = icl_get_languages();
121
+
122
+ if ( ! empty( $registered_languages ) ) {
123
+ foreach ( $registered_languages as $language )
124
+ $this->languages[$language['code']] = $language['display_name'];
125
+ }
126
+
127
+ // get default language
128
+ $this->lang_default = $sitepress->get_default_language();
129
+ }
130
+
131
+ // load Simple HTML DOM if needed
132
+ if ( ! function_exists( 'file_get_html' ) ) {
133
+ require_once( dirname( __FILE__ ) . '/iubenda-cookie-class/simple_html_dom.php' );
134
+ }
135
+
136
+ // load plugin class
137
+ require_once( dirname( __FILE__ ) . '/iubenda-cookie-class/iubenda.class.faster.php' );
138
+ require_once( dirname( __FILE__ ) . '/iubenda-cookie-class/iubenda.class.php' );
139
+
140
+ $links = array(
141
+ 'en' => array(
142
+ 'guide' => 'https://www.iubenda.com/en/iubenda-cookie-law-solution',
143
+ 'plugin_page' => 'https://www.iubenda.com/en/help/posts/1215',
144
+ 'generating_code' => 'https://www.iubenda.com/en/help/posts/1177',
145
+ 'support_forum' => 'https://support.iubenda.com/forums/314835-general/suggestions/9670701-discussion-regarding-the-iubenda-cookie-law-soluti',
146
+ 'documentation' => 'https://www.iubenda.com/en/help/posts/1215'
147
+ ),
148
+ 'it' => array(
149
+ 'guide' => 'https://www.iubenda.com/it/soluzione-cookie-law',
150
+ 'plugin_page' => 'https://www.iubenda.com/it/help/posts/810',
151
+ 'generating_code' => 'https://www.iubenda.com/it/help/posts/680',
152
+ 'support_forum' => 'https://support.iubenda.com/forums/314835-general/suggestions/9670701-discussion-regarding-the-iubenda-cookie-law-soluti',
153
+ 'documentation' => 'https://www.iubenda.com/it/help/posts/810',
154
+ )
155
+ );
156
+
157
+ $locale = explode( '_', get_locale() );
158
+ $locale_code = $locale[0];
159
+
160
+ // assign links
161
+ $this->links = in_array( $locale_code, array_keys( $links ) ) ? $links[$locale_code] : $links['en'];
162
+ }
163
+
164
+ /**
165
+ * Plugin activation.
166
+ *
167
+ * @return void
168
+ */
169
+ public function activation() {
170
+ add_option( 'iubenda_cookie_law_solution', $this->options, '', 'no' );
171
+ add_option( 'iubenda_cookie_law_version', $this->version, '', 'no' );
172
+ }
173
+
174
+ /**
175
+ * Plugin deactivation.
176
+ *
177
+ * @return void
178
+ */
179
+ public function deactivation() {
180
+ // remove options from database?
181
+ if ( $this->options['deactivation'] ) {
182
+ delete_option( 'iubenda_cookie_law_solution' );
183
+ delete_option( 'iubenda_cookie_law_version' );
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Plugin options migration for versions < 1.14.0
189
+ *
190
+ * @return void
191
+ */
192
+ public function update_plugin() {
193
+ if ( ! current_user_can( 'install_plugins' ) )
194
+ return;
195
+
196
+ $db_version = get_option( 'iubenda_cookie_law_version' );
197
+ $db_version = ! $db_version ? '1.13.0' : $db_version;
198
+
199
+ if ( $db_version != false ) {
200
+ if ( version_compare( $db_version, '1.14.0', '<' ) ) {
201
+ $options = array();
202
+
203
+ $old_new = array(
204
+ 'iubenda_parse' => 'parse',
205
+ 'skip_parsing' => 'skip_parsing',
206
+ 'iubenda_ctype' => 'ctype',
207
+ 'iubenda_parse' => 'parse',
208
+ 'parser_engine' => 'parser_engine',
209
+ 'iubenda_output_feed' => 'output_feed',
210
+ 'iubenda-code-default' => 'code_default',
211
+ 'default_skip_parsing' => '',
212
+ 'default_iubendactype' => '',
213
+ 'default_iubendaparse' => '',
214
+ 'default_parser_engine' => '',
215
+ 'iub_code' => '',
216
+ );
217
+
218
+ foreach ( $old_new as $old => $new ) {
219
+ if ( $new ) {
220
+ $options[$new] = get_option( $old );
221
+ }
222
+ delete_option( $old );
223
+ }
224
+
225
+ // multilang support
226
+ if ( ! empty( $this->languages ) ) {
227
+ foreach ( $this->languages as $lang ) {
228
+ $code = get_option( 'iubenda-code-' . $lang );
229
+
230
+ if ( ! empty( $code ) ) {
231
+ $options['code_' . $lang] = $code;
232
+
233
+ delete_option( 'iubenda-code-' . $lang );
234
+ }
235
+ }
236
+ }
237
+
238
+ add_option( 'iubenda_cookie_law_solution', $options, '', 'no' );
239
+ add_option( 'iubenda_cookie_law_version', $this->version, '', 'no' );
240
+ }
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Register shortcode function.
246
+ */
247
+ public function register_shortcode() {
248
+ add_shortcode( 'iub-cookie-policy', array( $this, 'shortcode' ) );
249
+ }
250
+
251
+ /**
252
+ * Handle shortcode function.
253
+ *
254
+ * @param array $atts
255
+ * @param mixed $content
256
+ * @return mixed
257
+ */
258
+ public function shortcode( $atts, $content = '' ) {
259
+ return '<!--IUB_COOKIE_POLICY_START-->' . do_shortcode( $content ) . '<!--IUB_COOKIE_POLICY_END-->';
260
+ }
261
+
262
+ /**
263
+ * Add submenu.
264
+ */
265
+ public function admin_menu_options() {
266
+ if ( $this->options['menu_position'] === 'submenu' ) {
267
+ // sub menu
268
+ add_submenu_page(
269
+ 'options-general.php', 'iubenda', 'iubenda', apply_filters( 'iubenda_cookie_law_cap', 'manage_options' ), 'iubenda-cookie-law-solution', array( $this, 'options_page' ), 'none'
270
+ );
271
+ } else {
272
+ // top menu
273
+ add_menu_page(
274
+ 'iubenda', 'iubenda', apply_filters( 'iubenda_cookie_law_cap', 'manage_options' ), 'iubenda-cookie-law-solution', array( $this, 'options_page' ), 'none'
275
+ );
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Load textdomain.
281
+ */
282
+ public function load_textdomain() {
283
+ load_plugin_textdomain( 'iubenda-cookie-law-solution', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
284
+ }
285
+
286
+ /**
287
+ * Load admin scripts and styles.
288
+ *
289
+ * @param string $page
290
+ * @return void
291
+ */
292
+ public function admin_enqueue_scripts( $page ) {
293
+ if ( ! in_array( $page, array( 'toplevel_page_iubenda-cookie-law-solution', 'settings_page_iubenda-cookie-law-solution' ) ) )
294
+ return;
295
+
296
+ wp_enqueue_script(
297
+ 'iubenda-admin', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' )
298
+ );
299
+
300
+ wp_enqueue_style( 'iubenda-admin', plugins_url( 'css/admin.css', __FILE__ ) );
301
+ }
302
+
303
+ /**
304
+ * Load admin style inline, for menu icon only.
305
+ *
306
+ * @return mixed
307
+ */
308
+ public function admin_print_styles() {
309
+ echo '
310
+ <style>
311
+ a.toplevel_page_iubenda-cookie-law-solution .wp-menu-image {
312
+ background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDkuNDE4IiBoZWlnaHQ9IjI3My4wMTgiIHZpZXdCb3g9IjAgMCAxMDkuNDE4IDI3My4wMTgiPjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBmaWxsPSIjRkZGIiBkPSJNMTA5LjQxOCA1NC41M0MxMDkuNDE4IDI0LjQwNCA4NC45MzYgMCA1NC43MDggMCAyNC40ODYgMCAwIDI0LjQwNCAwIDU0LjUzYzAgMTQuNzY1IDUuOSAyOC4xNCAxNS40ODcgMzcuOTUzTDQuMTI0IDI3My4wMThoMTAzLjg3TDk2LjQ3NyA4OS43MzJjOC4wODYtOS41MDQgMTIuOTQtMjEuNzgyIDEyLjk0LTM1LjIwMnptLTY1LjM2LTkuOTAzQzQ3LjAwNyA0MS42OCA1MC42MyA0MC4yIDU0LjkzIDQwLjJjNC4yIDAgNy43NzMgMS40OCAxMC43MjUgNC40MjcgMi45NDggMi45NDggNC40MjQgNi41MjIgNC40MjQgMTAuNzI0IDAgNC4xOTctMS40NzYgNy43OTUtNC40MjQgMTAuNzk1LTIuOTUyIDMtNi41MjQgNC40OTgtMTAuNzI0IDQuNDk4LTQuMTk4IDAtNy44LTEuNDk4LTEwLjc5Ny00LjQ5OC0zLTMtNC41LTYuNi00LjUtMTAuNzk0LS4wMDItNC4yIDEuNDczLTcuNzc0IDQuNDI2LTEwLjcyM3ptNDQuMTY1IDIwOC44M0gyMS40ODZ2LTUuNDAyYzYuNyAwIDExLjItLjY0NiAxMy40OTgtMS45NDYgMi4yOTgtMS4yOTUgNC4xMjUtMy40NSA1LjQ3NS02LjQ0NyAxLjM0Ni0zIDIuMDIzLTguNzQ3IDIuMDIzLTE3LjI0N3YtNTIuOTQzYzAtMTQuODk4LS40NTMtMjQuNTQtMS4zNTItMjguOTQ0LS42OTgtMy4xOTYtMS43OTctNS40Mi0zLjMtNi42Ny0xLjQ5NS0xLjI1LTMuNTQ4LTEuODc0LTYuMTQ3LTEuODc0LTIuNzk4IDAtNi4yLjc1LTEwLjE5NyAyLjI1bC0yLjEwMi01LjQgNDEuMzk0LTE2Ljc5N2g2LjZ2MTEwLjM3N2MwIDguNTk4LjYyNCAxNC4zMiAxLjg3NSAxNy4xNyAxLjI1IDIuODQ4IDMuMDk2IDQuOTc0IDUuNTQ4IDYuMzc0IDIuNDUgMS40MDMgNi45MjYgMi4wOTcgMTMuNDIzIDIuMDk3djUuNHoiLz48L3N2Zz4=);
313
+ background-position: center center;
314
+ background-repeat: no-repeat;
315
+ background-size: 7px auto;
316
+ }
317
+ </style>
318
+ ';
319
+ }
320
+
321
+ /**
322
+ * Redirect to the correct urle after switching menu position.
323
+ *
324
+ * @global string $pagenow
325
+ */
326
+ public function admin_page_redirect() {
327
+ if ( ! empty( $_GET['settings-updated'] ) && ! empty( $_GET['page'] ) && in_array( $_GET['page'], array( 'iubenda-cookie-law-solution' ) ) ) {
328
+ global $pagenow;
329
+
330
+ // no redirect by default
331
+ $redirect_to = false;
332
+
333
+ if ( $this->options['menu_position'] === 'submenu' && $pagenow === 'admin.php' ) {
334
+ // sub menu
335
+ $redirect_to = admin_url( 'options-general.php?page=iubenda-cookie-law-solution' );
336
+ } elseif ( $this->options['menu_position'] === 'topmenu' && $pagenow === 'options-general.php' ) {
337
+ // top menu
338
+ $redirect_to = admin_url( 'admin.php?page=iubenda-cookie-law-solution' );
339
+ }
340
+
341
+ if ( $redirect_to ) {
342
+ // make sure it's current host location
343
+ wp_safe_redirect( add_query_arg( 'settings-updated', true, $redirect_to ) );
344
+ exit;
345
+ }
346
+ }
347
+ }
348
+
349
+ /**
350
+ * Add wp_head content.
351
+ *
352
+ * @return mixed
353
+ */
354
+ public function wp_head() {
355
+ /* check if user is logged in, then disable the banner.
356
+ if ( is_user_logged_in() ) {
357
+ return;
358
+ }
359
+ */
360
+
361
+ // break on admin side
362
+ if ( is_admin() ) {
363
+ return;
364
+ }
365
+
366
+ // check content type
367
+ if ( (bool) $this->options['ctype'] == true ) {
368
+ $iub_headers = headers_list();
369
+ $destroy = true;
370
+
371
+ foreach ( $iub_headers as $h ) {
372
+ if ( strpos( $h, "Content-Type: text/html" ) !== false || strpos( $h, "Content-type: text/html" ) !== false ) {
373
+ $destroy = false;
374
+ }
375
+ }
376
+
377
+ if ( $destroy ) {
378
+ $this->no_html = true;
379
+ }
380
+ }
381
+
382
+ // is post or not html content type?
383
+ if ( $_POST || $this->no_html ) {
384
+ return;
385
+ }
386
+
387
+ // initial head output
388
+ $iubenda_code = "";
389
+
390
+ if ( $this->multilang === true && defined( 'ICL_LANGUAGE_CODE' ) && isset( $this->options['code_' . ICL_LANGUAGE_CODE] ) ) {
391
+ $iubenda_code .= $this->options['code_' . ICL_LANGUAGE_CODE];
392
+
393
+ // no code for current language, use default
394
+ if ( ! $iubenda_code ) {
395
+ $iubenda_code .= $this->options['code_default'];
396
+ }
397
+ } else {
398
+ $iubenda_code .= $this->options['code_default'];
399
+ }
400
+
401
+ $iubenda_code .= "\n
402
+ <script>
403
+ var iCallback = function() {};
404
+
405
+ if ( typeof _iub.csConfiguration != 'undefined' ) {
406
+ if ( 'callback' in _iub.csConfiguration ) {
407
+ if ( 'onConsentGiven' in _iub.csConfiguration.callback )
408
+ iCallback = _iub.csConfiguration.callback.onConsentGiven;
409
+
410
+ _iub.csConfiguration.callback.onConsentGiven = function() {
411
+ iCallback();
412
+
413
+ /* separator */
414
+ jQuery('noscript._no_script_iub').each(function (a, b) { var el = jQuery(b); el.after(el.html()); });
415
+ }
416
+ }
417
+ }
418
+ </script>";
419
+
420
+ echo $iubenda_code;
421
+ }
422
+
423
+ /**
424
+ * Initialize html output.
425
+ *
426
+ * @return void
427
+ */
428
+ public function output_start() {
429
+ if ( ! is_admin() ) {
430
+ ob_start( array( $this, 'output_callback' ) );
431
+ }
432
+ }
433
+
434
+ /**
435
+ * Finish html output.
436
+ *
437
+ * @return void
438
+ */
439
+ public function output_end() {
440
+ if ( ! is_admin() && ob_get_level() ) {
441
+ ob_end_flush();
442
+ }
443
+ }
444
+
445
+ /**
446
+ * Handle final html output.
447
+ *
448
+ * @param mixed $output
449
+ * @return mixed
450
+ */
451
+ public function output_callback( $output ) {
452
+ // break on ajax, xmlrpc or iub_no_parse request
453
+ if (
454
+ ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST )
455
+ || ( defined( 'DOING_AJAX' ) && DOING_AJAX )
456
+ || isset( $_SERVER["HTTP_X_REQUESTED_WITH"] )
457
+ || isset( $_GET['iub_no_parse'] )
458
+ ) {
459
+ return $output;
460
+ }
461
+
462
+ // break on admin side
463
+ if ( is_admin() ) {
464
+ return $output;
465
+ }
466
+
467
+ // break for logged in users?
468
+ /* if ( is_user_logged_in() ) {
469
+ return $output;
470
+ }
471
+ */
472
+
473
+ // break on rss feed
474
+ if ( is_feed() && $this->options['output_feed'] ) {
475
+ return $output;
476
+ }
477
+
478
+ if ( strpos( $output, "<html" ) === false ) {
479
+ return $output;
480
+ } elseif ( strpos( $output, "<html" ) > 200 ) {
481
+ return $output;
482
+ }
483
+
484
+ // check whether to run parser or not
485
+ if (
486
+ ! $this->options['parse'] || ( iubendaPage::consent_given() && $this->options['skip_parsing'] ) || iubendaPage::bot_detected() || $_POST || $this->no_html ) {
487
+
488
+ return $output;
489
+ }
490
+
491
+ $startime = microtime( true );
492
+
493
+ $output = apply_filters( 'iubenda_initial_output', $output );
494
+
495
+ // experimental class
496
+ if ( $this->options['parser_engine'] == 'new' ) {
497
+ $faster = new iubendaFaster;
498
+
499
+ // render output
500
+ $output = $faster->isParse( mb_convert_encoding( $output, 'HTML-ENTITIES', 'UTF-8' ) );
501
+
502
+ // append signature
503
+ $output .= '<!-- Parsed with iubenda experimental class in ' . round( microtime( true ) - $startime, 4 ) . ' sec. -->';
504
+ // default class
505
+ } else {
506
+ $page = new iubendaPage( $output );
507
+ $page->parse();
508
+
509
+ // render output
510
+ $output = $page->get_converted_page();
511
+
512
+ // append signature
513
+ $output .= '<!-- Parsed with iubenda default class in ' . round( microtime( true ) - $startime, 4 ) . ' sec. -->';
514
+ }
515
+
516
+ return apply_filters( 'iubenda_final_output', $output );
517
+ }
518
+
519
+ /**
520
+ * Register plugin options.
521
+ */
522
+ public function register_options() {
523
+ register_setting( 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution', array( $this, 'save_options' ) );
524
+
525
+ add_settings_section( 'iubenda_cookie_law_solution', '', '', 'iubenda_cookie_law_solution' );
526
+ add_settings_field( 'iub_code', __( 'Code', 'iubenda-cookie-law-solution' ), array( $this, 'iub_code' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
527
+ add_settings_field( 'iub_parse', __( 'Scripts blocking', 'iubenda-cookie-law-solution' ), array( $this, 'iub_parse' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
528
+ add_settings_field( 'iub_ctype', __( 'Content type', 'iubenda-cookie-law-solution' ), array( $this, 'iub_ctype' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
529
+ add_settings_field( 'iub_output_feed', __( 'RSS feed', 'iubenda-cookie-law-solution' ), array( $this, 'iub_output_feed' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
530
+ add_settings_field( 'iub_menu_position', __( 'Menu position', 'iubenda-cookie-law-solution' ), array( $this, 'iub_menu_position' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
531
+ add_settings_field( 'iub_deactivation', __( 'Deactivation', 'iubenda-cookie-law-solution' ), array( $this, 'iub_deactivation' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' );
532
+ }
533
+
534
+ /**
535
+ * Display errors and notices.
536
+ *
537
+ * @global string $pagenow
538
+ */
539
+ public function settings_errors() {
540
+ global $pagenow;
541
+
542
+ // force display notices in top menu settings page
543
+ if ( $pagenow != 'options-general.php' )
544
+ settings_errors( 'iub_settings_errors' );
545
+ }
546
+
547
+ /**
548
+ * Code option.
549
+ *
550
+ * @return mixed
551
+ */
552
+ public function iub_code() {
553
+ // multilang support
554
+ if ( $this->multilang && ! empty( $this->languages ) ) {
555
+ echo '
556
+ <div id="contextual-help-wrap" class="hidden" tabindex="-1" style="display: block;">
557
+ <div id="contextual-help-back"></div>
558
+ <div id="contextual-help-columns">
559
+ <div class="contextual-help-tabs">
560
+ <ul>';
561
+ foreach ( $this->languages as $lang_id => $lang_name ) {
562
+ echo '
563
+ <li id="tab-link-overview" class="' . ( $this->lang_default == $lang_id ? 'active' : '' ) . '">
564
+ <a href="#tab-panel-' . $lang_id . '" aria-controls="tab-panel-' . $lang_id . '">' . $lang_name . '</a>
565
+ </li>';
566
+ }
567
+ echo '
568
+ </ul>
569
+ </div>
570
+
571
+ <div class="contextual-help-tabs-wrap">';
572
+ foreach ( $this->languages as $lang_id => $lang_name ) {
573
+ // get code for the language
574
+ $code = ! empty( $this->options['code_' . $lang_id] ) ? html_entity_decode( trim( wp_kses( $this->options['code_' . $lang_id], array( 'style' => array( 'type' => array() ), 'script' => array( 'type' => array(), 'src' => array(), 'charset' => array(), 'async' => array() ) ) ) ) ) : '';
575
+ // handle default, if empty
576
+ $code = empty( $code ) && $lang_id == $this->lang_default ? html_entity_decode( trim( wp_kses( $this->options['code_default'], array( 'style' => array( 'type' => array() ), 'script' => array( 'type' => array(), 'src' => array(), 'charset' => array(), 'async' => array() ) ) ) ) ) : $code;
577
+
578
+ echo '
579
+ <div id="tab-panel-' . $lang_id . '" class="help-tab-content' . ( $this->lang_default == $lang_id ? ' active' : '' ) . '">
580
+ <textarea name="iubenda_cookie_law_solution[code_' . $lang_id . ']" class="large-text" cols="50" rows="10">' . $code . '</textarea>
581
+ <p class="description">' . sprintf( __( 'Enter the iubenda code for %s.', 'iubenda-cookie-law-solution' ), $lang_name ) . '</p>
582
+ </div>';
583
+ }
584
+ echo '
585
+ </div>
586
+ </div>
587
+ </div>';
588
+ } else {
589
+ echo '
590
+ <div id="iub_code_default">
591
+ <textarea name="iubenda_cookie_law_solution[code_default]" class="large-text" cols="50" rows="10">' . html_entity_decode( trim( wp_kses( $this->options['code_default'], array( 'style' => array( 'type' => array() ), 'script' => array( 'type' => array(), 'src' => array(), 'charset' => array(), 'async' => array() ) ) ) ) ) . '</textarea>
592
+ <p class="description">' . __( 'Enter the iubenda code.', 'iubenda-cookie-law-solution' ) . '</p>
593
+ </div>';
594
+ }
595
+ }
596
+
597
+ /**
598
+ * Parsing option.
599
+ *
600
+ * @return mixed
601
+ */
602
+ public function iub_parse() {
603
+ echo '
604
+ <div id="iub_parse_container">
605
+ <label><input id="iub_parse" type="checkbox" name="iubenda_cookie_law_solution[parse]" value="1" ' . checked( true, (bool) $this->options['parse'], false ) . '/>' . __( 'Automatically block scripts detected by the plugin.', 'iubenda-cookie-law-solution' ) . '</label>
606
+ <p class="description">' . '(' . sprintf( __( "see <a href=\"%s\" target=\"_blank\">our documentation</a> for the list of detected scripts.", 'iubenda-cookie-law-solution' ), $this->links['documentation'] ) . ')' . '</p>
607
+ <div id="iub_parser_engine_container"' . ( $this->options['parse'] === false ? ' style="display: none;"' : '' ) . '>
608
+ <div>
609
+ <label><input id="iub_parser_engine-default" type="radio" name="iubenda_cookie_law_solution[parser_engine]" value="default" ' . checked( 'default', $this->options['parser_engine'], false ) . ' />' . __( 'Default', 'iubenda-cookie-law-solution' ) . '</label>
610
+ <label><input id="iub_parser_engine-new" type="radio" name="iubenda_cookie_law_solution[parser_engine]" value="new" ' . checked( 'new', $this->options['parser_engine'], false ) . ' />' . __( 'Experimental', 'iubenda-cookie-law-solution' ) . '</label>
611
+ <p class="description">' . __( 'Select parsing engine.', 'iubenda-cookie-law-solution' ) . '</p>
612
+ </div>
613
+ <div>
614
+ <label><input id="iub_skip_parsing" type="checkbox" name="iubenda_cookie_law_solution[skip_parsing]" value="1" ' . checked( true, (bool) $this->options['skip_parsing'], false ) . '/>' . __( 'Leave scripts untouched on the page if the user has already given consent', 'iubenda-cookie-law-solution' ) . '</label>
615
+ <p class="description">(' . __( "improves performance, highly recommended, to be deactivated only if your site uses a caching system", 'iubenda-cookie-law-solution' ) . ')</p>
616
+ </div>
617
+ </div>
618
+ </div>';
619
+ }
620
+
621
+ /**
622
+ * Ctype option.
623
+ *
624
+ * @return mixed
625
+ */
626
+ public function iub_ctype() {
627
+ echo '
628
+ <div id="iub_ctype_container">
629
+ <label><input id="iub_ctype" type="checkbox" name="iubenda_cookie_law_solution[ctype]" value="1" ' . checked( true, (bool) $this->options['ctype'], false ) . '/>' . __( 'Restrict the plugin to run only for requests that have "Content-type: text / html" (recommended)', 'iubenda-cookie-law-solution' ) . '</label>
630
+ </div>';
631
+ }
632
+
633
+ /**
634
+ * RSS feed option.
635
+ *
636
+ * @return mixed
637
+ */
638
+ public function iub_output_feed() {
639
+ echo '
640
+ <div id="iub_output_feed_container">
641
+ <label><input id="iub_ctype" type="checkbox" name="iubenda_cookie_law_solution[output_feed]" value="1" ' . checked( true, (bool) $this->options['output_feed'], false ) . '/>' . __( 'Do not run the plugin inside the RSS feed (recommended)', 'iubenda-cookie-law-solution' ) . '</label>
642
+ </div>';
643
+ }
644
+
645
+ /**
646
+ * Menu option.
647
+ *
648
+ * @return mixed
649
+ */
650
+ public function iub_menu_position() {
651
+ echo '
652
+ <div id="iub_menu_position_container">
653
+ <label><input id="iub_menu_position-topmenu" type="radio" name="iubenda_cookie_law_solution[menu_position]" value="topmenu" ' . checked( 'topmenu', $this->options['menu_position'], false ) . ' />' . __( 'Top menu', 'iubenda-cookie-law-solution' ) . '</label>
654
+ <label><input id="iub_menu_position-submenu" type="radio" name="iubenda_cookie_law_solution[menu_position]" value="submenu" ' . checked( 'submenu', $this->options['menu_position'], false ) . ' />' . __( 'Submenu', 'iubenda-cookie-law-solution' ) . '</label>
655
+ <p class="description">' . __( 'Select whether to display iubenda in a top admin menu or the Settings submenu.', 'iubenda-cookie-law-solution' ) . '</p>
656
+ </div>';
657
+ }
658
+
659
+ /**
660
+ * Deactivation option.
661
+ *
662
+ * @return mixed
663
+ */
664
+ public function iub_deactivation() {
665
+ echo '
666
+ <div id="iub_deactivation_container">
667
+ <label><input id="iub_deactivation" type="checkbox" name="iubenda_cookie_law_solution[deactivation]" value="1" ' . checked( true, (bool) $this->options['deactivation'], false ) . '/>' . __( 'Delete all plugin data upon deactivation?', 'iubenda-cookie-law-solution' ) . '</label>
668
+ </div>';
669
+ }
670
+
671
+ /**
672
+ * Save options.
673
+ *
674
+ * @return void
675
+ */
676
+ public function save_options( $input ) {
677
+ if ( ! current_user_can( apply_filters( 'iubenda_cookie_law_cap', 'manage_options' ) ) )
678
+ return $input;
679
+
680
+ // save options
681
+ if ( isset( $_POST['save_iubenda_options'] ) ) {
682
+ $input['parse'] = (bool) isset( $input['parse'] );
683
+ $input['parser_engine'] = isset( $input['parser_engine'] ) && in_array( $input['parser_engine'], array( 'default', 'new' ) ) ? $input['parser_engine'] : $this->defaults['parser_engine'];
684
+ $input['skip_parsing'] = (bool) isset( $input['skip_parsing'] );
685
+ $input['ctype'] = (bool) isset( $input['ctype'] );
686
+ $input['output_feed'] = (bool) isset( $input['output_feed'] );
687
+ $input['menu_position'] = isset( $input['menu_position'] ) && in_array( $input['menu_position'], array( 'topmenu', 'submenu' ) ) ? $input['menu_position'] : $this->defaults['menu_position'];
688
+ $input['deactivation'] = (bool) isset( $input['deactivation'] );
689
+
690
+ // multilang support
691
+ if ( $this->multilang && ! empty( $this->languages ) ) {
692
+ foreach ( $this->languages as $lang_id => $lang_name ) {
693
+ $input['code_' . $lang_id] = ! empty( $input['code_' . $lang_id] ) ? wp_kses( $input['code_' . $lang_id], array( 'style' => array( 'type' => array() ), 'script' => array( 'type' => array(), 'src' => array(), 'charset' => array(), 'async' => array() ) ) ) : '';
694
+
695
+ // handle default lang too
696
+ if ( $lang_id == $this->lang_default ) {
697
+ $input['code_default'] = ! empty( $input['code_' . $lang_id] ) ? wp_kses( $input['code_' . $lang_id], array( 'style' => array( 'type' => array() ), 'script' => array( 'type' => array(), 'src' => array(), 'charset' => array(), 'async' => array() ) ) ) : $this->options['code_default'];
698
+ }
699
+ }
700
+ } else {
701
+ $input['code_default'] = ! empty( $input['code_default'] ) ? wp_kses( $input['code_default'], array( 'style' => array( 'type' => array() ), 'script' => array( 'type' => array(), 'src' => array(), 'charset' => array(), 'async' => array() ) ) ) : '';
702
+ }
703
+
704
+ add_settings_error( 'iub_settings_errors', 'iub_settings_updated', __( 'Settings saved.', 'iubenda-cookie-law-solution' ), 'updated' );
705
+ // reset options
706
+ } elseif ( isset( $_POST['reset_iubenda_options'] ) ) {
707
+ $input = $this->defaults;
708
+
709
+ // multilang support
710
+ if ( $this->multilang && ! empty( $this->languages ) ) {
711
+ foreach ( $this->languages as $lang_id => $lang_name ) {
712
+ $input['code_' . $lang_id] = '';
713
+ }
714
+ }
715
+ add_settings_error( 'iub_settings_errors', 'iub_settings_restored', __( 'Settings restored to defaults.', 'iubenda-cookie-law-solution' ), 'updated' );
716
+ }
717
+
718
+ return $input;
719
+ }
720
+
721
+ /**
722
+ * Load admin options page.
723
+ *
724
+ * @return void
725
+ */
726
+ public function options_page() {
727
+ if ( ! current_user_can( apply_filters( 'iubenda_cookie_law_cap', 'manage_options' ) ) ) {
728
+ wp_die( __( "You don't have permission to access this page.", 'iubenda-cookie-law-solution' ) );
729
+ }
730
+ ?>
731
+ <div class="wrap">
732
+ <div id="iubenda-view">
733
+ <?php
734
+ echo '
735
+ <a class="iubenda-link" href="http://iubenda.com"><img id="iubenda-logo" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG4AAAAdCAMAAAB8M6mmAAAAhFBMVEUAAAA0O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0I0O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr380O0Ibr3/////G69+35tdTw5/U8Ofx+vdiyKd+0rep4c/i9e8otIeN17/AB1g0AAAAHnRSTlMAEBAgIDAwQEBQUGBwcICAkJCgoLCwwMDQ0ODg8PCQCZ0FAAACrklEQVR4Xr2V63LbIBCFF1OZKBCiKAohlK7kXHt5//cruyDjjFTX42l9fnhh1+yHGB0EAJu7kXS/gUto8zRmPV2Edz/OergA7ctYtV0DCKPPBCgrF7kb4rzs3incrCzpEd05LKEDolqkb4nzNr1RuF1UB8TzcE1E/CPu+7Rbxwnozn06Eddw25H0wr9XsJQh3Flyazh4HGd9hRWpf4zbfptx15fAwR53dRHcWHFSkQDKoOJ05w5M1NjBdXpvFU0WW9TlHidN73rbVtz7844PU7mIiADQOkyaccIjqQOW6DHQ/3yTxiYg2pQhqVIfMPYDYiwZHdF3gdpk3K/XadoVH6hCgbbivMcsyzSPhntiFBAcbcOj6xI/QKl7UYynciOTj9YWJ/z8scfBjIOKQ68ADC2n8+oKNc37FHuqp7xMsQGuRzHvV1U/tMVQVwm0O4oLIg+4v0CkKXNiChZxEMVmbQrN/tBjweVdygXu7g84B3N/D6AxWhYdY8ZZgDroM6QaQUfGiwXu8Tiu5UyP0e3VLHERccUIqseCuzkVJzjjMEDVAtfgCk4HdLrgbk/FQcHhMZxa4hqPLg0WuKcTce1fcPITTvMbtoIbj+MaHvWIAxQFuXqYuuLYMKH08xQeTsVpbqRrPx1h9VVxFcd+6w77PX7G+dmtC5zDILK90XAl2nUjoD7A2fJUzRK3AYCBLzc5JCwqIarNTdmHxaRg7YBR5Gl3iJOx8EyKVkjFuxO8qhky7nV6m79ALXdDLyhGxXdf0EJYjO1s9yLFN2TZjgiIngaaSt4FjPla55AWc5o+dx/P0zQ9fzCOT5EfMBU19+nygl5CkeVEaCo6gOfI76AKuewwWgnQ0NRJcNwVxirGgdSGOlkFs5SxLZFrwppaXUoZ6qD1PFWSQ8p9wl3D/9ZvoAF23RgFj1kAAAAASUVORK5CYII="/></a>
736
+ <p cl