adblocker-enabled.js
2 years ago
adblocker-enabled.min.js
1 year ago
ga-adblock-counter.js
4 years ago
ga-adblock-counter.min.js
1 year ago
public.php
1 year ago
public.php
72 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Ad block finder module frontend helper class |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | */ |
| 8 | |
| 9 | use AdvancedAds\Options; |
| 10 | use AdvancedAds\Utilities\Conditional; |
| 11 | use AdvancedAds\Framework\Utilities\Arr; |
| 12 | |
| 13 | /** |
| 14 | * Class Advanced_Ads_Adblock_Finder |
| 15 | */ |
| 16 | class Advanced_Ads_Adblock_Finder { |
| 17 | |
| 18 | /** |
| 19 | * Advanced_Ads_Adblock_Finder constructor. |
| 20 | */ |
| 21 | public function __construct() { |
| 22 | add_action( 'wp_footer', [ $this, 'print_adblock_check_js' ], 9 ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Print the appropriate script into wp_footer. |
| 27 | * |
| 28 | * Don't print anything on AMP pages. |
| 29 | * Print minimal script if Advanced Ads Pro module "Ads for ad blockers" is active. |
| 30 | */ |
| 31 | public function print_adblock_check_js() { |
| 32 | if ( Conditional::is_amp() ) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | $options = Advanced_Ads::get_instance()->get_adblocker_options(); |
| 37 | $minified = ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG; |
| 38 | $ad_blocker_options = Options::instance()->get( 'adblocker' ); |
| 39 | |
| 40 | // if ad blocker counter is active. |
| 41 | if ( ! empty( $options['ga-UID'] ) ) { |
| 42 | printf( |
| 43 | '<script>(function(){var advanced_ads_ga_UID="%s",advanced_ads_ga_anonymIP=!!%d;%s})();</script>', |
| 44 | esc_attr( $options['ga-UID'] ), |
| 45 | esc_attr( |
| 46 | ! defined( 'ADVANCED_ADS_DISABLE_ANALYTICS_ANONYMIZE_IP' ) || |
| 47 | ! ADVANCED_ADS_DISABLE_ANALYTICS_ANONYMIZE_IP |
| 48 | ), |
| 49 | // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped,WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- escaping could break the script and we're getting the contents of a local file |
| 50 | $minified |
| 51 | ? file_get_contents( __DIR__ . '/ga-adblock-counter.min.js' ) |
| 52 | : file_get_contents( __DIR__ . '/adblocker-enabled.js' ) . file_get_contents( __DIR__ . '/ga-adblock-counter.js' ) |
| 53 | // phpcs:enable |
| 54 | ); |
| 55 | } elseif ( |
| 56 | defined( 'AAP_SLUG' ) |
| 57 | && ( |
| 58 | Options::instance()->get( 'adblocker.ads-for-adblockers.enabled' ) |
| 59 | || ( Arr::has( $ad_blocker_options, 'method' ) && 'nothing' !== $ad_blocker_options['method'] ) |
| 60 | ) |
| 61 | ) { |
| 62 | // if Advanced Ads Pro module "Ads for ad blockers" is active but no tracking. |
| 63 | // or if method is not "nothing". |
| 64 | printf( |
| 65 | '<script>%s</script>', |
| 66 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped,WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- escaping could break the script and we're getting the contents of a local file |
| 67 | file_get_contents( __DIR__ . '/adblocker-enabled' . ( $minified ? '.min' : '' ) . '.js' ) |
| 68 | ); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 |