Changeset 3050409
- Timestamp:
- 03/13/2024 10:38:36 AM (2 years ago)
- Location:
- iubenda-cookie-law-solution/tags/beta
- Files:
-
- 1 added
- 8 edited
-
includes/class-auto-blocking.php (modified) (3 diffs)
-
includes/class-configuration-parser.php (added)
-
includes/class-iubenda-amp.php (modified) (3 diffs)
-
includes/class-iubenda-settings.php (modified) (2 diffs)
-
includes/services/class-iubenda-cs-product-service.php (modified) (3 diffs)
-
includes/services/class-iubenda-pp-product-service.php (modified) (1 diff)
-
includes/services/class-iubenda-tc-product-service.php (modified) (1 diff)
-
iubenda_cookie_solution.php (modified) (8 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
iubenda-cookie-law-solution/tags/beta/includes/class-auto-blocking.php
r3036419 r3050409 44 44 */ 45 45 public function get_site_id_from_cs_code( $script ) { 46 return $this->retrieve_info_from_script_by_key( $script, 'siteId' );46 return iubenda()->configuration_parser->retrieve_info_from_script_by_key( $script, 'siteId' ); 47 47 } 48 48 … … 55 55 */ 56 56 public function get_cookie_policy_id_from_cs_code( $script ) { 57 return $this->retrieve_info_from_script_by_key( $script, 'cookiePolicyId' );57 return iubenda()->configuration_parser->retrieve_info_from_script_by_key( $script, 'cookiePolicyId' ); 58 58 } 59 59 … … 214 214 wp_send_json( $this->is_autoblocking_feature_available( $site_id ) ); 215 215 } 216 217 /**218 * Retrieve information from the provided script by a given key.219 *220 * This function extracts specific information from a script based on the provided key.221 * It first attempts to parse the configuration using iubenda()->parse_configuration().222 * If parsing fails, it tries parsing with $this->cs_product_service->parse_configuration_by_regex().223 *224 * @param string $script The script from which to extract information.225 * @param string $key The key for the information to retrieve.226 *227 * @return string The extracted information, or an empty string if not found.228 */229 private function retrieve_info_from_script_by_key( string $script, string $key ) {230 // Remove slashes from the script.231 $script = stripslashes( $script );232 233 // Try to parse the configuration using iubenda()->parse_configuration().234 $parsed_configuration = iubenda()->parse_configuration( $script );235 if ( ! empty( $parsed_configuration ) && isset( $parsed_configuration[ $key ] ) ) {236 return $parsed_configuration[ $key ];237 }238 239 // If parsing fails, try parsing with $this->cs_product_service->parse_configuration_by_regex().240 $parsed_configuration_by_regex = $this->cs_product_service->parse_configuration_by_regex( $script );241 if ( ! empty( $parsed_configuration_by_regex ) && isset( $parsed_configuration_by_regex[ $key ] ) ) {242 return $parsed_configuration_by_regex[ $key ];243 }244 245 // Return an empty string if the key is not found.246 return '';247 }248 216 } -
iubenda-cookie-law-solution/tags/beta/includes/class-iubenda-amp.php
r3031643 r3050409 104 104 } 105 105 106 $configuration_raw = iubenda()-> parse_configuration( $code );106 $configuration_raw = iubenda()->configuration_parser->extract_cs_config_from_code_amp( $code ); 107 107 108 108 if ( isset( $configuration_raw['gdprAppliesGlobally'] ) && ! $configuration_raw['gdprAppliesGlobally'] ) { … … 151 151 } 152 152 153 $configuration = iubenda()-> parse_configuration( $code );153 $configuration = iubenda()->configuration_parser->extract_cs_config_from_code_amp( $code ); 154 154 155 155 if ( empty( $configuration ) ) { … … 287 287 $html = ''; 288 288 289 $configuration_raw = iubenda()-> parse_configuration( $code );289 $configuration_raw = iubenda()->configuration_parser->extract_cs_config_from_code_amp( $code ); 290 290 291 291 if ( empty( $configuration_raw ) ) { 292 292 $code = stripslashes( $code ); 293 $configuration_raw = iubenda()-> parse_configuration( $code );294 } 295 296 $banner_configuration = iubenda()-> parse_configuration(293 $configuration_raw = iubenda()->configuration_parser->extract_cs_config_from_code_amp( $code ); 294 } 295 296 $banner_configuration = iubenda()->configuration_parser->extract_cs_config_from_code_amp( 297 297 $code, 298 298 array( -
iubenda-cookie-law-solution/tags/beta/includes/class-iubenda-settings.php
r3031643 r3050409 1022 1022 $code = iub_array_get( iubenda()->options['cs'], "code_{$k}" ); 1023 1023 if ( $code ) { 1024 $banner = iubenda()-> parse_configuration( $code, array( 'mode' => 'banner' ) );1024 $banner = iubenda()->configuration_parser->extract_cs_config_from_code( $code, array( 'mode' => 'banner' ) ); 1025 1025 $style = iub_array_get( $banner, 'backgroundColor' ) ? 'White' : 'Dark'; 1026 1026 $legislation = ( new Iubenda_CS_Product_Service() )->get_legislation_from_embed_code( $code ); … … 1170 1170 1171 1171 // get public_id & site_id if only the product key is CS and had a valid embed code. 1172 $parsed_code = array_filter( iubenda()->parse_configuration( $code ) );1173 if ( 'cs' === $product_key && ! empty( $parsed_code ) ) {1172 if ( 'cs' === $product_key ) { 1173 $site_id = iubenda()->configuration_parser->retrieve_info_from_script_by_key( $code, 'siteId' ); 1174 1174 // getting site id to save it into Iubenda global option. 1175 if ( iub_array_get( $parsed_code, 'siteId' ) ?? null) {1176 $result['site_id'] = iub_array_get( $parsed_code, 'siteId' );1175 if ( ! empty( $site_id ) ) { 1176 $result['site_id'] = $site_id; 1177 1177 } 1178 1178 1179 // getting public id to save it into Iubenda global option by lang. 1180 if ( iub_array_get( $parsed_code, 'cookiePolicyId' ) ?? null ) { 1181 $result['public_ids'][ $lang_id ] = iub_array_get( $parsed_code, 'cookiePolicyId' ); 1179 $cookie_policy_id = iubenda()->configuration_parser->retrieve_info_from_script_by_key( $code, 'cookiePolicyId' ); 1180 // getting site id to save it into Iubenda global option. 1181 if ( ! empty( $cookie_policy_id ) ) { 1182 $result['public_ids'][ $lang_id ] = $cookie_policy_id; 1182 1183 } 1183 1184 } 1184 1185 1185 1186 if ( in_array( $product_key, array( 'pp', 'tc' ), true ) ) { 1186 $parsed_code = iubenda()-> parse_tc_pp_configuration( $code );1187 $parsed_code = iubenda()->configuration_parser->extract_tc_pp_config_from_code( $code ); 1187 1188 1188 1189 // getting public id to save it into Iubenda global option lang. -
iubenda-cookie-law-solution/tags/beta/includes/services/class-iubenda-cs-product-service.php
r3031643 r3050409 141 141 $lang_id = substr( $index, 5 ); 142 142 143 // Getting data from embed code.144 $parsed_code = iubenda()->parse_configuration( $option );145 146 // Alternative method if parse_configuration return empty.147 if ( empty( $parsed_code ) ) {148 $parsed_code = $this->parse_configuration_by_regex( $option );149 }150 151 143 $new_cs_option[ "manual_{$index}" ] = $option; 152 144 $codes_statues[ $lang_id ] = true; 145 146 $cookie_policy_id = iubenda()->configuration_parser->retrieve_info_from_script_by_key( $option, 'cookiePolicyId' ); 153 147 // getting cookiePolicyId to save it into Iubenda global option. 154 if ( ! empty( iub_array_get( $parsed_code, 'cookiePolicyId' )) ) {155 $global_options['public_ids'][ $lang_id ] = sanitize_key( iub_array_get( $parsed_code, 'cookiePolicyId' ));148 if ( ! empty( $cookie_policy_id ) ) { 149 $global_options['public_ids'][ $lang_id ] = sanitize_key( $cookie_policy_id ); 156 150 } 157 151 152 $site_id = iubenda()->configuration_parser->retrieve_info_from_script_by_key( $option, 'siteId' ); 158 153 // getting site id to save it into Iubenda global option. 159 if ( empty( iub_array_get( $global_options, 'site_id' ) ) && ! empty( iub_array_get( $parsed_code, 'siteId' ) ) ) {160 $global_options['site_id'] = sanitize_key( iub_array_get( $parsed_code, 'siteId' ));154 if ( ! empty( $site_id ) && empty( iub_array_get( $global_options, 'site_id' ) ) ) { 155 $global_options['site_id'] = sanitize_key( $site_id ); 161 156 } 162 157 … … 170 165 } 171 166 172 // Try to get the Site ID from code. 173 $parsed_site_id = iub_array_get( $parsed_code, 'siteId' ); 174 if ( $parsed_site_id ) { 167 if ( ! empty( $site_id ) ) { 175 168 // Check if auto-blocking is enabled for this site. 176 iubenda()->iub_auto_blocking->fetch_auto_blocking_status_by_site_id( $ parsed_site_id );169 iubenda()->iub_auto_blocking->fetch_auto_blocking_status_by_site_id( $site_id ); 177 170 } 178 171 } … … 279 272 */ 280 273 public function get_legislation_from_embed_code( $code ) { 281 $parsed_options = iubenda()-> parse_configuration( $code );274 $parsed_options = iubenda()->configuration_parser->extract_cs_config_from_code( $code ); 282 275 $legislation = array(); 283 276 -
iubenda-cookie-law-solution/tags/beta/includes/services/class-iubenda-pp-product-service.php
r2922322 r3050409 61 61 $codes_statues[] = true; 62 62 } else { 63 $parsed_code = iubenda()-> parse_tc_pp_configuration( $code );63 $parsed_code = iubenda()->configuration_parser->extract_tc_pp_config_from_code( $code ); 64 64 // check if code is empty or code is invalid. 65 65 $codes_statues[] = (bool) $parsed_code; -
iubenda-cookie-law-solution/tags/beta/includes/services/class-iubenda-tc-product-service.php
r2922322 r3050409 45 45 foreach ( $languages as $lang_id => $v ) { 46 46 $code = iub_array_get( $new_tc_option, "code_{$lang_id}" ); 47 $parsed_code = iubenda()-> parse_tc_pp_configuration( $code );47 $parsed_code = iubenda()->configuration_parser->extract_tc_pp_config_from_code( $code ); 48 48 // check if code is empty or code is invalid. 49 49 $codes_statues[] = (bool) $parsed_code; -
iubenda-cookie-law-solution/tags/beta/iubenda_cookie_solution.php
r3036419 r3050409 4 4 * Plugin URI: https://www.iubenda.com 5 5 * Description: The iubenda plugin is an <strong>all-in-one</strong>, extremely easy to use 360° compliance solution, with text crafted by actual lawyers, that quickly <strong>scans your site and auto-configures to match your specific setup</strong>. It supports the GDPR (DSGVO, RGPD), UK-GDPR, ePrivacy, LGPD, USPR, CalOPPA, PECR and more. 6 * Version: 3.10. 06 * Version: 3.10.2-beta 7 7 * Author: iubenda 8 8 * Author URI: https://www.iubenda.com … … 46 46 * 47 47 * @class iubenda 48 * @version 3.10. 048 * @version 3.10.2-beta 49 49 */ 50 50 class iubenda { … … 139 139 * @var string 140 140 */ 141 public $version = '3.10. 0';141 public $version = '3.10.2'; 142 142 143 143 /** … … 304 304 305 305 /** 306 * Class Iubenda_Configuration_Parser 307 * Parses configurations from Iubenda code. 308 * 309 * @var Configuration_Parser 310 */ 311 public $configuration_parser; 312 313 /** 306 314 * Disable object clone. 307 315 * … … 349 357 self::$instance->iub_auto_blocking = new Auto_Blocking(); 350 358 self::$instance->radar_dashboard_widget = new Radar_Dashboard_Widget(); 359 self::$instance->configuration_parser = new Configuration_Parser(); 351 360 } 352 361 … … 523 532 private function includes() { 524 533 include_once IUBENDA_PLUGIN_PATH . 'includes/functions.php'; 534 include_once IUBENDA_PLUGIN_PATH . 'includes/class-configuration-parser.php'; 525 535 include_once IUBENDA_PLUGIN_PATH . 'includes/class-iubenda-settings.php'; 526 536 include_once IUBENDA_PLUGIN_PATH . 'includes/class-iubenda-forms.php'; … … 1163 1173 1164 1174 /** 1165 * Get configuration data parsed from iubenda code1166 *1167 * @param string $code code.1168 * @param array $args args.1169 *1170 * @return array1171 */1172 public function parse_configuration( $code, $args = array() ) {1173 // Check if the embed code have Callback Functions inside it or not.1174 if ( strpos( $code, 'callback' ) !== false ) {1175 $code = $this->replace_the_callback_functions_to_parse_configuration( $code );1176 }1177 1178 $configuration = array();1179 $defaults = array(1180 'mode' => 'basic',1181 'parse' => false,1182 );1183 1184 // parse incoming $args into an array and merge it with $defaults.1185 $args = wp_parse_args( $args, $defaults );1186 1187 if ( empty( $code ) ) {1188 return $configuration;1189 }1190 1191 // parse code if needed.1192 $parsed_code = true === $args['parse'] ? $this->parse_code( $code, true ) : $code;1193 1194 // get script.1195 $parsed_script = '';1196 1197 preg_match_all( '/src\=(?:[\"|\'])(.*?)(?:[\"|\'])/', $parsed_code, $matches );1198 1199 // find the iubenda script url.1200 if ( ! empty( $matches[1] ) ) {1201 foreach ( $matches[1] as $found_script ) {1202 if ( wp_http_validate_url( $found_script ) && strpos( $found_script, 'iubenda_cs.js' ) ) {1203 $parsed_script = $found_script;1204 continue;1205 }1206 }1207 }1208 1209 // strip tags.1210 $parsed_code = wp_kses( $parsed_code, array() );1211 1212 // get configuration.1213 preg_match( '/_iub.csConfiguration *= *{(.*?)\};/', $parsed_code, $matches );1214 1215 if ( ! empty( $matches[1] ) ) {1216 $parsed_code = '{' . $matches[1] . '}';1217 }1218 1219 // decode.1220 $decoded = json_decode( $parsed_code, true );1221 1222 if ( ! empty( $decoded ) && is_array( $decoded ) ) {1223 1224 $decoded['script'] = $parsed_script;1225 1226 // basic mode.1227 if ( 'basic' === $args['mode'] ) {1228 if ( isset( $decoded['banner'] ) ) {1229 unset( $decoded['banner'] );1230 }1231 if ( isset( $decoded['callback'] ) ) {1232 unset( $decoded['callback'] );1233 }1234 if ( isset( $decoded['perPurposeConsent'] ) ) {1235 unset( $decoded['perPurposeConsent'] );1236 }1237 // Banner mode to get banner configuration only.1238 } elseif ( 'banner' === (string) $args['mode'] ) {1239 if ( isset( $decoded['banner'] ) ) {1240 return $decoded['banner'];1241 }1242 1243 return array();1244 }1245 1246 $configuration = $decoded;1247 }1248 1249 return $configuration;1250 }1251 1252 /**1253 * Get configuration data parsed from TC & PP iubenda code.1254 *1255 * @param string $code Embed code.1256 *1257 * @return array|false1258 */1259 public function parse_tc_pp_configuration( $code ) {1260 if ( empty( $code ) ) {1261 return false;1262 }1263 1264 // Remove slashes and backslashes before use preg match all.1265 $code = stripslashes( $code );1266 1267 preg_match_all( '/<a[^>]+href=([\'"])(?<href>.+?)\1[^>]*>/i', $code, $result );1268 $url = iub_array_get( $result, 'href.0' );1269 1270 if ( ! $url ) {1271 return false;1272 }1273 1274 $button_style = strpos( stripslashes( $code ), 'iubenda-white' ) !== false ? 'white' : 'black';1275 $cookie_policy_id = basename( $url );1276 1277 return array(1278 'button_style' => $button_style,1279 'cookie_policy_id' => $cookie_policy_id,1280 );1281 }1282 1283 /**1284 1175 * Domain info helper function. 1285 1176 * … … 1443 1334 1444 1335 /** 1445 * Workaround to replace the callback functions with empty json array to parse configuration.1446 *1447 * @param string $code embed code.1448 *1449 * @return string|string[]1450 */1451 private function replace_the_callback_functions_to_parse_configuration( $code ) {1452 $callback_position = strpos( $code, 'callback' );1453 $opened_callback_braces = strpos( $code, '{', $callback_position );1454 $closing_callback_braces = $this->find_closing_bracket( $code, $opened_callback_braces );1455 1456 return substr_replace( $code, '{', $opened_callback_braces, $closing_callback_braces - $opened_callback_braces );1457 }1458 1459 /**1460 * Find closing bracket.1461 *1462 * @param string $target_string String.1463 * @param string $open_position Open Position.1464 *1465 * @return mixed1466 */1467 private function find_closing_bracket( $target_string, $open_position ) {1468 $close_pos = $open_position;1469 $counter = 1;1470 while ( $counter > 0 ) {1471 1472 // To Avoid the infinity loop.1473 if ( ! isset( $target_string[ $close_pos + 1 ] ) ) {1474 break;1475 }1476 1477 $c = $target_string[ ++$close_pos ];1478 if ( '{' === (string) $c ) {1479 ++$counter;1480 } elseif ( '}' === (string) $c ) {1481 --$counter;1482 }1483 }1484 1485 return $close_pos;1486 }1487 1488 /**1489 1336 * Compare between Iubenda DB version and This version and 1490 1337 * -
iubenda-cookie-law-solution/tags/beta/readme.txt
r3031643 r3050409 6 6 Requires PHP: 7.0.0 7 7 Tested up to: 6.4 8 Stable tag: 3.10. 08 Stable tag: 3.10.1 9 9 License: MIT License 10 10 License URI: http://opensource.org/licenses/MIT … … 268 268 == Changelog == 269 269 270 = 3.10.2-beta = 271 * Fix: DNS Lookup Optimization 272 273 = 3.10.1 = 274 * Prioritize the iubenda script over other scripts. 275 270 276 = 3.10.0 = 271 277 * Introduced iubenda automatic blocking feature. … … 851 857 == Upgrade Notice == 852 858 853 = 3.10. 0=854 * Introduced iubenda automatic blocking feature.859 = 3.10.2-beta = 860 * Fix: DNS Lookup Optimization
Note: See TracChangeset
for help on using the changeset viewer.