Plugin Directory

Changeset 3050409


Ignore:
Timestamp:
03/13/2024 10:38:36 AM (2 years ago)
Author:
iubenda
Message:

Tagging 3.10.2-beta

Location:
iubenda-cookie-law-solution/tags/beta
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • iubenda-cookie-law-solution/tags/beta/includes/class-auto-blocking.php

    r3036419 r3050409  
    4444     */
    4545    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' );
    4747    }
    4848
     
    5555     */
    5656    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' );
    5858    }
    5959
     
    214214        wp_send_json( $this->is_autoblocking_feature_available( $site_id ) );
    215215    }
    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     }
    248216}
  • iubenda-cookie-law-solution/tags/beta/includes/class-iubenda-amp.php

    r3031643 r3050409  
    104104            }
    105105
    106             $configuration_raw = iubenda()->parse_configuration( $code );
     106            $configuration_raw = iubenda()->configuration_parser->extract_cs_config_from_code_amp( $code );
    107107
    108108            if ( isset( $configuration_raw['gdprAppliesGlobally'] ) && ! $configuration_raw['gdprAppliesGlobally'] ) {
     
    151151            }
    152152
    153             $configuration = iubenda()->parse_configuration( $code );
     153            $configuration = iubenda()->configuration_parser->extract_cs_config_from_code_amp( $code );
    154154
    155155            if ( empty( $configuration ) ) {
     
    287287        $html = '';
    288288
    289         $configuration_raw = iubenda()->parse_configuration( $code );
     289        $configuration_raw = iubenda()->configuration_parser->extract_cs_config_from_code_amp( $code );
    290290
    291291        if ( empty( $configuration_raw ) ) {
    292292            $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(
    297297            $code,
    298298            array(
  • iubenda-cookie-law-solution/tags/beta/includes/class-iubenda-settings.php

    r3031643 r3050409  
    10221022                $code = iub_array_get( iubenda()->options['cs'], "code_{$k}" );
    10231023                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' ) );
    10251025                    $style       = iub_array_get( $banner, 'backgroundColor' ) ? 'White' : 'Dark';
    10261026                    $legislation = ( new Iubenda_CS_Product_Service() )->get_legislation_from_embed_code( $code );
     
    11701170
    11711171                        // 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' );
    11741174                            // 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;
    11771177                            }
    11781178
    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;
    11821183                            }
    11831184                        }
    11841185
    11851186                        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 );
    11871188
    11881189                            // 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  
    141141                    $lang_id = substr( $index, 5 );
    142142
    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 
    151143                    $new_cs_option[ "manual_{$index}" ] = $option;
    152144                    $codes_statues[ $lang_id ]          = true;
     145
     146                    $cookie_policy_id = iubenda()->configuration_parser->retrieve_info_from_script_by_key( $option, 'cookiePolicyId' );
    153147                    // 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 );
    156150                    }
    157151
     152                    $site_id = iubenda()->configuration_parser->retrieve_info_from_script_by_key( $option, 'siteId' );
    158153                    // 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 );
    161156                    }
    162157
     
    170165                    }
    171166
    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 ) ) {
    175168                        // 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 );
    177170                    }
    178171                }
     
    279272     */
    280273    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 );
    282275        $legislation    = array();
    283276
  • iubenda-cookie-law-solution/tags/beta/includes/services/class-iubenda-pp-product-service.php

    r2922322 r3050409  
    6161                $codes_statues[]                    = true;
    6262            } else {
    63                 $parsed_code = iubenda()->parse_tc_pp_configuration( $code );
     63                $parsed_code = iubenda()->configuration_parser->extract_tc_pp_config_from_code( $code );
    6464                // check if code is empty or code is invalid.
    6565                $codes_statues[] = (bool) $parsed_code;
  • iubenda-cookie-law-solution/tags/beta/includes/services/class-iubenda-tc-product-service.php

    r2922322 r3050409  
    4545        foreach ( $languages as $lang_id => $v ) {
    4646            $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 );
    4848            // check if code is empty or code is invalid.
    4949            $codes_statues[] = (bool) $parsed_code;
  • iubenda-cookie-law-solution/tags/beta/iubenda_cookie_solution.php

    r3036419 r3050409  
    44 * Plugin URI: https://www.iubenda.com
    55 * 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.0
     6 * Version: 3.10.2-beta
    77 * Author: iubenda
    88 * Author URI: https://www.iubenda.com
     
    4646 *
    4747 * @class   iubenda
    48  * @version 3.10.0
     48 * @version 3.10.2-beta
    4949 */
    5050class iubenda {
     
    139139     * @var string
    140140     */
    141     public $version = '3.10.0';
     141    public $version = '3.10.2';
    142142
    143143    /**
     
    304304
    305305    /**
     306     * Class Iubenda_Configuration_Parser
     307     * Parses configurations from Iubenda code.
     308     *
     309     * @var Configuration_Parser
     310     */
     311    public $configuration_parser;
     312
     313    /**
    306314     * Disable object clone.
    307315     *
     
    349357            self::$instance->iub_auto_blocking         = new Auto_Blocking();
    350358            self::$instance->radar_dashboard_widget    = new Radar_Dashboard_Widget();
     359            self::$instance->configuration_parser      = new Configuration_Parser();
    351360        }
    352361
     
    523532    private function includes() {
    524533        include_once IUBENDA_PLUGIN_PATH . 'includes/functions.php';
     534        include_once IUBENDA_PLUGIN_PATH . 'includes/class-configuration-parser.php';
    525535        include_once IUBENDA_PLUGIN_PATH . 'includes/class-iubenda-settings.php';
    526536        include_once IUBENDA_PLUGIN_PATH . 'includes/class-iubenda-forms.php';
     
    11631173
    11641174    /**
    1165      * Get configuration data parsed from iubenda code
    1166      *
    1167      * @param   string $code  code.
    1168      * @param   array  $args  args.
    1169      *
    1170      * @return array
    1171      */
    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|false
    1258      */
    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     /**
    12841175     * Domain info helper function.
    12851176     *
     
    14431334
    14441335    /**
    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 mixed
    1466      */
    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     /**
    14891336     * Compare between Iubenda DB version and This version and
    14901337     *
  • iubenda-cookie-law-solution/tags/beta/readme.txt

    r3031643 r3050409  
    66Requires PHP: 7.0.0
    77Tested up to: 6.4
    8 Stable tag: 3.10.0
     8Stable tag: 3.10.1
    99License: MIT License
    1010License URI: http://opensource.org/licenses/MIT
     
    268268== Changelog ==
    269269
     270= 3.10.2-beta =
     271* Fix: DNS Lookup Optimization
     272
     273= 3.10.1 =
     274* Prioritize the iubenda script over other scripts.
     275
    270276= 3.10.0 =
    271277* Introduced iubenda automatic blocking feature.
     
    851857== Upgrade Notice ==
    852858
    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.