*/ final class Script { /** * The unique identifier of this plugin. * * @since 2.0.0 * @access protected * @var string $plugin_name The string used to uniquely identify this plugin. */ protected $plugin_name; /** * The current version of the plugin. * * @since 2.0.0 * @access protected * @var string $version The current version of the plugin. */ private $version; /** * No pub Class * * @since 2.0.0 * @access private * @var NoPub $no_pub The no pub class. */ private $no_pub; /** * Define the core functionality of the plugin. * * @since 2.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. * @param NoPub $no_pub The no pub class. */ public function __construct( $plugin_name, $version, $no_pub ) { $this->plugin_name = $plugin_name; $this->version = $version; $this->no_pub = $no_pub; if ( ACTIRISE_CRON !== 'true' ) { $this->update_fastcmp(); } } /** * Register all of the hooks related to the public-facing functionality * of the plugin. * * @since 2.0.0 * @return void */ public function head_integration() { /** @var string $uuid */ $uuid = Options::get( 'settings-uuid', '' ); /** @var string $type_tag */ $type_tag = Options::get( 'settings-uuid-type', 'boot' ); /** @var string $custom_value1 */ $custom_value1 = Options::get( 'custom1', '' ); /** @var string $custom_value2 */ $custom_value2 = Options::get( 'custom2', '' ); /** @var string $custom_value3 */ $custom_value3 = Options::get( 'custom3', '' ); /** @var string $custom_value4 */ $custom_value4 = Options::get( 'custom4', '' ); /** @var string $custom_value5 */ $custom_value5 = Options::get( 'custom5', '' ); $script_option = version_compare( get_bloginfo( 'version' ), '6.3', '>=' ) ? array( 'in_footer' => false, ) : false; if ( Options::get( 'fastcmp-enabled', false ) === true ) { $fastcmp_options = Helpers::get_fastcmp_options( true ); if ( $fastcmp_options['privacyPolicy'] !== '' && $fastcmp_options['uuid'] !== '' ) { /** @var string $exclude_iab_vendors */ $exclude_iab_vendors = wp_json_encode( $fastcmp_options['excludedIabVendors'] ); /** @var string $exclude_google_vendors */ $exclude_google_vendors = wp_json_encode( $fastcmp_options['excludedGoogleVendors'] ); $custom_vendor = ''; $custom_vendor_string = ''; if ( count( $fastcmp_options['customsVendor'] ) > 0 ) { $custom_vendor_string = '['; /** @var object{name: string, id: string} $customs_vendor */ foreach ( $fastcmp_options['customsVendor'] as $customs_vendor ) { $custom_vendor_string .= '{name: "' . esc_attr( $customs_vendor->name ) . '", id: "' . esc_attr( $customs_vendor->id ) . '"},'; } $custom_vendor_string = substr( $custom_vendor_string, 0, -1 ); $custom_vendor_string .= ']'; $custom_vendor .= 'custom: {vendors: ' . $custom_vendor_string . '},'; } $consentModeOptions = ''; if ( $fastcmp_options['googleTagsStatus'] === true ) { $consentModeDefaultOptions = sprintf( "{ ad_storage: '%s', analytics_storage: '%s', personalization_storage: '%s', functionality_storage: '%s', security_storage: '%s', ad_personalization: '%s', ad_user_data: '%s' }", $fastcmp_options['googleAdStorage'] === true ? 'granted' : 'denied', $fastcmp_options['googleAnalyticsStorage'] === true ? 'granted' : 'denied', $fastcmp_options['googlePersonalizationStorage'] === true ? 'granted' : 'denied', $fastcmp_options['googleFunctionalityStorage'] === true ? 'granted' : 'denied', $fastcmp_options['googleSecurityStorage'] === true ? 'granted' : 'denied', $fastcmp_options['googleAdPersonalization'] === true ? 'granted' : 'denied', $fastcmp_options['googleAdUserData'] === true ? 'granted' : 'denied' ); /** @var string $google_specific_data */ $google_specific_data = $fastcmp_options['googleSpecificData']; if ( $fastcmp_options['googleSpecificEnabled'] === true && ! is_wp_error( Helpers::cmp_consent_valid_code( $google_specific_data ) ) && ! empty( $google_specific_data ) ) { $consentModeOptions = sprintf( 'default: [ %s, %s ],', $consentModeDefaultOptions, $google_specific_data ); } else { $consentModeOptions = sprintf( 'default: %s,', $consentModeDefaultOptions ); } } $consentMode = sprintf( 'googleConsentMode: { enabled: %s, %s },', $fastcmp_options['consentV2'] === true ? 'true' : 'false', $consentModeOptions ); $consentMode = preg_replace( '/\s\s+/', '', $consentMode ); $fastcmp_config = sprintf( "window.FAST_CMP_OPTIONS = { domainUid: '%s', countryCode: '%s', policyUrl: '%s', displaySynchronous: false, publisherName: '%s', bootstrap: { excludedIABVendors: %s, excludedGoogleVendors: %s, }, jurisdiction: '%s', %s %s %s };", esc_js( $fastcmp_options['uuid'] ), esc_js( $fastcmp_options['headOffice'] ), esc_js( $fastcmp_options['privacyPolicy'] ), esc_js( $fastcmp_options['name'] ), esc_js( $exclude_iab_vendors ), esc_js( $exclude_google_vendors ), esc_js( $fastcmp_options['targetedAudience'] ), $consentMode, $fastcmp_options['logo'] !== '' ? "publisherLogo: function (c) { return c.createElement('img', { src: '" . $fastcmp_options['logo'] . "', height: '40' }) }," : '', $custom_vendor ); $stublight = $fastcmp_options['stubLight']; $fast_cmp_options_script = array( 'data-no-optimize' => '1', 'data-wpmeteor-nooptimize' => 'true', 'data-cfasync' => 'false', 'nowprocket' => '', ); if ( defined( 'WP_ROCKET_VERSION' ) === false ) { $fast_cmp_options_script['charset'] = 'UTF-8'; } wp_enqueue_script( 'fastcmp', 'https://static.fastcmp.com/fast-cmp-stub.js', array(), 'latest', $script_option ); wp_add_inline_script( 'fastcmp', $fastcmp_config . "\n" . $stublight, 'before' ); $fastcmp_options = Helpers::get_fastcmp_options( true ); $this->add_fastcmp_style( $fastcmp_options ); } } if ( $uuid === '' ) { return; } $presized_div_selected = $this->get_presized_slot_active(); $no_pub = $this->no_pub->check_no_pub() ? 'no_pub: true,' : ''; wp_enqueue_script( 'actirise', ACTIRISE_URL_FLASHBID . esc_js( $type_tag ) . '/' . esc_js( $uuid ) . '.js', array(), 'latest', $script_option ); $data_var = sprintf( "window._hbdbrk=window._hbdbrk||[];window._hbdbrk.push(['_vars', {page_type:'%s',pid:3,custom1:'%s',custom2:'%s',custom3:'%s',custom4:'%s',custom5:'%s',%s}]);", esc_attr( Helpers::get_page_type() ), esc_attr( Helpers::get_custom_value( $custom_value1, 'custom1' ) ), esc_attr( Helpers::get_custom_value( $custom_value2, 'custom2' ) ), esc_attr( Helpers::get_custom_value( $custom_value3, 'custom3' ) ), esc_attr( Helpers::get_custom_value( $custom_value4, 'custom4' ) ), esc_attr( Helpers::get_custom_value( $custom_value5, 'custom5' ) ), esc_attr( $no_pub ) ); /** @var string $adstxt_active */ $adstxt_active = Options::get( 'adstxt-active', false ) ? '1' : '0'; /** @var string $presizeddiv_active */ $presizeddiv_active = Options::get( 'presizeddiv-active', false ) ? '1' : '0'; /** @var string $adstxt_last_update */ $adstxt_last_update = Options::get( 'adstxt-lastupdate', '-1' ); /** @var string $presizeddiv_last_update */ $presizeddiv_last_update = Options::get( 'presizeddiv-lastupdate', '-1' ); /** @var string $presizeddiv_last_update */ $version_lastupdate = Options::get( 'version-lastupdate', '-1' ); $actirise_plugin = sprintf( "window.actirisePlugin=window.actirisePlugin||{};window.actirisePlugin.version='%s';window.actirisePlugin.version_lastupdate=%s;window.actirisePlugin.adsTxt={active:%s,lastUpdate:%s};window.actirisePlugin.presized={active:%s,lastUpdate:%s};window.actirisePlugin.cron=%s;window.actirisePlugin.fastcmp=%s;window.actirisePlugin.autoUpdate=%s;", esc_attr( $this->version ), esc_attr( $version_lastupdate === '-1' ? '-1' : 'new Date(' . $version_lastupdate . ' * 1000)' ), esc_attr( $adstxt_active ), esc_attr( $adstxt_last_update === '-1' ? '-1' : 'new Date(' . $adstxt_last_update . ' * 1000)' ), esc_attr( $presizeddiv_active ), esc_attr( $presizeddiv_last_update === '-1' ? '-1' : 'new Date(' . $presizeddiv_last_update . ' * 1000)' ), esc_attr( ( defined( 'ACTIRISE_CRON' ) && ACTIRISE_CRON === 'true' ) === true ? 'true' : 'false' ), esc_attr( Options::get( 'fastcmp-enabled', false ) === true ? 'true' : 'false' ), esc_attr( Helpers::has_auto_update() ? 'true' : 'false' ) ); wp_add_inline_script( 'actirise', $data_var . "\n" . $actirise_plugin, 'after' ); } /** * Change js attribute. * * @since 2.5.7 * @param string $tag The tag. * @param string $handle The handle. * @return string */ public function change_js_attribute( $tag, $handle ) { if ( 'actirise' === $handle ) { /** @var string $tag */ $tag = preg_replace( '#\sid=([\'"])actirise-js([\'"])#', '', $tag ); /** @var string $tag */ $tag = str_replace( 'src=', 'data-cfasync="false" defer src=', $tag ); /** @var string $tag */ $tag = preg_replace( '#\sid=([\'"])actirise-js-after([\'"])#', '', $tag ); /** @var string $tag */ $tag = preg_replace( '/\?ver=[0-9.a-z]+/', '', $tag ); } if ( 'fastcmp' === $handle ) { /** @var string $tag */ $tag = preg_replace( '#\sid=([\'"])fastcmp-js-before([\'"])#', ' data-no-optimize="1" data-wpmeteor-nooptimize="true" data-cfasync="false" nowprocket="" charset="UTF-8"', $tag ); /** @var string $tag */ $tag = str_replace( 'src=', 'async data-no-optimize="1" data-wpmeteor-nooptimize="true" data-cfasync="false" nowprocket="" charset="UTF-8" src=', $tag ); /** @var string $tag */ $tag = preg_replace( '#\sid=([\'"])fastcmp-js([\'"])#', '', $tag ); /** @var string $tag */ $tag = preg_replace( '/\?ver=[0-9.a-z]+/', '', $tag ); } return $tag; } /** * Get fastcmp style. * * @since 2.4.0 * @param array{acceptButtonStyle: array{bg: string, font: string}, declineButtonStyle: array{bg: string, border: string, font: string}, parametersButtonStyle: array{bg: string, border: string, font: string}, customStyle: string} $fastcmp_options The fastcmp options. * @return void */ public function add_fastcmp_style( $fastcmp_options ) { wp_register_style( 'fast-cmp-custom-styles', false, array(), $this->version ); wp_enqueue_style( 'fast-cmp-custom-styles' ); $custom_css = ''; if ( $fastcmp_options['acceptButtonStyle']['bg'] !== '' || $fastcmp_options['acceptButtonStyle']['font'] !== '' ) { $custom_css .= '#fast-cmp-container button.fast-cmp-button-primary{'; if ( $fastcmp_options['acceptButtonStyle']['bg'] !== '' ) { $custom_css .= 'background-color:' . esc_attr( $fastcmp_options['acceptButtonStyle']['bg'] ) . '!important;'; } if ( $fastcmp_options['acceptButtonStyle']['font'] !== '' ) { $custom_css .= 'color:' . esc_attr( $fastcmp_options['acceptButtonStyle']['font'] ) . '!important;'; } if ( $fastcmp_options['acceptButtonStyle']['bg'] === 'transparent' ) { $custom_css .= 'border: 1px solid ' . esc_attr( $fastcmp_options['acceptButtonStyle']['font'] ) . '!important;'; } $custom_css .= '}'; } if ( $fastcmp_options['acceptButtonStyle']['bg'] !== '' ) { $custom_css .= '#fast-cmp-container #fast-cmp-home button.fast-cmp-button-secondary{'; $custom_css .= 'box-shadow: inset 0 0 0 1px ' . esc_attr( $fastcmp_options['declineButtonStyle']['font'] ) . '!important;'; $custom_css .= '}'; $custom_css .= '#fast-cmp-container #fast-cmp-home button.fast-cmp-navigation-button{'; $custom_css .= 'box-shadow: inset 0 0 0 1px ' . esc_attr( $fastcmp_options['parametersButtonStyle']['font'] ) . '!important;'; $custom_css .= '}'; } if ( $fastcmp_options['declineButtonStyle']['bg'] !== '' || $fastcmp_options['declineButtonStyle']['font'] !== '' ) { $custom_css .= '#fast-cmp-container #fast-cmp-home button.fast-cmp-button-secondary{'; if ( $fastcmp_options['declineButtonStyle']['bg'] !== '' && $fastcmp_options['declineButtonStyle']['bg'] !== 'transparent' ) { $custom_css .= 'background-color:' . esc_attr( $fastcmp_options['declineButtonStyle']['bg'] ) . '!important;'; } if ( $fastcmp_options['declineButtonStyle']['font'] !== '' ) { $custom_css .= 'color:' . esc_attr( $fastcmp_options['declineButtonStyle']['font'] ) . '!important;'; } $custom_css .= '}'; } if ( $fastcmp_options['declineButtonStyle']['border'] !== '' ) { $custom_css .= '#fast-cmp-container #fast-cmp-home button.fast-cmp-button-secondary:hover{'; $custom_css .= 'box-shadow: inset 0 0 0 1px ' . esc_attr( $fastcmp_options['declineButtonStyle']['border'] ) . '!important;'; if ( $fastcmp_options['declineButtonStyle']['font'] !== '' ) { $custom_css .= 'color:' . esc_attr( $fastcmp_options['declineButtonStyle']['font'] ) . '!important;'; } $custom_css .= '}'; } if ( $fastcmp_options['parametersButtonStyle']['bg'] !== '' || $fastcmp_options['parametersButtonStyle']['font'] !== '' ) { $custom_css .= '#fast-cmp-container #fast-cmp-home button.fast-cmp-navigation-button{'; if ( $fastcmp_options['parametersButtonStyle']['bg'] !== '' && $fastcmp_options['parametersButtonStyle']['bg'] !== 'transparent' ) { $custom_css .= 'background-color:' . esc_attr( $fastcmp_options['parametersButtonStyle']['bg'] ) . '!important;'; } if ( $fastcmp_options['parametersButtonStyle']['font'] !== '' ) { $custom_css .= 'color:' . esc_attr( $fastcmp_options['parametersButtonStyle']['font'] ) . '!important;'; } $custom_css .= '}'; } if ( $fastcmp_options['parametersButtonStyle']['border'] !== '' ) { $custom_css .= '#fast-cmp-container #fast-cmp-home button.fast-cmp-navigation-button:hover{'; $custom_css .= 'box-shadow: inset 0 0 0 1px ' . esc_attr( $fastcmp_options['parametersButtonStyle']['border'] ) . '!important;'; if ( $fastcmp_options['parametersButtonStyle']['font'] !== '' ) { $custom_css .= 'color:' . esc_attr( $fastcmp_options['parametersButtonStyle']['font'] ) . '!important;'; } $custom_css .= '}'; } if ( $fastcmp_options['acceptButtonStyle']['bg'] !== '' ) { $border_color = $fastcmp_options['acceptButtonStyle']['bg'] === 'transparent' ? '#6f6f6f' : $fastcmp_options['acceptButtonStyle']['bg']; $font_color = $fastcmp_options['acceptButtonStyle']['bg'] === 'transparent' ? '#0065d9' : $fastcmp_options['acceptButtonStyle']['font']; $custom_css .= '#fast-cmp-container a {'; $custom_css .= 'color: ' . esc_attr( $font_color ) . '!important;'; $custom_css .= '}'; $custom_css .= '#fast-cmp-container .fast-cmp-layout-header .fast-cmp-navigation-button {'; $custom_css .= 'background-color: ' . esc_attr( $fastcmp_options['acceptButtonStyle']['bg'] ) . '!important;'; $custom_css .= 'color: white!important;'; $custom_css .= '}'; $custom_css .= '#fast-cmp-container #fast-cmp-consents .fast-cmp-layout-nav button.fast-cmp-navigation-button {'; $custom_css .= 'color: ' . esc_attr( $border_color ) . '!important;'; $custom_css .= 'box-shadow: inset 0 0 0 1px ' . esc_attr( $border_color ) . '!important;'; $custom_css .= '}'; $custom_css .= '#fast-cmp-form .fast-cmp-spinner {'; $custom_css .= 'border-left-color: ' . esc_attr( $font_color ) . '!important;'; $custom_css .= '}'; $custom_css .= '#fast-cmp-container button.fast-cmp-button-primary:focus {'; $custom_css .= 'border-color: ' . esc_attr( $border_color ) . '!important;'; $custom_css .= 'box-shadow: inset 0 0 0 2px ' . esc_attr( $border_color ) . ', inset 0 0 0 4px #fff!important;'; $custom_css .= 'outline: solid transparent !important;'; $custom_css .= '}'; } $fastcmp_options['customStyle'] = preg_replace( '/\s\s+/', '', $fastcmp_options['customStyle'] ); if ( ! is_null( $fastcmp_options['customStyle'] ) && $fastcmp_options['customStyle'] !== '' ) { $custom_css .= trim( $fastcmp_options['customStyle'] ); } wp_add_inline_style( 'fast-cmp-custom-styles', $custom_css ); } /** * Get presized slot active. * * @since 2.0.0 * @return array */ private function get_presized_slot_active() { $presized_div = get_option( $this->plugin_name . '-presizeddiv-selected', array() ); if ( ! is_array( $presized_div ) ) { $presized_div = array(); } return $presized_div; } /** * Update fastcmp. * * @since 2.2.0 * @return void */ private function update_fastcmp() { $cron = new Cron(); $cron->check_scheduled_task_with_transient( 'get_fast_cmp', array( $cron, 'get_fast_cmp', ) ); } }